diff --git a/meson.build b/meson.build index 21a08b3..58e1e8f 100644 --- a/meson.build +++ b/meson.build @@ -2,6 +2,7 @@ project( 'depot', version: '0.16.1', meson_version: '>=0.60.0', + default_options: ['buildtype=release'], ) fs = import('fs') @@ -79,6 +80,8 @@ test( cargo.full_path(), src_root, build_root, + cargo_profile, + cargo_release ? '1' : '0', ], suite: ['cargo'], timeout: 0, diff --git a/src/shell_helpers.rs b/src/shell_helpers.rs index dc03f6f..d0b173a 100644 --- a/src/shell_helpers.rs +++ b/src/shell_helpers.rs @@ -21,7 +21,15 @@ pub struct ShellHelpers { impl ShellHelpers { /// Create helper commands for a given staging tree (`DESTDIR`). pub fn new(destdir: &Path) -> Result { - let tempdir = tempfile::tempdir().context("Failed to create shell helper tempdir")?; + let helper_root = destdir.join(INTERNAL_DEPOT_DIR).join("helpers"); + fs::create_dir_all(&helper_root).with_context(|| { + format!( + "Failed to create shell helper root dir: {}", + helper_root.display() + ) + })?; + let tempdir = + tempfile::tempdir_in(&helper_root).context("Failed to create shell helper tempdir")?; let bin_dir = tempdir.path().join("bin"); fs::create_dir_all(&bin_dir) .with_context(|| format!("Failed to create helper bin dir: {}", bin_dir.display()))?; @@ -241,7 +249,8 @@ printf '%s\n' "$path" #[cfg(test)] mod tests { - use super::shell_ident_suffix; + use super::{INTERNAL_DEPOT_DIR, ShellHelpers, shell_ident_suffix}; + use tempfile::tempdir; #[test] fn shell_ident_suffix_normalizes_package_names() { @@ -250,4 +259,26 @@ mod tests { assert_eq!(shell_ident_suffix("3foo"), "_3FOO"); assert_eq!(shell_ident_suffix("foo.bar+baz"), "FOO_BAR_BAZ"); } + + #[test] + fn shell_helpers_use_destdir_internal_helper_dir() { + let destdir = tempdir().unwrap(); + let helpers = ShellHelpers::new(destdir.path()).unwrap(); + let mut envs = Vec::new(); + helpers.apply_to_env_vars(&mut envs); + + let path = envs + .iter() + .find(|(key, _)| key == "PATH") + .map(|(_, value)| value) + .unwrap(); + + let helper_prefix = destdir + .path() + .join(INTERNAL_DEPOT_DIR) + .join("helpers") + .to_string_lossy() + .into_owned(); + assert!(path.starts_with(&helper_prefix)); + } } diff --git a/tools/meson/cargo-test.sh b/tools/meson/cargo-test.sh index 1d13200..290e21c 100644 --- a/tools/meson/cargo-test.sh +++ b/tools/meson/cargo-test.sh @@ -1,14 +1,16 @@ #!/bin/sh set -eu -if [ "$#" -ne 3 ]; then - echo "usage: $0 " >&2 +if [ "$#" -ne 5 ]; then + echo "usage: $0 " >&2 exit 2 fi cargo_bin="$1" src_root="$2" build_root="$3" +profile="$4" +release_flag="$5" cargo_home="$build_root/cargo-home" cargo_target_dir="$build_root/cargo-target" @@ -18,4 +20,8 @@ mkdir -p "$cargo_home" "$cargo_target_dir" export CARGO_HOME="$cargo_home" export CARGO_TARGET_DIR="$cargo_target_dir" +if [ "$release_flag" = "1" ]; then + exec "$cargo_bin" test --locked --manifest-path "$src_root/Cargo.toml" --profile "$profile" +fi + exec "$cargo_bin" test --locked --manifest-path "$src_root/Cargo.toml"