Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(backend): include backend dependencies in paths #2893

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading