Merge pull request #141 from ddunbar/duplicate-command-names
[BuildSystem] Diagnose duplicate command names.
diff --git a/lib/BuildSystem/BuildFile.cpp b/lib/BuildSystem/BuildFile.cpp
index 1e55963..9e939d8 100644
--- a/lib/BuildSystem/BuildFile.cpp
+++ b/lib/BuildSystem/BuildFile.cpp
@@ -622,6 +622,12 @@
static_cast<llvm::yaml::ScalarNode*>(entry.getKey()));
llvm::yaml::MappingNode* attrs = static_cast<llvm::yaml::MappingNode*>(
entry.getValue());
+
+ // Check that the command is not a duplicate.
+ if (commands.count(name) != 0) {
+ error(entry.getKey(), "duplicate command in 'commands' map");
+ continue;
+ }
// Get the initial attribute, which must be the tool name.
auto it = attrs->begin();
diff --git a/tests/BuildSystem/Parser/errors.llbuild b/tests/BuildSystem/Parser/errors.llbuild
index af5a29b..6244255 100644
--- a/tests/BuildSystem/Parser/errors.llbuild
+++ b/tests/BuildSystem/Parser/errors.llbuild
@@ -81,8 +81,6 @@
tool: ["bad", "key"]
command3:
tool: "good"
- command3:
- tool: "good"
# CHECK-ERR-NOT: error:
# CHECK-ERR: error: invalid value type for 'inputs' command key
inputs: {}
@@ -111,3 +109,7 @@
attribute7:
["bad", "key"]: value
"ok": ["bad", "value"]
+
+ # CHECK-ERR: errors.llbuild:[[@LINE+1]]:2: error: duplicate command in 'commands' map
+ command7:
+ tool: "duplicate"