Skip to content

Commit

Permalink
Use System type WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
neunenak committed Dec 24, 2024
1 parent 78c67e2 commit b806a9f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
19 changes: 2 additions & 17 deletions src/attribute_set.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
use {super::*, std::collections};

#[derive(Debug, Copy, Clone)]
pub(crate) enum InvertedStatus {
Normal,
Inverted,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize)]
pub(crate) struct AttributeSet<'src>(BTreeSet<Attribute<'src>>);

Expand All @@ -18,23 +12,14 @@ impl<'src> AttributeSet<'src> {
self.0.iter().any(|attr| attr.discriminant() == target)
}

pub(crate) fn contains_invertible(
&self,
target: AttributeDiscriminant,
) -> Option<InvertedStatus> {
pub(crate) fn contains_invertible(&self, target: AttributeDiscriminant) -> Option<bool> {
self.get(target).and_then(|attr| {
Some(match attr {
Attribute::Linux { enabled }
| Attribute::Macos { enabled }
| Attribute::Openbsd { enabled }
| Attribute::Unix { enabled }
| Attribute::Windows { enabled } => {
if *enabled {
InvertedStatus::Normal
} else {
InvertedStatus::Inverted
}
}
| Attribute::Windows { enabled } => enabled,
_ => panic!("contains_invertible called with non-invertible attribute"),
})
})
Expand Down
38 changes: 36 additions & 2 deletions src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>> {
Expand Down Expand Up @@ -116,8 +148,6 @@ impl<'src, D> Recipe<'src, D> {
}

pub(crate) fn enabled(&self) -> bool {
use attribute_set::InvertedStatus;

struct Systems {
linux: bool,
macos: bool,
Expand Down Expand Up @@ -149,6 +179,9 @@ impl<'src, D> Recipe<'src, D> {
return true;
}

let current = System::current();

/*
let systems = Systems {
linux: matches!(linux, Some(InvertedStatus::Normal)),
macos: matches!(macos, Some(InvertedStatus::Normal)),
Expand Down Expand Up @@ -190,6 +223,7 @@ impl<'src, D> Recipe<'src, D> {
if cfg!(unix) {
return !(disabled.unix) && (systems.unix || !systems.windows);
}
*/
false
}

Expand Down

0 comments on commit b806a9f

Please sign in to comment.