Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2114,6 +2114,7 @@ change their behavior.
| `[doc(DOC)]`<sup>1.27.0</sup> | module, recipe | Set recipe or module's [documentation comment](#documentation-comments) to `DOC`. |
| `[extension(EXT)]`<sup>1.32.0</sup> | recipe | Set shebang recipe script's file extension to `EXT`. `EXT` should include a period if one is desired. |
| `[group(NAME)]`<sup>1.27.0</sup> | module, recipe | Put recipe or module in in [group](#groups) `NAME`. |
| `[android]`<sup>1.43.0</sup> | recipe | Enable recipe on Android. |
| `[linux]`<sup>1.8.0</sup> | recipe | Enable recipe on Linux. |
| `[macos]`<sup>1.8.0</sup> | recipe | Enable recipe on MacOS. |
| `[metadata(METADATA)]`<sup>1.42.0</sup> | recipe | Attach `METADATA` to recipe. |
Expand Down
8 changes: 6 additions & 2 deletions src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use super::*;
#[strum_discriminants(derive(EnumString, Ord, PartialOrd))]
#[strum_discriminants(strum(serialize_all = "kebab-case"))]
pub(crate) enum Attribute<'src> {
Android,
Confirm(Option<StringLiteral<'src>>),
Default,
Doc(Option<StringLiteral<'src>>),
Expand All @@ -35,7 +36,8 @@ impl AttributeDiscriminant {
fn argument_range(self) -> RangeInclusive<usize> {
match self {
Self::Confirm | Self::Doc => 0..=1,
Self::Default
Self::Android
| Self::Default
| Self::ExitMessage
| Self::Linux
| Self::Macos
Expand Down Expand Up @@ -84,6 +86,7 @@ impl<'src> Attribute<'src> {
}

Ok(match discriminant {
AttributeDiscriminant::Android => Self::Android,
AttributeDiscriminant::Confirm => Self::Confirm(arguments.into_iter().next()),
AttributeDiscriminant::Default => Self::Default,
AttributeDiscriminant::Doc => Self::Doc(arguments.into_iter().next()),
Expand Down Expand Up @@ -133,7 +136,8 @@ impl Display for Attribute<'_> {
write!(f, "{}", self.name())?;

match self {
Self::Confirm(None)
Self::Android
| Self::Confirm(None)
| Self::Default
| Self::Doc(None)
| Self::ExitMessage
Expand Down
4 changes: 3 additions & 1 deletion src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,15 @@ impl<'src, D> Recipe<'src, D> {
}

pub(crate) fn enabled(&self) -> bool {
let android = self.attributes.contains(AttributeDiscriminant::Android);
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)
(!windows && !android && !linux && !macos && !openbsd && !unix)
|| (cfg!(target_os = "android") && (android || unix))
|| (cfg!(target_os = "linux") && (linux || unix))
|| (cfg!(target_os = "macos") && (macos || unix))
|| (cfg!(target_os = "openbsd") && (openbsd || unix))
Expand Down
9 changes: 5 additions & 4 deletions tests/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ fn all() {
[macos]
[linux]
[openbsd]
[android]
[unix]
[windows]
[no-exit-message]
Expand Down Expand Up @@ -49,7 +50,7 @@ fn multiple_attributes_one_line() {
Test::new()
.justfile(
"
[macos,windows,linux,openbsd]
[macos,windows,linux,openbsd,android]
[no-exit-message]
foo:
exit 1
Expand All @@ -65,7 +66,7 @@ fn multiple_attributes_one_line_error_message() {
Test::new()
.justfile(
"
[macos,windows linux,openbsd]
[macos,windows linux,openbsd,android]
[no-exit-message]
foo:
exit 1
Expand All @@ -76,7 +77,7 @@ fn multiple_attributes_one_line_error_message() {
error: Expected ']', ':', ',', or '(', but found identifier
——▶ justfile:1:16
1 │ [macos,windows linux,openbsd]
1 │ [macos,windows linux,openbsd,android]
│ ^^^^^
",
)
Expand All @@ -89,7 +90,7 @@ fn multiple_attributes_one_line_duplicate_check() {
Test::new()
.justfile(
"
[macos, windows, linux, openbsd]
[macos, windows, linux, openbsd, android]
[linux]
foo:
exit 1
Expand Down
9 changes: 9 additions & 0 deletions tests/os_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ fn os() {
[openbsd]
foo:
echo bob

[android]
foo:
echo babs
",
)
.stdout(if cfg!(target_os = "macos") {
Expand All @@ -61,6 +65,8 @@ fn os() {
"quxx\n"
} else if cfg!(target_os = "openbsd") {
"bob\n"
} else if cfg!(target_os = "android") {
"babs\n"
} else {
panic!("unexpected os family")
})
Expand All @@ -72,6 +78,8 @@ fn os() {
"echo quxx\n"
} else if cfg!(target_os = "openbsd") {
"echo bob\n"
} else if cfg!(target_os = "android") {
"echo babs\n"
} else {
panic!("unexpected os family")
})
Expand All @@ -83,6 +91,7 @@ fn all() {
Test::new()
.justfile(
"
[android]
[linux]
[macos]
[openbsd]
Expand Down