]> git.lizzy.rs Git - rust.git/commitdiff
ensure that compile-flags arguments are the last in ui tests
authorPietro Albini <pietro.albini@ferrous-systems.com>
Thu, 20 Oct 2022 09:35:28 +0000 (11:35 +0200)
committerPietro Albini <pietro.albini@ferrous-systems.com>
Tue, 25 Oct 2022 08:41:23 +0000 (10:41 +0200)
Before this commit, compiletest would add `-L path/to/aux` at the end of
the rustc flags, even after the custom ones set with the compile-flags
header comment. This made it impossible to check how rustc would behave
when a flag requiring an argument was passed without the argument,
because the argument would become `-L`.

This PR fixes that by adding the `-L path/to/aux` before the arguments
defined in compile-flags, at least for UI tests. Other test suites might
either be fixed as well by this change, or still present the old
behavior.

src/tools/compiletest/src/runtest.rs

index 8f289876f7307b391525979598dbbef6a8b8e37a..ab0d568ffa7ab726cdacb1b6e8ae381e0b0c8cd6 100644 (file)
@@ -1499,10 +1499,13 @@ fn compile_test_general(
             _ => AllowUnused::No,
         };
 
-        let mut rustc =
-            self.make_compile_args(&self.testpaths.file, output_file, emit_metadata, allow_unused);
-
-        rustc.arg("-L").arg(&self.aux_output_dir_name());
+        let rustc = self.make_compile_args(
+            &self.testpaths.file,
+            output_file,
+            emit_metadata,
+            allow_unused,
+            LinkToAux::Yes,
+        );
 
         self.compose_and_run_compiler(rustc, None)
     }
@@ -1729,8 +1732,13 @@ fn build_auxiliary(&self, source_path: &str, aux_dir: &Path) -> bool {
         // Create the directory for the stdout/stderr files.
         create_dir_all(aux_cx.output_base_dir()).unwrap();
         let input_file = &aux_testpaths.file;
-        let mut aux_rustc =
-            aux_cx.make_compile_args(input_file, aux_output, EmitMetadata::No, AllowUnused::No);
+        let mut aux_rustc = aux_cx.make_compile_args(
+            input_file,
+            aux_output,
+            EmitMetadata::No,
+            AllowUnused::No,
+            LinkToAux::No,
+        );
 
         for key in &aux_props.unset_rustc_env {
             aux_rustc.env_remove(key);
@@ -1869,6 +1877,7 @@ fn make_compile_args(
         output_file: TargetLocation,
         emit_metadata: EmitMetadata,
         allow_unused: AllowUnused,
+        link_to_aux: LinkToAux,
     ) -> Command {
         let is_aux = input_file.components().map(|c| c.as_os_str()).any(|c| c == "auxiliary");
         let is_rustdoc = self.is_rustdoc() && !is_aux;
@@ -2056,6 +2065,10 @@ fn make_compile_args(
             rustc.arg("-Ctarget-feature=-crt-static");
         }
 
+        if let LinkToAux::Yes = link_to_aux {
+            rustc.arg("-L").arg(self.aux_output_dir_name());
+        }
+
         rustc.args(&self.props.compile_flags);
 
         rustc
@@ -2247,13 +2260,16 @@ fn fatal_proc_rec_with_ctx(
     // codegen tests (using FileCheck)
 
     fn compile_test_and_save_ir(&self) -> ProcRes {
-        let aux_dir = self.aux_output_dir_name();
-
         let output_file = TargetLocation::ThisDirectory(self.output_base_dir());
         let input_file = &self.testpaths.file;
-        let mut rustc =
-            self.make_compile_args(input_file, output_file, EmitMetadata::No, AllowUnused::No);
-        rustc.arg("-L").arg(aux_dir).arg("--emit=llvm-ir");
+        let mut rustc = self.make_compile_args(
+            input_file,
+            output_file,
+            EmitMetadata::No,
+            AllowUnused::No,
+            LinkToAux::Yes,
+        );
+        rustc.arg("--emit=llvm-ir");
 
         self.compose_and_run_compiler(rustc, None)
     }
@@ -2265,10 +2281,13 @@ fn compile_test_and_save_assembly(&self) -> (ProcRes, PathBuf) {
 
         let output_file = TargetLocation::ThisFile(output_path.clone());
         let input_file = &self.testpaths.file;
-        let mut rustc =
-            self.make_compile_args(input_file, output_file, EmitMetadata::No, AllowUnused::No);
-
-        rustc.arg("-L").arg(self.aux_output_dir_name());
+        let mut rustc = self.make_compile_args(
+            input_file,
+            output_file,
+            EmitMetadata::No,
+            AllowUnused::No,
+            LinkToAux::Yes,
+        );
 
         match self.props.assembly_output.as_ref().map(AsRef::as_ref) {
             Some("emit-asm") => {
@@ -2409,8 +2428,8 @@ fn compare_to_default_rustdoc(&mut self, out_dir: &Path) {
             output_file,
             EmitMetadata::No,
             AllowUnused::Yes,
+            LinkToAux::Yes,
         );
-        rustc.arg("-L").arg(&new_rustdoc.aux_output_dir_name());
         new_rustdoc.build_all_auxiliary(&mut rustc);
 
         let proc_res = new_rustdoc.document(&compare_dir);
@@ -3354,13 +3373,13 @@ fn run_ui_test(&self) {
         if self.props.run_rustfix && self.config.compare_mode.is_none() {
             // And finally, compile the fixed code and make sure it both
             // succeeds and has no diagnostics.
-            let mut rustc = self.make_compile_args(
+            let rustc = self.make_compile_args(
                 &self.testpaths.file.with_extension(UI_FIXED),
                 TargetLocation::ThisFile(self.make_exe_name()),
                 emit_metadata,
                 AllowUnused::No,
+                LinkToAux::Yes,
             );
-            rustc.arg("-L").arg(&self.aux_output_dir_name());
             let res = self.compose_and_run_compiler(rustc, None);
             if !res.status.success() {
                 self.fatal_proc_rec("failed to compile fixed code", &res);
@@ -3948,3 +3967,8 @@ enum AllowUnused {
     Yes,
     No,
 }
+
+enum LinkToAux {
+    Yes,
+    No,
+}