@@ -33,35 +33,58 @@ 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]
3741fn 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+ }
83+
84+ test ( parse ( "" ) , None ) ;
6585
66- assert_eq ! ( & cfg. out, expected_out) ;
86+ {
87+ let build_dir = if cfg ! ( windows) { Some ( "C:\\ tmp" ) } else { Some ( "/tmp" ) } ;
88+ test ( parse ( "build.build-dir = \" /tmp\" " ) , build_dir) ;
89+ }
6790}
0 commit comments