Skip to content

Commit 40475b4

Browse files
authored
Rollup merge of rust-lang#147898 - Zalathar:aux-props, r=jieyouxu
compiletest: Move `AuxProps` out of `EarlyProps` The primary purpose of `EarlyProps` is to discover revisions, so that we can create a separate test structure for each revision. Revisions can (and do) have different auxiliaries, and up-to-date checking is already done per-revision, so it makes more sense to perform up-to-date checks based on the current revisions's auxiliaries only. r? jieyouxu
2 parents d376a49 + d828c11 commit 40475b4

File tree

3 files changed

+38
-41
lines changed

3 files changed

+38
-41
lines changed

src/tools/compiletest/src/directives.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use tracing::*;
88

99
use crate::common::{CodegenBackend, Config, Debugger, FailMode, PassMode, RunFailMode, TestMode};
1010
use crate::debuggers::{extract_cdb_version, extract_gdb_version};
11-
use crate::directives::auxiliary::{AuxProps, parse_and_update_aux};
11+
pub(crate) use crate::directives::auxiliary::AuxProps;
12+
use crate::directives::auxiliary::parse_and_update_aux;
1213
use crate::directives::directive_names::{
1314
KNOWN_DIRECTIVE_NAMES, KNOWN_HTMLDOCCK_DIRECTIVE_NAMES, KNOWN_JSONDOCCK_DIRECTIVE_NAMES,
1415
};
@@ -21,7 +22,7 @@ use crate::executor::{CollectedTestDesc, ShouldPanic};
2122
use crate::util::static_regex;
2223
use crate::{fatal, help};
2324

