From 70cbe007845cab260d915ab1726cb19fa9e673dd Mon Sep 17 00:00:00 2001 From: Dieter Baron Date: Tue, 6 Aug 2024 11:08:58 +0200 Subject: [PATCH] Check for unknown rules. --- src/Build.cc | 5 +++++ tests/filename-source-vs-build.test | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Build.cc b/src/Build.cc index 027cd06..7dbdf51 100644 --- a/src/Build.cc +++ b/src/Build.cc @@ -33,6 +33,7 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "File.h" +#include Build::Build(const File* file, Tokenizer& tokenizer): ScopedDirective(file) { outputs = Dependencies{tokenizer, true}; @@ -45,6 +46,10 @@ Build::Build(const File* file, Tokenizer& tokenizer): ScopedDirective(file) { Build::Build(const File* file, std::string rule_name, Dependencies outputs, Dependencies inputs, Bindings bindings): ScopedDirective{file, std::move(bindings)}, rule_name{std::move(rule_name)}, outputs{std::move(outputs)}, inputs{std::move(inputs)} {} void Build::process(const File& file) { + rule = file.find_rule(rule_name); + if (!rule) { + throw Exception("unknown rule %s", rule_name.c_str()); + } inputs.resolve(file); bindings.resolve(file); } diff --git a/tests/filename-source-vs-build.test b/tests/filename-source-vs-build.test index 3d1fd1e..b30cb07 100644 --- a/tests/filename-source-vs-build.test +++ b/tests/filename-source-vs-build.test @@ -7,7 +7,7 @@ rule a command = a $in $out build file: a input -build output: file sub/file +build output: a file sub/file subninja sub/build.fninja end-of-inline-data @@ -32,7 +32,7 @@ rule fast-ninja build file : a ../input -build output : file sub/file +build output : a file sub/file build build.ninja sub/build.ninja : fast-ninja ../build.fninja ../sub/build.fninja