1313//! This file implements the various regression test suites that we execute on
1414//! our CI.
1515
16- extern crate build_helper;
17-
1816use std:: collections:: HashSet ;
1917use std:: env;
18+ use std:: iter;
2019use std:: fmt;
2120use std:: fs:: { self , File } ;
2221use std:: path:: { PathBuf , Path } ;
2322use std:: process:: Command ;
2423use std:: io:: Read ;
2524
26- use build_helper:: output;
25+ use build_helper:: { self , output} ;
2726
2827use { Build , Compiler , Mode } ;
2928use dist;
3029use util:: { self , dylib_path, dylib_path_var, exe} ;
3130
32- const ADB_TEST_DIR : & ' static str = "/data/tmp/work" ;
31+ const ADB_TEST_DIR : & str = "/data/tmp/work" ;
3332
3433/// The two modes of the test runner; tests or benchmarks.
3534#[ derive( Copy , Clone ) ]
@@ -60,7 +59,7 @@ impl fmt::Display for TestKind {
6059}
6160
6261fn try_run ( build : & Build , cmd : & mut Command ) {
63- if build. flags . cmd . no_fail_fast ( ) {
62+ if ! build. fail_fast {
6463 if !build. try_run ( cmd) {
6564 let failures = build. delayed_failures . get ( ) ;
6665 build. delayed_failures . set ( failures + 1 ) ;
@@ -71,7 +70,7 @@ fn try_run(build: &Build, cmd: &mut Command) {
7170}
7271
7372fn try_run_quiet ( build : & Build , cmd : & mut Command ) {
74- if build. flags . cmd . no_fail_fast ( ) {
73+ if ! build. fail_fast {
7574 if !build. try_run_quiet ( cmd) {
7675 let failures = build. delayed_failures . get ( ) ;
7776 build. delayed_failures . set ( failures + 1 ) ;
@@ -99,7 +98,7 @@ pub fn linkcheck(build: &Build, host: &str) {
9998/// This tool in `src/tools` will check out a few Rust projects and run `cargo
10099/// test` to ensure that we don't regress the test suites there.
101100pub fn cargotest ( build : & Build , stage : u32 , host : & str ) {
102- let ref compiler = Compiler :: new ( stage, host) ;
101+ let compiler = Compiler :: new ( stage, host) ;
103102
104103 // Note that this is a short, cryptic, and not scoped directory name. This
105104 // is currently to minimize the length of path on Windows where we otherwise
@@ -109,11 +108,11 @@ pub fn cargotest(build: &Build, stage: u32, host: &str) {
109108
110109 let _time = util:: timeit ( ) ;
111110 let mut cmd = Command :: new ( build. tool ( & Compiler :: new ( 0 , host) , "cargotest" ) ) ;
112- build. prepare_tool_cmd ( compiler, & mut cmd) ;
113- try_run ( build, cmd. arg ( & build. cargo )
111+ build. prepare_tool_cmd ( & compiler, & mut cmd) ;
112+ try_run ( build, cmd. arg ( & build. initial_cargo )
114113 . arg ( & out_dir)
115- . env ( "RUSTC" , build. compiler_path ( compiler) )
116- . env ( "RUSTDOC" , build. rustdoc ( compiler) ) ) ;
114+ . env ( "RUSTC" , build. compiler_path ( & compiler) )
115+ . env ( "RUSTDOC" , build. rustdoc ( & compiler) ) ) ;
117116}
118117
119118/// Runs `cargo test` for `cargo` packaged with Rust.
@@ -124,13 +123,12 @@ pub fn cargo(build: &Build, stage: u32, host: &str) {
124123 // and not RUSTC because the Cargo test suite has tests that will
125124 // fail if rustc is not spelled `rustc`.
126125 let path = build. sysroot ( compiler) . join ( "bin" ) ;
127- let old_path = :: std:: env:: var ( "PATH" ) . expect ( "" ) ;
128- let sep = if cfg ! ( windows) { ";" } else { ":" } ;
129- let ref newpath = format ! ( "{}{}{}" , path. display( ) , sep, old_path) ;
126+ let old_path = env:: var_os ( "PATH" ) . unwrap_or_default ( ) ;
127+ let newpath = env:: join_paths ( iter:: once ( path) . chain ( env:: split_paths ( & old_path) ) ) . expect ( "" ) ;
130128
131129 let mut cargo = build. cargo ( compiler, Mode :: Tool , host, "test" ) ;
132130 cargo. arg ( "--manifest-path" ) . arg ( build. src . join ( "src/tools/cargo/Cargo.toml" ) ) ;
133- if build. flags . cmd . no_fail_fast ( ) {
131+ if ! build. fail_fast {
134132 cargo. arg ( "--no-fail-fast" ) ;
135133 }
136134
@@ -198,9 +196,9 @@ pub fn compiletest(build: &Build,
198196 cmd. arg ( "--mode" ) . arg ( mode) ;
199197 cmd. arg ( "--target" ) . arg ( target) ;
200198 cmd. arg ( "--host" ) . arg ( compiler. host ) ;
201- cmd. arg ( "--llvm-filecheck" ) . arg ( build. llvm_filecheck ( & build. config . build ) ) ;
199+ cmd. arg ( "--llvm-filecheck" ) . arg ( build. llvm_filecheck ( & build. build ) ) ;
202200
203- if let Some ( nodejs) = build. config . nodejs . as_ref ( ) {
201+ if let Some ( ref nodejs) = build. config . nodejs {
204202 cmd. arg ( "--nodejs" ) . arg ( nodejs) ;
205203 }
206204
@@ -224,7 +222,7 @@ pub fn compiletest(build: &Build,
224222
225223 cmd. arg ( "--docck-python" ) . arg ( build. python ( ) ) ;
226224
227- if build. config . build . ends_with ( "apple-darwin" ) {
225+ if build. build . ends_with ( "apple-darwin" ) {
228226 // Force /usr/bin/python on macOS for LLDB tests because we're loading the
229227 // LLDB plugin's compiled module which only works with the system python
230228 // (namely not Homebrew-installed python)
@@ -251,7 +249,7 @@ pub fn compiletest(build: &Build,
251249
252250 cmd. args ( & build. flags . cmd . test_args ( ) ) ;
253251
254- if build. config . verbose ( ) || build . flags . verbose ( ) {
252+ if build. is_verbose ( ) {
255253 cmd. arg ( "--verbose" ) ;
256254 }
257255
@@ -279,7 +277,7 @@ pub fn compiletest(build: &Build,
279277
280278 if build. remote_tested ( target) {
281279 cmd. arg ( "--remote-test-client" )
282- . arg ( build. tool ( & Compiler :: new ( 0 , & build. config . build ) ,
280+ . arg ( build. tool ( & Compiler :: new ( 0 , & build. build ) ,
283281 "remote-test-client" ) ) ;
284282 }
285283
@@ -368,7 +366,7 @@ pub fn error_index(build: &Build, compiler: &Compiler) {
368366 "error_index_generator" )
369367 . arg ( "markdown" )
370368 . arg ( & output)
371- . env ( "CFG_BUILD" , & build. config . build ) ) ;
369+ . env ( "CFG_BUILD" , & build. build ) ) ;
372370
373371 markdown_test ( build, compiler, & output) ;
374372}
@@ -450,7 +448,7 @@ pub fn krate(build: &Build,
450448 cargo. arg ( "--manifest-path" )
451449 . arg ( build. src . join ( path) . join ( "Cargo.toml" ) )
452450 . arg ( "--features" ) . arg ( features) ;
453- if test_kind. subcommand ( ) == "test" && build. flags . cmd . no_fail_fast ( ) {
451+ if test_kind. subcommand ( ) == "test" && ! build. fail_fast {
454452 cargo. arg ( "--no-fail-fast" ) ;
455453 }
456454
@@ -520,16 +518,14 @@ fn krate_emscripten(build: &Build,
520518 compiler : & Compiler ,
521519 target : & str ,
522520 mode : Mode ) {
523- let mut tests = Vec :: new ( ) ;
524521 let out_dir = build. cargo_out ( compiler, mode, target) ;
525- find_tests ( & out_dir. join ( "deps" ) , target, & mut tests ) ;
522+ let tests = find_tests ( & out_dir. join ( "deps" ) , target) ;
526523
524+ let nodejs = build. config . nodejs . as_ref ( ) . expect ( "nodejs not configured" ) ;
527525 for test in tests {
528- let test_file_name = test. to_string_lossy ( ) . into_owned ( ) ;
529- println ! ( "running {}" , test_file_name) ;
530- let nodejs = build. config . nodejs . as_ref ( ) . expect ( "nodejs not configured" ) ;
526+ println ! ( "running {}" , test. display( ) ) ;
531527 let mut cmd = Command :: new ( nodejs) ;
532- cmd. arg ( & test_file_name ) ;
528+ cmd. arg ( & test ) ;
533529 if build. config . quiet_tests {
534530 cmd. arg ( "--quiet" ) ;
535531 }
@@ -541,11 +537,10 @@ fn krate_remote(build: &Build,
541537 compiler : & Compiler ,
542538 target : & str ,
543539 mode : Mode ) {
544- let mut tests = Vec :: new ( ) ;
545540 let out_dir = build. cargo_out ( compiler, mode, target) ;
546- find_tests ( & out_dir. join ( "deps" ) , target, & mut tests ) ;
541+ let tests = find_tests ( & out_dir. join ( "deps" ) , target) ;
547542
548- let tool = build. tool ( & Compiler :: new ( 0 , & build. config . build ) ,
543+ let tool = build. tool ( & Compiler :: new ( 0 , & build. build ) ,
549544 "remote-test-client" ) ;
550545 for test in tests {
551546 let mut cmd = Command :: new ( & tool) ;
@@ -559,9 +554,8 @@ fn krate_remote(build: &Build,
559554 }
560555}
561556
562- fn find_tests ( dir : & Path ,
563- target : & str ,
564- dst : & mut Vec < PathBuf > ) {
557+ fn find_tests ( dir : & Path , target : & str ) -> Vec < PathBuf > {
558+ let mut dst = Vec :: new ( ) ;
565559 for e in t ! ( dir. read_dir( ) ) . map ( |e| t ! ( e) ) {
566560 let file_type = t ! ( e. file_type( ) ) ;
567561 if !file_type. is_file ( ) {
@@ -576,6 +570,7 @@ fn find_tests(dir: &Path,
576570 dst. push ( e. path ( ) ) ;
577571 }
578572 }
573+ dst
579574}
580575
581576pub fn remote_copy_libs ( build : & Build , compiler : & Compiler , target : & str ) {
@@ -590,7 +585,7 @@ pub fn remote_copy_libs(build: &Build, compiler: &Compiler, target: &str) {
590585 . join ( exe ( "remote-test-server" , target) ) ;
591586
592587 // Spawn the emulator and wait for it to come online
593- let tool = build. tool ( & Compiler :: new ( 0 , & build. config . build ) ,
588+ let tool = build. tool ( & Compiler :: new ( 0 , & build. build ) ,
594589 "remote-test-client" ) ;
595590 let mut cmd = Command :: new ( & tool) ;
596591 cmd. arg ( "spawn-emulator" )
@@ -616,7 +611,7 @@ pub fn remote_copy_libs(build: &Build, compiler: &Compiler, target: &str) {
616611
617612/// Run "distcheck", a 'make check' from a tarball
618613pub fn distcheck ( build : & Build ) {
619- if build. config . build != "x86_64-unknown-linux-gnu" {
614+ if build. build != "x86_64-unknown-linux-gnu" {
620615 return
621616 }
622617 if !build. config . host . iter ( ) . any ( |s| s == "x86_64-unknown-linux-gnu" ) {
@@ -641,7 +636,7 @@ pub fn distcheck(build: &Build) {
641636 . args ( & build. config . configure_args )
642637 . arg ( "--enable-vendor" )
643638 . current_dir ( & dir) ) ;
644- build. run ( Command :: new ( build_helper:: make ( & build. config . build ) )
639+ build. run ( Command :: new ( build_helper:: make ( & build. build ) )
645640 . arg ( "check" )
646641 . current_dir ( & dir) ) ;
647642
@@ -659,7 +654,7 @@ pub fn distcheck(build: &Build) {
659654 build. run ( & mut cmd) ;
660655
661656 let toml = dir. join ( "rust-src/lib/rustlib/src/rust/src/libstd/Cargo.toml" ) ;
662- build. run ( Command :: new ( & build. cargo )
657+ build. run ( Command :: new ( & build. initial_cargo )
663658 . arg ( "generate-lockfile" )
664659 . arg ( "--manifest-path" )
665660 . arg ( & toml)
@@ -668,13 +663,13 @@ pub fn distcheck(build: &Build) {
668663
669664/// Test the build system itself
670665pub fn bootstrap ( build : & Build ) {
671- let mut cmd = Command :: new ( & build. cargo ) ;
666+ let mut cmd = Command :: new ( & build. initial_cargo ) ;
672667 cmd. arg ( "test" )
673668 . current_dir ( build. src . join ( "src/bootstrap" ) )
674669 . env ( "CARGO_TARGET_DIR" , build. out . join ( "bootstrap" ) )
675670 . env ( "RUSTC_BOOTSTRAP" , "1" )
676- . env ( "RUSTC" , & build. rustc ) ;
677- if build. flags . cmd . no_fail_fast ( ) {
671+ . env ( "RUSTC" , & build. initial_rustc ) ;
672+ if ! build. fail_fast {
678673 cmd. arg ( "--no-fail-fast" ) ;
679674 }
680675 cmd. arg ( "--" ) . args ( & build. flags . cmd . test_args ( ) ) ;
0 commit comments