Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(476)

Unified Diff: tools/gn/ninja_build_writer.cc

Issue 455193003: GN: Generate error if multiple rules generate same file (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Just check outputs when producing final ninja file Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/ninja_build_writer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
« no previous file with comments | « tools/gn/ninja_build_writer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698