From 563eee660941f3e144de87eacf8bad220f1ad1c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladimir=20T=C3=A1mara=20Pati=C3=B1o?= Date: Sun, 1 Dec 2024 20:01:34 -0500 Subject: [PATCH] Add `[openbsd]` recipe attribute (#2497) --- README.md | 7 ++++--- crates-io-readme.md | 8 +++++--- src/attribute.rs | 4 ++++ src/recipe.rs | 10 ++++++---- tests/attributes.rs | 15 ++++++++------- tests/os_attributes.rs | 13 +++++++++++-- 6 files changed, 38 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 27e3307a50..976892075a 100644 --- a/README.md +++ b/README.md @@ -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. @@ -1986,6 +1986,7 @@ change their behavior. | `[no-cd]`1.9.0 | recipe | Don't change directory before executing recipe. | | `[no-exit-message]`1.7.0 | recipe | Don't print an error message if recipe fails. | | `[no-quiet]`1.23.0 | recipe | Override globally quiet recipes and always echo out the recipe. | +| `[openbsd]`master | recipe | Enable recipe on OpenBSD. | | `[positional-arguments]`1.29.0 | recipe | Turn on [positional arguments](#positional-arguments) for this recipe. | | `[private]`1.10.0 | alias, recipe | Make recipe, alias, or variable private. See [Private Recipes](#private-recipes). | | `[script]`1.33.0 | recipe | Execute recipe as script. See [script recipes](#script-recipes) for more details. | diff --git a/crates-io-readme.md b/crates-io-readme.md index c05ac0a639..63c900f2b6 100644 --- a/crates-io-readme.md +++ b/crates-io-readme.md @@ -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: @@ -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). diff --git a/src/attribute.rs b/src/attribute.rs index 39a0a80060..4ec813f076 100644 --- a/src/attribute.rs +++ b/src/attribute.rs @@ -18,6 +18,7 @@ pub(crate) enum Attribute<'src> { NoCd, NoExitMessage, NoQuiet, + Openbsd, PositionalArguments, Private, Script(Option>), @@ -36,6 +37,7 @@ impl AttributeDiscriminant { | Self::NoCd | Self::NoExitMessage | Self::NoQuiet + | Self::Openbsd | Self::PositionalArguments | Self::Private | Self::Unix @@ -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({ @@ -131,6 +134,7 @@ impl Display for Attribute<'_> { | Self::NoCd | Self::NoExitMessage | Self::NoQuiet + | Self::Openbsd | Self::PositionalArguments | Self::Private | Self::Script(None) diff --git a/src/recipe.rs b/src/recipe.rs index 81fbc7ac2f..ac7fdd6596 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -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 { diff --git a/tests/attributes.rs b/tests/attributes.rs index 9f022025de..80393f1aa2 100644 --- a/tests/attributes.rs +++ b/tests/attributes.rs @@ -6,9 +6,10 @@ fn all() { .justfile( " [macos] - [windows] [linux] + [openbsd] [unix] + [windows] [no-exit-message] foo: exit 1 @@ -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 @@ -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 @@ -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) @@ -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 diff --git a/tests/os_attributes.rs b/tests/os_attributes.rs index 81729850f7..de74058043 100644 --- a/tests/os_attributes.rs +++ b/tests/os_attributes.rs @@ -47,6 +47,10 @@ fn os() { [linux] foo: echo quxx + + [openbsd] + foo: + echo bob ", ) .stdout(if cfg!(target_os = "macos") { @@ -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") }) @@ -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") }) @@ -75,10 +83,11 @@ fn all() { Test::new() .justfile( " - [macos] - [windows] [linux] + [macos] + [openbsd] [unix] + [windows] foo: echo bar ",