From 33a5dc57efbd3a7a106fce45085df7d403569271 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 19 Apr 2023 13:42:22 +0000 Subject: [PATCH 1/2] Allow aux builds to have nested aux builds --- src/lib.rs | 102 +++++++++++------- tests/integrations/basic-fail/Cargo.stderr | 3 +- .../actual_tests_bless/auxiliary/nested.rs | 5 + .../tests/actual_tests_bless/nested_aux.rs | 8 ++ 4 files changed, 81 insertions(+), 37 deletions(-) create mode 100644 tests/integrations/basic-fail/tests/actual_tests_bless/auxiliary/nested.rs create mode 100644 tests/integrations/basic-fail/tests/actual_tests_bless/nested_aux.rs diff --git a/src/lib.rs b/src/lib.rs index 26a40227..930c12ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -921,11 +921,11 @@ fn build_aux( kind: &str, aux: &Path, extra_args: &mut Vec, -) -> Option<(Command, Vec, Vec)> { +) -> std::result::Result<(), (Command, Vec, Vec)> { let comments = match parse_comments_in_file(aux_file) { Ok(comments) => comments, Err((msg, mut errors)) => { - return Some(( + return Err(( build_command(path, config, revision, comments, None, &mut errors), errors, msg, @@ -933,6 +933,7 @@ fn build_aux( } }; assert_eq!(comments.revisions, None); + // Put aux builds into a separate directory per test so that // tests running in parallel but building the same aux build don't conflict. // FIXME: put aux builds into the regular build queue. @@ -954,9 +955,16 @@ fn build_aux( ); if !errors.is_empty() { - return Some((aux_cmd, errors, vec![])); + return Err((aux_cmd, errors, vec![])); } + let current_extra_args = + build_aux_files(aux_file, aux_file.parent().unwrap(), &comments, "", config)?; + // Make sure we see our dependencies + aux_cmd.args(current_extra_args.iter()); + // Make sure our dependents also see our dependencies. + extra_args.extend(current_extra_args); + aux_cmd.arg("--crate-type").arg(kind); aux_cmd.arg("--emit=link"); let filename = aux.file_stem().unwrap().to_str().unwrap(); @@ -966,7 +974,7 @@ fn build_aux( kind: "compilation of aux build failed".to_string(), status: output.status, }; - return Some(( + return Err(( aux_cmd, vec![error], rustc_stderr::process(path, &output.stderr).rendered, @@ -984,8 +992,11 @@ fn build_aux( let path = out_dir.join(file); extra_args.push("--extern".into()); extra_args.push(format!("{crate_name}={}", path.display())); + // Help cargo find the crates added with `--extern`. + extra_args.push("-L".into()); + extra_args.push(out_dir.display().to_string()); } - None + Ok(()) } fn run_test( @@ -994,37 +1005,16 @@ fn run_test( revision: &str, comments: &Comments, ) -> (Command, Errors, Vec) { - let mut extra_args = vec![]; - let aux_dir = path.parent().unwrap().join("auxiliary"); - for rev in comments.for_revision(revision) { - for (aux, kind, line) in &rev.aux_builds { - let aux_file = if aux.starts_with("..") { - aux_dir.parent().unwrap().join(aux) - } else { - aux_dir.join(aux) - }; - if let Some((command, errors, msg)) = build_aux( - &aux_file, - path, - config, - revision, - comments, - kind, - aux, - &mut extra_args, - ) { - return ( - command, - vec![Error::Aux { - path: aux_file, - errors, - line: *line, - }], - msg, - ); - } - } - } + let extra_args = match build_aux_files( + path, + &path.parent().unwrap().join("auxiliary"), + comments, + revision, + config, + ) { + Ok(value) => value, + Err(value) => return value, + }; let mut errors = vec![]; @@ -1103,6 +1093,46 @@ fn run_test( (cmd, errors, stderr) } +fn build_aux_files( + path: &Path, + aux_dir: &Path, + comments: &Comments, + revision: &str, + config: &Config, +) -> Result, (Command, Vec, Vec)> { + let mut extra_args = vec![]; + for rev in comments.for_revision(revision) { + for (aux, kind, line) in &rev.aux_builds { + let aux_file = if aux.starts_with("..") { + aux_dir.parent().unwrap().join(aux) + } else { + aux_dir.join(aux) + }; + if let Err((command, errors, msg)) = build_aux( + &aux_file, + path, + config, + revision, + comments, + kind, + aux, + &mut extra_args, + ) { + return Err(( + command, + vec![Error::Aux { + path: aux_file, + errors, + line: *line, + }], + msg, + )); + } + } + } + Ok(extra_args) +} + fn run_test_binary( mode: Mode, path: &Path, diff --git a/tests/integrations/basic-fail/Cargo.stderr b/tests/integrations/basic-fail/Cargo.stderr index 220542c0..3287a1b3 100644 --- a/tests/integrations/basic-fail/Cargo.stderr +++ b/tests/integrations/basic-fail/Cargo.stderr @@ -182,6 +182,7 @@ tests/actual_tests_bless/foomp-rustfix-fail-revisions.rs (a) ... FAILED tests/actual_tests_bless/foomp-rustfix-fail-revisions.rs (b) ... FAILED tests/actual_tests_bless/foomp-rustfix-fail.rs ... FAILED tests/actual_tests_bless/foomp_aux.rs ... ok +tests/actual_tests_bless/nested_aux.rs ... ok tests/actual_tests_bless/non_top_level_configs.rs ... FAILED tests/actual_tests_bless/pass.rs ... ok tests/actual_tests_bless/revised_revision.rs ... FAILED @@ -404,7 +405,7 @@ FAILURES: tests/actual_tests_bless/revisioned_executable_panic.rs tests/actual_tests_bless/revisions_bad.rs -test result: FAIL. 12 tests failed, 11 tests passed, 3 ignored, 0 filtered out +test result: FAIL. 12 tests failed, 12 tests passed, 3 ignored, 0 filtered out Compiler: rustc "--error-format=json" Building test dependencies... tests/actual_tests_bless_yolo/foomp-rustfix-fail.rs ... ok diff --git a/tests/integrations/basic-fail/tests/actual_tests_bless/auxiliary/nested.rs b/tests/integrations/basic-fail/tests/actual_tests_bless/auxiliary/nested.rs new file mode 100644 index 00000000..dad6ebcc --- /dev/null +++ b/tests/integrations/basic-fail/tests/actual_tests_bless/auxiliary/nested.rs @@ -0,0 +1,5 @@ +//@aux-build:foomp.rs + +pub fn bar() { + foomp::add(1, 2); +} diff --git a/tests/integrations/basic-fail/tests/actual_tests_bless/nested_aux.rs b/tests/integrations/basic-fail/tests/actual_tests_bless/nested_aux.rs new file mode 100644 index 00000000..fd533438 --- /dev/null +++ b/tests/integrations/basic-fail/tests/actual_tests_bless/nested_aux.rs @@ -0,0 +1,8 @@ +//@aux-build:nested.rs +//@check-pass + +use nested::bar; + +fn main() { + bar(); +} From 7a027d98dae986bd0d922737141393d9cccb89e0 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 19 Apr 2023 13:46:40 +0000 Subject: [PATCH 2/2] Version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- tests/integrations/basic-bin/Cargo.lock | 2 +- tests/integrations/basic-fail-mode/Cargo.lock | 2 +- tests/integrations/basic-fail/Cargo.lock | 2 +- tests/integrations/basic/Cargo.lock | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 33866763..e2d2d062 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -540,7 +540,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.8.1" +version = "0.8.2" dependencies = [ "bstr", "cargo-platform", diff --git a/Cargo.toml b/Cargo.toml index a5d7d3bc..21cb707e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ui_test" -version = "0.8.1" +version = "0.8.2" edition = "2021" license = "MIT OR Apache-2.0" description = "A test framework for testing rustc diagnostics output" diff --git a/tests/integrations/basic-bin/Cargo.lock b/tests/integrations/basic-bin/Cargo.lock index 335f24d8..c677c6f7 100644 --- a/tests/integrations/basic-bin/Cargo.lock +++ b/tests/integrations/basic-bin/Cargo.lock @@ -527,7 +527,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.8.1" +version = "0.8.2" dependencies = [ "bstr", "cargo-platform", diff --git a/tests/integrations/basic-fail-mode/Cargo.lock b/tests/integrations/basic-fail-mode/Cargo.lock index 6894ca14..4b7aeae0 100644 --- a/tests/integrations/basic-fail-mode/Cargo.lock +++ b/tests/integrations/basic-fail-mode/Cargo.lock @@ -528,7 +528,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.8.1" +version = "0.8.2" dependencies = [ "bstr", "cargo-platform", diff --git a/tests/integrations/basic-fail/Cargo.lock b/tests/integrations/basic-fail/Cargo.lock index 946990c7..a467bcc5 100644 --- a/tests/integrations/basic-fail/Cargo.lock +++ b/tests/integrations/basic-fail/Cargo.lock @@ -528,7 +528,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.8.1" +version = "0.8.2" dependencies = [ "bstr", "cargo-platform", diff --git a/tests/integrations/basic/Cargo.lock b/tests/integrations/basic/Cargo.lock index a3ba381c..d8c1b2a7 100644 --- a/tests/integrations/basic/Cargo.lock +++ b/tests/integrations/basic/Cargo.lock @@ -528,7 +528,7 @@ dependencies = [ [[package]] name = "ui_test" -version = "0.8.1" +version = "0.8.2" dependencies = [ "bstr", "cargo-platform",