Properly exit when an unknown tool is defined.
And pass along the correct error instead of overwriting it.
Change-Id: I2fc533c029de611e800d80e44d39b29f603a68ba
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/4803
Commit-Queue: Julie Hockett <juliehockett@google.com>
Reviewed-by: Brett Wilson <brettw@google.com>
diff --git a/tools/gn/function_toolchain.cc b/tools/gn/function_toolchain.cc
index 7fc57c7..3d2a100 100644
--- a/tools/gn/function_toolchain.cc
+++ b/tools/gn/function_toolchain.cc
@@ -753,10 +753,9 @@
return Value();
std::unique_ptr<Tool> tool =
- Tool::CreateTool(tool_name, &block_scope, toolchain, err);
+ Tool::CreateTool(function, tool_name, &block_scope, toolchain, err);
if (!tool) {
- *err = Err(function, "Unknown tool type");
return Value();
}
diff --git a/tools/gn/tool.cc b/tools/gn/tool.cc
index f60e3d4..7a06b03 100644
--- a/tools/gn/tool.cc
+++ b/tools/gn/tool.cc
@@ -53,14 +53,14 @@
return false;
}
-bool Tool::ValidateSubstitutionList(const std::vector<const Substitution*>& list,
- const Value* origin,
- Err* err) const {
+bool Tool::ValidateSubstitutionList(
+ const std::vector<const Substitution*>& list,
+ const Value* origin,
+ Err* err) const {
for (const auto& cur_type : list) {
if (!ValidateSubstitution(cur_type)) {
*err = Err(*origin, "Pattern not valid here.",
- "You used the pattern " +
- std::string(cur_type->name) +
+ "You used the pattern " + std::string(cur_type->name) +
" which is not valid\nfor this variable.");
return false;
}
@@ -196,11 +196,16 @@
return true;
}
-std::unique_ptr<Tool> Tool::CreateTool(const std::string& name,
+std::unique_ptr<Tool> Tool::CreateTool(const ParseNode* function,
+ const std::string& name,
Scope* scope,
Toolchain* toolchain,
Err* err) {
std::unique_ptr<Tool> tool = CreateTool(name);
+ if (!tool) {
+ *err = Err(function, "Unknown tool type.");
+ return nullptr;
+ }
if (CTool* c_tool = tool->AsC()) {
if (c_tool->InitTool(scope, toolchain, err))
return tool;
@@ -212,6 +217,7 @@
return nullptr;
}
NOTREACHED();
+ *err = Err(function, "Unknown tool type.");
return nullptr;
}
diff --git a/tools/gn/tool.h b/tools/gn/tool.h
index d800886..ec2eb94 100644
--- a/tools/gn/tool.h
+++ b/tools/gn/tool.h
@@ -165,7 +165,8 @@
// Create a tool based on given features.
static std::unique_ptr<Tool> CreateTool(const std::string& name);
- static std::unique_ptr<Tool> CreateTool(const std::string& name,
+ static std::unique_ptr<Tool> CreateTool(const ParseNode* function,
+ const std::string& name,
Scope* scope,
Toolchain* toolchain,
Err* err);