Skip to content

Commit f435138

Browse files
authored
Rollup merge of #136542 - jieyouxu:build-base, r=onur-ozkan
[`compiletest`-related cleanups 4/7] Make the distinction between root build directory vs test suite specific build directory in compiletest less confusing Reference for overall changes: #136437 Part **4** of **7** of the *`compiletest`-related cleanups* PR series. ### Summary - Remove `--build-base` compiletest flag, and introduce `--build-{root,test-suite-root}` flags instead. `--build-base` previously actually is test suite specific build directory, not the root `build/` directory. - Feed the root build directory directly from bootstrap to compiletest via `--build-root` instead of doing multiple layers of parent unwrapping[^parent] based on the test suite specific build directory. - Remove a redundant `to_path_buf()`. [^parent]: Please do not unwrap the parents. r? bootstrap
2 parents 96cfc75 + 7d2e4e4 commit f435138

File tree

8 files changed

+57
-40
lines changed

8 files changed

+57
-40
lines changed

src/bootstrap/src/core/build_steps/test.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1793,14 +1793,18 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17931793
cmd.arg("--src-root").arg(&builder.src);
17941794
cmd.arg("--src-test-suite-root").arg(builder.src.join("tests").join(suite));
17951795

1796-
cmd.arg("--build-base").arg(testdir(builder, compiler.host).join(suite));
1796+
// N.B. it's important to distinguish between the *root* build directory, the *host* build
1797+
// directory immediately under the root build directory, and the test-suite-specific build
1798+
// directory.
1799+
cmd.arg("--build-root").arg(&builder.out);
1800+
cmd.arg("--build-test-suite-root").arg(testdir(builder, compiler.host).join(suite));
17971801

17981802
// When top stage is 0, that means that we're testing an externally provided compiler.
17991803
// In that case we need to use its specific sysroot for tests to pass.
18001804
let sysroot = if builder.top_stage == 0 {
18011805
builder.initial_sysroot.clone()
18021806
} else {
1803-
builder.sysroot(compiler).to_path_buf()
1807+
builder.sysroot(compiler)
18041808
};
18051809

18061810
cmd.arg("--sysroot-base").arg(sysroot);

