Skip to content

Commit

Permalink
fix: elixir installation failed
Browse files Browse the repository at this point in the history
  • Loading branch information
roele committed Jan 21, 2025
1 parent de703d8 commit 3a8beb5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
35 changes: 35 additions & 0 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,33 @@ pub trait Backend: Debug + Send + Sync {
Ok(ts)
}

fn dependency_toolset_with_ctx(&self, ctx: &InstallContext) -> eyre::Result<Toolset> {
let config = Config::get();
let dependencies: HashSet<String> = 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<PathBuf> {
file::which_non_pristine(bin).or_else(|| {
self.dependency_toolset()
Expand All @@ -603,6 +630,14 @@ pub trait Backend: Debug + Send + Sync {
self.dependency_toolset()?.full_env(&config)
}

fn dependency_env_with_ctx(
&self,
ctx: &InstallContext,
) -> eyre::Result<BTreeMap<String, String>> {
let config = Config::get();
self.dependency_toolset_with_ctx(ctx)?.full_env(&config)
}

fn fuzzy_match_filter(&self, versions: Vec<String>, query: &str) -> eyre::Result<Vec<String>> {
let escaped_query = regex::escape(query);
let query = if query == "latest" {
Expand Down
1 change: 1 addition & 0 deletions src/cli/install_into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/install_context.rs
Original file line number Diff line number Diff line change
@@ -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<Vec<ToolRequest>>,
pub ts: &'a Toolset,
pub pr: Box<dyn SingleReport>,
pub force: bool,
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/core/elixir.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use std::collections::HashSet;
use std::path::{Path, PathBuf};

use crate::backend::Backend;
use crate::cli::args::BackendArg;
use crate::cmd::CmdLineRunner;
use crate::config::Config;
use crate::http::{HTTP, HTTP_FETCH};
use crate::install_context::InstallContext;
use crate::plugins::VERSION_REGEX;
use crate::toolset::ToolVersion;
use crate::toolset::{ToolSource, ToolVersion, Toolset};
use crate::ui::progress_report::SingleReport;
use crate::{file, plugins};
use eyre::Result;
Expand Down Expand Up @@ -34,7 +36,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()
}
Expand Down
7 changes: 5 additions & 2 deletions src/toolset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,15 @@ 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() {
if leaf_deps.len() < versions.len() {
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)?;
}

Expand Down Expand Up @@ -278,6 +279,7 @@ impl Toolset {

fn install_some_versions(
&mut self,
tool_request: &Vec<ToolRequest>,
versions: Vec<ToolRequest>,
mpr: &MultiProgressReport,
opts: &InstallOptions,
Expand Down Expand Up @@ -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.clone()),
ts,
pr: mpr.add(&tv.style()),
force: opts.force,
Expand Down

0 comments on commit 3a8beb5

Please sign in to comment.