@@ -33,35 +33,54 @@ fn download_ci_llvm() {
33
33
) ) ;
34
34
}
35
35
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
36
40
#[ test]
37
41
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 ( ) ;
39
45
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) ;
42
49
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) ;
45
54
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
+ ) ;
47
65
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 ) ;
51
69
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 ( ) ;
55
71
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 ( ) ;
57
79
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
+ }
65
83
66
- assert_eq ! ( & cfg. out, expected_out) ;
84
+ test ( parse ( "" ) , None ) ;
85
+ test ( parse ( "build.build-dir = \" /tmp\" " ) , Some ( "/tmp" ) ) ;
67
86
}
0 commit comments