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

Side by Side Diff: tools/gn/ninja_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: Created 6 years, 2 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/gn/ninja_writer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "tools/gn/ninja_writer.h" 5 #include "tools/gn/ninja_writer.h"
6 6
7 #include "tools/gn/builder.h" 7 #include "tools/gn/builder.h"
8 #include "tools/gn/loader.h" 8 #include "tools/gn/loader.h"
9 #include "tools/gn/location.h" 9 #include "tools/gn/location.h"
10 #include "tools/gn/ninja_build_writer.h" 10 #include "tools/gn/ninja_build_writer.h"
11 #include "tools/gn/ninja_toolchain_writer.h" 11 #include "tools/gn/ninja_toolchain_writer.h"
12 #include "tools/gn/settings.h" 12 #include "tools/gn/settings.h"
13 13
14 NinjaWriter::NinjaWriter(const BuildSettings* build_settings, 14 NinjaWriter::NinjaWriter(const BuildSettings* build_settings,
15 Builder* builder) 15 Builder* builder)
16 : build_settings_(build_settings), 16 : build_settings_(build_settings),
17 builder_(builder) { 17 builder_(builder) {
18 } 18 }
19 19
20 NinjaWriter::~NinjaWriter() { 20 NinjaWriter::~NinjaWriter() {
21 } 21 }
22 22
23 // static 23 // static
24 bool NinjaWriter::RunAndWriteFiles(const BuildSettings* build_settings, 24 bool NinjaWriter::RunAndWriteFiles(const BuildSettings* build_settings,
25 Builder* builder) { 25 Builder* builder,
26 Err* err) {
26 NinjaWriter writer(build_settings, builder); 27 NinjaWriter writer(build_settings, builder);
27 28
28 std::vector<const Settings*> all_settings; 29 std::vector<const Settings*> all_settings;
29 std::vector<const Target*> default_targets; 30 std::vector<const Target*> default_targets;
30 if (!writer.WriteToolchains(&all_settings, &default_targets)) 31 if (!writer.WriteToolchains(&all_settings, &default_targets, err))
31 return false; 32 return false;
32 return writer.WriteRootBuildfiles(all_settings, default_targets); 33 return writer.WriteRootBuildfiles(all_settings, default_targets, err);
33 } 34 }
34 35
35 // static 36 // static
36 bool NinjaWriter::RunAndWriteToolchainFiles( 37 bool NinjaWriter::RunAndWriteToolchainFiles(
37 const BuildSettings* build_settings, 38 const BuildSettings* build_settings,
38 Builder* builder, 39 Builder* builder,
39 std::vector<const Settings*>* all_settings) { 40 std::vector<const Settings*>* all_settings,
41 Err* err) {
40 NinjaWriter writer(build_settings, builder); 42 NinjaWriter writer(build_settings, builder);
41 std::vector<const Target*> default_targets; 43 std::vector<const Target*> default_targets;
42 return writer.WriteToolchains(all_settings, &default_targets); 44 return writer.WriteToolchains(all_settings, &default_targets, err);
43 } 45 }
44 46
45 bool NinjaWriter::WriteToolchains(std::vector<const Settings*>* all_settings, 47 bool NinjaWriter::WriteToolchains(std::vector<const Settings*>* all_settings,
46 std::vector<const Target*>* default_targets) { 48 std::vector<const Target*>* default_targets,
49 Err* err) {
47 // Categorize all targets by toolchain. 50 // Categorize all targets by toolchain.
48 typedef std::map<Label, std::vector<const Target*> > CategorizedMap; 51 typedef std::map<Label, std::vector<const Target*> > CategorizedMap;
49 CategorizedMap categorized; 52 CategorizedMap categorized;
50 53
51 std::vector<const BuilderRecord*> all_records = builder_->GetAllRecords(); 54 std::vector<const BuilderRecord*> all_records = builder_->GetAllRecords();
52 for (size_t i = 0; i < all_records.size(); i++) { 55 for (size_t i = 0; i < all_records.size(); i++) {
53 if (all_records[i]->type() == BuilderRecord::ITEM_TARGET && 56 if (all_records[i]->type() == BuilderRecord::ITEM_TARGET &&
54 all_records[i]->should_generate()) { 57 all_records[i]->should_generate()) {
55 categorized[all_records[i]->label().GetToolchainLabel()].push_back( 58 categorized[all_records[i]->label().GetToolchainLabel()].push_back(
56 all_records[i]->item()->AsTarget()); 59 all_records[i]->item()->AsTarget());
(...skipping 24 matching lines...) Expand all
81 return false; 84 return false;
82 } 85 }
83 } 86 }
84 87
85 *default_targets = categorized[default_label]; 88 *default_targets = categorized[default_label];
86 return true; 89 return true;
87 } 90 }
88 91
89 bool NinjaWriter::WriteRootBuildfiles( 92 bool NinjaWriter::WriteRootBuildfiles(
90 const std::vector<const Settings*>& all_settings, 93 const std::vector<const Settings*>& all_settings,
91 const std::vector<const Target*>& default_targets) { 94 const std::vector<const Target*>& default_targets,
95 Err* err) {
92 // All Settings objects should have the same default toolchain, and there 96 // All Settings objects should have the same default toolchain, and there
93 // should always be at least one settings object in the build. 97 // should always be at least one settings object in the build.
94 CHECK(!all_settings.empty()); 98 CHECK(!all_settings.empty());
95 const Toolchain* default_toolchain = 99 const Toolchain* default_toolchain =
96 builder_->GetToolchain(all_settings[0]->default_toolchain_label()); 100 builder_->GetToolchain(all_settings[0]->default_toolchain_label());
97 101
98 // Write the root buildfile. 102 // Write the root buildfile.
99 if (!NinjaBuildWriter::RunAndWriteFile(build_settings_, all_settings, 103 return NinjaBuildWriter::RunAndWriteFile(build_settings_, all_settings,
100 default_toolchain, default_targets)) { 104 default_toolchain, default_targets,
101 Err(Location(), 105 err);
102 "Couldn't open toolchain buildfile(s) for writing").PrintToStdout();
103 return false;
104 }
105 return true;
106 } 106 }
OLDNEW
« no previous file with comments | « tools/gn/ninja_writer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698