Skip to content

Commit

Permalink
fix: resolve bug with backends not resolving mise-installed tools (#2059
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jdx authored May 12, 2024
1 parent 273c73d commit ef1da53
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 8 deletions.
35 changes: 34 additions & 1 deletion src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ use eyre::Context;
use signal_hook::consts::{SIGHUP, SIGINT, SIGQUIT, SIGTERM, SIGUSR1, SIGUSR2};
use signal_hook::iterator::Signals;

use crate::config::Settings;
use crate::config::{Config, Settings};
use crate::env;
use crate::errors::Error::ScriptFailed;
use crate::file::display_path;
use crate::toolset::ToolsetBuilder;
use crate::ui::progress_report::SingleReport;

/// Create a command with any number of of positional arguments, which may be
Expand Down Expand Up @@ -50,6 +51,17 @@ macro_rules! cmd {
};
}

#[macro_export]
macro_rules! cmd_env {
( $program:expr $(, $arg:expr )* $(,)? ) => {
{
use std::ffi::OsString;
let args: std::vec::Vec<OsString> = std::vec![$( Into::<OsString>::into($arg) ),*];
$crate::cmd::cmd_env($program, args)
}
};
}

/// Create a command with any number of of positional arguments, which may be
/// different types (anything that implements
/// [`Into<OsString>`](https://doc.rust-lang.org/std/convert/trait.From.html)).
Expand Down Expand Up @@ -91,6 +103,27 @@ where
duct::cmd(program, args)
}

/// run a command with mise env setup
pub fn cmd_env<T, U>(program: T, args: U) -> Expression
where
T: IntoExecutablePath,
U: IntoIterator,
U::Item: Into<OsString>,
{
let config = Config::get();
let mut env = env::PRISTINE_ENV.clone();
match ToolsetBuilder::new()
.build(&config)
.and_then(|ts| ts.env_with_path(&config))
{
Ok(mise_env) => env.extend(mise_env),
Err(e) => {
debug!("failed to build toolset: {e}");
}
}
cmd(program, args).full_env(env)
}

pub struct CmdLineRunner<'a> {
cmd: Command,
pr: Option<&'a dyn SingleReport>,
Expand Down
2 changes: 1 addition & 1 deletion src/forge/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Forge for CargoForge {
.arg("--root")
.arg(ctx.tv.install_path())
.with_pr(ctx.pr.as_ref())
.envs(config.env()?)
.envs(ctx.ts.env_with_path(&config)?)
.prepend_path(ctx.ts.list_paths())?
.execute()?;

Expand Down
5 changes: 3 additions & 2 deletions src/forge/go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ impl Forge for GoForge {
let mut mod_path = Some(self.name());

while let Some(cur_mod_path) = mod_path {
let res = cmd!("go", "list", "-m", "-versions", "-json", cur_mod_path).read();
let res =
cmd_env!("go", "list", "-m", "-versions", "-json", cur_mod_path).read();
if let Ok(raw) = res {
let res = serde_json::from_str::<GoModInfo>(&raw);
if let Ok(mut mod_info) = res {
Expand Down Expand Up @@ -84,7 +85,7 @@ impl Forge for GoForge {
.arg("install")
.arg(&format!("{}@{}", self.name(), version))
.with_pr(ctx.pr.as_ref())
.envs(config.env()?)
.envs(ctx.ts.env_with_path(&config)?)
.env("GOBIN", ctx.tv.install_path().join("bin"))
.execute()?;

Expand Down
4 changes: 2 additions & 2 deletions src/forge/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Forge for NPMForge {
fn latest_stable_version(&self) -> eyre::Result<Option<String>> {
self.latest_version_cache
.get_or_try_init(|| {
let raw = cmd!("npm", "view", self.name(), "dist-tags", "--json").read()?;
let raw = cmd_env!("npm", "view", self.name(), "dist-tags", "--json").read()?;
let dist_tags: Value = serde_json::from_str(&raw)?;
let latest = match dist_tags["latest"] {
Value::String(ref s) => Some(s.clone()),
Expand Down Expand Up @@ -77,7 +77,7 @@ impl Forge for NPMForge {
.arg("--prefix")
.arg(ctx.tv.install_path())
.with_pr(ctx.pr.as_ref())
.envs(config.env()?)
.envs(ctx.ts.env_with_path(&config)?)
.prepend_path(ctx.ts.list_paths())?
.execute()?;

Expand Down
2 changes: 1 addition & 1 deletion src/forge/pipx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Forge for PIPXForge {
.with_pr(ctx.pr.as_ref())
.env("PIPX_HOME", ctx.tv.install_path())
.env("PIPX_BIN_DIR", ctx.tv.install_path().join("bin"))
.envs(config.env()?)
.envs(ctx.ts.env_with_path(&config)?)
.prepend_path(ctx.ts.list_paths())?
// Prepend install path so pipx doesn't issue a warning about missing path
.prepend_path(vec![ctx.tv.install_path().join("bin")])?
Expand Down
2 changes: 1 addition & 1 deletion src/forge/ubi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Forge for UbiForge {
.arg("--project")
.arg(self.name())
.with_pr(ctx.pr.as_ref())
.envs(config.env()?)
.envs(ctx.ts.env_with_path(&config)?)
.prepend_path(ctx.ts.list_paths())?;

if name_is_url(self.name()) {
Expand Down
1 change: 1 addition & 0 deletions src/toolset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ impl Toolset {
t.install_version(ctx)?;
installed.push(tv);
}
installing.lock().unwrap().remove(t.id());
}
Ok(installed)
})
Expand Down

0 comments on commit ef1da53

Please sign in to comment.