Skip to content

Commit 9d3faba

Browse files
Auto merge of #148160 - Zalathar:paths, r=<try>
(DRAFT) compiletest: Split `TestPaths` into `RootTestPaths` and `TestOrAuxPaths`. try-job: x86_64-msvc-1 try-job: i686-msvc-1 try-job: x86_64-mingw-1 try-job: test-various try-job: armhf-gnu try-job: aarch64-apple
2 parents b1b464d + 7939794 commit 9d3faba

File tree

10 files changed

+144
-87
lines changed

10 files changed

+144
-87
lines changed

src/tools/compiletest/src/common.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ fn query_rustc_output(config: &Config, args: &[&str], envs: HashMap<String, Stri
11061106

11071107
/// Path information for a single test file.
11081108
#[derive(Debug, Clone)]
1109-
pub(crate) struct TestPaths {
1109+
pub(crate) struct RootTestPaths {
11101110
/// Full path to the test file.
11111111
///
11121112
/// For example:
@@ -1131,9 +1131,28 @@ pub(crate) struct TestPaths {
11311131
pub(crate) relative_dir: Utf8PathBuf,
11321132
}
11331133

1134+
impl RootTestPaths {
1135+
pub(crate) fn clone_to_test_or_aux_paths(&self) -> TestOrAuxPaths {
1136+
let Self { file, relative_dir } = self;
1137+
let file = file.clone();
1138+
let relative_dir = relative_dir.clone();
1139+
TestOrAuxPaths { file, relative_dir }
1140+
}
1141+
}
1142+
1143+
/// For unfortunate historical reasons, this contains either paths for a single
1144+
/// test file, or paths for a single auxiliary source file.
1145+
#[derive(Debug, Clone)]
1146+
pub(crate) struct TestOrAuxPaths {
1147+
/// See `TestPaths::file`.
1148+
pub(crate) file: Utf8PathBuf,
1149+
/// See `TestPaths::relative_dir`.
1150+
pub(crate) relative_dir: Utf8PathBuf,
1151+
}
1152+
11341153
/// Used by `ui` tests to generate things like `foo.stderr` from `foo.rs`.
11351154
pub fn expected_output_path(
1136-
testpaths: &TestPaths,
1155+
testpaths: &RootTestPaths,
11371156
revision: Option<&str>,
11381157
compare_mode: &Option<CompareMode>,
11391158
kind: &str,
@@ -1195,7 +1214,7 @@ pub fn output_relative_path(config: &Config, relative_dir: &Utf8Path) -> Utf8Pat
11951214
/// Generates a unique name for the test, such as `testname.revision.mode`.
11961215
pub fn output_testname_unique(
11971216
config: &Config,
1198-
testpaths: &TestPaths,
1217+
testpaths: &RootTestPaths,
11991218
revision: Option<&str>,
12001219
) -> Utf8PathBuf {
12011220
let mode = config.compare_mode.as_ref().map_or("", |m| m.to_str());
@@ -1212,7 +1231,7 @@ pub fn output_testname_unique(
12121231
/// /path/to/build/host-tuple/test/ui/relative/testname.revision.mode/
12131232
pub fn output_base_dir(
12141233
config: &Config,
1215-
testpaths: &TestPaths,
1234+
testpaths: &RootTestPaths,
12161235
revision: Option<&str>,
12171236
) -> Utf8PathBuf {
12181237
output_relative_path(config, &testpaths.relative_dir)
@@ -1224,7 +1243,7 @@ pub fn output_base_dir(
12241243
/// /path/to/build/host-tuple/test/ui/relative/testname.revision.mode/testname
12251244
pub fn output_base_name(
12261245
config: &Config,
1227-
testpaths: &TestPaths,
1246+
testpaths: &RootTestPaths,
12281247
revision: Option<&str>,
12291248
) -> Utf8PathBuf {
12301249
output_base_dir(config, testpaths, revision).join(testpaths.file.file_stem().unwrap())
@@ -1234,7 +1253,7 @@ pub fn output_base_name(
12341253
/// /path/to/build/host-tuple/test/ui/relative/testname.mode/testname.inc
12351254
pub fn incremental_dir(
12361255
config: &Config,
1237-
testpaths: &TestPaths,
1256+
testpaths: &RootTestPaths,
12381257
revision: Option<&str>,
12391258
) -> Utf8PathBuf {
12401259
output_base_name(config, testpaths, revision).with_extension("inc")

src/tools/compiletest/src/executor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::{env, hint, mem, panic, thread};
1414

1515
use camino::Utf8PathBuf;
1616

17-
use crate::common::{Config, TestPaths};
17+
use crate::common::{Config, RootTestPaths};
1818
use crate::output_capture::{self, ConsoleOut};
1919
use crate::panic_hook;
2020

@@ -125,7 +125,7 @@ struct TestThreadArgs {
125125
id: TestId,
126126

127127
config: Arc<Config>,
128-
testpaths: TestPaths,
128+
testpaths: RootTestPaths,
129129
revision: Option<String>,
130130
should_fail: ShouldFail,
131131

@@ -328,7 +328,7 @@ fn get_concurrency() -> usize {
328328
pub(crate) struct CollectedTest {
329329
pub(crate) desc: CollectedTestDesc,
330330
pub(crate) config: Arc<Config>,
331-
pub(crate) testpaths: TestPaths,
331+
pub(crate) testpaths: RootTestPaths,
332332
pub(crate) revision: Option<String>,
333333
}
334334

src/tools/compiletest/src/lib.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ use walkdir::WalkDir;
3838

3939
use self::directives::{EarlyProps, make_test_description};
4040
use crate::common::{
41-
CodegenBackend, CompareMode, Config, Debugger, PassMode, TestMode, TestPaths, UI_EXTENSIONS,
42-
expected_output_path, output_base_dir, output_relative_path,
41+
CodegenBackend, CompareMode, Config, Debugger, PassMode, RootTestPaths, TestMode,
42+
UI_EXTENSIONS, expected_output_path, output_base_dir, output_relative_path,
4343
};
4444
use crate::directives::{AuxProps, DirectivesCache, FileDirectives};
4545
use crate::edition::parse_edition;
@@ -773,7 +773,7 @@ fn collect_tests_from_dir(
773773
if cx.config.mode == TestMode::RunMake {
774774
let mut collector = TestCollector::new();
775775
if dir.join("rmake.rs").exists() {
776-
let paths = TestPaths {
776+
let paths = RootTestPaths {
777777
file: dir.to_path_buf(),
778778
relative_dir: relative_dir_path.parent().unwrap().to_path_buf(),
779779
};
@@ -814,8 +814,10 @@ fn collect_tests_from_dir(
814814
let rel_test_path = relative_dir_path.join(file_path.file_stem().unwrap());
815815
collector.found_path_stems.insert(rel_test_path);
816816

817-
let paths =
818-
TestPaths { file: file_path, relative_dir: relative_dir_path.to_path_buf() };
817+
let paths = RootTestPaths {
818+
file: file_path,
819+
relative_dir: relative_dir_path.to_path_buf(),
820+
};
819821
make_test(cx, &mut collector, &paths);
820822
} else if file_path.is_dir() {
821823
// Recurse to find more tests in a subdirectory.
@@ -852,7 +854,7 @@ fn is_test(file_name: &str) -> bool {
852854

853855
/// For a single test file, creates one or more test structures (one per revision) that can be
854856
/// handed over to the executor to run, possibly in parallel.
855-
fn make_test(cx: &TestCollectorCx, collector: &mut TestCollector, testpaths: &TestPaths) {
857+
fn make_test(cx: &TestCollectorCx, collector: &mut TestCollector, testpaths: &RootTestPaths) {
856858
// For run-make tests, each "test file" is actually a _directory_ containing an `rmake.rs`. But
857859
// for the purposes of directive parsing, we want to look at that recipe file, not the directory
858860
// itself.
@@ -929,7 +931,11 @@ fn make_test(cx: &TestCollectorCx, collector: &mut TestCollector, testpaths: &Te
929931

930932
/// The path of the `stamp` file that gets created or updated whenever a
931933
/// particular test completes successfully.
932-
fn stamp_file_path(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> Utf8PathBuf {
934+
fn stamp_file_path(
935+
config: &Config,
936+
testpaths: &RootTestPaths,
937+
revision: Option<&str>,
938+
) -> Utf8PathBuf {
933939
output_base_dir(config, testpaths, revision).join("stamp")
934940
}
935941

@@ -939,7 +945,7 @@ fn stamp_file_path(config: &Config, testpaths: &TestPaths, revision: Option<&str
939945
/// (Might be inaccurate in some cases.)
940946
fn files_related_to_test(
941947
config: &Config,
942-
testpaths: &TestPaths,
948+
testpaths: &RootTestPaths,
943949
aux_props: &AuxProps,
944950
revision: Option<&str>,
945951
) -> Vec<Utf8PathBuf> {
@@ -985,7 +991,7 @@ fn files_related_to_test(
985991
/// flag can be used to ignore up-to-date checking and always re-run tests.)
986992
fn is_up_to_date(
987993
cx: &TestCollectorCx,
988-
testpaths: &TestPaths,
994+
testpaths: &RootTestPaths,
989995
aux_props: &AuxProps,
990996
revision: Option<&str>,
991997
) -> bool {
@@ -1061,7 +1067,7 @@ impl Stamp {
10611067
/// Creates a name for this test/revision that can be handed over to the executor.
10621068
fn make_test_name_and_filterable_path(
10631069
config: &Config,
1064-
testpaths: &TestPaths,
1070+
testpaths: &RootTestPaths,
10651071
revision: Option<&str>,
10661072
) -> (String, Utf8PathBuf) {
10671073
// Print the name of the file, relative to the sources root.

0 commit comments

Comments
 (0)