1
1
use std:: collections:: { BTreeSet , HashMap , HashSet } ;
2
+ use std:: iter;
2
3
use std:: process:: Command ;
3
- use std:: str:: FromStr ;
4
4
use std:: sync:: OnceLock ;
5
- use std:: { fmt, iter} ;
6
5
7
6
use build_helper:: git:: GitConfig ;
8
7
use camino:: { Utf8Path , Utf8PathBuf } ;
9
8
use semver:: Version ;
10
9
use serde:: de:: { Deserialize , Deserializer , Error as _} ;
11
10
12
- pub use self :: Mode :: * ;
13
11
use crate :: executor:: { ColorConfig , OutputFormat } ;
14
12
use crate :: fatal;
15
- use crate :: util:: { Utf8PathBufExt , add_dylib_path} ;
16
-
17
- macro_rules! string_enum {
18
- ( $( #[ $meta: meta] ) * $vis: vis enum $name: ident { $( $variant: ident => $repr: expr, ) * } ) => {
19
- $( #[ $meta] ) *
20
- $vis enum $name {
21
- $( $variant, ) *
22
- }
23
-
24
- impl $name {
25
- $vis const VARIANTS : & ' static [ Self ] = & [ $( Self :: $variant, ) * ] ;
26
- $vis const STR_VARIANTS : & ' static [ & ' static str ] = & [ $( Self :: $variant. to_str( ) , ) * ] ;
27
-
28
- $vis const fn to_str( & self ) -> & ' static str {
29
- match self {
30
- $( Self :: $variant => $repr, ) *
31
- }
32
- }
33
- }
34
-
35
- impl fmt:: Display for $name {
36
- fn fmt( & self , f: & mut fmt:: Formatter <' _>) -> fmt:: Result {
37
- fmt:: Display :: fmt( self . to_str( ) , f)
38
- }
39
- }
40
-
41
- impl FromStr for $name {
42
- type Err = String ;
43
-
44
- fn from_str( s: & str ) -> Result <Self , Self :: Err > {
45
- match s {
46
- $( $repr => Ok ( Self :: $variant) , ) *
47
- _ => Err ( format!( concat!( "unknown `" , stringify!( $name) , "` variant: `{}`" ) , s) ) ,
48
- }
49
- }
50
- }
51
- }
52
- }
53
-
54
- // Make the macro visible outside of this module, for tests.
55
- #[ cfg( test) ]
56
- pub ( crate ) use string_enum;
13
+ use crate :: util:: { Utf8PathBufExt , add_dylib_path, string_enum} ;
57
14
58
15
string_enum ! {
59
16
#[ derive( Clone , Copy , PartialEq , Debug ) ]
60
- pub enum Mode {
17
+ pub enum TestMode {
61
18
Pretty => "pretty" ,
62
19
DebugInfo => "debuginfo" ,
63
20
Codegen => "codegen" ,
@@ -76,18 +33,12 @@ string_enum! {
76
33
}
77
34
}
78
35
79
- impl Default for Mode {
80
- fn default ( ) -> Self {
81
- Mode :: Ui
82
- }
83
- }
84
-
85
- impl Mode {
36
+ impl TestMode {
86
37
pub fn aux_dir_disambiguator ( self ) -> & ' static str {
87
38
// Pretty-printing tests could run concurrently, and if they do,
88
39
// they need to keep their output segregated.
89
40
match self {
90
- Pretty => ".pretty" ,
41
+ TestMode :: Pretty => ".pretty" ,
91
42
_ => "" ,
92
43
}
93
44
}
@@ -96,7 +47,7 @@ impl Mode {
96
47
// Coverage tests use the same test files for multiple test modes,
97
48
// so each mode should have a separate output directory.
98
49
match self {
99
- CoverageMap | CoverageRun => self . to_str ( ) ,
50
+ TestMode :: CoverageMap | TestMode :: CoverageRun => self . to_str ( ) ,
100
51
_ => "" ,
101
52
}
102
53
}
@@ -193,9 +144,9 @@ pub enum Sanitizer {
193
144
///
194
145
/// FIXME: audit these options to make sure we are not hashing less than necessary for build stamp
195
146
/// (for changed test detection).
196
- #[ derive( Debug , Default , Clone ) ]
147
+ #[ derive( Debug , Clone ) ]
197
148
pub struct Config {
198
- /// Some test [`Mode `]s support [snapshot testing], where a *reference snapshot* of outputs (of
149
+ /// Some [`TestMode `]s support [snapshot testing], where a *reference snapshot* of outputs (of
199
150
/// `stdout`, `stderr`, or other form of artifacts) can be compared to the *actual output*.
200
151
///
201
152
/// This option can be set to `true` to update the *reference snapshots* in-place, otherwise
@@ -317,20 +268,20 @@ pub struct Config {
317
268
/// FIXME: reconsider this string; this is hashed for test build stamp.
318
269
pub stage_id : String ,
319
270
320
- /// The test [`Mode `]. E.g. [`Mode ::Ui`]. Each test mode can correspond to one or more test
271
+ /// The [`TestMode `]. E.g. [`TestMode ::Ui`]. Each test mode can correspond to one or more test
321
272
/// suites.
322
273
///
323
274
/// FIXME: stop using stringly-typed test suites!
324
- pub mode : Mode ,
275
+ pub mode : TestMode ,
325
276
326
277
/// The test suite.
327
278
///
328
- /// Example: `tests/ui/` is the "UI" test *suite*, which happens to also be of the [`Mode::Ui`]
329
- /// test *mode*.
279
+ /// Example: `tests/ui/` is the "UI" test *suite*, which happens to also be of the
280
+ /// [`TestMode::Ui`] test *mode*.
330
281
///
331
282
/// Note that the same test directory (e.g. `tests/coverage/`) may correspond to multiple test
332
- /// modes, e.g. `tests/coverage/` can be run under both [`Mode ::CoverageRun`] and
333
- /// [`Mode ::CoverageMap`].
283
+ /// modes, e.g. `tests/coverage/` can be run under both [`TestMode ::CoverageRun`] and
284
+ /// [`TestMode ::CoverageMap`].
334
285
///
335
286
/// FIXME: stop using stringly-typed test suites!
336
287
pub suite : String ,
@@ -586,8 +537,8 @@ pub struct Config {
586
537
// Configuration for various run-make tests frobbing things like C compilers or querying about
587
538
// various LLVM component information.
588
539
//
589
- // FIXME: this really should be better packaged together.
590
- // FIXME: these need better docs, e.g. for *host*, or for *target*?
540
+ // FIXME: this really should be better packaged together. FIXME: these need better docs, e.g.
541
+ // for *host*, or for *target*?
591
542
pub cc : String ,
592
543
pub cxx : String ,
593
544
pub cflags : String ,
@@ -653,6 +604,107 @@ pub struct Config {
653
604
}
654
605
655
606
impl Config {
607
+ /// Incomplete config intended for `src/tools/rustdoc-gui-test` **only** as
608
+ /// `src/tools/rustdoc-gui-test` wants to reuse `compiletest`'s directive -> test property
609
+ /// handling for `//@ {compile,run}-flags`, do not use for any other purpose.
610
+ ///
611
+ /// FIXME(#143827): this setup feels very hacky. It so happens that `tests/rustdoc-gui/`
612
+ /// **only** uses `//@ {compile,run}-flags` for now and not any directives that actually rely on
613
+ /// info that is assumed available in a fully populated [`Config`].
614
+ pub fn incomplete_for_rustdoc_gui_test ( ) -> Config {
615
+ // FIXME(#143827): spelling this out intentionally, because this is questionable.
616
+ //
617
+ // For instance, `//@ ignore-stage1` will not work at all.
618
+ Config {
619
+ mode : TestMode :: Rustdoc ,
620
+
621
+ // Dummy values.
622
+ edition : Default :: default ( ) ,
623
+ bless : Default :: default ( ) ,
624
+ fail_fast : Default :: default ( ) ,
625
+ compile_lib_path : Utf8PathBuf :: default ( ) ,
626
+ run_lib_path : Utf8PathBuf :: default ( ) ,
627
+ rustc_path : Utf8PathBuf :: default ( ) ,
628
+ cargo_path : Default :: default ( ) ,
629
+ stage0_rustc_path : Default :: default ( ) ,
630
+ rustdoc_path : Default :: default ( ) ,
631
+ coverage_dump_path : Default :: default ( ) ,
632
+ python : Default :: default ( ) ,
633
+ jsondocck_path : Default :: default ( ) ,
634
+ jsondoclint_path : Default :: default ( ) ,
635
+ llvm_filecheck : Default :: default ( ) ,
636
+ llvm_bin_dir : Default :: default ( ) ,
637
+ run_clang_based_tests_with : Default :: default ( ) ,
638
+ src_root : Utf8PathBuf :: default ( ) ,
639
+ src_test_suite_root : Utf8PathBuf :: default ( ) ,
640
+ build_root : Utf8PathBuf :: default ( ) ,
641
+ build_test_suite_root : Utf8PathBuf :: default ( ) ,
642
+ sysroot_base : Utf8PathBuf :: default ( ) ,
643
+ stage : Default :: default ( ) ,
644
+ stage_id : String :: default ( ) ,
645
+ suite : Default :: default ( ) ,
646
+ debugger : Default :: default ( ) ,
647
+ run_ignored : Default :: default ( ) ,
648
+ with_rustc_debug_assertions : Default :: default ( ) ,
649
+ with_std_debug_assertions : Default :: default ( ) ,
650
+ filters : Default :: default ( ) ,
651
+ skip : Default :: default ( ) ,
652
+ filter_exact : Default :: default ( ) ,
653
+ force_pass_mode : Default :: default ( ) ,
654
+ run : Default :: default ( ) ,
655
+ runner : Default :: default ( ) ,
656
+ host_rustcflags : Default :: default ( ) ,
657
+ target_rustcflags : Default :: default ( ) ,
658
+ rust_randomized_layout : Default :: default ( ) ,
659
+ optimize_tests : Default :: default ( ) ,
660
+ target : Default :: default ( ) ,
661
+ host : Default :: default ( ) ,
662
+ cdb : Default :: default ( ) ,
663
+ cdb_version : Default :: default ( ) ,
664
+ gdb : Default :: default ( ) ,
665
+ gdb_version : Default :: default ( ) ,
666
+ lldb_version : Default :: default ( ) ,
667
+ llvm_version : Default :: default ( ) ,
668
+ system_llvm : Default :: default ( ) ,
669
+ android_cross_path : Default :: default ( ) ,
670
+ adb_path : Default :: default ( ) ,
671
+ adb_test_dir : Default :: default ( ) ,
672
+ adb_device_status : Default :: default ( ) ,
673
+ lldb_python_dir : Default :: default ( ) ,
674
+ verbose : Default :: default ( ) ,
675
+ format : Default :: default ( ) ,
676
+ color : Default :: default ( ) ,
677
+ remote_test_client : Default :: default ( ) ,
678
+ compare_mode : Default :: default ( ) ,
679
+ rustfix_coverage : Default :: default ( ) ,
680
+ has_html_tidy : Default :: default ( ) ,
681
+ has_enzyme : Default :: default ( ) ,
682
+ channel : Default :: default ( ) ,
683
+ git_hash : Default :: default ( ) ,
684
+ cc : Default :: default ( ) ,
685
+ cxx : Default :: default ( ) ,
686
+ cflags : Default :: default ( ) ,
687
+ cxxflags : Default :: default ( ) ,
688
+ ar : Default :: default ( ) ,
689
+ target_linker : Default :: default ( ) ,
690
+ host_linker : Default :: default ( ) ,
691
+ llvm_components : Default :: default ( ) ,
692
+ nodejs : Default :: default ( ) ,
693
+ npm : Default :: default ( ) ,
694
+ force_rerun : Default :: default ( ) ,
695
+ only_modified : Default :: default ( ) ,
696
+ target_cfgs : Default :: default ( ) ,
697
+ builtin_cfg_names : Default :: default ( ) ,
698
+ supported_crate_types : Default :: default ( ) ,
699
+ nocapture : Default :: default ( ) ,
700
+ nightly_branch : Default :: default ( ) ,
701
+ git_merge_commit_email : Default :: default ( ) ,
702
+ profiler_runtime : Default :: default ( ) ,
703
+ diff_command : Default :: default ( ) ,
704
+ minicore_path : Default :: default ( ) ,
705
+ }
706
+ }
707
+
656
708
/// FIXME: this run scheme is... confusing.
657
709
pub fn run_enabled ( & self ) -> bool {
658
710
self . run . unwrap_or_else ( || {
0 commit comments