Skip to content

Commit

Permalink
Auto merge of rust-lang#96517 - ferrocene:pa-files-related-to-test, r…
Browse files Browse the repository at this point in the history
…=Mark-Simulacrum

[compiletest] Extract code to detect files related to a test into a different function

In the code that checks whether a test needs to be re-executed, compiletest checks the modification date of all the files related to the test. I need the list of files related to the test for other purposes inside compiletest, and while I could copy/paste the code `is_up_to_date` runs, that would produce incomplete results if more related files are added in the future.

This PR extracts the code to detect related files into a separate function, allowing the rest of compiletest to access the same data.

r? `@Mark-Simulacrum`
  • Loading branch information
bors committed May 1, 2022
2 parents 4dd8b42 + 62f9844 commit 4c5efea
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions src/tools/compiletest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,40 @@ fn stamp(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> Path
output_base_dir(config, testpaths, revision).join("stamp")
}

fn files_related_to_test(
config: &Config,
testpaths: &TestPaths,
props: &EarlyProps,
revision: Option<&str>,
) -> Vec<PathBuf> {
let mut related = vec![];

if testpaths.file.is_dir() {
// run-make tests use their individual directory
for entry in WalkDir::new(&testpaths.file) {
let path = entry.unwrap().into_path();
if path.is_file() {
related.push(path);
}
}
} else {
related.push(testpaths.file.clone());
}

for aux in &props.aux {
let path = testpaths.file.parent().unwrap().join("auxiliary").join(aux);
related.push(path);
}

// UI test files.
for extension in UI_EXTENSIONS {
let path = expected_output_path(testpaths, revision, &config.compare_mode, extension);
related.push(path);
}

related
}

fn is_up_to_date(
config: &Config,
testpaths: &TestPaths,
Expand All @@ -686,20 +720,10 @@ fn is_up_to_date(

// Check timestamps.
let mut inputs = inputs.clone();
// Use `add_dir` to account for run-make tests, which use their individual directory
inputs.add_dir(&testpaths.file);

for aux in &props.aux {
let path = testpaths.file.parent().unwrap().join("auxiliary").join(aux);
for path in files_related_to_test(config, testpaths, props, revision) {
inputs.add_path(&path);
}

// UI test files.
for extension in UI_EXTENSIONS {
let path = &expected_output_path(testpaths, revision, &config.compare_mode, extension);
inputs.add_path(path);
}

inputs < Stamp::from_path(&stamp_name)
}

Expand Down

0 comments on commit 4c5efea

Please sign in to comment.