Skip to content

Commit 7317ad8

Browse files
author
duncan
committed
add [android] recipe attribute
1 parent 5434a0a commit 7317ad8

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,6 +2114,7 @@ change their behavior.
21142114
| `[doc(DOC)]`<sup>1.27.0</sup> | module, recipe | Set recipe or module's [documentation comment](#documentation-comments) to `DOC`. |
21152115
| `[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. |
21162116
| `[group(NAME)]`<sup>1.27.0</sup> | module, recipe | Put recipe or module in in [group](#groups) `NAME`. |
2117+
| `[android]`<sup>1.43.0</sup> | recipe | Enable recipe on Android. |
21172118
| `[linux]`<sup>1.8.0</sup> | recipe | Enable recipe on Linux. |
21182119
| `[macos]`<sup>1.8.0</sup> | recipe | Enable recipe on MacOS. |
21192120
| `[metadata(METADATA)]`<sup>1.42.0</sup> | recipe | Attach `METADATA` to recipe. |

src/attribute.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use super::*;
99
#[strum_discriminants(derive(EnumString, Ord, PartialOrd))]
1010
#[strum_discriminants(strum(serialize_all = "kebab-case"))]
1111
pub(crate) enum Attribute<'src> {
12+
Android,
1213
Confirm(Option<StringLiteral<'src>>),
1314
Default,
1415
Doc(Option<StringLiteral<'src>>),
@@ -35,7 +36,8 @@ impl AttributeDiscriminant {
3536
fn argument_range(self) -> RangeInclusive<usize> {
3637
match self {
3738
Self::Confirm | Self::Doc => 0..=1,
38-
Self::Default
39+
Self::Android
40+
| Self::Default
3941
| Self::ExitMessage
4042
| Self::Linux
4143
| Self::Macos
@@ -84,6 +86,7 @@ impl<'src> Attribute<'src> {
8486
}
8587

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

135138
match self {
136-
Self::Confirm(None)
139+
Self::Android
140+
| Self::Confirm(None)
137141
| Self::Default
138142
| Self::Doc(None)
139143
| Self::ExitMessage

src/recipe.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,15 @@ impl<'src, D> Recipe<'src, D> {
134134
}
135135

136136
pub(crate) fn enabled(&self) -> bool {
137+
let android = self.attributes.contains(AttributeDiscriminant::Android);
137138
let linux = self.attributes.contains(AttributeDiscriminant::Linux);
138139
let macos = self.attributes.contains(AttributeDiscriminant::Macos);
139140
let openbsd = self.attributes.contains(AttributeDiscriminant::Openbsd);
140141
let unix = self.attributes.contains(AttributeDiscriminant::Unix);
141142
let windows = self.attributes.contains(AttributeDiscriminant::Windows);
142143

143-
(!windows && !linux && !macos && !openbsd && !unix)
144+
(!windows && !android && !linux && !macos && !openbsd && !unix)
145+
|| (cfg!(target_os = "android") && (android || unix))
144146
|| (cfg!(target_os = "linux") && (linux || unix))
145147
|| (cfg!(target_os = "macos") && (macos || unix))
146148
|| (cfg!(target_os = "openbsd") && (openbsd || unix))

tests/attributes.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ fn all() {
88
[macos]
99
[linux]
1010
[openbsd]
11+
[android]
1112
[unix]
1213
[windows]
1314
[no-exit-message]
@@ -49,7 +50,7 @@ fn multiple_attributes_one_line() {
4950
Test::new()
5051
.justfile(
5152
"
52-
[macos,windows,linux,openbsd]
53+
[macos,windows,linux,openbsd,android]
5354
[no-exit-message]
5455
foo:
5556
exit 1
@@ -65,7 +66,7 @@ fn multiple_attributes_one_line_error_message() {
6566
Test::new()
6667
.justfile(
6768
"
68-
[macos,windows linux,openbsd]
69+
[macos,windows linux,openbsd,android]
6970
[no-exit-message]
7071
foo:
7172
exit 1
@@ -76,7 +77,7 @@ fn multiple_attributes_one_line_error_message() {
7677
error: Expected ']', ':', ',', or '(', but found identifier
7778
——▶ justfile:1:16
7879
79-
1 │ [macos,windows linux,openbsd]
80+
1 │ [macos,windows linux,openbsd,android]
8081
│ ^^^^^
8182
",
8283
)
@@ -89,7 +90,7 @@ fn multiple_attributes_one_line_duplicate_check() {
8990
Test::new()
9091
.justfile(
9192
"
92-
[macos, windows, linux, openbsd]
93+
[macos, windows, linux, openbsd, android]
9394
[linux]
9495
foo:
9596
exit 1

tests/os_attributes.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ fn os() {
5151
[openbsd]
5252
foo:
5353
echo bob
54+
55+
[android]
56+
foo:
57+
echo babs
5458
",
5559
)
5660
.stdout(if cfg!(target_os = "macos") {
@@ -61,6 +65,8 @@ fn os() {
6165
"quxx\n"
6266
} else if cfg!(target_os = "openbsd") {
6367
"bob\n"
68+
} else if cfg!(target_os = "android") {
69+
"babs\n"
6470
} else {
6571
panic!("unexpected os family")
6672
})
@@ -72,6 +78,8 @@ fn os() {
7278
"echo quxx\n"
7379
} else if cfg!(target_os = "openbsd") {
7480
"echo bob\n"
81+
} else if cfg!(target_os = "android") {
82+
"echo babs\n"
7583
} else {
7684
panic!("unexpected os family")
7785
})
@@ -83,6 +91,7 @@ fn all() {
8391
Test::new()
8492
.justfile(
8593
"
94+
[android]
8695
[linux]
8796
[macos]
8897
[openbsd]

0 commit comments

Comments
 (0)