Skip to content

Commit

Permalink
fix(backend): include backend dependencies in paths (#2893)
Browse files Browse the repository at this point in the history
* fix(backend): include backend dependencies in paths

* fix(shims): remove workaround for infinite loop in shims
  • Loading branch information
risu729 authored Nov 5, 2024
1 parent a1cdc4b commit f64181b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 21 deletions.
3 changes: 1 addition & 2 deletions src/backend/go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ impl Backend for GoBackend {
self.remote_version_cache
.get_or_try_init(|| {
let mut mod_path = Some(self.name());
let env = self.dependency_env()?;

while let Some(cur_mod_path) = mod_path {
let res = cmd!("go", "list", "-m", "-versions", "-json", cur_mod_path)
.full_env(&env)
.full_env(self.dependency_env()?)
.read();
if let Ok(raw) = res {
let res = serde_json::from_str::<GoModInfo>(&raw);
Expand Down
4 changes: 3 additions & 1 deletion src/backend/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ impl Backend for NPMBackend {
fn _list_remote_versions(&self) -> eyre::Result<Vec<String>> {
self.remote_version_cache
.get_or_try_init(|| {
let raw = cmd!(PROGRAM, "view", self.name(), "versions", "--json").read()?;
let raw = cmd!(PROGRAM, "view", self.name(), "versions", "--json")
.full_env(self.dependency_env()?)
.read()?;
let versions: Vec<String> = serde_json::from_str(&raw)?;
Ok(versions)
})
Expand Down
5 changes: 4 additions & 1 deletion src/backend/spm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ impl SPMBackend {
"--package-path",
&repo_dir
)
.full_env(self.dependency_env()?)
.read()?;
let executables = serde_json::from_str::<PackageDescription>(&package_json)
.wrap_err("Failed to parse package description")?
Expand Down Expand Up @@ -153,7 +154,8 @@ impl SPMBackend {
.arg(executable)
.arg("--package-path")
.arg(repo_dir)
.with_pr(ctx.pr.as_ref());
.with_pr(ctx.pr.as_ref())
.prepend_path(self.dependency_toolset()?.list_paths())?;
build_cmd.execute()?;
let bin_path = cmd!(
"swift",
Expand All @@ -166,6 +168,7 @@ impl SPMBackend {
&repo_dir,
"--show-bin-path"
)
.full_env(self.dependency_env()?)
.read()?;
Ok(PathBuf::from(bin_path.trim().to_string()))
}
Expand Down
17 changes: 0 additions & 17 deletions src/shims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub fn handle_shim() -> Result<()> {
let args = env::ARGS.read().unwrap();
trace!("shim[{bin_name}] args: {}", args.join(" "));
let mut args: Vec<OsString> = args.iter().map(OsString::from).collect();
remove_shim_dir_from_path();
args[0] = which_shim(&env::MISE_BIN_NAME)?.into();
env::set_var("__MISE_SHIM", "1");
let exec = Exec {
Expand Down Expand Up @@ -272,22 +271,6 @@ fn make_shim(target: &Path, shim: &Path) -> Result<()> {
Ok(())
}

/// prevent shims from being called in a loop
fn remove_shim_dir_from_path() {
let path = env::var_os(&*env::PATH_KEY).unwrap_or_default();
let paths = env::split_paths(&path).filter(|p| {
p != *dirs::SHIMS
&& !p
.canonicalize()
.is_ok_and(|p| p == dirs::SHIMS.canonicalize().unwrap_or_default())
});
let path = env::join_paths(paths)
.unwrap()
.to_string_lossy()
.to_string();
env::set_var(&*env::PATH_KEY, &path);
}

fn err_no_version_set(ts: Toolset, bin_name: &str, tvs: Vec<ToolVersion>) -> Result<PathBuf> {
if tvs.is_empty() {
bail!("{} is not a valid shim", bin_name);
Expand Down

0 comments on commit f64181b

Please sign in to comment.