diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 08d0ada271..0b8e174834 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -18,7 +18,9 @@ use crate::plugins::{Plugin, PluginType, VERSION_REGEX}; use crate::registry::REGISTRY; use crate::runtime_symlinks::is_runtime_symlink; use crate::toolset::outdated_info::OutdatedInfo; -use crate::toolset::{install_state, is_outdated_version, ToolRequest, ToolVersion, Toolset}; +use crate::toolset::{ + install_state, is_outdated_version, ToolRequest, ToolSource, ToolVersion, Toolset, +}; use crate::ui::progress_report::SingleReport; use crate::{dirs, env, file, hash, lock_file, plugins, versions_host}; use backend_type::BackendType; @@ -588,6 +590,33 @@ pub trait Backend: Debug + Send + Sync { Ok(ts) } + fn dependency_toolset_with_ctx(&self, ctx: &InstallContext) -> eyre::Result { + let config = Config::get(); + let dependencies: HashSet = self + .get_all_dependencies(true)? + .into_iter() + .map(|ba| ba.short) + .collect(); + let mut ts: Toolset = config + .get_tool_request_set()? + .filter_by_tool(dependencies.clone()) + .into(); + let tr_args = match &ctx.tr { + Some(tr) => tr + .into_iter() + .filter(|tr| dependencies.contains(&tr.ba().short)) + .collect(), + None => vec![], + }; + let mut ts_args = Toolset::new(ToolSource::Unknown); + for tr in tr_args { + ts_args.add_version(tr.clone()); + } + ts.merge(ts_args); + ts.resolve()?; + Ok(ts) + } + fn dependency_which(&self, bin: &str) -> Option { file::which_non_pristine(bin).or_else(|| { self.dependency_toolset() @@ -603,6 +632,14 @@ pub trait Backend: Debug + Send + Sync { self.dependency_toolset()?.full_env(&config) } + fn dependency_env_with_ctx( + &self, + ctx: &InstallContext, + ) -> eyre::Result> { + let config = Config::get(); + self.dependency_toolset_with_ctx(ctx)?.full_env(&config) + } + fn fuzzy_match_filter(&self, versions: Vec, query: &str) -> eyre::Result> { let escaped_query = regex::escape(query); let query = if query == "latest" { diff --git a/src/cli/install_into.rs b/src/cli/install_into.rs index 826ef8cdb3..4af3d01d2c 100644 --- a/src/cli/install_into.rs +++ b/src/cli/install_into.rs @@ -40,6 +40,7 @@ impl InstallInto { let backend = tv.backend()?; let mpr = MultiProgressReport::get(); let install_ctx = InstallContext { + tr: None, ts: &ts, pr: mpr.add(&tv.style()), force: true, diff --git a/src/install_context.rs b/src/install_context.rs index 20b6f05fa9..41878e4a58 100644 --- a/src/install_context.rs +++ b/src/install_context.rs @@ -1,7 +1,8 @@ -use crate::toolset::Toolset; +use crate::toolset::{ToolRequest, Toolset}; use crate::ui::progress_report::SingleReport; pub struct InstallContext<'a> { + pub tr: Option>, pub ts: &'a Toolset, pub pr: Box, pub force: bool, diff --git a/src/plugins/core/elixir.rs b/src/plugins/core/elixir.rs index 9cbbdaf43f..ccba717ea9 100644 --- a/src/plugins/core/elixir.rs +++ b/src/plugins/core/elixir.rs @@ -34,7 +34,7 @@ impl ElixirPlugin { ctx.pr.set_message("elixir --version".into()); CmdLineRunner::new(self.elixir_bin(tv)) .with_pr(&ctx.pr) - .envs(self.dependency_env()?) + .envs(self.dependency_env_with_ctx(&ctx)?) .arg("--version") .execute() } diff --git a/src/toolset/mod.rs b/src/toolset/mod.rs index fb43010886..7568d85221 100644 --- a/src/toolset/mod.rs +++ b/src/toolset/mod.rs @@ -235,6 +235,7 @@ impl Toolset { hooks::run_one_hook(self, Hooks::Preinstall, None); self.init_request_options(&mut versions); show_python_install_hint(&versions); + let tool_request = versions.clone(); let mut installed = vec![]; let mut leaf_deps = get_leaf_dependencies(&versions)?; while !leaf_deps.is_empty() { @@ -242,7 +243,7 @@ impl Toolset { debug!("installing {} leaf tools first", leaf_deps.len()); } versions.retain(|tr| !leaf_deps.contains(tr)); - installed.extend(self.install_some_versions(leaf_deps, mpr, opts)?); + installed.extend(self.install_some_versions(&tool_request, leaf_deps, mpr, opts)?); leaf_deps = get_leaf_dependencies(&versions)?; } @@ -278,6 +279,7 @@ impl Toolset { fn install_some_versions( &mut self, + tool_request: &[ToolRequest], versions: Vec, mpr: &MultiProgressReport, opts: &InstallOptions, @@ -319,9 +321,10 @@ impl Toolset { let next_job = || queue.lock().unwrap().pop(); let mut installed = vec![]; while let Some((t, versions)) = next_job() { - for tr in versions { + for tr in versions.clone() { let tv = tr.resolve(&opts.resolve_options)?; let ctx = InstallContext { + tr: Some(tool_request.to_owned()), ts, pr: mpr.add(&tv.style()), force: opts.force,