Skip to content

Commit

Permalink
Add [openbsd] recipe attribute (#2497)
Browse files Browse the repository at this point in the history
  • Loading branch information
vtamara authored Dec 2, 2024
1 parent cdf104b commit 563eee6
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 19 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ Yay, all your tests passed!
[`make`'s complexity and idiosyncrasies](#what-are-the-idiosyncrasies-of-make-that-just-avoids).
No need for `.PHONY` recipes!

- Linux, MacOS, and Windows are supported with no additional dependencies.
(Although if your system doesn't have an `sh`, you'll need to
[choose a different shell](#shell).)
- Linux, MacOS, Windows, and other reasonable unices are supported with no
additional dependencies. (Although if your system doesn't have an `sh`,
you'll need to [choose a different shell](#shell).)

- Errors are specific and informative, and syntax errors are reported along
with their source context.
Expand Down Expand Up @@ -1986,6 +1986,7 @@ change their behavior.
| `[no-cd]`<sup>1.9.0</sup> | recipe | Don't change directory before executing recipe. |
| `[no-exit-message]`<sup>1.7.0</sup> | recipe | Don't print an error message if recipe fails. |
| `[no-quiet]`<sup>1.23.0</sup> | recipe | Override globally quiet recipes and always echo out the recipe. |
| `[openbsd]`<sup>master</sup> | recipe | Enable recipe on OpenBSD. |
| `[positional-arguments]`<sup>1.29.0</sup> | recipe | Turn on [positional arguments](#positional-arguments) for this recipe. |
| `[private]`<sup>1.10.0</sup> | alias, recipe | Make recipe, alias, or variable private. See [Private Recipes](#private-recipes). |
| `[script]`<sup>1.33.0</sup> | recipe | Execute recipe as script. See [script recipes](#script-recipes) for more details. |
Expand Down
8 changes: 5 additions & 3 deletions crates-io-readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
`just` is a handy way to save and run project-specific commands.

Commands are stored in a file called `justfile` or `Justfile` with syntax inspired by `make`:
Commands are stored in a file called `justfile` or `Justfile` with syntax
inspired by `make`:

```make
build:
Expand All @@ -15,8 +16,9 @@ test TEST: build
./test --test {{TEST}}
```

`just` produces detailed error messages and avoids `make`'s idiosyncrasies, so debugging a justfile is easier and less surprising than debugging a makefile.
`just` produces detailed error messages and avoids `make`'s idiosyncrasies, so
debugging a justfile is easier and less surprising than debugging a makefile.

It works on Linux, MacOS, and Windows.
It works on all operating systems supported by Rust.

Read more on [GitHub](https://github.com/casey/just).
4 changes: 4 additions & 0 deletions src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub(crate) enum Attribute<'src> {
NoCd,
NoExitMessage,
NoQuiet,
Openbsd,
PositionalArguments,
Private,
Script(Option<Interpreter<'src>>),
Expand All @@ -36,6 +37,7 @@ impl AttributeDiscriminant {
| Self::NoCd
| Self::NoExitMessage
| Self::NoQuiet
| Self::Openbsd
| Self::PositionalArguments
| Self::Private
| Self::Unix
Expand Down Expand Up @@ -83,6 +85,7 @@ impl<'src> Attribute<'src> {
AttributeDiscriminant::NoCd => Self::NoCd,
AttributeDiscriminant::NoExitMessage => Self::NoExitMessage,
AttributeDiscriminant::NoQuiet => Self::NoQuiet,
AttributeDiscriminant::Openbsd => Self::Openbsd,
AttributeDiscriminant::PositionalArguments => Self::PositionalArguments,
AttributeDiscriminant::Private => Self::Private,
AttributeDiscriminant::Script => Self::Script({
Expand Down Expand Up @@ -131,6 +134,7 @@ impl Display for Attribute<'_> {
| Self::NoCd
| Self::NoExitMessage
| Self::NoQuiet
| Self::Openbsd
| Self::PositionalArguments
| Self::Private
| Self::Script(None)
Expand Down
10 changes: 6 additions & 4 deletions src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,19 @@ impl<'src, D> Recipe<'src, D> {
}

pub(crate) fn enabled(&self) -> bool {
let windows = self.attributes.contains(&Attribute::Windows);
let linux = self.attributes.contains(&Attribute::Linux);
let macos = self.attributes.contains(&Attribute::Macos);
let openbsd = self.attributes.contains(&Attribute::Openbsd);
let unix = self.attributes.contains(&Attribute::Unix);
let windows = self.attributes.contains(&Attribute::Windows);

(!windows && !linux && !macos && !unix)
|| (cfg!(target_os = "windows") && windows)
(!windows && !linux && !macos && !openbsd && !unix)
|| (cfg!(target_os = "linux") && (linux || unix))
|| (cfg!(target_os = "macos") && (macos || unix))
|| (cfg!(windows) && windows)
|| (cfg!(target_os = "openbsd") && (openbsd || unix))
|| (cfg!(target_os = "windows") && windows)
|| (cfg!(unix) && unix)
|| (cfg!(windows) && windows)
}

fn print_exit_message(&self) -> bool {
Expand Down
15 changes: 8 additions & 7 deletions tests/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ fn all() {
.justfile(
"
[macos]
[windows]
[linux]
[openbsd]
[unix]
[windows]
[no-exit-message]
foo:
exit 1
Expand Down Expand Up @@ -48,7 +49,7 @@ fn multiple_attributes_one_line() {
Test::new()
.justfile(
"
[macos, windows,linux]
[macos,windows,linux,openbsd]
[no-exit-message]
foo:
exit 1
Expand All @@ -64,7 +65,7 @@ fn multiple_attributes_one_line_error_message() {
Test::new()
.justfile(
"
[macos, windows linux]
[macos,windows linux,openbsd]
[no-exit-message]
foo:
exit 1
Expand All @@ -73,10 +74,10 @@ fn multiple_attributes_one_line_error_message() {
.stderr(
"
error: Expected ']', ':', ',', or '(', but found identifier
——▶ justfile:1:17
——▶ justfile:1:16
1 │ [macos, windows linux]
^^^^^
1 │ [macos,windows linux,openbsd]
│ ^^^^^
",
)
.status(1)
Expand All @@ -88,7 +89,7 @@ fn multiple_attributes_one_line_duplicate_check() {
Test::new()
.justfile(
"
[macos, windows, linux]
[macos, windows, linux, openbsd]
[linux]
foo:
exit 1
Expand Down
13 changes: 11 additions & 2 deletions tests/os_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ fn os() {
[linux]
foo:
echo quxx
[openbsd]
foo:
echo bob
",
)
.stdout(if cfg!(target_os = "macos") {
Expand All @@ -55,6 +59,8 @@ fn os() {
"baz\n"
} else if cfg!(target_os = "linux") {
"quxx\n"
} else if cfg!(target_os = "openbsd") {
"bob\n"
} else {
panic!("unexpected os family")
})
Expand All @@ -64,6 +70,8 @@ fn os() {
"echo baz\n"
} else if cfg!(target_os = "linux") {
"echo quxx\n"
} else if cfg!(target_os = "openbsd") {
"echo bob\n"
} else {
panic!("unexpected os family")
})
Expand All @@ -75,10 +83,11 @@ fn all() {
Test::new()
.justfile(
"
[macos]
[windows]
[linux]
[macos]
[openbsd]
[unix]
[windows]
foo:
echo bar
",
Expand Down

0 comments on commit 563eee6

Please sign in to comment.