Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ impl<'run, 'src> Analyzer<'run, 'src> {
unstable_features.insert(UnstableFeature::ScriptInterpreterSetting);
}

if settings.windows_script_interpreter.is_some() {
unstable_features.insert(UnstableFeature::WindowsScriptInterpreterSetting);
}

let source = root.to_owned();
let root = paths.get(root).unwrap();

Expand Down
1 change: 1 addition & 0 deletions src/keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub(crate) enum Keyword {
Unexport,
Unstable,
WindowsPowershell,
WindowsScriptInterpreter,
WindowsShell,
WorkingDirectory,
X,
Expand Down
1 change: 1 addition & 0 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ impl<'src> Node<'src> for Set<'src> {
}
Setting::ScriptInterpreter(Interpreter { command, arguments })
| Setting::Shell(Interpreter { command, arguments })
| Setting::WindowsScriptInterpreter(Interpreter { command, arguments })
| Setting::WindowsShell(Interpreter { command, arguments }) => {
set.push_mut(Tree::string(&command.cooked));
for argument in arguments {
Expand Down
3 changes: 3 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,9 @@ impl<'run, 'src> Parser<'run, 'src> {
Keyword::ScriptInterpreter => Some(Setting::ScriptInterpreter(self.parse_interpreter()?)),
Keyword::Shell => Some(Setting::Shell(self.parse_interpreter()?)),
Keyword::Tempdir => Some(Setting::Tempdir(self.parse_string_literal()?)),
Keyword::WindowsScriptInterpreter => {
Some(Setting::WindowsScriptInterpreter(self.parse_interpreter()?))
}
Keyword::WindowsShell => Some(Setting::WindowsShell(self.parse_interpreter()?)),
Keyword::WorkingDirectory => Some(Setting::WorkingDirectory(self.parse_string_literal()?)),
_ => None,
Expand Down
5 changes: 5 additions & 0 deletions src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,11 @@ impl<'src, D> Recipe<'src, D> {
Executor::Command(
interpreter
.as_ref()
.or(if cfg!(windows) {
context.module.settings.windows_script_interpreter.as_ref()
} else {
None
})
.or(context.module.settings.script_interpreter.as_ref())
.unwrap_or_else(|| Interpreter::default_script_interpreter()),
)
Expand Down
6 changes: 5 additions & 1 deletion src/setting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub(crate) enum Setting<'src> {
Tempdir(StringLiteral<'src>),
Unstable(bool),
WindowsPowerShell(bool),
WindowsScriptInterpreter(Interpreter<'src>),
WindowsShell(Interpreter<'src>),
WorkingDirectory(StringLiteral<'src>),
}
Expand All @@ -40,7 +41,10 @@ impl Display for Setting<'_> {
| Self::Quiet(value)
| Self::Unstable(value)
| Self::WindowsPowerShell(value) => write!(f, "{value}"),
Self::ScriptInterpreter(shell) | Self::Shell(shell) | Self::WindowsShell(shell) => {
Self::ScriptInterpreter(shell)
| Self::Shell(shell)
| Self::WindowsScriptInterpreter(shell)
| Self::WindowsShell(shell) => {
write!(f, "[{shell}]")
}
Self::DotenvFilename(value)
Expand Down
5 changes: 5 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub(crate) struct Settings<'src> {
pub(crate) tempdir: Option<String>,
pub(crate) unstable: bool,
pub(crate) windows_powershell: bool,
#[serde(skip)]
pub(crate) windows_script_interpreter: Option<Interpreter<'src>>,
pub(crate) windows_shell: Option<Interpreter<'src>>,
pub(crate) working_directory: Option<PathBuf>,
}
Expand Down Expand Up @@ -87,6 +89,9 @@ impl<'src> Settings<'src> {
Setting::WindowsPowerShell(windows_powershell) => {
settings.windows_powershell = windows_powershell;
}
Setting::WindowsScriptInterpreter(windows_script_interpreter) => {
settings.windows_script_interpreter = Some(windows_script_interpreter);
}
Setting::WindowsShell(windows_shell) => {
settings.windows_shell = Some(windows_shell);
}
Expand Down
7 changes: 7 additions & 0 deletions src/unstable_feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub(crate) enum UnstableFeature {
ScriptAttribute,
ScriptInterpreterSetting,
WhichFunction,
WindowsScriptInterpreterSetting,
}

impl Display for UnstableFeature {
Expand All @@ -22,6 +23,12 @@ impl Display for UnstableFeature {
write!(f, "The `script-interpreter` setting is currently unstable.")
}
Self::WhichFunction => write!(f, "The `which()` function is currently unstable."),
Self::WindowsScriptInterpreterSetting => {
write!(
f,
"The `windows-script-interpreter` setting is currently unstable."
)
}
}
}
}
2 changes: 2 additions & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ mod which_function;
#[cfg(windows)]
mod windows;
#[cfg(target_family = "windows")]
mod windows_script_interpreter;
#[cfg(target_family = "windows")]
mod windows_shell;
mod working_directory;

Expand Down
48 changes: 48 additions & 0 deletions tests/windows_script_interpreter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use super::*;

#[test]
fn windows_script_interpreter_setting() {
Test::new()
.justfile(
r#"
set unstable
set windows-script-interpreter := ["pwsh.exe", "-NoLogo", "-Command"]
set script-interpreter := ["asdfasdfasdfasdf"]

[script]
foo:
Write-Output bar
"#,
)
.shell(false)
.stdout("bar\r\n")
.run();
}

#[test]
fn script_interpreter_setting_is_unstable() {
Test::new()
.justfile("set windows-script-interpreter := ['sh']")
.status(EXIT_FAILURE)
.stderr_regex(r"error: The `windows-script-interpreter` setting is currently unstable\..*")
.run();
}

#[test]
fn overrides_script_interpreter() {
Test::new()
.justfile(
r#"
set unstable
set script-interpreter := ["cmd.exe", "/c"]
set windows-script-interpreter := ["pwsh.exe", "-NoLogo", "-Command"]

[script]
foo:
Write-Output bar
"#,
)
.shell(false)
.stdout("bar\r\n")
.run();
}