From 8f2a45dd143b8898c1e654fbde581f57e5ca9c7d Mon Sep 17 00:00:00 2001 From: jeremy ku-benjet Date: Thu, 8 Aug 2024 19:04:43 -0400 Subject: [PATCH] make it an error in rhai to have empty ops --- fud2/fud-core/src/run.rs | 5 ----- fud2/fud-core/src/script/error.rs | 11 +++++++++++ fud2/fud-core/src/script/plugin.rs | 10 +++++++++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/fud2/fud-core/src/run.rs b/fud2/fud-core/src/run.rs index b3fef72f6..50a1a8b62 100644 --- a/fud2/fud-core/src/run.rs +++ b/fud2/fud-core/src/run.rs @@ -183,11 +183,6 @@ impl EmitBuild for RulesOp { )?; } - // If the sequences of rules was empty, output a phoney rule creating the desired output. - if self.cmds.is_empty() { - emitter.build_cmd(outputs, "phony", inputs, &[])?; - } - Ok(()) } } diff --git a/fud2/fud-core/src/script/error.rs b/fud2/fud-core/src/script/error.rs index 2a803b4e4..903e4794b 100644 --- a/fud2/fud-core/src/script/error.rs +++ b/fud2/fud-core/src/script/error.rs @@ -21,6 +21,7 @@ pub(super) enum RhaiSystemErrorKind { ExpectedString(String), ExpectedShell, ExpectedShellDeps, + EmptyOp, } impl RhaiSystemError { @@ -90,6 +91,13 @@ impl RhaiSystemError { } } + pub(super) fn empty_op() -> Self { + Self { + kind: RhaiSystemErrorKind::EmptyOp, + position: rhai::Position::NONE, + } + } + pub(super) fn with_pos(mut self, p: rhai::Position) -> Self { self.position = p; self @@ -126,6 +134,9 @@ impl Display for RhaiSystemError { RhaiSystemErrorKind::ExpectedShellDeps => { write!(f, "Expected `shell_deps`, got shell. Ops may contain only one of `shell` or `shell_deps` calls, not calls to both") } + RhaiSystemErrorKind::EmptyOp => { + write!(f, "Error: Op must contain at least one call to `shell` or `shell_deps`.") + } } } } diff --git a/fud2/fud-core/src/script/plugin.rs b/fud2/fud-core/src/script/plugin.rs index 040e32db3..0158d485b 100644 --- a/fud2/fud-core/src/script/plugin.rs +++ b/fud2/fud-core/src/script/plugin.rs @@ -352,8 +352,16 @@ impl ScriptContext { c } Some(ShellCommands::Cmds(c)) => c.clone(), - None => vec![], + + None => { + // If cmds is empty, then the op doesn't do anything and should be considered + // erroneous. + return Err(RhaiSystemError::empty_op() + .with_pos(pos) + .into()); + } }; + let op_name = name.clone(); let config_vars = config_vars.clone(); let op_emitter = crate::run::RulesOp {