Skip to content

Commit 542ab53

Browse files
committed
tests.rs: Read executable binary location from environment at runtime
This commit changes how the `CARGO_BIN_EXE_coreutils` environment variable is read. Previously, it was read using the `env!` macro, which returns the value of the variable as exposed by cargo during compilation. The problem with that is that it renders the process of testing for cross compiled targets, similar to what build systems like Yocto do, more difficult. The solution to this is to read said variable at runtime and if it is not defined, to default to the version offered by cargo. This way ensures that first of all, current functionality remains unchanged and that the code can be more easily cross compiled and tested in environments outside of cargo. Also, this commit closes #9246 . Signed-off-by: Andreas Stergiopoulos <andreas.stergiopoulos@smile.fr>
1 parent 9f28bf0 commit 542ab53

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

tests/tests.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
55

6-
use std::env;
6+
use std::{env, path::PathBuf};
77

88
pub const TESTS_BINARY: &str = env!("CARGO_BIN_EXE_coreutils");
99

1010
// Use the ctor attribute to run this function before any tests
1111
#[ctor::ctor]
1212
fn init() {
13+
let cargo_bin_exe_location =
14+
PathBuf::from(env::var("CARGO_BIN_EXE_coreutils").unwrap_or(TESTS_BINARY.to_string()));
15+
1316
unsafe {
1417
// Necessary for uutests to be able to find the binary
15-
std::env::set_var("UUTESTS_BINARY_PATH", TESTS_BINARY);
18+
std::env::set_var("UUTESTS_BINARY_PATH", cargo_bin_exe_location);
1619
}
1720
}
1821

0 commit comments

Comments
 (0)