]> git.lizzy.rs Git - rust.git/commitdiff
make `compose_and_run_compiler` take `Command`
authorAndy Russell <arussell123@gmail.com>
Thu, 10 Aug 2017 19:18:00 +0000 (15:18 -0400)
committerAndy Russell <arussell123@gmail.com>
Wed, 16 Aug 2017 15:45:06 +0000 (11:45 -0400)
src/tools/compiletest/src/runtest.rs

index 300861b22a168aca97fe8bb512173430990c8535..4d54d5d0d0c082ad3ad473729ab287b6e067c7f4 100644 (file)
@@ -365,45 +365,35 @@ fn compare_source(&self,
     }
 
     fn typecheck_source(&self, src: String) -> ProcRes {
-        let args = self.make_typecheck_args();
-        self.compose_and_run_compiler(args, Some(src))
-    }
+        let mut rustc = Command::new(&self.config.rustc_path);
+
+        let out_dir = self.output_base_name().with_extension("pretty-out");
+        let _ = fs::remove_dir_all(&out_dir);
+        create_dir_all(&out_dir).unwrap();
 
-    fn make_typecheck_args(&self) -> ProcArgs {
-        let aux_dir = self.aux_output_dir_name();
         let target = if self.props.force_host {
             &*self.config.host
         } else {
             &*self.config.target
         };
 
-        let out_dir = self.output_base_name().with_extension("pretty-out");
-        let _ = fs::remove_dir_all(&out_dir);
-        create_dir_all(&out_dir).unwrap();
+        let aux_dir = self.aux_output_dir_name();
+
+        rustc.arg("-")
+            .arg("-Zno-trans")
+            .arg("--out-dir").arg(&out_dir)
+            .arg(&format!("--target={}", target))
+            .arg("-L").arg(&self.config.build_base)
+            .arg("-L").arg(aux_dir);
 
-        // FIXME (#9639): This needs to handle non-utf8 paths
-        let mut args = vec!["-".to_owned(),
-                            "-Zno-trans".to_owned(),
-                            "--out-dir".to_owned(),
-                            out_dir.to_str().unwrap().to_owned(),
-                            format!("--target={}", target),
-                            "-L".to_owned(),
-                            self.config.build_base.to_str().unwrap().to_owned(),
-                            "-L".to_owned(),
-                            aux_dir.to_str().unwrap().to_owned()];
         if let Some(revision) = self.revision {
-            args.extend(vec![
-                "--cfg".to_string(),
-                revision.to_string(),
-            ]);
-        }
-        args.extend(self.split_maybe_args(&self.config.target_rustcflags));
-        args.extend(self.props.compile_flags.iter().cloned());
-        // FIXME (#9639): This needs to handle non-utf8 paths
-        ProcArgs {
-            prog: self.config.rustc_path.to_str().unwrap().to_owned(),
-            args,
+            rustc.args(&["--cfg", revision]);
         }
+
+        rustc.args(self.split_maybe_args(&self.config.target_rustcflags));
+        rustc.args(&self.props.compile_flags);
+
+        self.compose_and_run_compiler(rustc, Some(src))
     }
 
     fn run_debuginfo_gdb_test(&self) {
@@ -1126,10 +1116,11 @@ fn compile_test(&self) -> ProcRes {
             }
             _ => {}
         }
-        let args = self.make_compile_args(extra_args,
-                                          &self.testpaths.file,
-                                          TargetLocation::ThisFile(self.make_exe_name()));
-        self.compose_and_run_compiler(args, None)
+        let ProcArgs { prog, args } = self.make_compile_args(
+            extra_args, &self.testpaths.file, TargetLocation::ThisFile(self.make_exe_name()));
+        let mut rustc = Command::new(prog);
+        rustc.args(args);
+        self.compose_and_run_compiler(rustc, None)
     }
 
     fn document(&self, out_dir: &Path) -> ProcRes {
@@ -1153,18 +1144,16 @@ fn document(&self, out_dir: &Path) -> ProcRes {
         }
 
         let aux_dir = self.aux_output_dir_name();
-        let mut args = vec!["-L".to_owned(),
-                            aux_dir.to_str().unwrap().to_owned(),
-                            "-o".to_owned(),
-                            out_dir.to_str().unwrap().to_owned(),
-                            self.testpaths.file.to_str().unwrap().to_owned()];
-        args.extend(self.props.compile_flags.iter().cloned());
-        let args = ProcArgs {
-            prog: self.config.rustdoc_path
-                .as_ref().expect("--rustdoc-path passed").to_str().unwrap().to_owned(),
-            args,
-        };
-        self.compose_and_run_compiler(args, None)
+
+        let rustdoc_path = self.config.rustdoc_path.as_ref().expect("--rustdoc-path passed");
+        let mut rustdoc = Command::new(rustdoc_path);
+
+        rustdoc.arg("-L").arg(aux_dir)
+            .arg("-o").arg(out_dir)
+            .arg(&self.testpaths.file)
+            .args(&self.props.compile_flags);
+
+        self.compose_and_run_compiler(rustdoc, None)
     }
 
     fn exec_compiled_test(&self) -> ProcRes {
@@ -1247,7 +1236,7 @@ fn compute_aux_test_paths(&self, rel_ab: &str) -> TestPaths {
         }
     }
 
-    fn compose_and_run_compiler(&self, args: ProcArgs, input: Option<String>) -> ProcRes {
+    fn compose_and_run_compiler(&self, mut rustc: Command, input: Option<String>) -> ProcRes {
         if !self.props.aux_builds.is_empty() {
             create_dir_all(&self.aux_output_dir_name()).unwrap();
         }
@@ -1307,11 +1296,7 @@ fn compose_and_run_compiler(&self, args: ProcArgs, input: Option<String>) -> Pro
             }
         }
 
-        let ProcArgs { prog, args } = args;
-        let mut rustc = Command::new(prog);
-        rustc.args(args)
-            .envs(self.props.rustc_env.clone());
-
+        rustc.envs(self.props.rustc_env.clone());
         self.compose_and_run(rustc,
                              self.config.compile_lib_path.to_str().unwrap(),
                              Some(aux_dir.to_str().unwrap()),
@@ -1681,7 +1666,10 @@ fn compile_test_and_save_ir(&self) -> ProcRes {
                                               self.output_base_name().parent()
                                                                      .unwrap()
                                                                      .to_path_buf()));
-        self.compose_and_run_compiler(args, None)
+        let ProcArgs { prog, args } = args;
+        let mut rustc = Command::new(prog);
+        rustc.args(args);
+        self.compose_and_run_compiler(rustc, None)
     }
 
     fn check_ir_with_filecheck(&self) -> ProcRes {