Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow aux builds to have nested aux builds #56

Merged
merged 2 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
102 changes: 66 additions & 36 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,18 +921,19 @@ fn build_aux(
kind: &str,
aux: &Path,
extra_args: &mut Vec<String>,
) -> Option<(Command, Vec<Error>, Vec<u8>)> {
) -> std::result::Result<(), (Command, Vec<Error>, Vec<u8>)> {
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,
))
}
};
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.
Expand All @@ -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();
Expand All @@ -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,
Expand All @@ -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(
Expand All @@ -994,37 +1005,16 @@ fn run_test(
revision: &str,
comments: &Comments,
) -> (Command, Errors, Vec<u8>) {
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![];

Expand Down Expand Up @@ -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<Vec<String>, (Command, Vec<Error>, Vec<u8>)> {
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,
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/basic-bin/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/integrations/basic-fail-mode/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/integrations/basic-fail/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tests/integrations/basic-fail/Cargo.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@aux-build:foomp.rs

pub fn bar() {
foomp::add(1, 2);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//@aux-build:nested.rs
//@check-pass

use nested::bar;

fn main() {
bar();
}
2 changes: 1 addition & 1 deletion tests/integrations/basic/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.