@@ -54,14 +54,15 @@ pub fn run(input: &str,
5454           libs :  SearchPaths , 
5555           externs :  Externs , 
5656           mut  test_args :  Vec < String > , 
57-            crate_name :  Option < String > ) 
57+            crate_name :  Option < String > , 
58+            maybe_sysroot :  Option < PathBuf > ) 
5859           -> isize  { 
5960    let  input_path = PathBuf :: from ( input) ; 
6061    let  input = config:: Input :: File ( input_path. clone ( ) ) ; 
6162
6263    let  sessopts = config:: Options  { 
63-         maybe_sysroot :  Some ( env :: current_exe ( ) . unwrap ( ) . parent ( ) . unwrap ( ) 
64-                                                . parent ( ) . unwrap ( ) . to_path_buf ( ) ) , 
64+         maybe_sysroot :  maybe_sysroot . clone ( ) . or_else ( 
65+             ||  Some ( env :: current_exe ( ) . unwrap ( ) . parent ( ) . unwrap ( ) . parent ( ) . unwrap ( ) . to_path_buf ( ) ) ) , 
6566        search_paths :  libs. clone ( ) , 
6667        crate_types :  vec ! [ config:: CrateTypeDylib ] , 
6768        externs :  externs. clone ( ) , 
@@ -99,7 +100,8 @@ pub fn run(input: &str,
99100                                       libs, 
100101                                       externs, 
101102                                       false , 
102-                                        opts) ; 
103+                                        opts, 
104+                                        maybe_sysroot) ; 
103105
104106    { 
105107        let  dep_graph = DepGraph :: new ( false ) ; 
@@ -157,7 +159,8 @@ fn scrape_test_config(krate: &::rustc::hir::Crate) -> TestOptions {
157159fn  runtest ( test :  & str ,  cratename :  & str ,  cfgs :  Vec < String > ,  libs :  SearchPaths , 
158160           externs :  Externs , 
159161           should_panic :  bool ,  no_run :  bool ,  as_test_harness :  bool , 
160-            compile_fail :  bool ,  mut  error_codes :  Vec < String > ,  opts :  & TestOptions )  { 
162+            compile_fail :  bool ,  mut  error_codes :  Vec < String > ,  opts :  & TestOptions , 
163+            maybe_sysroot :  Option < PathBuf > )  { 
161164    // the test harness wants its own `main` & top level functions, so 
162165    // never wrap the test in `fn main() { ... }` 
163166    let  test = maketest ( test,  Some ( cratename) ,  as_test_harness,  opts) ; 
@@ -168,8 +171,8 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths,
168171    let  outputs = OutputTypes :: new ( & [ ( OutputType :: Exe ,  None ) ] ) ; 
169172
170173    let  sessopts = config:: Options  { 
171-         maybe_sysroot :  Some ( env :: current_exe ( ) . unwrap ( ) . parent ( ) . unwrap ( ) 
172-                                                . parent ( ) . unwrap ( ) . to_path_buf ( ) ) , 
174+         maybe_sysroot :  maybe_sysroot . or_else ( 
175+             ||  Some ( env :: current_exe ( ) . unwrap ( ) . parent ( ) . unwrap ( ) . parent ( ) . unwrap ( ) . to_path_buf ( ) ) ) , 
173176        search_paths :  libs, 
174177        crate_types :  vec ! [ config:: CrateTypeExecutable ] , 
175178        output_types :  outputs, 
@@ -379,11 +382,12 @@ pub struct Collector {
379382    current_header :  Option < String > , 
380383    cratename :  String , 
381384    opts :  TestOptions , 
385+     maybe_sysroot :  Option < PathBuf > , 
382386} 
383387
384388impl  Collector  { 
385389    pub  fn  new ( cratename :  String ,  cfgs :  Vec < String > ,  libs :  SearchPaths ,  externs :  Externs , 
386-                use_headers :  bool ,  opts :  TestOptions )  -> Collector  { 
390+                use_headers :  bool ,  opts :  TestOptions ,   maybe_sysroot :   Option < PathBuf > )  -> Collector  { 
387391        Collector  { 
388392            tests :  Vec :: new ( ) , 
389393            names :  Vec :: new ( ) , 
@@ -395,6 +399,7 @@ impl Collector {
395399            current_header :  None , 
396400            cratename :  cratename, 
397401            opts :  opts, 
402+             maybe_sysroot :  maybe_sysroot, 
398403        } 
399404    } 
400405
@@ -413,6 +418,7 @@ impl Collector {
413418        let  externs = self . externs . clone ( ) ; 
414419        let  cratename = self . cratename . to_string ( ) ; 
415420        let  opts = self . opts . clone ( ) ; 
421+         let  maybe_sysroot = self . maybe_sysroot . clone ( ) ; 
416422        debug ! ( "Creating test {}: {}" ,  name,  test) ; 
417423        self . tests . push ( testing:: TestDescAndFn  { 
418424            desc :  testing:: TestDesc  { 
@@ -432,7 +438,8 @@ impl Collector {
432438                        as_test_harness, 
433439                        compile_fail, 
434440                        error_codes, 
435-                         & opts) ; 
441+                         & opts, 
442+                         maybe_sysroot) ; 
436443            } ) 
437444        } ) ; 
438445    } 
0 commit comments