diff --git a/GRAMMAR.md b/GRAMMAR.md index 683b5a6509..40f7548cd8 100644 --- a/GRAMMAR.md +++ b/GRAMMAR.md @@ -72,6 +72,7 @@ setting : 'allow-duplicate-recipes' boolean? | 'export' boolean? | 'fallback' boolean? | 'ignore-comments' boolean? + | 'no-cd' boolean? | 'positional-arguments' boolean? | 'script-interpreter' ':=' string_list | 'quiet' boolean? diff --git a/src/execution_context.rs b/src/execution_context.rs index bd39ecfcd3..a60905c332 100644 --- a/src/execution_context.rs +++ b/src/execution_context.rs @@ -10,6 +10,10 @@ pub(crate) struct ExecutionContext<'src: 'run, 'run> { } impl<'src: 'run, 'run> ExecutionContext<'src, 'run> { + pub(crate) fn change_directory(&self) -> bool { + !self.module.settings.no_cd + } + pub(crate) fn working_directory(&self) -> PathBuf { let base = if self.module.is_submodule() { &self.module.working_directory diff --git a/src/keyword.rs b/src/keyword.rs index ff06c39d27..6b38972482 100644 --- a/src/keyword.rs +++ b/src/keyword.rs @@ -17,6 +17,7 @@ pub(crate) enum Keyword { False, If, IgnoreComments, + NoCd, Import, Mod, PositionalArguments, diff --git a/src/node.rs b/src/node.rs index 3ccf862d57..226d6dba82 100644 --- a/src/node.rs +++ b/src/node.rs @@ -296,7 +296,8 @@ impl<'src> Node<'src> for Set<'src> { | Setting::Quiet(value) | Setting::Unstable(value) | Setting::WindowsPowerShell(value) - | Setting::IgnoreComments(value) => { + | Setting::IgnoreComments(value) + | Setting::NoCd(value) => { set.push_mut(value.to_string()); } Setting::ScriptInterpreter(Interpreter { command, arguments }) diff --git a/src/parser.rs b/src/parser.rs index b896cd0b13..95db0c2281 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -952,6 +952,7 @@ impl<'run, 'src> Parser<'run, 'src> { Keyword::Export => Some(Setting::Export(self.parse_set_bool()?)), Keyword::Fallback => Some(Setting::Fallback(self.parse_set_bool()?)), Keyword::IgnoreComments => Some(Setting::IgnoreComments(self.parse_set_bool()?)), + Keyword::NoCd => Some(Setting::NoCd(self.parse_set_bool()?)), Keyword::PositionalArguments => Some(Setting::PositionalArguments(self.parse_set_bool()?)), Keyword::Quiet => Some(Setting::Quiet(self.parse_set_bool()?)), Keyword::Unstable => Some(Setting::Unstable(self.parse_set_bool()?)), diff --git a/src/recipe.rs b/src/recipe.rs index 78b3ef27fa..cc22626ecb 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -133,7 +133,7 @@ impl<'src, D> Recipe<'src, D> { } fn working_directory<'a>(&'a self, context: &'a ExecutionContext) -> Option { - if self.change_directory() { + if self.change_directory() && context.change_directory() { Some(context.working_directory()) } else { None diff --git a/src/setting.rs b/src/setting.rs index 2b68713580..a606bcbbda 100644 --- a/src/setting.rs +++ b/src/setting.rs @@ -11,6 +11,7 @@ pub(crate) enum Setting<'src> { Export(bool), Fallback(bool), IgnoreComments(bool), + NoCd(bool), PositionalArguments(bool), Quiet(bool), ScriptInterpreter(Interpreter<'src>), @@ -32,6 +33,7 @@ impl<'src> Display for Setting<'src> { | Self::Export(value) | Self::Fallback(value) | Self::IgnoreComments(value) + | Self::NoCd(value) | Self::PositionalArguments(value) | Self::Quiet(value) | Self::Unstable(value) diff --git a/src/settings.rs b/src/settings.rs index 795ddebd1f..90b420a7fe 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -16,6 +16,7 @@ pub(crate) struct Settings<'src> { pub(crate) export: bool, pub(crate) fallback: bool, pub(crate) ignore_comments: bool, + pub(crate) no_cd: bool, pub(crate) positional_arguments: bool, pub(crate) quiet: bool, #[serde(skip)] @@ -61,6 +62,9 @@ impl<'src> Settings<'src> { Setting::IgnoreComments(ignore_comments) => { settings.ignore_comments = ignore_comments; } + Setting::NoCd(no_cd) => { + settings.no_cd = no_cd; + } Setting::PositionalArguments(positional_arguments) => { settings.positional_arguments = positional_arguments; } diff --git a/tests/json.rs b/tests/json.rs index bf962a1e3f..b76ac1c85f 100644 --- a/tests/json.rs +++ b/tests/json.rs @@ -59,6 +59,7 @@ fn alias() { "tempdir" : null, "unstable": false, "ignore_comments": false, + "no_cd": false, "unstable": false, "windows_powershell": false, "windows_shell": null, @@ -99,6 +100,7 @@ fn assignment() { "export": false, "fallback": false, "ignore_comments": false, + "no_cd": false, "positional_arguments": false, "quiet": false, "shell": null, @@ -153,6 +155,7 @@ fn private_assignment() { "export": false, "fallback": false, "ignore_comments": false, + "no_cd": false, "positional_arguments": false, "quiet": false, "shell": null, @@ -211,6 +214,7 @@ fn body() { "export": false, "fallback": false, "ignore_comments": false, + "no_cd": false, "positional_arguments": false, "quiet": false, "shell": null, @@ -281,6 +285,7 @@ fn dependencies() { "export": false, "fallback": false, "ignore_comments": false, + "no_cd": false, "positional_arguments": false, "quiet": false, "shell": null, @@ -389,6 +394,7 @@ fn dependency_argument() { "export": false, "fallback": false, "ignore_comments": false, + "no_cd": false, "positional_arguments": false, "quiet": false, "shell": null, @@ -459,6 +465,7 @@ fn duplicate_recipes() { "export": false, "fallback": false, "ignore_comments": false, + "no_cd": false, "positional_arguments": false, "quiet": false, "shell": null, @@ -507,6 +514,7 @@ fn duplicate_variables() { "export": false, "fallback": false, "ignore_comments": false, + "no_cd": false, "positional_arguments": false, "quiet": false, "shell": null, @@ -558,6 +566,7 @@ fn doc_comment() { "export": false, "fallback": false, "ignore_comments": false, + "no_cd": false, "positional_arguments": false, "quiet": false, "shell": null, @@ -595,6 +604,7 @@ fn empty_justfile() { "export": false, "fallback": false, "ignore_comments": false, + "no_cd": false, "positional_arguments": false, "quiet": false, "shell": null, @@ -753,6 +763,7 @@ fn parameters() { "export": false, "fallback": false, "ignore_comments": false, + "no_cd": false, "positional_arguments": false, "quiet": false, "shell": null, @@ -844,6 +855,7 @@ fn priors() { "export": false, "fallback": false, "ignore_comments": false, + "no_cd": false, "positional_arguments": false, "quiet": false, "shell": null, @@ -895,6 +907,7 @@ fn private() { "export": false, "fallback": false, "ignore_comments": false, + "no_cd": false, "positional_arguments": false, "quiet": false, "shell": null, @@ -946,6 +959,7 @@ fn quiet() { "export": false, "fallback": false, "ignore_comments": false, + "no_cd": false, "positional_arguments": false, "quiet": false, "shell": null, @@ -1009,6 +1023,7 @@ fn settings() { "export": true, "fallback": true, "ignore_comments": true, + "no_cd": false, "positional_arguments": true, "quiet": true, "shell": { @@ -1066,6 +1081,7 @@ fn shebang() { "export": false, "fallback": false, "ignore_comments": false, + "no_cd": false, "positional_arguments": false, "quiet": false, "shell": null, @@ -1117,6 +1133,7 @@ fn simple() { "export": false, "fallback": false, "ignore_comments": false, + "no_cd": false, "positional_arguments": false, "quiet": false, "shell": null, @@ -1176,6 +1193,7 @@ fn attribute() { "tempdir" : null, "unstable": false, "ignore_comments": false, + "no_cd": false, "windows_powershell": false, "windows_shell": null, "working_directory" : null, @@ -1245,6 +1263,7 @@ fn module() { "tempdir" : null, "unstable": false, "ignore_comments": false, + "no_cd": false, "windows_powershell": false, "windows_shell": null, "working_directory" : null, @@ -1269,6 +1288,7 @@ fn module() { "tempdir" : null, "unstable": false, "ignore_comments": false, + "no_cd": false, "windows_powershell": false, "windows_shell": null, "working_directory" : null, @@ -1340,6 +1360,7 @@ fn module_group() { "tempdir" : null, "unstable": false, "ignore_comments": false, + "no_cd": false, "windows_powershell": false, "windows_shell": null, "working_directory" : null, @@ -1364,6 +1385,7 @@ fn module_group() { "tempdir" : null, "unstable": false, "ignore_comments": false, + "no_cd": false, "windows_powershell": false, "windows_shell": null, "working_directory" : null, diff --git a/tests/working_directory.rs b/tests/working_directory.rs index 3396b73eb7..c8de901085 100644 --- a/tests/working_directory.rs +++ b/tests/working_directory.rs @@ -235,6 +235,26 @@ fn no_cd_overrides_setting() { .run(); } +#[test] +fn no_cd_setting() { + Test::new() + .justfile( + " + set no-cd + default: + basename $PWD + ", + ) + .current_dir("start_dir") + .tree(tree! { + start_dir: { + } + }) + .stderr("basename $PWD\n") + .stdout("start_dir\n") + .run(); +} + #[test] fn working_dir_in_submodule_is_relative_to_module_path() { Test::new()