Index: tools/gn/ninja_build_writer.cc |
diff --git a/tools/gn/ninja_build_writer.cc b/tools/gn/ninja_build_writer.cc |
index 1436af6da7e2ff0ce77e18f967b9b177c3d98f64..519b09c6aec84164c45b76fa56690dc3821aeaa4 100644 |
--- a/tools/gn/ninja_build_writer.cc |
+++ b/tools/gn/ninja_build_writer.cc |
@@ -15,6 +15,7 @@ |
#include "base/strings/utf_string_conversions.h" |
#include "build/build_config.h" |
#include "tools/gn/build_settings.h" |
+#include "tools/gn/err.h" |
#include "tools/gn/escape.h" |
#include "tools/gn/filesystem_utils.h" |
#include "tools/gn/input_file_manager.h" |
@@ -91,11 +92,11 @@ NinjaBuildWriter::NinjaBuildWriter( |
NinjaBuildWriter::~NinjaBuildWriter() { |
} |
-void NinjaBuildWriter::Run() { |
+bool NinjaBuildWriter::Run() { |
brettw
2014/09/26 18:01:20
Yeah, this should probably take an Err* out param.
|
WriteNinjaRules(); |
WriteLinkPool(); |
WriteSubninjas(); |
- WritePhonyAndAllRules(); |
+ return WritePhonyAndAllRules(); |
} |
// static |
@@ -124,8 +125,7 @@ bool NinjaBuildWriter::RunAndWriteFile( |
NinjaBuildWriter gen(build_settings, all_settings, default_toolchain, |
default_toolchain_targets, file, depfile); |
- gen.Run(); |
- return true; |
+ return gen.Run(); |
} |
void NinjaBuildWriter::WriteNinjaRules() { |
@@ -171,7 +171,7 @@ void NinjaBuildWriter::WriteSubninjas() { |
out_ << std::endl; |
} |
-void NinjaBuildWriter::WritePhonyAndAllRules() { |
+bool NinjaBuildWriter::WritePhonyAndAllRules() { |
std::string all_rules; |
// Write phony rules for all uniquely-named targets in the default toolchain. |
@@ -180,6 +180,7 @@ void NinjaBuildWriter::WritePhonyAndAllRules() { |
// which we also find. |
std::map<std::string, int> small_name_count; |
std::vector<const Target*> toplevel_targets; |
+ base::hash_set<std::string> target_files; |
for (size_t i = 0; i < default_toolchain_targets_.size(); i++) { |
const Target* target = default_toolchain_targets_[i]; |
const Label& label = target->label(); |
@@ -204,6 +205,11 @@ void NinjaBuildWriter::WritePhonyAndAllRules() { |
OutputFile target_file(target->dependency_output_file()); |
// The output files may have leading "./" so normalize those away. |
NormalizePath(&target_file.value()); |
+ if (!target_files.insert(target_file.value()).second) { |
+ Err(Location(), "Duplicate rules for " + target_file.value()) |
+ .PrintToStdout(); |
+ return false; |
+ } |
// Write the long name "foo/bar:baz" for the target "//foo/bar:baz". |
std::string long_name = label.GetUserVisibleName(false); |
@@ -244,6 +250,7 @@ void NinjaBuildWriter::WritePhonyAndAllRules() { |
out_ << "\nbuild all: phony " << all_rules << std::endl; |
out_ << "default all" << std::endl; |
} |
+ return true; |
} |
void NinjaBuildWriter::WritePhonyRule(const Target* target, |