feat: enhance cargo test script to support profile and release flag
This commit is contained in:
@@ -2,6 +2,7 @@ project(
|
|||||||
'depot',
|
'depot',
|
||||||
version: '0.16.1',
|
version: '0.16.1',
|
||||||
meson_version: '>=0.60.0',
|
meson_version: '>=0.60.0',
|
||||||
|
default_options: ['buildtype=release'],
|
||||||
)
|
)
|
||||||
|
|
||||||
fs = import('fs')
|
fs = import('fs')
|
||||||
@@ -79,6 +80,8 @@ test(
|
|||||||
cargo.full_path(),
|
cargo.full_path(),
|
||||||
src_root,
|
src_root,
|
||||||
build_root,
|
build_root,
|
||||||
|
cargo_profile,
|
||||||
|
cargo_release ? '1' : '0',
|
||||||
],
|
],
|
||||||
suite: ['cargo'],
|
suite: ['cargo'],
|
||||||
timeout: 0,
|
timeout: 0,
|
||||||
|
|||||||
+33
-2
@@ -21,7 +21,15 @@ pub struct ShellHelpers {
|
|||||||
impl ShellHelpers {
|
impl ShellHelpers {
|
||||||
/// Create helper commands for a given staging tree (`DESTDIR`).
|
/// Create helper commands for a given staging tree (`DESTDIR`).
|
||||||
pub fn new(destdir: &Path) -> Result<Self> {
|
pub fn new(destdir: &Path) -> Result<Self> {
|
||||||
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");
|
let bin_dir = tempdir.path().join("bin");
|
||||||
fs::create_dir_all(&bin_dir)
|
fs::create_dir_all(&bin_dir)
|
||||||
.with_context(|| format!("Failed to create helper bin dir: {}", bin_dir.display()))?;
|
.with_context(|| format!("Failed to create helper bin dir: {}", bin_dir.display()))?;
|
||||||
@@ -241,7 +249,8 @@ printf '%s\n' "$path"
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::shell_ident_suffix;
|
use super::{INTERNAL_DEPOT_DIR, ShellHelpers, shell_ident_suffix};
|
||||||
|
use tempfile::tempdir;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn shell_ident_suffix_normalizes_package_names() {
|
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("3foo"), "_3FOO");
|
||||||
assert_eq!(shell_ident_suffix("foo.bar+baz"), "FOO_BAR_BAZ");
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
if [ "$#" -ne 3 ]; then
|
if [ "$#" -ne 5 ]; then
|
||||||
echo "usage: $0 <cargo> <src_root> <build_root>" >&2
|
echo "usage: $0 <cargo> <src_root> <build_root> <profile> <release_flag>" >&2
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cargo_bin="$1"
|
cargo_bin="$1"
|
||||||
src_root="$2"
|
src_root="$2"
|
||||||
build_root="$3"
|
build_root="$3"
|
||||||
|
profile="$4"
|
||||||
|
release_flag="$5"
|
||||||
|
|
||||||
cargo_home="$build_root/cargo-home"
|
cargo_home="$build_root/cargo-home"
|
||||||
cargo_target_dir="$build_root/cargo-target"
|
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_HOME="$cargo_home"
|
||||||
export CARGO_TARGET_DIR="$cargo_target_dir"
|
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"
|
exec "$cargo_bin" test --locked --manifest-path "$src_root/Cargo.toml"
|
||||||
|
|||||||
Reference in New Issue
Block a user