compiletest/common.rs
1use std::collections::{BTreeSet, HashMap, HashSet};
2use std::iter;
3use std::process::Command;
4use std::sync::OnceLock;
5
6use build_helper::git::GitConfig;
7use camino::{Utf8Path, Utf8PathBuf};
8use semver::Version;
9
10use crate::executor::ColorConfig;
11use crate::fatal;
12use crate::util::{Utf8PathBufExt, add_dylib_path, string_enum};
13
14string_enum! {
15 #[derive(Clone, Copy, PartialEq, Debug)]
16 pub enum TestMode {
17 Pretty => "pretty",
18 DebugInfo => "debuginfo",
19 Codegen => "codegen",
20 Rustdoc => "rustdoc",
21 RustdocJson => "rustdoc-json",
22 CodegenUnits => "codegen-units",
23 Incremental => "incremental",
24 RunMake => "run-make",
25 Ui => "ui",
26 RustdocJs => "rustdoc-js",
27 MirOpt => "mir-opt",
28 Assembly => "assembly",
29 CoverageMap => "coverage-map",
30 CoverageRun => "coverage-run",
31 Crashes => "crashes",
32 }
33}
34
35impl TestMode {
36 pub fn aux_dir_disambiguator(self) -> &'static str {
37 // Pretty-printing tests could run concurrently, and if they do,
38 // they need to keep their output segregated.
39 match self {
40 TestMode::Pretty => ".pretty",
41 _ => "",
42 }
43 }
44
45 pub fn output_dir_disambiguator(self) -> &'static str {
46 // Coverage tests use the same test files for multiple test modes,
47 // so each mode should have a separate output directory.
48 match self {
49 TestMode::CoverageMap | TestMode::CoverageRun => self.to_str(),
50 _ => "",
51 }
52 }
53}
54
55// Note that coverage tests use the same test files for multiple test modes.
56string_enum! {
57 #[derive(Clone, Copy, PartialEq, Debug)]
58 pub enum TestSuite {
59 AssemblyLlvm => "assembly-llvm",
60 CodegenLlvm => "codegen-llvm",
61 CodegenUnits => "codegen-units",
62 Coverage => "coverage",
63 CoverageRunRustdoc => "coverage-run-rustdoc",
64 Crashes => "crashes",
65 Debuginfo => "debuginfo",
66 Incremental => "incremental",
67 MirOpt => "mir-opt",
68 Pretty => "pretty",
69 RunMake => "run-make",
70 Rustdoc => "rustdoc",
71 RustdocGui => "rustdoc-gui",
72 RustdocJs => "rustdoc-js",
73 RustdocJsStd=> "rustdoc-js-std",
74 RustdocJson => "rustdoc-json",
75 RustdocUi => "rustdoc-ui",
76 Ui => "ui",
77 UiFullDeps => "ui-fulldeps",
78 }
79}
80
81string_enum! {
82 #[derive(Clone, Copy, PartialEq, Debug, Hash)]
83 pub enum PassMode {
84 Check => "check",
85 Build => "build",
86 Run => "run",
87 }
88}
89
90string_enum! {
91 #[derive(Clone, Copy, PartialEq, Debug, Hash)]
92 pub enum RunResult {
93 Pass => "run-pass",
94 Fail => "run-fail",
95 Crash => "run-crash",
96 }
97}
98
99#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
100pub enum RunFailMode {
101 /// Running the program must make it exit with a regular failure exit code
102 /// in the range `1..=127`. If the program is terminated by e.g. a signal
103 /// the test will fail.
104 Fail,
105 /// Running the program must result in a crash, e.g. by `SIGABRT` or
106 /// `SIGSEGV` on Unix or on Windows by having an appropriate NTSTATUS high
107 /// bit in the exit code.
108 Crash,
109 /// Running the program must either fail or crash. Useful for e.g. sanitizer
110 /// tests since some sanitizer implementations exit the process with code 1
111 /// to in the face of memory errors while others abort (crash) the process
112 /// in the face of memory errors.
113 FailOrCrash,
114}
115
116#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
117pub enum FailMode {
118 Check,
119 Build,
120 Run(RunFailMode),
121}
122
123string_enum! {
124 #[derive(Clone, Debug, PartialEq)]
125 pub enum CompareMode {
126 Polonius => "polonius",
127 NextSolver => "next-solver",
128 NextSolverCoherence => "next-solver-coherence",
129 SplitDwarf => "split-dwarf",
130 SplitDwarfSingle => "split-dwarf-single",
131 }
132}
133
134string_enum! {
135 #[derive(Clone, Copy, Debug, PartialEq)]
136 pub enum Debugger {
137 Cdb => "cdb",
138 Gdb => "gdb",
139 Lldb => "lldb",
140 }
141}
142
143#[derive(Clone, Copy, Debug, PartialEq, Default, serde::Deserialize)]
144#[serde(rename_all = "kebab-case")]
145pub enum PanicStrategy {
146 #[default]
147 Unwind,
148 Abort,
149}
150
151impl PanicStrategy {
152 pub(crate) fn for_miropt_test_tools(&self) -> miropt_test_tools::PanicStrategy {
153 match self {
154 PanicStrategy::Unwind => miropt_test_tools::PanicStrategy::Unwind,
155 PanicStrategy::Abort => miropt_test_tools::PanicStrategy::Abort,
156 }
157 }
158}
159
160#[derive(Clone, Debug, PartialEq, serde::Deserialize)]
161#[serde(rename_all = "kebab-case")]
162pub enum Sanitizer {
163 Address,
164 Cfi,
165 Dataflow,
166 Kcfi,
167 KernelAddress,
168 Leak,
169 Memory,
170 Memtag,
171 Safestack,
172 ShadowCallStack,
173 Thread,
174 Hwaddress,
175}
176
177#[derive(Clone, Copy, Debug, PartialEq)]
178pub enum CodegenBackend {
179 Cranelift,
180 Gcc,
181 Llvm,
182}
183
184impl<'a> TryFrom<&'a str> for CodegenBackend {
185 type Error = &'static str;
186
187 fn try_from(value: &'a str) -> Result<Self, Self::Error> {
188 match value.to_lowercase().as_str() {
189 "cranelift" => Ok(Self::Cranelift),
190 "gcc" => Ok(Self::Gcc),
191 "llvm" => Ok(Self::Llvm),
192 _ => Err("unknown backend"),
193 }
194 }
195}
196
197impl CodegenBackend {
198 pub fn as_str(self) -> &'static str {
199 match self {
200 Self::Cranelift => "cranelift",
201 Self::Gcc => "gcc",
202 Self::Llvm => "llvm",
203 }
204 }
205}
206
207/// Configuration for `compiletest` *per invocation*.
208///
209/// In terms of `bootstrap`, this means that `./x test tests/ui tests/run-make` actually correspond
210/// to *two* separate invocations of `compiletest`.
211///
212/// FIXME: this `Config` struct should be broken up into smaller logically contained sub-config
213/// structs, it's too much of a "soup" of everything at the moment.
214///
215/// # Configuration sources
216///
217/// Configuration values for `compiletest` comes from several sources:
218///
219/// - CLI args passed from `bootstrap` while running the `compiletest` binary.
220/// - Env vars.
221/// - Discovery (e.g. trying to identify a suitable debugger based on filesystem discovery).
222/// - Cached output of running the `rustc` under test (e.g. output of `rustc` print requests).
223///
224/// FIXME: make sure we *clearly* account for sources of *all* config options.
225///
226/// FIXME: audit these options to make sure we are not hashing less than necessary for build stamp
227/// (for changed test detection).
228#[derive(Debug, Clone)]
229pub struct Config {
230 /// Some [`TestMode`]s support [snapshot testing], where a *reference snapshot* of outputs (of
231 /// `stdout`, `stderr`, or other form of artifacts) can be compared to the *actual output*.
232 ///
233 /// This option can be set to `true` to update the *reference snapshots* in-place, otherwise
234 /// `compiletest` will only try to compare.
235 ///
236 /// [snapshot testing]: https://jestjs.io/docs/snapshot-testing
237 pub bless: bool,
238
239 /// Attempt to stop as soon as possible after any test fails. We may still run a few more tests
240 /// before stopping when multiple test threads are used.
241 pub fail_fast: bool,
242
243 /// Path to libraries needed to run the *staged* `rustc`-under-test on the **host** platform.
244 ///
245 /// FIXME: maybe rename this to reflect (1) which target platform (host, not target), and (2)
246 /// which `rustc` (the `rustc`-under-test, not the stage 0 `rustc` unless forced).
247 pub compile_lib_path: Utf8PathBuf,
248
249 /// Path to libraries needed to run the compiled executable for the **target** platform. This
250 /// corresponds to the **target** sysroot libraries, including the **target** standard library.
251 ///
252 /// FIXME: maybe rename this to reflect (1) which target platform (target, not host), and (2)
253 /// what "run libraries" are against.
254 ///
255 /// FIXME: this is very under-documented in conjunction with the `remote-test-client` scheme and
256 /// `RUNNER` scheme to actually run the target executable under the target platform environment,
257 /// cf. [`Self::remote_test_client`] and [`Self::runner`].
258 pub run_lib_path: Utf8PathBuf,
259
260 /// Path to the *staged* `rustc`-under-test. Unless forced, this `rustc` is *staged*, and must
261 /// not be confused with [`Self::stage0_rustc_path`].
262 ///
263 /// FIXME: maybe rename this to reflect that this is the `rustc`-under-test.
264 pub rustc_path: Utf8PathBuf,
265
266 /// Path to a *staged* **host** platform cargo executable (unless stage 0 is forced). This
267 /// staged `cargo` is only used within `run-make` test recipes during recipe run time (and is
268 /// *not* used to compile the test recipes), and so must be staged as there may be differences
269 /// between e.g. beta `cargo` vs in-tree `cargo`.
270 ///
271 /// FIXME: maybe rename this to reflect that this is a *staged* host cargo.
272 ///
273 /// FIXME(#134109): split `run-make` into two test suites, a test suite *with* staged cargo, and
274 /// another test suite *without*.
275 pub cargo_path: Option<Utf8PathBuf>,
276
277 /// Path to the stage 0 `rustc` used to build `run-make` recipes. This must not be confused with
278 /// [`Self::rustc_path`].
279 pub stage0_rustc_path: Option<Utf8PathBuf>,
280
281 /// Path to the stage 1 or higher `rustc` used to obtain target information via
282 /// `--print=all-target-specs-json` and similar queries.
283 ///
284 /// Normally this is unset, because [`Self::rustc_path`] can be used instead.
285 /// But when running "stage 1" ui-fulldeps tests, `rustc_path` is a stage 0
286 /// compiler, whereas target specs must be obtained from a stage 1+ compiler
287 /// (in case the JSON format has changed since the last bootstrap bump).
288 pub query_rustc_path: Option<Utf8PathBuf>,
289
290 /// Path to the `rustdoc`-under-test. Like [`Self::rustc_path`], this `rustdoc` is *staged*.
291 pub rustdoc_path: Option<Utf8PathBuf>,
292
293 /// Path to the `src/tools/coverage-dump/` bootstrap tool executable.
294 pub coverage_dump_path: Option<Utf8PathBuf>,
295
296 /// Path to the Python 3 executable to use for LLDB and htmldocck.
297 ///
298 /// FIXME: the `lldb` setup currently requires I believe Python 3.10 **exactly**, it can't even
299 /// be Python 3.11 or 3.9...
300 pub python: String,
301
302 /// Path to the `src/tools/jsondocck/` bootstrap tool executable.
303 pub jsondocck_path: Option<String>,
304
305 /// Path to the `src/tools/jsondoclint/` bootstrap tool executable.
306 pub jsondoclint_path: Option<String>,
307
308 /// Path to a host LLVM `FileCheck` executable.
309 pub llvm_filecheck: Option<Utf8PathBuf>,
310
311 /// Path to a host LLVM bintools directory.
312 pub llvm_bin_dir: Option<Utf8PathBuf>,
313
314 /// The path to the **target** `clang` executable to run `clang`-based tests with. If `None`,
315 /// then these tests will be ignored.
316 pub run_clang_based_tests_with: Option<String>,
317
318 /// Path to the directory containing the sources. This corresponds to the root folder of a
319 /// `rust-lang/rust` checkout.
320 ///
321 /// FIXME: this name is confusing, because this is actually `$checkout_root`, **not** the
322 /// `$checkout_root/src/` folder.
323 pub src_root: Utf8PathBuf,
324
325 /// Path to the directory containing the test suites sources. This corresponds to the
326 /// `$src_root/tests/` folder.
327 ///
328 /// Must be an immediate subdirectory of [`Self::src_root`].
329 ///
330 /// FIXME: this name is also confusing, maybe just call it `tests_root`.
331 pub src_test_suite_root: Utf8PathBuf,
332
333 /// Path to the build directory (e.g. `build/`).
334 pub build_root: Utf8PathBuf,
335
336 /// Path to the test suite specific build directory (e.g. `build/host/test/ui/`).
337 ///
338 /// Must be a subdirectory of [`Self::build_root`].
339 pub build_test_suite_root: Utf8PathBuf,
340
341 /// Path to the directory containing the sysroot of the `rustc`-under-test.
342 ///
343 /// When stage 0 is forced, this will correspond to the sysroot *of* that specified stage 0
344 /// `rustc`.
345 ///
346 /// FIXME: this name is confusing, because it doesn't specify *which* compiler this sysroot
347 /// corresponds to. It's actually the `rustc`-under-test, and not the bootstrap `rustc`, unless
348 /// stage 0 is forced and no custom stage 0 `rustc` was otherwise specified (so that it
349 /// *happens* to run against the bootstrap `rustc`, but this non-custom bootstrap `rustc` case
350 /// is not really supported).
351 pub sysroot_base: Utf8PathBuf,
352
353 /// The number of the stage under test.
354 pub stage: u32,
355
356 /// The id of the stage under test (stage1-xxx, etc).
357 ///
358 /// FIXME: reconsider this string; this is hashed for test build stamp.
359 pub stage_id: String,
360
361 /// The [`TestMode`]. E.g. [`TestMode::Ui`]. Each test mode can correspond to one or more test
362 /// suites.
363 ///
364 /// FIXME: stop using stringly-typed test suites!
365 pub mode: TestMode,
366
367 /// The test suite.
368 ///
369 /// Example: `tests/ui/` is [`TestSuite::Ui`] test *suite*, which happens to also be of the
370 /// [`TestMode::Ui`] test *mode*.
371 ///
372 /// Note that the same test suite (e.g. `tests/coverage/`) may correspond to multiple test
373 /// modes, e.g. `tests/coverage/` can be run under both [`TestMode::CoverageRun`] and
374 /// [`TestMode::CoverageMap`].
375 pub suite: TestSuite,
376
377 /// When specified, **only** the specified [`Debugger`] will be used to run against the
378 /// `tests/debuginfo` test suite. When unspecified, `compiletest` will attempt to find all three
379 /// of {`lldb`, `cdb`, `gdb`} implicitly, and then try to run the `debuginfo` test suite against
380 /// all three debuggers.
381 ///
382 /// FIXME: this implicit behavior is really nasty, in that it makes it hard for the user to
383 /// control *which* debugger(s) are available and used to run the debuginfo test suite. We
384 /// should have `bootstrap` allow the user to *explicitly* configure the debuggers, and *not*
385 /// try to implicitly discover some random debugger from the user environment. This makes the
386 /// debuginfo test suite particularly hard to work with.
387 pub debugger: Option<Debugger>,
388
389 /// Run ignored tests *unconditionally*, overriding their ignore reason.
390 ///
391 /// FIXME: this is wired up through the test execution logic, but **not** accessible from
392 /// `bootstrap` directly; `compiletest` exposes this as `--ignored`. I.e. you'd have to use `./x
393 /// test $test_suite -- --ignored=true`.
394 pub run_ignored: bool,
395
396 /// Whether *staged* `rustc`-under-test was built with debug assertions.
397 ///
398 /// FIXME: make it clearer that this refers to the staged `rustc`-under-test, not stage 0
399 /// `rustc`.
400 pub with_rustc_debug_assertions: bool,
401
402 /// Whether *staged* `std` was built with debug assertions.
403 ///
404 /// FIXME: make it clearer that this refers to the staged `std`, not stage 0 `std`.
405 pub with_std_debug_assertions: bool,
406
407 /// Only run tests that match these filters (using `libtest` "test name contains" filter logic).
408 ///
409 /// FIXME(#139660): the current hand-rolled test executor intentionally mimics the `libtest`
410 /// "test name contains" filter matching logic to preserve previous `libtest` executor behavior,
411 /// but this is often not intuitive. We should consider changing that behavior with an MCP to do
412 /// test path *prefix* matching which better corresponds to how `compiletest` `tests/` are
413 /// organized, and how users would intuitively expect the filtering logic to work like.
414 pub filters: Vec<String>,
415
416 /// Skip tests matching these substrings. The matching logic exactly corresponds to
417 /// [`Self::filters`] but inverted.
418 ///
419 /// FIXME(#139660): ditto on test matching behavior.
420 pub skip: Vec<String>,
421
422 /// Exactly match the filter, rather than a substring.
423 ///
424 /// FIXME(#139660): ditto on test matching behavior.
425 pub filter_exact: bool,
426
427 /// Force the pass mode of a check/build/run test to instead use this mode instead.
428 ///
429 /// FIXME: make it even more obvious (especially in PR CI where `--pass=check` is used) when a
430 /// pass mode is forced when the test fails, because it can be very non-obvious when e.g. an
431 /// error is emitted only when `//@ build-pass` but not `//@ check-pass`.
432 pub force_pass_mode: Option<PassMode>,
433
434 /// Explicitly enable or disable running of the target test binary.
435 ///
436 /// FIXME: this scheme is a bit confusing, and at times questionable. Re-evaluate this run
437 /// scheme.
438 ///
439 /// FIXME: Currently `--run` is a tri-state, it can be `--run={auto,always,never}`, and when
440 /// `--run=auto` is specified, it's run if the platform doesn't end with `-fuchsia`. See
441 /// [`Config::run_enabled`].
442 pub run: Option<bool>,
443
444 /// A command line to prefix target program execution with, for running under valgrind for
445 /// example, i.e. `$runner target.exe [args..]`. Similar to `CARGO_*_RUNNER` configuration.
446 ///
447 /// Note: this is not to be confused with [`Self::remote_test_client`], which is a different
448 /// scheme.
449 ///
450 /// FIXME: the runner scheme is very under-documented.
451 pub runner: Option<String>,
452
453 /// Compiler flags to pass to the *staged* `rustc`-under-test when building for the **host**
454 /// platform.
455 pub host_rustcflags: Vec<String>,
456
457 /// Compiler flags to pass to the *staged* `rustc`-under-test when building for the **target**
458 /// platform.
459 pub target_rustcflags: Vec<String>,
460
461 /// Whether the *staged* `rustc`-under-test and the associated *staged* `std` has been built
462 /// with randomized struct layouts.
463 pub rust_randomized_layout: bool,
464
465 /// Whether tests should be optimized by default (`-O`). Individual test suites and test files
466 /// may override this setting.
467 ///
468 /// FIXME: this flag / config option is somewhat misleading. For instance, in ui tests, it's
469 /// *only* applied to the [`PassMode::Run`] test crate and not its auxiliaries.
470 pub optimize_tests: bool,
471
472 /// Target platform tuple.
473 pub target: String,
474
475 /// Host platform tuple.
476 pub host: String,
477
478 /// Path to / name of the Microsoft Console Debugger (CDB) executable.
479 ///
480 /// FIXME: this is an *opt-in* "override" option. When this isn't provided, we try to conjure a
481 /// cdb by looking at the user's program files on Windows... See `debuggers::find_cdb`.
482 pub cdb: Option<Utf8PathBuf>,
483
484 /// Version of CDB.
485 ///
486 /// FIXME: `cdb_version` is *derived* from cdb, but it's *not* technically a config!
487 ///
488 /// FIXME: audit cdb version gating.
489 pub cdb_version: Option<[u16; 4]>,
490
491 /// Path to / name of the GDB executable.
492 ///
493 /// FIXME: the fallback path when `gdb` isn't provided tries to find *a* `gdb` or `gdb.exe` from
494 /// `PATH`, which is... arguably questionable.
495 ///
496 /// FIXME: we are propagating a python from `PYTHONPATH`, not from an explicit config for gdb
497 /// debugger script.
498 pub gdb: Option<String>,
499
500 /// Version of GDB, encoded as ((major * 1000) + minor) * 1000 + patch
501 ///
502 /// FIXME: this gdb version gating scheme is possibly questionable -- gdb does not use semver,
503 /// only its major version is likely materially meaningful, cf.
504 /// <https://sourceware.org/gdb/wiki/Internals%20Versions>. Even the major version I'm not sure
505 /// is super meaningful. Maybe min gdb `major.minor` version gating is sufficient for the
506 /// purposes of debuginfo tests?
507 ///
508 /// FIXME: `gdb_version` is *derived* from gdb, but it's *not* technically a config!
509 pub gdb_version: Option<u32>,
510
511 /// Version of LLDB.
512 ///
513 /// FIXME: `lldb_version` is *derived* from lldb, but it's *not* technically a config!
514 pub lldb_version: Option<u32>,
515
516 /// Version of LLVM.
517 ///
518 /// FIXME: Audit the fallback derivation of
519 /// [`crate::directives::extract_llvm_version_from_binary`], that seems very questionable?
520 pub llvm_version: Option<Version>,
521
522 /// Is LLVM a system LLVM.
523 pub system_llvm: bool,
524
525 /// Path to the android tools.
526 ///
527 /// Note: this is only used for android gdb debugger script in the debuginfo test suite.
528 ///
529 /// FIXME: take a look at this; this is piggy-backing off of gdb code paths but only for
530 /// `arm-linux-androideabi` target.
531 pub android_cross_path: Utf8PathBuf,
532
533 /// Extra parameter to run adb on `arm-linux-androideabi`.
534 ///
535 /// FIXME: is this *only* `arm-linux-androideabi`, or is it also for other Tier 2/3 android
536 /// targets?
537 ///
538 /// FIXME: take a look at this; this is piggy-backing off of gdb code paths but only for
539 /// `arm-linux-androideabi` target.
540 pub adb_path: String,
541
542 /// Extra parameter to run test suite on `arm-linux-androideabi`.
543 ///
544 /// FIXME: is this *only* `arm-linux-androideabi`, or is it also for other Tier 2/3 android
545 /// targets?
546 ///
547 /// FIXME: take a look at this; this is piggy-backing off of gdb code paths but only for
548 /// `arm-linux-androideabi` target.
549 pub adb_test_dir: String,
550
551 /// Status whether android device available or not. When unavailable, this will cause tests to
552 /// panic when the test binary is attempted to be run.
553 ///
554 /// FIXME: take a look at this; this also influences adb in gdb code paths in a strange way.
555 pub adb_device_status: bool,
556
557 /// Path containing LLDB's Python module.
558 ///
559 /// FIXME: `PYTHONPATH` takes precedence over this flag...? See `runtest::run_lldb`.
560 pub lldb_python_dir: Option<String>,
561
562 /// Verbose dump a lot of info.
563 ///
564 /// FIXME: this is *way* too coarse; the user can't select *which* info to verbosely dump.
565 pub verbose: bool,
566
567 /// Whether to use colors in test output.
568 ///
569 /// Note: the exact control mechanism is delegated to [`colored`].
570 pub color: ColorConfig,
571
572 /// Where to find the remote test client process, if we're using it.
573 ///
574 /// Note: this is *only* used for target platform executables created by `run-make` test
575 /// recipes.
576 ///
577 /// Note: this is not to be confused with [`Self::runner`], which is a different scheme.
578 ///
579 /// FIXME: the `remote_test_client` scheme is very under-documented.
580 pub remote_test_client: Option<Utf8PathBuf>,
581
582 /// [`CompareMode`] describing what file the actual ui output will be compared to.
583 ///
584 /// FIXME: currently, [`CompareMode`] is a mishmash of lot of things (different borrow-checker
585 /// model, different trait solver, different debugger, etc.).
586 pub compare_mode: Option<CompareMode>,
587
588 /// If true, this will generate a coverage file with UI test files that run `MachineApplicable`
589 /// diagnostics but are missing `run-rustfix` annotations. The generated coverage file is
590 /// created in `$test_suite_build_root/rustfix_missing_coverage.txt`
591 pub rustfix_coverage: bool,
592
593 /// Whether to run `tidy` (html-tidy) when a rustdoc test fails.
594 pub has_html_tidy: bool,
595
596 /// Whether to run `enzyme` autodiff tests.
597 pub has_enzyme: bool,
598
599 /// The current Rust channel info.
600 ///
601 /// FIXME: treat this more carefully; "stable", "beta" and "nightly" are definitely valid, but
602 /// channel might also be "dev" or such, which should be treated as "nightly".
603 pub channel: String,
604
605 /// Whether adding git commit information such as the commit hash has been enabled for building.
606 ///
607 /// FIXME: `compiletest` cannot trust `bootstrap` for this information, because `bootstrap` can
608 /// have bugs and had bugs on that logic. We need to figure out how to obtain this e.g. directly
609 /// from CI or via git locally.
610 pub git_hash: bool,
611
612 /// The default Rust edition.
613 ///
614 /// FIXME: perform stronger validation for this. There are editions that *definitely* exists,
615 /// but there might also be "future" edition.
616 pub edition: Option<String>,
617
618 // Configuration for various run-make tests frobbing things like C compilers or querying about
619 // various LLVM component information.
620 //
621 // FIXME: this really should be better packaged together.
622 // FIXME: these need better docs, e.g. for *host*, or for *target*?
623 pub cc: String,
624 pub cxx: String,
625 pub cflags: String,
626 pub cxxflags: String,
627 pub ar: String,
628 pub target_linker: Option<String>,
629 pub host_linker: Option<String>,
630 pub llvm_components: String,
631
632 /// Path to a NodeJS executable. Used for JS doctests, emscripten and WASM tests.
633 pub nodejs: Option<String>,
634 /// Path to a npm executable. Used for rustdoc GUI tests.
635 pub npm: Option<String>,
636
637 /// Whether to rerun tests even if the inputs are unchanged.
638 pub force_rerun: bool,
639
640 /// Only rerun the tests that result has been modified according to `git status`.
641 ///
642 /// FIXME: this is undocumented.
643 ///
644 /// FIXME: how does this interact with [`Self::force_rerun`]?
645 pub only_modified: bool,
646
647 // FIXME: these are really not "config"s, but rather are information derived from
648 // `rustc`-under-test. This poses an interesting conundrum: if we're testing the
649 // `rustc`-under-test, can we trust its print request outputs and target cfgs? In theory, this
650 // itself can break or be unreliable -- ideally, we'd be sharing these kind of information not
651 // through `rustc`-under-test's execution output. In practice, however, print requests are very
652 // unlikely to completely break (we also have snapshot ui tests for them). Furthermore, even if
653 // we share them via some kind of static config, that static config can still be wrong! Who
654 // tests the tester? Therefore, we make a pragmatic compromise here, and use information derived
655 // from print requests produced by the `rustc`-under-test.
656 //
657 // FIXME: move them out from `Config`, because they are *not* configs.
658 pub target_cfgs: OnceLock<TargetCfgs>,
659 pub builtin_cfg_names: OnceLock<HashSet<String>>,
660 pub supported_crate_types: OnceLock<HashSet<String>>,
661
662 /// FIXME: this is why we still need to depend on *staged* `std`, it's because we currently rely
663 /// on `#![feature(internal_output_capture)]` for [`std::io::set_output_capture`] to implement
664 /// `libtest`-esque `--no-capture`.
665 ///
666 /// FIXME: rename this to the more canonical `no_capture`, or better, invert this to `capture`
667 /// to avoid `!nocapture` double-negatives.
668 pub nocapture: bool,
669
670 /// True if the experimental new output-capture implementation should be
671 /// used, avoiding the need for `#![feature(internal_output_capture)]`.
672 pub new_output_capture: bool,
673
674 /// Needed both to construct [`build_helper::git::GitConfig`].
675 pub nightly_branch: String,
676 pub git_merge_commit_email: String,
677
678 /// True if the profiler runtime is enabled for this target. Used by the
679 /// `needs-profiler-runtime` directive in test files.
680 pub profiler_runtime: bool,
681
682 /// Command for visual diff display, e.g. `diff-tool --color=always`.
683 pub diff_command: Option<String>,
684
685 /// Path to minicore aux library (`tests/auxiliary/minicore.rs`), used for `no_core` tests that
686 /// need `core` stubs in cross-compilation scenarios that do not otherwise want/need to
687 /// `-Zbuild-std`. Used in e.g. ABI tests.
688 pub minicore_path: Utf8PathBuf,
689
690 /// Current codegen backend used.
691 pub default_codegen_backend: CodegenBackend,
692 /// Name/path of the backend to use instead of `default_codegen_backend`.
693 pub override_codegen_backend: Option<String>,
694}
695
696impl Config {
697 /// Incomplete config intended for `src/tools/rustdoc-gui-test` **only** as
698 /// `src/tools/rustdoc-gui-test` wants to reuse `compiletest`'s directive -> test property
699 /// handling for `//@ {compile,run}-flags`, do not use for any other purpose.
700 ///
701 /// FIXME(#143827): this setup feels very hacky. It so happens that `tests/rustdoc-gui/`
702 /// **only** uses `//@ {compile,run}-flags` for now and not any directives that actually rely on
703 /// info that is assumed available in a fully populated [`Config`].
704 pub fn incomplete_for_rustdoc_gui_test() -> Config {
705 // FIXME(#143827): spelling this out intentionally, because this is questionable.
706 //
707 // For instance, `//@ ignore-stage1` will not work at all.
708 Config {
709 mode: TestMode::Rustdoc,
710 // E.g. this has no sensible default tbh.
711 suite: TestSuite::Ui,
712
713 // Dummy values.
714 edition: Default::default(),
715 bless: Default::default(),
716 fail_fast: Default::default(),
717 compile_lib_path: Utf8PathBuf::default(),
718 run_lib_path: Utf8PathBuf::default(),
719 rustc_path: Utf8PathBuf::default(),
720 cargo_path: Default::default(),
721 stage0_rustc_path: Default::default(),
722 query_rustc_path: Default::default(),
723 rustdoc_path: Default::default(),
724 coverage_dump_path: Default::default(),
725 python: Default::default(),
726 jsondocck_path: Default::default(),
727 jsondoclint_path: Default::default(),
728 llvm_filecheck: Default::default(),
729 llvm_bin_dir: Default::default(),
730 run_clang_based_tests_with: Default::default(),
731 src_root: Utf8PathBuf::default(),
732 src_test_suite_root: Utf8PathBuf::default(),
733 build_root: Utf8PathBuf::default(),
734 build_test_suite_root: Utf8PathBuf::default(),
735 sysroot_base: Utf8PathBuf::default(),
736 stage: Default::default(),
737 stage_id: String::default(),
738 debugger: Default::default(),
739 run_ignored: Default::default(),
740 with_rustc_debug_assertions: Default::default(),
741 with_std_debug_assertions: Default::default(),
742 filters: Default::default(),
743 skip: Default::default(),
744 filter_exact: Default::default(),
745 force_pass_mode: Default::default(),
746 run: Default::default(),
747 runner: Default::default(),
748 host_rustcflags: Default::default(),
749 target_rustcflags: Default::default(),
750 rust_randomized_layout: Default::default(),
751 optimize_tests: Default::default(),
752 target: Default::default(),
753 host: Default::default(),
754 cdb: Default::default(),
755 cdb_version: Default::default(),
756 gdb: Default::default(),
757 gdb_version: Default::default(),
758 lldb_version: Default::default(),
759 llvm_version: Default::default(),
760 system_llvm: Default::default(),
761 android_cross_path: Default::default(),
762 adb_path: Default::default(),
763 adb_test_dir: Default::default(),
764 adb_device_status: Default::default(),
765 lldb_python_dir: Default::default(),
766 verbose: Default::default(),
767 color: Default::default(),
768 remote_test_client: Default::default(),
769 compare_mode: Default::default(),
770 rustfix_coverage: Default::default(),
771 has_html_tidy: Default::default(),
772 has_enzyme: Default::default(),
773 channel: Default::default(),
774 git_hash: Default::default(),
775 cc: Default::default(),
776 cxx: Default::default(),
777 cflags: Default::default(),
778 cxxflags: Default::default(),
779 ar: Default::default(),
780 target_linker: Default::default(),
781 host_linker: Default::default(),
782 llvm_components: Default::default(),
783 nodejs: Default::default(),
784 npm: Default::default(),
785 force_rerun: Default::default(),
786 only_modified: Default::default(),
787 target_cfgs: Default::default(),
788 builtin_cfg_names: Default::default(),
789 supported_crate_types: Default::default(),
790 nocapture: Default::default(),
791 new_output_capture: Default::default(),
792 nightly_branch: Default::default(),
793 git_merge_commit_email: Default::default(),
794 profiler_runtime: Default::default(),
795 diff_command: Default::default(),
796 minicore_path: Default::default(),
797 default_codegen_backend: CodegenBackend::Llvm,
798 override_codegen_backend: None,
799 }
800 }
801
802 /// FIXME: this run scheme is... confusing.
803 pub fn run_enabled(&self) -> bool {
804 self.run.unwrap_or_else(|| {
805 // Auto-detect whether to run based on the platform.
806 !self.target.ends_with("-fuchsia")
807 })
808 }
809
810 pub fn target_cfgs(&self) -> &TargetCfgs {
811 self.target_cfgs.get_or_init(|| TargetCfgs::new(self))
812 }
813
814 pub fn target_cfg(&self) -> &TargetCfg {
815 &self.target_cfgs().current
816 }
817
818 pub fn matches_arch(&self, arch: &str) -> bool {
819 self.target_cfg().arch == arch ||
820 // Matching all the thumb variants as one can be convenient.
821 // (thumbv6m, thumbv7em, thumbv7m, etc.)
822 (arch == "thumb" && self.target.starts_with("thumb"))
823 }
824
825 pub fn matches_os(&self, os: &str) -> bool {
826 self.target_cfg().os == os
827 }
828
829 pub fn matches_env(&self, env: &str) -> bool {
830 self.target_cfg().env == env
831 }
832
833 pub fn matches_abi(&self, abi: &str) -> bool {
834 self.target_cfg().abi == abi
835 }
836
837 pub fn matches_family(&self, family: &str) -> bool {
838 self.target_cfg().families.iter().any(|f| f == family)
839 }
840
841 pub fn is_big_endian(&self) -> bool {
842 self.target_cfg().endian == Endian::Big
843 }
844
845 pub fn get_pointer_width(&self) -> u32 {
846 *&self.target_cfg().pointer_width
847 }
848
849 pub fn can_unwind(&self) -> bool {
850 self.target_cfg().panic == PanicStrategy::Unwind
851 }
852
853 /// Get the list of builtin, 'well known' cfg names
854 pub fn builtin_cfg_names(&self) -> &HashSet<String> {
855 self.builtin_cfg_names.get_or_init(|| builtin_cfg_names(self))
856 }
857
858 /// Get the list of crate types that the target platform supports.
859 pub fn supported_crate_types(&self) -> &HashSet<String> {
860 self.supported_crate_types.get_or_init(|| supported_crate_types(self))
861 }
862
863 pub fn has_threads(&self) -> bool {
864 // Wasm targets don't have threads unless `-threads` is in the target
865 // name, such as `wasm32-wasip1-threads`.
866 if self.target.starts_with("wasm") {
867 return self.target.contains("threads");
868 }
869 true
870 }
871
872 pub fn has_asm_support(&self) -> bool {
873 // This should match the stable list in `LoweringContext::lower_inline_asm`.
874 static ASM_SUPPORTED_ARCHS: &[&str] = &[
875 "x86",
876 "x86_64",
877 "arm",
878 "aarch64",
879 "arm64ec",
880 "riscv32",
881 "riscv64",
882 "loongarch32",
883 "loongarch64",
884 "s390x",
885 // These targets require an additional asm_experimental_arch feature.
886 // "nvptx64", "hexagon", "mips", "mips64", "spirv", "wasm32",
887 ];
888 ASM_SUPPORTED_ARCHS.contains(&self.target_cfg().arch.as_str())
889 }
890
891 pub fn git_config(&self) -> GitConfig<'_> {
892 GitConfig {
893 nightly_branch: &self.nightly_branch,
894 git_merge_commit_email: &self.git_merge_commit_email,
895 }
896 }
897
898 pub fn has_subprocess_support(&self) -> bool {
899 // FIXME(#135928): compiletest is always a **host** tool. Building and running an
900 // capability detection executable against the **target** is not trivial. The short term
901 // solution here is to hard-code some targets to allow/deny, unfortunately.
902
903 let unsupported_target = self.target_cfg().env == "sgx"
904 || matches!(self.target_cfg().arch.as_str(), "wasm32" | "wasm64")
905 || self.target_cfg().os == "emscripten";
906 !unsupported_target
907 }
908}
909
910/// Known widths of `target_has_atomic`.
911pub const KNOWN_TARGET_HAS_ATOMIC_WIDTHS: &[&str] = &["8", "16", "32", "64", "128", "ptr"];
912
913#[derive(Debug, Clone)]
914pub struct TargetCfgs {
915 pub current: TargetCfg,
916 pub all_targets: HashSet<String>,
917 pub all_archs: HashSet<String>,
918 pub all_oses: HashSet<String>,
919 pub all_oses_and_envs: HashSet<String>,
920 pub all_envs: HashSet<String>,
921 pub all_abis: HashSet<String>,
922 pub all_families: HashSet<String>,
923 pub all_pointer_widths: HashSet<String>,
924 pub all_rustc_abis: HashSet<String>,
925}
926
927impl TargetCfgs {
928 fn new(config: &Config) -> TargetCfgs {
929 let mut targets: HashMap<String, TargetCfg> = serde_json::from_str(&query_rustc_output(
930 config,
931 &["--print=all-target-specs-json", "-Zunstable-options"],
932 Default::default(),
933 ))
934 .unwrap();
935
936 let mut all_targets = HashSet::new();
937 let mut all_archs = HashSet::new();
938 let mut all_oses = HashSet::new();
939 let mut all_oses_and_envs = HashSet::new();
940 let mut all_envs = HashSet::new();
941 let mut all_abis = HashSet::new();
942 let mut all_families = HashSet::new();
943 let mut all_pointer_widths = HashSet::new();
944 // NOTE: for distinction between `abi` and `rustc_abi`, see comment on
945 // `TargetCfg::rustc_abi`.
946 let mut all_rustc_abis = HashSet::new();
947
948 // If current target is not included in the `--print=all-target-specs-json` output,
949 // we check whether it is a custom target from the user or a synthetic target from bootstrap.
950 if !targets.contains_key(&config.target) {
951 let mut envs: HashMap<String, String> = HashMap::new();
952
953 if let Ok(t) = std::env::var("RUST_TARGET_PATH") {
954 envs.insert("RUST_TARGET_PATH".into(), t);
955 }
956
957 // This returns false only when the target is neither a synthetic target
958 // nor a custom target from the user, indicating it is most likely invalid.
959 if config.target.ends_with(".json") || !envs.is_empty() {
960 targets.insert(
961 config.target.clone(),
962 serde_json::from_str(&query_rustc_output(
963 config,
964 &[
965 "--print=target-spec-json",
966 "-Zunstable-options",
967 "--target",
968 &config.target,
969 ],
970 envs,
971 ))
972 .unwrap(),
973 );
974 }
975 }
976
977 for (target, cfg) in targets.iter() {
978 all_archs.insert(cfg.arch.clone());
979 all_oses.insert(cfg.os.clone());
980 all_oses_and_envs.insert(cfg.os_and_env());
981 all_envs.insert(cfg.env.clone());
982 all_abis.insert(cfg.abi.clone());
983 for family in &cfg.families {
984 all_families.insert(family.clone());
985 }
986 all_pointer_widths.insert(format!("{}bit", cfg.pointer_width));
987 if let Some(rustc_abi) = &cfg.rustc_abi {
988 all_rustc_abis.insert(rustc_abi.clone());
989 }
990 all_targets.insert(target.clone());
991 }
992
993 Self {
994 current: Self::get_current_target_config(config, &targets),
995 all_targets,
996 all_archs,
997 all_oses,
998 all_oses_and_envs,
999 all_envs,
1000 all_abis,
1001 all_families,
1002 all_pointer_widths,
1003 all_rustc_abis,
1004 }
1005 }
1006
1007 fn get_current_target_config(
1008 config: &Config,
1009 targets: &HashMap<String, TargetCfg>,
1010 ) -> TargetCfg {
1011 let mut cfg = targets[&config.target].clone();
1012
1013 // To get the target information for the current target, we take the target spec obtained
1014 // from `--print=all-target-specs-json`, and then we enrich it with the information
1015 // gathered from `--print=cfg --target=$target`.
1016 //
1017 // This is done because some parts of the target spec can be overridden with `-C` flags,
1018 // which are respected for `--print=cfg` but not for `--print=all-target-specs-json`. The
1019 // code below extracts them from `--print=cfg`: make sure to only override fields that can
1020 // actually be changed with `-C` flags.
1021 for config in query_rustc_output(
1022 config,
1023 &["--print=cfg", "--target", &config.target],
1024 Default::default(),
1025 )
1026 .trim()
1027 .lines()
1028 {
1029 let (name, value) = config
1030 .split_once("=\"")
1031 .map(|(name, value)| {
1032 (
1033 name,
1034 Some(
1035 value
1036 .strip_suffix('\"')
1037 .expect("key-value pair should be properly quoted"),
1038 ),
1039 )
1040 })
1041 .unwrap_or_else(|| (config, None));
1042
1043 match (name, value) {
1044 // Can be overridden with `-C panic=$strategy`.
1045 ("panic", Some("abort")) => cfg.panic = PanicStrategy::Abort,
1046 ("panic", Some("unwind")) => cfg.panic = PanicStrategy::Unwind,
1047 ("panic", other) => panic!("unexpected value for panic cfg: {other:?}"),
1048
1049 ("target_has_atomic", Some(width))
1050 if KNOWN_TARGET_HAS_ATOMIC_WIDTHS.contains(&width) =>
1051 {
1052 cfg.target_has_atomic.insert(width.to_string());
1053 }
1054 ("target_has_atomic", Some(other)) => {
1055 panic!("unexpected value for `target_has_atomic` cfg: {other:?}")
1056 }
1057 // Nightly-only std-internal impl detail.
1058 ("target_has_atomic", None) => {}
1059 _ => {}
1060 }
1061 }
1062
1063 cfg
1064 }
1065}
1066
1067#[derive(Clone, Debug, serde::Deserialize)]
1068#[serde(rename_all = "kebab-case")]
1069pub struct TargetCfg {
1070 pub(crate) arch: String,
1071 #[serde(default = "default_os")]
1072 pub(crate) os: String,
1073 #[serde(default)]
1074 pub(crate) env: String,
1075 #[serde(default)]
1076 pub(crate) abi: String,
1077 #[serde(rename = "target-family", default)]
1078 pub(crate) families: Vec<String>,
1079 #[serde(rename = "target-pointer-width")]
1080 pub(crate) pointer_width: u32,
1081 #[serde(rename = "target-endian", default)]
1082 endian: Endian,
1083 #[serde(rename = "panic-strategy", default)]
1084 pub(crate) panic: PanicStrategy,
1085 #[serde(default)]
1086 pub(crate) dynamic_linking: bool,
1087 #[serde(rename = "supported-sanitizers", default)]
1088 pub(crate) sanitizers: Vec<Sanitizer>,
1089 #[serde(rename = "supports-xray", default)]
1090 pub(crate) xray: bool,
1091 #[serde(default = "default_reloc_model")]
1092 pub(crate) relocation_model: String,
1093 // NOTE: `rustc_abi` should not be confused with `abi`. `rustc_abi` was introduced in #137037 to
1094 // make SSE2 *required* by the ABI (kind of a hack to make a target feature *required* via the
1095 // target spec).
1096 pub(crate) rustc_abi: Option<String>,
1097
1098 // Not present in target cfg json output, additional derived information.
1099 #[serde(skip)]
1100 /// Supported target atomic widths: e.g. `8` to `128` or `ptr`. This is derived from the builtin
1101 /// `target_has_atomic` `cfg`s e.g. `target_has_atomic="8"`.
1102 pub(crate) target_has_atomic: BTreeSet<String>,
1103}
1104
1105impl TargetCfg {
1106 pub(crate) fn os_and_env(&self) -> String {
1107 format!("{}-{}", self.os, self.env)
1108 }
1109}
1110
1111fn default_os() -> String {
1112 "none".into()
1113}
1114
1115fn default_reloc_model() -> String {
1116 "pic".into()
1117}
1118
1119#[derive(Eq, PartialEq, Clone, Debug, Default, serde::Deserialize)]
1120#[serde(rename_all = "kebab-case")]
1121pub enum Endian {
1122 #[default]
1123 Little,
1124 Big,
1125}
1126
1127fn builtin_cfg_names(config: &Config) -> HashSet<String> {
1128 query_rustc_output(
1129 config,
1130 &["--print=check-cfg", "-Zunstable-options", "--check-cfg=cfg()"],
1131 Default::default(),
1132 )
1133 .lines()
1134 .map(|l| if let Some((name, _)) = l.split_once('=') { name.to_string() } else { l.to_string() })
1135 .chain(std::iter::once(String::from("test")))
1136 .collect()
1137}
1138
1139pub const KNOWN_CRATE_TYPES: &[&str] =
1140 &["bin", "cdylib", "dylib", "lib", "proc-macro", "rlib", "staticlib"];
1141
1142fn supported_crate_types(config: &Config) -> HashSet<String> {
1143 let crate_types: HashSet<_> = query_rustc_output(
1144 config,
1145 &["--target", &config.target, "--print=supported-crate-types", "-Zunstable-options"],
1146 Default::default(),
1147 )
1148 .lines()
1149 .map(|l| l.to_string())
1150 .collect();
1151
1152 for crate_type in crate_types.iter() {
1153 assert!(
1154 KNOWN_CRATE_TYPES.contains(&crate_type.as_str()),
1155 "unexpected crate type `{}`: known crate types are {:?}",
1156 crate_type,
1157 KNOWN_CRATE_TYPES
1158 );
1159 }
1160
1161 crate_types
1162}
1163
1164fn query_rustc_output(config: &Config, args: &[&str], envs: HashMap<String, String>) -> String {
1165 let query_rustc_path = config.query_rustc_path.as_deref().unwrap_or(&config.rustc_path);
1166
1167 let mut command = Command::new(query_rustc_path);
1168 add_dylib_path(&mut command, iter::once(&config.compile_lib_path));
1169 command.args(&config.target_rustcflags).args(args);
1170 command.env("RUSTC_BOOTSTRAP", "1");
1171 command.envs(envs);
1172
1173 let output = match command.output() {
1174 Ok(output) => output,
1175 Err(e) => {
1176 fatal!("failed to run {command:?}: {e}");
1177 }
1178 };
1179 if !output.status.success() {
1180 fatal!(
1181 "failed to run {command:?}\n--- stdout\n{}\n--- stderr\n{}",
1182 String::from_utf8(output.stdout).unwrap(),
1183 String::from_utf8(output.stderr).unwrap(),
1184 );
1185 }
1186 String::from_utf8(output.stdout).unwrap()
1187}
1188
1189#[derive(Debug, Clone)]
1190pub struct TestPaths {
1191 pub file: Utf8PathBuf, // e.g., compile-test/foo/bar/baz.rs
1192 pub relative_dir: Utf8PathBuf, // e.g., foo/bar
1193}
1194
1195/// Used by `ui` tests to generate things like `foo.stderr` from `foo.rs`.
1196pub fn expected_output_path(
1197 testpaths: &TestPaths,
1198 revision: Option<&str>,
1199 compare_mode: &Option<CompareMode>,
1200 kind: &str,
1201) -> Utf8PathBuf {
1202 assert!(UI_EXTENSIONS.contains(&kind));
1203 let mut parts = Vec::new();
1204
1205 if let Some(x) = revision {
1206 parts.push(x);
1207 }
1208 if let Some(ref x) = *compare_mode {
1209 parts.push(x.to_str());
1210 }
1211 parts.push(kind);
1212
1213 let extension = parts.join(".");
1214 testpaths.file.with_extension(extension)
1215}
1216
1217pub const UI_EXTENSIONS: &[&str] = &[
1218 UI_STDERR,
1219 UI_SVG,
1220 UI_WINDOWS_SVG,
1221 UI_STDOUT,
1222 UI_FIXED,
1223 UI_RUN_STDERR,
1224 UI_RUN_STDOUT,
1225 UI_STDERR_64,
1226 UI_STDERR_32,
1227 UI_STDERR_16,
1228 UI_COVERAGE,
1229 UI_COVERAGE_MAP,
1230];
1231pub const UI_STDERR: &str = "stderr";
1232pub const UI_SVG: &str = "svg";
1233pub const UI_WINDOWS_SVG: &str = "windows.svg";
1234pub const UI_STDOUT: &str = "stdout";
1235pub const UI_FIXED: &str = "fixed";
1236pub const UI_RUN_STDERR: &str = "run.stderr";
1237pub const UI_RUN_STDOUT: &str = "run.stdout";
1238pub const UI_STDERR_64: &str = "64bit.stderr";
1239pub const UI_STDERR_32: &str = "32bit.stderr";
1240pub const UI_STDERR_16: &str = "16bit.stderr";
1241pub const UI_COVERAGE: &str = "coverage";
1242pub const UI_COVERAGE_MAP: &str = "cov-map";
1243
1244/// Absolute path to the directory where all output for all tests in the given `relative_dir` group
1245/// should reside. Example:
1246///
1247/// ```text
1248/// /path/to/build/host-tuple/test/ui/relative/
1249/// ```
1250///
1251/// This is created early when tests are collected to avoid race conditions.
1252pub fn output_relative_path(config: &Config, relative_dir: &Utf8Path) -> Utf8PathBuf {
1253 config.build_test_suite_root.join(relative_dir)
1254}
1255
1256/// Generates a unique name for the test, such as `testname.revision.mode`.
1257pub fn output_testname_unique(
1258 config: &Config,
1259 testpaths: &TestPaths,
1260 revision: Option<&str>,
1261) -> Utf8PathBuf {
1262 let mode = config.compare_mode.as_ref().map_or("", |m| m.to_str());
1263 let debugger = config.debugger.as_ref().map_or("", |m| m.to_str());
1264 Utf8PathBuf::from(&testpaths.file.file_stem().unwrap())
1265 .with_extra_extension(config.mode.output_dir_disambiguator())
1266 .with_extra_extension(revision.unwrap_or(""))
1267 .with_extra_extension(mode)
1268 .with_extra_extension(debugger)
1269}
1270
1271/// Absolute path to the directory where all output for the given
1272/// test/revision should reside. Example:
1273/// /path/to/build/host-tuple/test/ui/relative/testname.revision.mode/
1274pub fn output_base_dir(
1275 config: &Config,
1276 testpaths: &TestPaths,
1277 revision: Option<&str>,
1278) -> Utf8PathBuf {
1279 output_relative_path(config, &testpaths.relative_dir)
1280 .join(output_testname_unique(config, testpaths, revision))
1281}
1282
1283/// Absolute path to the base filename used as output for the given
1284/// test/revision. Example:
1285/// /path/to/build/host-tuple/test/ui/relative/testname.revision.mode/testname
1286pub fn output_base_name(
1287 config: &Config,
1288 testpaths: &TestPaths,
1289 revision: Option<&str>,
1290) -> Utf8PathBuf {
1291 output_base_dir(config, testpaths, revision).join(testpaths.file.file_stem().unwrap())
1292}
1293
1294/// Absolute path to the directory to use for incremental compilation. Example:
1295/// /path/to/build/host-tuple/test/ui/relative/testname.mode/testname.inc
1296pub fn incremental_dir(
1297 config: &Config,
1298 testpaths: &TestPaths,
1299 revision: Option<&str>,
1300) -> Utf8PathBuf {
1301 output_base_name(config, testpaths, revision).with_extension("inc")
1302}