#[cfg(unix)]
use ic_host_process::testing::write_executable_script;
use std::path::PathBuf;
pub fn unique_temp_directory(label: &str) -> PathBuf {
ic_host_fs::testing::create_fixture_directory(
&std::env::temp_dir(),
&format!("ic-testkit-{label}"),
)
.expect("create test directory")
}
#[cfg(unix)]
pub(super) fn fake_wasm_build_spec(label: &str) -> (PathBuf, super::wasm_cache::WasmBuildSpec) {
let root = unique_temp_directory(label);
crate::cargo_fixture::write_workspace(&root, &["fixture"]).expect("write workspace manifest");
crate::cargo_fixture::write_fixture_package(
&root.join("fixture"),
"[lib]\ncrate-type = [\"cdylib\"]\n",
"pub fn value() -> u8 { 1 }\n",
)
.expect("write fixture package");
let cargo = std::env::var_os("CARGO").unwrap_or_else(|| "cargo".into());
let quoted_cargo = format!("'{}'", cargo.to_string_lossy().replace('\'', "'\"'\"'"));
let wrapper = root.join("cargo.sh");
write_executable_script(
&wrapper,
format!(
r#"#!/bin/sh
set -eu
if [ "$1" = build ]; then
target="$CARGO_TARGET_DIR"
mkdir -p "$target/wasm32-unknown-unknown/debug"
printf '\000asm\001\000\000\000' > "$target/wasm32-unknown-unknown/debug/fixture.wasm"
exit 0
fi
exec {quoted_cargo} "$@"
"#
),
)
.expect("write executable test script");
let spec =
super::wasm_cache::WasmBuildSpec::new(&root, &root.join("exact"), &["fixture"], "debug")
.with_isolated_builds()
.with_cargo_program(wrapper);
(root, spec)
}