Skip to content

Commit cb22866

Browse files
authored
Rollup merge of rust-lang#109162 - ozkanonur:extend_detect_src_and_out_test, r=jyn514
extend `detect_src_and_out` test > I was thinking about the following cases when I wrote the comment in rust-lang#109055 > > 1. Running bootstrap from the source root. > 2. Running from a subdirectory of the source root. > 3. Running from outside the source root. > 4. Running on a different machine from where bootstrap was compiled (which will be important > for rust-lang#107812). You can mostly replicate this by renaming the source root so it no longer exists on disk. > 5. Running with `--build-dir`. > 6. Running with `$RUST_BOOTSTRAP_CONFIG` set in the environment and `build-dir` set in the file. Tested all the topics mentioned above. All worked fine. The test is now also covers if build dir is manually specified in config. r? `@jyn514` helps rust-lang#109120 partially
2 parents 846cdcf + 38b1741 commit cb22866

File tree

1 file changed

+40
-21
lines changed

1 file changed

+40
-21
lines changed

src/bootstrap/config/tests.rs

+40-21
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,54 @@ fn download_ci_llvm() {
3333
));
3434
}
3535

36+
// FIXME(ozkanonur): extend scope of the test
37+
// refs:
38+
// - https://github.com/rust-lang/rust/issues/109120
39+
// - https://github.com/rust-lang/rust/pull/109162#issuecomment-1496782487
3640
#[test]
3741
fn detect_src_and_out() {
38-
let cfg = parse("");
42+
fn test(cfg: Config, build_dir: Option<&str>) {
43+
// This will bring absolute form of `src/bootstrap` path
44+
let current_dir = std::env::current_dir().unwrap();
3945

40-
// This will bring absolute form of `src/bootstrap` path
41-
let current_dir = std::env::current_dir().unwrap();
46+
// get `src` by moving into project root path
47+
let expected_src = current_dir.ancestors().nth(2).unwrap();
48+
assert_eq!(&cfg.src, expected_src);
4249

43-
// get `src` by moving into project root path
44-
let expected_src = current_dir.ancestors().nth(2).unwrap();
50+
// Sanity check for `src`
51+
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
52+
let expected_src = manifest_dir.ancestors().nth(2).unwrap();
53+
assert_eq!(&cfg.src, expected_src);
4554

46-
assert_eq!(&cfg.src, expected_src);
55+
// test if build-dir was manually given in config.toml
56+
if let Some(custom_build_dir) = build_dir {
57+
assert_eq!(&cfg.out, Path::new(custom_build_dir));
58+
}
59+
// test the native bootstrap way
60+
else {
61+
// This should bring output path of bootstrap in absolute form
62+
let cargo_target_dir = env::var_os("CARGO_TARGET_DIR").expect(
63+
"CARGO_TARGET_DIR must been provided for the test environment from bootstrap",
64+
);
4765

48-
// This should bring output path of bootstrap in absolute form
49-
let cargo_target_dir = env::var_os("CARGO_TARGET_DIR")
50-
.expect("CARGO_TARGET_DIR must been provided for the test environment from bootstrap");
66+
// Move to `build` from `build/bootstrap`
67+
let expected_out = Path::new(&cargo_target_dir).parent().unwrap();
68+
assert_eq!(&cfg.out, expected_out);
5169

52-
// Move to `build` from `build/bootstrap`
53-
let expected_out = Path::new(&cargo_target_dir).parent().unwrap();
54-
assert_eq!(&cfg.out, expected_out);
70+
let args: Vec<String> = env::args().collect();
5571

56-
let args: Vec<String> = env::args().collect();
72+
// Another test for `out` as a sanity check
73+
//
74+
// This will bring something similar to:
75+
// `{build-dir}/bootstrap/debug/deps/bootstrap-c7ee91d5661e2804`
76+
// `{build-dir}` can be anywhere, not just in the rust project directory.
77+
let dep = Path::new(args.first().unwrap());
78+
let expected_out = dep.ancestors().nth(4).unwrap();
5779

58-
// Another test for `out` as a sanity check
59-
//
60-
// This will bring something similar to:
61-
// `{config_toml_place}/build/bootstrap/debug/deps/bootstrap-c7ee91d5661e2804`
62-
// `{config_toml_place}` can be anywhere, not just in the rust project directory.
63-
let dep = Path::new(args.first().unwrap());
64-
let expected_out = dep.ancestors().nth(4).unwrap();
80+
assert_eq!(&cfg.out, expected_out);
81+
}
82+
}
6583

66-
assert_eq!(&cfg.out, expected_out);
84+
test(parse(""), None);
85+
test(parse("build.build-dir = \"/tmp\""), Some("/tmp"));
6786
}

0 commit comments

Comments
 (0)