24-
pub(crate) mod auxiliary;
25+
mod auxiliary;
2526
mod cfg;
2627
mod directive_names;
2728
mod file;
@@ -44,10 +45,6 @@ impl DirectivesCache {
4445
/// the test.
4546
#[derive(Default)]
4647
pub(crate) struct EarlyProps {
47-
/// Auxiliary crates that should be built and made available to this test.
48-
/// Included in [`EarlyProps`] so that the indicated files can participate
49-
/// in up-to-date checking. Building happens via [`TestProps::aux`] instead.
50-
pub(crate) aux: AuxProps,
5148
pub(crate) revisions: Vec<String>,
5249
}
5350

@@ -66,7 +63,6 @@ impl EarlyProps {
6663
file_directives,
6764
// (dummy comment to force args into vertical layout)
6865
&mut |ln: &DirectiveLine<'_>| {
69-
parse_and_update_aux(config, ln, &mut props.aux);
7066
config.parse_and_update_revisions(ln, &mut props.revisions);
7167
},
7268
);
@@ -1310,6 +1306,7 @@ pub(crate) fn make_test_description(
13101306
file_directives: &FileDirectives<'_>,
13111307
test_revision: Option<&str>,
13121308
poisoned: &mut bool,
1309+
aux_props: &mut AuxProps,
13131310
) -> CollectedTestDesc {
13141311
let mut ignore = false;
13151312
let mut ignore_message = None;
@@ -1327,6 +1324,9 @@ pub(crate) fn make_test_description(
13271324
return;
13281325
}
13291326

1327+
// Parse `aux-*` directives, for use by up-to-date checks.
1328+
parse_and_update_aux(config, ln, aux_props);
1329+
13301330
macro_rules! decision {
13311331
($e:expr) => {
13321332
match $e {

src/tools/compiletest/src/directives/tests.rs

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ use semver::Version;
33

44
use crate::common::{Config, Debugger, TestMode};
55
use crate::directives::{
6-
DirectivesCache, EarlyProps, Edition, EditionRange, FileDirectives, extract_llvm_version,
7-
extract_version_range, iter_directives, line_directive, parse_edition, parse_normalize_rule,
6+
AuxProps, DirectivesCache, EarlyProps, Edition, EditionRange, FileDirectives,
7+
extract_llvm_version, extract_version_range, iter_directives, line_directive, parse_edition,
8+
parse_normalize_rule,
89
};
910
use crate::executor::{CollectedTestDesc, ShouldPanic};
1011

@@ -20,6 +21,7 @@ fn make_test_description(
2021
let mut poisoned = false;
2122
let file_directives = FileDirectives::from_file_contents(path, file_contents);
2223

24+
let mut aux_props = AuxProps::default();
2325
let test = crate::directives::make_test_description(
2426
config,
2527
&cache,
@@ -29,6 +31,7 @@ fn make_test_description(
2931
&file_directives,
3032
revision,
3133
&mut poisoned,
34+
&mut aux_props,
3235
);
3336
if poisoned {
3437
panic!("poisoned!");
@@ -225,7 +228,7 @@ fn cfg() -> ConfigBuilder {
225228
ConfigBuilder::default()
226229
}
227230

228-
fn parse_rs(config: &Config, contents: &str) -> EarlyProps {
231+
fn parse_early_props(config: &Config, contents: &str) -> EarlyProps {
229232
let file_directives = FileDirectives::from_file_contents(Utf8Path::new("a.rs"), contents);
230233
EarlyProps::from_file_directives(config, &file_directives)
231234
}
@@ -253,25 +256,7 @@ fn should_fail() {
253256
fn revisions() {
254257
let config: Config = cfg().build();
255258

256-
assert_eq!(parse_rs(&config, "//@ revisions: a b c").revisions, vec!["a", "b", "c"],);
257-
}
258-
259-
#[test]
260-
fn aux_build() {
261-
let config: Config = cfg().build();
262-
263-
assert_eq!(
264-
parse_rs(
265-
&config,
266-
r"
267-
//@ aux-build: a.rs
268-
//@ aux-build: b.rs
269-
"
270-
)
271-
.aux
272-
.builds,
273-
vec!["a.rs", "b.rs"],
274-
);
259+
assert_eq!(parse_early_props(&config, "//@ revisions: a b c").revisions, vec!["a", "b", "c"],);
275260
}
276261

277262
#[test]
@@ -550,7 +535,7 @@ fn test_extract_version_range() {
550535
#[should_panic(expected = "duplicate revision: `rpass1` in line ` rpass1 rpass1`")]
551536
fn test_duplicate_revisions() {
552537
let config: Config = cfg().build();
553-
parse_rs(&config, "//@ revisions: rpass1 rpass1");
538+
parse_early_props(&config, "//@ revisions: rpass1 rpass1");
554539
}
555540

556541
#[test]
@@ -559,14 +544,14 @@ fn test_duplicate_revisions() {
559544
)]
560545
fn test_assembly_mode_forbidden_revisions() {
561546
let config = cfg().mode("assembly").build();
562-
parse_rs(&config, "//@ revisions: CHECK");
547+
parse_early_props(&config, "//@ revisions: CHECK");
563548
}
564549

565550
#[test]
566551
#[should_panic(expected = "revision name `true` is not permitted")]
567552
fn test_forbidden_revisions() {
568553
let config = cfg().mode("ui").build();
569-
parse_rs(&config, "//@ revisions: true");
554+
parse_early_props(&config, "//@ revisions: true");
570555
}
571556

572557
#[test]
@@ -575,7 +560,7 @@ fn test_forbidden_revisions() {
575560
)]
576561
fn test_codegen_mode_forbidden_revisions() {
577562
let config = cfg().mode("codegen").build();
578-
parse_rs(&config, "//@ revisions: CHECK");
563+
parse_early_props(&config, "//@ revisions: CHECK");
579564
}
580565

581566
#[test]
@@ -584,7 +569,7 @@ fn test_codegen_mode_forbidden_revisions() {
584569
)]
585570
fn test_miropt_mode_forbidden_revisions() {
586571
let config = cfg().mode("mir-opt").build();
587-
parse_rs(&config, "//@ revisions: CHECK");
572+
parse_early_props(&config, "//@ revisions: CHECK");
588573
}
589574

590575
#[test]
@@ -608,7 +593,7 @@ fn test_forbidden_revisions_allowed_in_non_filecheck_dir() {
608593
let content = format!("//@ revisions: {rev}");
609594
for mode in modes {
610595
let config = cfg().mode(mode).build();
611-
parse_rs(&config, &content);
596+
parse_early_props(&config, &content);
612597
}
613598
}
614599
}

src/tools/compiletest/src/lib.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use crate::common::{
4141
CodegenBackend, CompareMode, Config, Debugger, PassMode, TestMode, TestPaths, UI_EXTENSIONS,
4242
expected_output_path, output_base_dir, output_relative_path,
4343
};
44-
use crate::directives::{DirectivesCache, FileDirectives};
44+
use crate::directives::{AuxProps, DirectivesCache, FileDirectives};
4545
use crate::edition::parse_edition;
4646
use crate::executor::{CollectedTest, ColorConfig};
4747

@@ -891,6 +891,11 @@ fn make_test(cx: &TestCollectorCx, collector: &mut TestCollector, testpaths: &Te
891891
// Create a test name and description to hand over to the executor.
892892
let (test_name, filterable_path) =
893893
make_test_name_and_filterable_path(&cx.config, testpaths, revision);
894+
895+
// While scanning for ignore/only/needs directives, also collect aux
896+
// paths for up-to-date checking.
897+
let mut aux_props = AuxProps::default();
898+
894899
// Create a description struct for the test/revision.
895900
// This is where `ignore-*`/`only-*`/`needs-*` directives are handled,
896901
// because they historically needed to set the libtest ignored flag.
@@ -903,11 +908,15 @@ fn make_test(cx: &TestCollectorCx, collector: &mut TestCollector, testpaths: &Te
903908
&file_directives,
904909
revision,
905910
&mut collector.poisoned,
911+
&mut aux_props,
906912
);
907913

908914
// If a test's inputs haven't changed since the last time it ran,
909915
// mark it as ignored so that the executor will skip it.
910-
if !cx.config.force_rerun && is_up_to_date(cx, testpaths, &early_props, revision) {
916+
if !desc.ignore
917+
&& !cx.config.force_rerun
918+
&& is_up_to_date(cx, testpaths, &aux_props, revision)
919+
{
911920
desc.ignore = true;
912921
// Keep this in sync with the "up-to-date" message detected by bootstrap.
913922
// FIXME(Zalathar): Now that we are no longer tied to libtest, we could
@@ -936,7 +945,7 @@ fn stamp_file_path(config: &Config, testpaths: &TestPaths, revision: Option<&str
936945
fn files_related_to_test(
937946
config: &Config,
938947
testpaths: &TestPaths,
939-
props: &EarlyProps,
948+
aux_props: &AuxProps,
940949
revision: Option<&str>,
941950
) -> Vec<Utf8PathBuf> {
942951
let mut related = vec![];
@@ -953,8 +962,11 @@ fn files_related_to_test(
953962
related.push(testpaths.file.clone());
954963
}
955964

956-
for aux in props.aux.all_aux_path_strings() {
965+
for aux in aux_props.all_aux_path_strings() {
957966
// FIXME(Zalathar): Perform all `auxiliary` path resolution in one place.
967+
// FIXME(Zalathar): This only finds auxiliary files used _directly_ by
968+
// the test file; if a transitive auxiliary is modified, the test might
969+
// be treated as "up-to-date" even though it should run.
958970
let path = testpaths.file.parent().unwrap().join("auxiliary").join(aux);
959971
related.push(path);
960972
}
@@ -979,7 +991,7 @@ fn files_related_to_test(
979991
fn is_up_to_date(
980992
cx: &TestCollectorCx,
981993
testpaths: &TestPaths,
982-
props: &EarlyProps,
994+
aux_props: &AuxProps,
983995
revision: Option<&str>,
984996
) -> bool {
985997
let stamp_file_path = stamp_file_path(&cx.config, testpaths, revision);
@@ -1000,7 +1012,7 @@ fn is_up_to_date(
10001012
// Check the timestamp of the stamp file against the last modified time
10011013
// of all files known to be relevant to the test.
10021014
let mut inputs_stamp = cx.common_inputs_stamp.clone();
1003-
for path in files_related_to_test(&cx.config, testpaths, props, revision) {
1015+
for path in files_related_to_test(&cx.config, testpaths, aux_props, revision) {
10041016
inputs_stamp.add_path(&path);
10051017
}
10061018

0 commit comments

Comments
 (0)