-
Notifications
You must be signed in to change notification settings - Fork 13.3k
build_helper::compiletest module factored out of compiletest for use by bootstrap #135653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
//! Types representing arguments to compiletest. | ||
|
||
use std::fmt; | ||
use std::str::FromStr; | ||
|
||
pub use self::Mode::*; | ||
|
||
macro_rules! string_enum { | ||
($(#[$meta:meta])* $vis:vis enum $name:ident { $($variant:ident => $repr:expr,)* }) => { | ||
$(#[$meta])* | ||
$vis enum $name { | ||
$($variant,)* | ||
} | ||
|
||
impl $name { | ||
$vis const VARIANTS: &'static [Self] = &[$(Self::$variant,)*]; | ||
$vis const STR_VARIANTS: &'static [&'static str] = &[$(Self::$variant.to_str(),)*]; | ||
|
||
$vis const fn to_str(&self) -> &'static str { | ||
match self { | ||
$(Self::$variant => $repr,)* | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for $name { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
fmt::Display::fmt(self.to_str(), f) | ||
} | ||
} | ||
|
||
impl FromStr for $name { | ||
type Err = String; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
match s { | ||
$($repr => Ok(Self::$variant),)* | ||
_ => Err(format!(concat!("unknown `", stringify!($name), "` variant: `{}`"), s)), | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Make the macro visible outside of this module, for tests. | ||
#[cfg(test)] | ||
pub(crate) use string_enum; | ||
|
||
string_enum! { | ||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] | ||
pub enum Mode { | ||
Pretty => "pretty", | ||
DebugInfo => "debuginfo", | ||
Codegen => "codegen", | ||
Rustdoc => "rustdoc", | ||
RustdocJson => "rustdoc-json", | ||
CodegenUnits => "codegen-units", | ||
Incremental => "incremental", | ||
RunMake => "run-make", | ||
Ui => "ui", | ||
RustdocJs => "rustdoc-js", | ||
MirOpt => "mir-opt", | ||
Assembly => "assembly", | ||
CoverageMap => "coverage-map", | ||
CoverageRun => "coverage-run", | ||
Crashes => "crashes", | ||
} | ||
} | ||
|
||
impl Default for Mode { | ||
fn default() -> Self { | ||
Mode::Ui | ||
} | ||
} | ||
|
||
impl Mode { | ||
pub fn aux_dir_disambiguator(self) -> &'static str { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't feel like these two helpers belong in build_helpers? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that would require turning them into free functions. do you want me to do that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, please do move them as free functions into compiletest, this is an impl detail that doesn't feel like they belong here |
||
// Pretty-printing tests could run concurrently, and if they do, | ||
// they need to keep their output segregated. | ||
match self { | ||
Pretty => ".pretty", | ||
_ => "", | ||
} | ||
} | ||
|
||
pub fn output_dir_disambiguator(self) -> &'static str { | ||
// Coverage tests use the same test files for multiple test modes, | ||
// so each mode should have a separate output directory. | ||
match self { | ||
CoverageMap | CoverageRun => self.to_str(), | ||
_ => "", | ||
} | ||
} | ||
} | ||
|
||
string_enum! { | ||
#[derive(Clone, Copy, PartialEq, Debug, Hash)] | ||
pub enum PassMode { | ||
Check => "check", | ||
Build => "build", | ||
Run => "run", | ||
} | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)] | ||
pub enum FailMode { | ||
Check, | ||
Build, | ||
Run, | ||
} | ||
|
||
string_enum! { | ||
#[derive(Clone, Debug, PartialEq)] | ||
pub enum CompareMode { | ||
Polonius => "polonius", | ||
NextSolver => "next-solver", | ||
NextSolverCoherence => "next-solver-coherence", | ||
SplitDwarf => "split-dwarf", | ||
SplitDwarfSingle => "split-dwarf-single", | ||
} | ||
} | ||
|
||
string_enum! { | ||
#[derive(Clone, Copy, Debug, PartialEq)] | ||
pub enum Debugger { | ||
Cdb => "cdb", | ||
Gdb => "gdb", | ||
Lldb => "lldb", | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please call this TestMode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why? the command line flag is called
--mode
, no? so why shouldn't the struct match?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because build_helpers is a shared dep between bootstrap, compiletest, and some other bootstrap tools. bootstrap itself already has a
Mode
, not to mentionMode
is a very generic term.--mode
for compiletest is fine because it's very clear from context as its a flag of the compiletest binary itself (only matters when bootstrap is actually trying to run compiletest binary).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would think its position in the
compiletest
module would be adequate context.i can if you really want me to, it's just gonna take a bit since it's refactoring across several crates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I would prefer if this is called
TestMode
and not justMode
.