src/tools/compiletest/src/common.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,10 @@ pub struct Config {
220220
/// The directory containing the test suite sources. Must be a subdirectory of `src_root`.
221221
pub src_test_suite_root: PathBuf,
222222

223-
/// The directory where programs should be built
224-
pub build_base: PathBuf,
223+
/// Root build directory (e.g. `build/`).
224+
pub build_root: PathBuf,
225+
/// Test suite specific build directory (e.g. `build/host/test/ui/`).
226+
pub build_test_suite_root: PathBuf,
225227

226228
/// The directory containing the compiler sysroot
227229
pub sysroot_base: PathBuf,
@@ -347,7 +349,7 @@ pub struct Config {
347349

348350
/// If true, this will generate a coverage file with UI test files that run `MachineApplicable`
349351
/// diagnostics but are missing `run-rustfix` annotations. The generated coverage file is
350-
/// created in `/<build_base>/rustfix_missing_coverage.txt`
352+
/// created in `<test_suite_build_root>/rustfix_missing_coverage.txt`
351353
pub rustfix_coverage: bool,
352354

353355
/// whether to run `tidy` (html-tidy) when a rustdoc test fails
@@ -812,12 +814,16 @@ pub const UI_STDERR_16: &str = "16bit.stderr";
812814
pub const UI_COVERAGE: &str = "coverage";
813815
pub const UI_COVERAGE_MAP: &str = "cov-map";
814816

815-
/// Absolute path to the directory where all output for all tests in the given
816-
/// `relative_dir` group should reside. Example:
817-
/// /path/to/build/host-tuple/test/ui/relative/
817+
/// Absolute path to the directory where all output for all tests in the given `relative_dir` group
818+
/// should reside. Example:
819+
///
820+
/// ```text
821+
/// /path/to/build/host-tuple/test/ui/relative/
822+
/// ```
823+
///
818824
/// This is created early when tests are collected to avoid race conditions.
819825
pub fn output_relative_path(config: &Config, relative_dir: &Path) -> PathBuf {
820-
config.build_base.join(relative_dir)
826+
config.build_test_suite_root.join(relative_dir)
821827
}
822828

823829
/// Generates a unique name for the test, such as `testname.revision.mode`.

src/tools/compiletest/src/header.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1070,10 +1070,11 @@ impl Config {
10701070
}
10711071
}
10721072

1073+
// FIXME(jieyouxu): fix some of these variable names to more accurately reflect what they do.
10731074
fn expand_variables(mut value: String, config: &Config) -> String {
10741075
const CWD: &str = "{{cwd}}";
10751076
const SRC_BASE: &str = "{{src-base}}";
1076-
const BUILD_BASE: &str = "{{build-base}}";
1077+
const TEST_SUITE_BUILD_BASE: &str = "{{build-base}}";
10771078
const RUST_SRC_BASE: &str = "{{rust-src-base}}";
10781079
const SYSROOT_BASE: &str = "{{sysroot-base}}";
10791080
const TARGET_LINKER: &str = "{{target-linker}}";
@@ -1088,12 +1089,13 @@ fn expand_variables(mut value: String, config: &Config) -> String {
10881089
value = value.replace(SRC_BASE, &config.src_test_suite_root.to_str().unwrap());
10891090
}
10901091

1091-
if value.contains(BUILD_BASE) {
1092-
value = value.replace(BUILD_BASE, &config.build_base.to_string_lossy());
1092+
if value.contains(TEST_SUITE_BUILD_BASE) {
1093+
value =
1094+
value.replace(TEST_SUITE_BUILD_BASE, &config.build_test_suite_root.to_str().unwrap());
10931095
}
10941096

10951097
if value.contains(SYSROOT_BASE) {
1096-
value = value.replace(SYSROOT_BASE, &config.sysroot_base.to_string_lossy());
1098+
value = value.replace(SYSROOT_BASE, &config.sysroot_base.to_str().unwrap());
10971099
}
10981100

10991101
if value.contains(TARGET_LINKER) {

src/tools/compiletest/src/header/tests.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ impl ConfigBuilder {
155155
"--jsondocck-path=",
156156
"--src-root=",
157157
"--src-test-suite-root=",
158-
"--build-base=",
158+
"--build-root=",
159+
"--build-test-suite-root=",
159160
"--sysroot-base=",
160161
"--cc=c",
161162
"--cxx=c++",

src/tools/compiletest/src/lib.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
6363
.optopt("", "llvm-filecheck", "path to LLVM's FileCheck binary", "DIR")
6464
.reqopt("", "src-root", "directory containing sources", "PATH")
6565
.reqopt("", "src-test-suite-root", "directory containing test suite sources", "PATH")
66-
.reqopt("", "build-base", "directory to deposit test outputs", "PATH")
66+
.reqopt("", "build-root", "path to root build directory", "PATH")
67+
.reqopt("", "build-test-suite-root", "path to test suite specific build directory", "PATH")
6768
.reqopt("", "sysroot-base", "directory containing the compiler sysroot", "PATH")
6869
.reqopt("", "stage", "stage number under test", "N")
6970
.reqopt("", "stage-id", "the target-stage identifier", "stageN-TARGET")
@@ -157,7 +158,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
157158
"",
158159
"rustfix-coverage",
159160
"enable this to generate a Rustfix coverage file, which is saved in \
160-
`./<build_base>/rustfix_missing_coverage.txt`",
161+
`./<build_test_suite_root>/rustfix_missing_coverage.txt`",
161162
)
162163
.optflag("", "force-rerun", "rerun tests even if the inputs are unchanged")
163164
.optflag("", "only-modified", "only run tests that result been modified")
@@ -309,6 +310,10 @@ pub fn parse_config(args: Vec<String>) -> Config {
309310
src_test_suite_root.display()
310311
);
311312

313+
let build_root = opt_path(matches, "build-root");
314+
let build_test_suite_root = opt_path(matches, "build-test-suite-root");
315+
assert!(build_test_suite_root.starts_with(&build_root));
316+
312317
Config {
313318
bless: matches.opt_present("bless"),
314319
compile_lib_path: make_absolute(opt_path(matches, "compile-lib-path")),
@@ -327,7 +332,9 @@ pub fn parse_config(args: Vec<String>) -> Config {
327332
src_root,
328333
src_test_suite_root,
329334

330-
build_base: opt_path(matches, "build-base"),
335+
build_root,
336+
build_test_suite_root,
337+
331338
sysroot_base: opt_path(matches, "sysroot-base"),
332339

333340
stage,
@@ -438,7 +445,11 @@ pub fn log_config(config: &Config) {
438445
logv(c, format!("src_root: {}", config.src_root.display()));
439446
logv(c, format!("src_test_suite_root: {}", config.src_test_suite_root.display()));
440447

441-
logv(c, format!("build_base: {:?}", config.build_base.display()));
448+
logv(c, format!("build_root: {}", config.build_root.display()));
449+
logv(c, format!("build_test_suite_root: {}", config.build_test_suite_root.display()));
450+
451+
logv(c, format!("sysroot_base: {}", config.sysroot_base.display()));
452+
442453
logv(c, format!("stage: {}", config.stage));
443454
logv(c, format!("stage_id: {}", config.stage_id));
444455
logv(c, format!("mode: {}", config.mode));
@@ -488,7 +499,7 @@ pub fn run_tests(config: Arc<Config>) {
488499
// we first make sure that the coverage file does not exist.
489500
// It will be created later on.
490501
if config.rustfix_coverage {
491-
let mut coverage_file_path = config.build_base.clone();
502+
let mut coverage_file_path = config.build_test_suite_root.clone();
492503
coverage_file_path.push("rustfix_missing_coverage.txt");
493504
if coverage_file_path.exists() {
494505
if let Err(e) = fs::remove_file(&coverage_file_path) {

src/tools/compiletest/src/runtest.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,9 @@ impl<'test> TestCx<'test> {
535535
.arg(&out_dir)
536536
.arg(&format!("--target={}", target))
537537
.arg("-L")
538-
.arg(&self.config.build_base)
538+
// FIXME(jieyouxu): this search path seems questionable. Is this intended for
539+
// `rust_test_helpers` in ui tests?
540+
.arg(&self.config.build_test_suite_root)
539541
.arg("-L")
540542
.arg(aux_dir)
541543
.arg("-A")
@@ -1366,7 +1368,7 @@ impl<'test> TestCx<'test> {
13661368
// Note: avoid adding a subdirectory of an already filtered directory here, otherwise the
13671369
// same slice of text will be double counted and the truncation might not happen.
13681370
add_path(&self.config.src_test_suite_root);
1369-
add_path(&self.config.build_base);
1371+
add_path(&self.config.build_test_suite_root);
13701372

13711373
read2_abbreviated(child, &filter_paths_from_len).expect("failed to read output")
13721374
}
@@ -1421,7 +1423,7 @@ impl<'test> TestCx<'test> {
14211423
}
14221424

14231425
fn get_mir_dump_dir(&self) -> PathBuf {
1424-
let mut mir_dump_dir = PathBuf::from(self.config.build_base.as_path());
1426+
let mut mir_dump_dir = self.config.build_test_suite_root.clone();
14251427
debug!("input_file: {:?}", self.testpaths.file);
14261428
mir_dump_dir.push(&self.testpaths.relative_dir);
14271429
mir_dump_dir.push(self.testpaths.file.file_stem().unwrap());
@@ -2410,14 +2412,10 @@ impl<'test> TestCx<'test> {
24102412
let rust_src_dir = rust_src_dir.read_link().unwrap_or(rust_src_dir.to_path_buf());
24112413
normalize_path(&rust_src_dir.join("library"), "$SRC_DIR_REAL");
24122414

2413-
// Paths into the build directory
2414-
let test_build_dir = &self.config.build_base;
2415-
let parent_build_dir = test_build_dir.parent().unwrap().parent().unwrap().parent().unwrap();
2416-
24172415
// eg. /home/user/rust/build/x86_64-unknown-linux-gnu/test/ui
2418-
normalize_path(test_build_dir, "$TEST_BUILD_DIR");
2416+
normalize_path(&self.config.build_test_suite_root, "$TEST_BUILD_DIR");
24192417
// eg. /home/user/rust/build
2420-
normalize_path(parent_build_dir, "$BUILD_DIR");
2418+
normalize_path(&self.config.build_root, "$BUILD_DIR");
24212419

24222420
if json {
24232421
// escaped newlines in json strings should be readable

src/tools/compiletest/src/runtest/run_make.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,7 @@ impl TestCx<'_> {
179179
// library.
180180
// 2. We need to run the recipe binary.
181181

182-
// `self.config.build_base` is actually the build base folder + "test" + test suite name, it
183-
// looks like `build/<host_triple>/test/run-make`. But we want `build/<host_triple>/`. Note
184-
// that the `build` directory does not need to be called `build`, nor does it need to be
185-
// under `src_root`, so we must compute it based off of `self.config.build_base`.
186-
let build_root =
187-
self.config.build_base.parent().and_then(Path::parent).unwrap().to_path_buf();
182+
let host_build_root = self.config.build_root.join(&self.config.host);
188183

189184
// We construct the following directory tree for each rmake.rs test:
190185
// ```
@@ -242,10 +237,10 @@ impl TestCx<'_> {
242237

243238
let stage_number = self.config.stage;
244239

245-
let stage_tools_bin = build_root.join(format!("stage{stage_number}-tools-bin"));
240+
let stage_tools_bin = host_build_root.join(format!("stage{stage_number}-tools-bin"));
246241
let support_lib_path = stage_tools_bin.join("librun_make_support.rlib");
247242

248-
let stage_tools = build_root.join(format!("stage{stage_number}-tools"));
243+
let stage_tools = host_build_root.join(format!("stage{stage_number}-tools"));
249244
let support_lib_deps = stage_tools.join(&self.config.host).join("release").join("deps");
250245
let support_lib_deps_deps = stage_tools.join("release").join("deps");
251246

@@ -311,7 +306,7 @@ impl TestCx<'_> {
311306
// to work correctly.
312307
//
313308
// See <https://github.com/rust-lang/rust/pull/122248> for more background.
314-
let stage0_sysroot = build_root.join("stage0-sysroot");
309+
let stage0_sysroot = host_build_root.join("stage0-sysroot");
315310
if std::env::var_os("COMPILETEST_FORCE_STAGE0").is_some() {
316311
rustc.arg("--sysroot").arg(&stage0_sysroot);
317312
}
@@ -326,7 +321,7 @@ impl TestCx<'_> {
326321
// provided through env vars.
327322

328323
// Compute stage-specific standard library paths.
329-
let stage_std_path = build_root.join(format!("stage{stage_number}")).join("lib");
324+
let stage_std_path = host_build_root.join(format!("stage{stage_number}")).join("lib");
330325

331326
// Compute dynamic library search paths for recipes.
332327
let recipe_dylib_search_paths = {
@@ -372,7 +367,7 @@ impl TestCx<'_> {
372367
// Provide path to sources root.
373368
.env("SOURCE_ROOT", &self.config.src_root)
374369
// Path to the host build directory.
375-
.env("BUILD_ROOT", &build_root)
370+
.env("BUILD_ROOT", &host_build_root)
376371
// Provide path to stage-corresponding rustc.
377372
.env("RUSTC", &self.config.rustc_path)
378373
// Provide the directory to libraries that are needed to run the *compiler*. This is not

src/tools/compiletest/src/runtest/ui.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl TestCx<'_> {
6666
&& !self.props.run_rustfix
6767
&& !self.props.rustfix_only_machine_applicable
6868
{
69-
let mut coverage_file_path = self.config.build_base.clone();
69+
let mut coverage_file_path = self.config.build_test_suite_root.clone();
7070
coverage_file_path.push("rustfix_missing_coverage.txt");
7171
debug!("coverage_file_path: {}", coverage_file_path.display());
7272

0 commit comments

Comments
 (0)