Skip to main content

compiletest/
common.rs

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