-
Notifications
You must be signed in to change notification settings - Fork 641
Description
Is it intuitive to support OS-specific attributes on all top-level declarations in a justfile, not just recipes?
The OS is hardcoded into the executable, so the logic is straightforward:
E.g just.exe parses and completely ignores anything with [macos] or [linux] on it
This simplifies things overall and implements multiple tickets:
set windows-shell :=can be deprecated, replaced by[windows] ; set shell :=- Get
windows-script-interpreterfor free, can close Add windows-script-interpreter setting #2944 - Implements Support OS attributes on aliases #1493 & Allow (some) attributes on aliases #2627
- Implements OS-specific attributes on import #2786
- Replace conditional variable declarations:
-
SHEBANG := if os() == 'windows' { 'busybox sh' } else { '/usr/bin/env sh' } recipe: #!{{SHEBANG}} - becomes:
[windows] SHEBANG := 'busybox sh' [unix] SHEBANG := '/usr/bin/env sh' recipe: #!{{SHEBANG}}
-
Design challenges
Requires OS-specific attribute on both windows and unix setting/variable declarations:
[unix] # <-- if you omit this, error "Setting redefined"
set shell := ['bash', '-euc']
[windows]
set shell := ['busybox', 'bash', '-euc']
We should raise the "redefinition" error on Unix, too. Even though we're ignoring the second declaration on Unix, the error warns us that this justfile will fail on Windows.
Alternatively, could allow redefinition if second one has OS attribute. The un-attributed declaration becomes automatically [not-windows].
Limitations
Falls short of enabling if {} else {} logic in settings. But that's currently impossible anyway.
# If anyone has been wanting to do this, they still won't be able to
if which('sh') {
set shell := ['sh', '-euc']
} else {
set shell := ['somethingelse', '-euc']
}