Skip to content

Commit

Permalink
fix: ensure that the base directory is applied as "current"
Browse files Browse the repository at this point in the history
Trunk claims that the base directory of the configuration is considered
the "current" directory. However, for some cargo features, setting
--manifest-path is not enough. So we do apply the base dir explicitly.
  • Loading branch information
ctron committed Aug 7, 2024
1 parent a62b3a3 commit 0cd0f50
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
11 changes: 9 additions & 2 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,19 @@ pub fn strip_prefix(target: &Path) -> &Path {

/// Run a global command with the given arguments and make sure it completes successfully. If it
/// fails an error is returned.
#[tracing::instrument(level = "trace", skip(name, path, args))]
#[tracing::instrument(level = "trace", skip(name, args))]
pub async fn run_command(
name: &str,
path: &Path,
path: impl AsRef<Path> + Debug,
args: &[impl AsRef<OsStr> + Debug],
working_dir: impl AsRef<Path> + Debug,
) -> Result<()> {
tracing::debug!(?args, "{name} args");

let path = path.as_ref();

let status = Command::new(path)
.current_dir(working_dir.as_ref())
.args(args)
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
Expand All @@ -181,12 +186,14 @@ pub async fn run_command(
.wait()
.await
.with_context(|| format!("error during {name} call"))?;

if !status.success() {
bail!(
"{name} call to executable '{}' with args: '{args:?}' returned a bad status: {status}",
path.display()
);
}

Ok(())
}

Expand Down
16 changes: 11 additions & 5 deletions src/pipelines/rust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ impl RustApp {
}
}

let build_res = common::run_command("cargo", Path::new("cargo"), &args)
let build_res = common::run_command("cargo", "cargo", &args, &self.cfg.working_directory)
.await
.context("error during cargo build execution");

Expand All @@ -423,6 +423,7 @@ impl RustApp {
tracing::debug!("fetching cargo artifacts");
args.push("--message-format=json");
let artifacts_out = Command::new("cargo")
.current_dir(&self.cfg.core.working_directory)
.args(args.as_slice())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
Expand Down Expand Up @@ -536,9 +537,14 @@ impl RustApp {

// Invoke wasm-bindgen.
tracing::debug!("calling wasm-bindgen for {}", self.name);
common::run_command(wasm_bindgen_name, &wasm_bindgen, &args)
.await
.map_err(|err| check_target_not_found_err(err, wasm_bindgen_name))?;
common::run_command(
wasm_bindgen_name,
&wasm_bindgen,
&args,
&self.cfg.working_directory,
)
.await
.map_err(|err| check_target_not_found_err(err, wasm_bindgen_name))?;

// Copy the generated WASM & JS loader to the dist dir.
tracing::debug!("copying generated wasm-bindgen artifacts");
Expand Down Expand Up @@ -875,7 +881,7 @@ impl RustApp {

// Invoke wasm-opt.
tracing::debug!("calling wasm-opt");
common::run_command(wasm_opt_name, &wasm_opt, &args)
common::run_command(wasm_opt_name, &wasm_opt, &args, &self.cfg.working_directory)
.await
.map_err(|err| check_target_not_found_err(err, wasm_opt_name))?;

Expand Down
8 changes: 7 additions & 1 deletion src/pipelines/sass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,13 @@ impl Sass {

let rel_path = common::strip_prefix(&self.asset.path);
tracing::debug!(path = ?rel_path, "compiling sass/scss");
common::run_command(Application::Sass.name(), &sass, args).await?;
common::run_command(
Application::Sass.name(),
&sass,
args,
&self.cfg.working_directory,
)
.await?;

let css = fs::read_to_string(&temp_target_file_path)
.await
Expand Down
8 changes: 7 additions & 1 deletion src/pipelines/tailwind_css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ impl TailwindCss {

let rel_path = common::strip_prefix(&self.asset.path);
tracing::debug!(path = ?rel_path, "compiling tailwind css");
common::run_command(Application::TailwindCss.name(), &tailwind, &args).await?;
common::run_command(
Application::TailwindCss.name(),
&tailwind,
&args,
&self.cfg.working_directory,
)
.await?;

let css = fs::read_to_string(&file_path).await?;
fs::remove_file(&file_path).await?;
Expand Down

0 comments on commit 0cd0f50

Please sign in to comment.