ensure that compile-flags arguments are the last in ui tests

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.
This commit is contained in:
Pietro Albini 2022-10-20 11:35:28 +02:00
parent 31d754a1df
commit 6457df3d4b
No known key found for this signature in database
GPG Key ID: CD76B35F7734769E

View File

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