This commit is contained in:
duncanawoods 2025-12-08 10:20:44 +03:00 committed by GitHub
commit 4e813fc0a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 24 additions and 7 deletions

View file

@ -2142,6 +2142,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. |

View file

@ -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>>),
@ -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
@ -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()),
@ -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

View file

@ -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))

View file

@ -8,6 +8,7 @@ fn all() {
[macos]
[linux]
[openbsd]
[android]
[unix]
[windows]
[no-exit-message]
@ -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
@ -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
@ -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]
^^^^^
",
)
@ -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

View file

@ -51,6 +51,10 @@ fn os() {
[openbsd]
foo:
echo bob
[android]
foo:
echo babs
",
)
.stdout(if cfg!(target_os = "macos") {
@ -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")
})
@ -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")
})
@ -83,6 +91,7 @@ fn all() {
Test::new()
.justfile(
"
[android]
[linux]
[macos]
[openbsd]