-
Notifications
You must be signed in to change notification settings - Fork 498
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
Invertible attributes #2393
base: master
Are you sure you want to change the base?
Invertible attributes #2393
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 |
---|---|---|
|
@@ -16,6 +16,38 @@ fn error_from_signal(recipe: &str, line_number: Option<usize>, exit_status: Exit | |
} | ||
} | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
enum System { | ||
Windows, | ||
MacOS, | ||
Linux, | ||
OpenBSD, | ||
Unix, | ||
} | ||
|
||
impl System { | ||
fn current() -> &'static [System] { | ||
use System::*; | ||
if cfg!(target_os = "linux") { | ||
return &[Linux, Unix]; | ||
} | ||
if cfg!(target_os = "openbsd") { | ||
&[OpenBSD, Unix]; | ||
} | ||
if cfg!(target_os = "macos") { | ||
&[MacOS, Unix]; | ||
} | ||
if cfg!(target_os = "windows") || cfg!(windows) { | ||
return &[Windows]; | ||
} | ||
if cfg!(unix) { | ||
return &[Unix]; | ||
} | ||
|
||
&[] | ||
} | ||
} | ||
|
||
/// A recipe, e.g. `foo: bar baz` | ||
#[derive(PartialEq, Debug, Clone, Serialize)] | ||
pub(crate) struct Recipe<'src, D = Dependency<'src>> { | ||
|
@@ -116,19 +148,83 @@ impl<'src, D> Recipe<'src, D> { | |
} | ||
|
||
pub(crate) fn enabled(&self) -> bool { | ||
let linux = self.attributes.contains(AttributeDiscriminant::Linux); | ||
let macos = self.attributes.contains(AttributeDiscriminant::Macos); | ||
let openbsd = self.attributes.contains(AttributeDiscriminant::Openbsd); | ||
let unix = self.attributes.contains(AttributeDiscriminant::Unix); | ||
let windows = self.attributes.contains(AttributeDiscriminant::Windows); | ||
|
||
(!windows && !linux && !macos && !openbsd && !unix) | ||
|| (cfg!(target_os = "linux") && (linux || unix)) | ||
|| (cfg!(target_os = "macos") && (macos || unix)) | ||
|| (cfg!(target_os = "openbsd") && (openbsd || unix)) | ||
|| (cfg!(target_os = "windows") && windows) | ||
|| (cfg!(unix) && unix) | ||
|| (cfg!(windows) && windows) | ||
struct Systems { | ||
linux: bool, | ||
macos: bool, | ||
openbsd: bool, | ||
unix: bool, | ||
windows: bool, | ||
} | ||
|
||
let linux = self | ||
.attributes | ||
.contains_invertible(AttributeDiscriminant::Linux); | ||
let macos = self | ||
.attributes | ||
.contains_invertible(AttributeDiscriminant::Macos); | ||
let openbsd = self | ||
.attributes | ||
.contains_invertible(AttributeDiscriminant::Openbsd); | ||
let unix = self | ||
.attributes | ||
.contains_invertible(AttributeDiscriminant::Unix); | ||
let windows = self | ||
.attributes | ||
.contains_invertible(AttributeDiscriminant::Windows); | ||
|
||
if [linux, macos, openbsd, unix, windows] | ||
.into_iter() | ||
.all(|x| x.is_none()) | ||
{ | ||
return true; | ||
} | ||
|
||
let current = System::current(); | ||
|
||
/* | ||
let systems = Systems { | ||
linux: matches!(linux, Some(InvertedStatus::Normal)), | ||
macos: matches!(macos, Some(InvertedStatus::Normal)), | ||
openbsd: matches!(openbsd, Some(InvertedStatus::Normal)), | ||
unix: matches!(unix, Some(InvertedStatus::Normal)), | ||
windows: matches!(windows, Some(InvertedStatus::Normal)), | ||
}; | ||
|
||
let disabled = Systems { | ||
linux: matches!(linux, Some(InvertedStatus::Inverted)), | ||
macos: matches!(macos, Some(InvertedStatus::Inverted)), | ||
openbsd: matches!(openbsd, Some(InvertedStatus::Inverted)), | ||
unix: matches!(unix, Some(InvertedStatus::Inverted)), | ||
windows: matches!(windows, Some(InvertedStatus::Inverted)), | ||
}; | ||
|
||
if cfg!(target_os = "linux") { | ||
return !(disabled.linux || disabled.unix) | ||
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. Are these 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 think this maybe all gets easier if we have a
And then we can handle all these checks in the same way. |
||
&& ((systems.linux || systems.unix) | ||
|| (!systems.openbsd && !systems.windows && !systems.macos)); | ||
} | ||
|
||
if cfg!(target_os = "openbsd") { | ||
return !disabled.openbsd | ||
&& (systems.openbsd || (!systems.windows && !systems.macos && !systems.linux)); | ||
} | ||
|
||
if cfg!(target_os = "windows") || cfg!(windows) { | ||
return !disabled.windows | ||
&& (systems.windows | ||
|| (!systems.openbsd && !systems.unix && !systems.macos && !systems.linux)); | ||
} | ||
|
||
if cfg!(target_os = "macos") { | ||
return !disabled.macos | ||
&& (systems.macos || (!systems.openbsd && !systems.windows && !systems.linux)); | ||
} | ||
|
||
if cfg!(unix) { | ||
return !(disabled.unix) && (systems.unix || !systems.windows); | ||
} | ||
*/ | ||
false | ||
} | ||
|
||
fn print_exit_message(&self) -> bool { | ||
|
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 think this is probably cleaner than using mutable variables:
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.
And I think we should actually, since we don't have any invertable variables which aren't system variables, change the argument to
Attribute::new
to be !inverted, and withinAttribute::new
it's calledenabled
.