diff options
| author | bors <bors@rust-lang.org> | 2023-04-06 21:18:49 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-04-06 21:18:49 +0000 |
| commit | 28a29282f6dde2e4aba6e1e4cfea5c9430a00217 (patch) | |
| tree | f1f1e43fc8df65cc1901be50ad6325693a892267 /src/bootstrap | |
| parent | de74dab880447f5227030b261dbd0f2bc4f32dba (diff) | |
| parent | 925a3040c7f0a84885a91ba8919d1f6d7516302a (diff) | |
| download | rust-28a29282f6dde2e4aba6e1e4cfea5c9430a00217.tar.gz rust-28a29282f6dde2e4aba6e1e4cfea5c9430a00217.zip | |
Auto merge of #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 #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 #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 #109120 partially
Diffstat (limited to 'src/bootstrap')
| -rw-r--r-- | src/bootstrap/config/tests.rs | 65 |
1 files changed, 44 insertions, 21 deletions
diff --git a/src/bootstrap/config/tests.rs b/src/bootstrap/config/tests.rs index 5cea143e0a7..50569eb4f37 100644 --- a/src/bootstrap/config/tests.rs +++ b/src/bootstrap/config/tests.rs @@ -33,35 +33,58 @@ fn download_ci_llvm() { )); } +// FIXME(ozkanonur): extend scope of the test +// refs: +// - https://github.com/rust-lang/rust/issues/109120 +// - https://github.com/rust-lang/rust/pull/109162#issuecomment-1496782487 #[test] fn detect_src_and_out() { - let cfg = parse(""); + fn test(cfg: Config, build_dir: Option<&str>) { + // This will bring absolute form of `src/bootstrap` path + let current_dir = std::env::current_dir().unwrap(); - // This will bring absolute form of `src/bootstrap` path - let current_dir = std::env::current_dir().unwrap(); + // get `src` by moving into project root path + let expected_src = current_dir.ancestors().nth(2).unwrap(); + assert_eq!(&cfg.src, expected_src); - // get `src` by moving into project root path - let expected_src = current_dir.ancestors().nth(2).unwrap(); + // Sanity check for `src` + let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR")); + let expected_src = manifest_dir.ancestors().nth(2).unwrap(); + assert_eq!(&cfg.src, expected_src); - assert_eq!(&cfg.src, expected_src); + // test if build-dir was manually given in config.toml + if let Some(custom_build_dir) = build_dir { + assert_eq!(&cfg.out, Path::new(custom_build_dir)); + } + // test the native bootstrap way + else { + // This should bring output path of bootstrap in absolute form + let cargo_target_dir = env::var_os("CARGO_TARGET_DIR").expect( + "CARGO_TARGET_DIR must been provided for the test environment from bootstrap", + ); - // This should bring output path of bootstrap in absolute form - let cargo_target_dir = env::var_os("CARGO_TARGET_DIR") - .expect("CARGO_TARGET_DIR must been provided for the test environment from bootstrap"); + // Move to `build` from `build/bootstrap` + let expected_out = Path::new(&cargo_target_dir).parent().unwrap(); + assert_eq!(&cfg.out, expected_out); - // Move to `build` from `build/bootstrap` - let expected_out = Path::new(&cargo_target_dir).parent().unwrap(); - assert_eq!(&cfg.out, expected_out); + let args: Vec<String> = env::args().collect(); - let args: Vec<String> = env::args().collect(); + // Another test for `out` as a sanity check + // + // This will bring something similar to: + // `{build-dir}/bootstrap/debug/deps/bootstrap-c7ee91d5661e2804` + // `{build-dir}` can be anywhere, not just in the rust project directory. + let dep = Path::new(args.first().unwrap()); + let expected_out = dep.ancestors().nth(4).unwrap(); - // Another test for `out` as a sanity check - // - // This will bring something similar to: - // `{config_toml_place}/build/bootstrap/debug/deps/bootstrap-c7ee91d5661e2804` - // `{config_toml_place}` can be anywhere, not just in the rust project directory. - let dep = Path::new(args.first().unwrap()); - let expected_out = dep.ancestors().nth(4).unwrap(); + assert_eq!(&cfg.out, expected_out); + } + } + + test(parse(""), None); - assert_eq!(&cfg.out, expected_out); + { + let build_dir = if cfg!(windows) { Some("C:\\tmp") } else { Some("/tmp") }; + test(parse("build.build-dir = \"/tmp\""), build_dir); + } } |
