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

Side by Side Diff: tools/gn/ninja_writer.cc

Issue 2006923004: Add support for user defined "pool" to GN. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 6 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
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"
(...skipping 11 matching lines...) Expand all
22 } 22 }
23 23
24 // static 24 // static
25 bool NinjaWriter::RunAndWriteFiles(const BuildSettings* build_settings, 25 bool NinjaWriter::RunAndWriteFiles(const BuildSettings* build_settings,
26 Builder* builder, 26 Builder* builder,
27 Err* err) { 27 Err* err) {
28 NinjaWriter writer(build_settings, builder); 28 NinjaWriter writer(build_settings, builder);
29 29
30 std::vector<const Settings*> all_settings; 30 std::vector<const Settings*> all_settings;
31 std::vector<const Target*> default_targets; 31 std::vector<const Target*> default_targets;
32 if (!writer.WriteToolchains(&all_settings, &default_targets, err)) 32 std::vector<const Pool*> all_pools;
33 if (!writer.WriteToolchains(&all_settings, &default_targets, &all_pools, err))
33 return false; 34 return false;
34 return writer.WriteRootBuildfiles(all_settings, default_targets, err); 35 return writer.WriteRootBuildfiles(all_settings, default_targets, all_pools,
36 err);
35 } 37 }
36 38
37 // static 39 // static
38 bool NinjaWriter::RunAndWriteToolchainFiles( 40 bool NinjaWriter::RunAndWriteToolchainFiles(
39 const BuildSettings* build_settings, 41 const BuildSettings* build_settings,
40 Builder* builder, 42 Builder* builder,
41 std::vector<const Settings*>* all_settings, 43 std::vector<const Settings*>* all_settings,
42 Err* err) { 44 Err* err) {
43 NinjaWriter writer(build_settings, builder); 45 NinjaWriter writer(build_settings, builder);
44 std::vector<const Target*> default_targets; 46 std::vector<const Target*> default_targets;
45 return writer.WriteToolchains(all_settings, &default_targets, err); 47 std::vector<const Pool*> all_pools;
48 return writer.WriteToolchains(all_settings, &default_targets, &all_pools,
49 err);
46 } 50 }
47 51
48 bool NinjaWriter::WriteToolchains(std::vector<const Settings*>* all_settings, 52 bool NinjaWriter::WriteToolchains(std::vector<const Settings*>* all_settings,
49 std::vector<const Target*>* default_targets, 53 std::vector<const Target*>* default_targets,
54 std::vector<const Pool*>* all_pools,
50 Err* err) { 55 Err* err) {
51 // Categorize all targets by toolchain. 56 // Categorize all targets by toolchain.
52 typedef std::map<Label, std::vector<const Target*> > CategorizedMap; 57 typedef std::map<Label, std::vector<const Target*> > CategorizedMap;
53 CategorizedMap categorized; 58 CategorizedMap categorized;
54 59
55 std::vector<const BuilderRecord*> all_records = builder_->GetAllRecords(); 60 std::vector<const BuilderRecord*> all_records = builder_->GetAllRecords();
56 for (const auto& all_record : all_records) { 61 for (const auto& all_record : all_records) {
57 if (all_record->type() == BuilderRecord::ITEM_TARGET && 62 if (all_record->type() == BuilderRecord::ITEM_TARGET &&
58 all_record->should_generate()) { 63 all_record->should_generate()) {
59 categorized[all_record->label().GetToolchainLabel()].push_back( 64 categorized[all_record->label().GetToolchainLabel()].push_back(
(...skipping 12 matching lines...) Expand all
72 std::sort(i.second.begin(), i.second.end(), 77 std::sort(i.second.begin(), i.second.end(),
73 [](const Target* a, const Target* b) { 78 [](const Target* a, const Target* b) {
74 return a->label() < b->label(); 79 return a->label() < b->label();
75 }); 80 });
76 } 81 }
77 82
78 Label default_label = builder_->loader()->GetDefaultToolchain(); 83 Label default_label = builder_->loader()->GetDefaultToolchain();
79 84
80 // Write out the toolchain buildfiles, and also accumulate the set of 85 // Write out the toolchain buildfiles, and also accumulate the set of
81 // all settings and find the list of targets in the default toolchain. 86 // all settings and find the list of targets in the default toolchain.
87 UniqueVector<const Pool*> pools;
82 for (const auto& i : categorized) { 88 for (const auto& i : categorized) {
83 const Settings* settings = 89 const Settings* settings =
84 builder_->loader()->GetToolchainSettings(i.first); 90 builder_->loader()->GetToolchainSettings(i.first);
85 const Toolchain* toolchain = builder_->GetToolchain(i.first); 91 const Toolchain* toolchain = builder_->GetToolchain(i.first);
86 92
87 all_settings->push_back(settings); 93 all_settings->push_back(settings);
88 94
89 if (!NinjaToolchainWriter::RunAndWriteFile(settings, toolchain, i.second)) { 95 if (!NinjaToolchainWriter::RunAndWriteFile(settings, toolchain, i.second)) {
90 Err(Location(), 96 Err(Location(),
91 "Couldn't open toolchain buildfile(s) for writing").PrintToStdout(); 97 "Couldn't open toolchain buildfile(s) for writing").PrintToStdout();
92 return false; 98 return false;
93 } 99 }
100
101 for (int j = Toolchain::TYPE_NONE + 1; j < Toolchain::TYPE_NUMTYPES; j++) {
102 Toolchain::ToolType tool_type = static_cast<Toolchain::ToolType>(j);
103 const Tool* tool = toolchain->GetTool(tool_type);
104 if (tool && tool->pool().ptr)
105 pools.push_back(tool->pool().ptr);
106 }
94 } 107 }
95 108
109 *all_pools = pools.vector();
96 *default_targets = categorized[default_label]; 110 *default_targets = categorized[default_label];
97 return true; 111 return true;
98 } 112 }
99 113
100 bool NinjaWriter::WriteRootBuildfiles( 114 bool NinjaWriter::WriteRootBuildfiles(
101 const std::vector<const Settings*>& all_settings, 115 const std::vector<const Settings*>& all_settings,
102 const std::vector<const Target*>& default_targets, 116 const std::vector<const Target*>& default_targets,
117 const std::vector<const Pool*>& all_pools,
103 Err* err) { 118 Err* err) {
104 // All Settings objects should have the same default toolchain, and there 119 // All Settings objects should have the same default toolchain, and there
105 // should always be at least one settings object in the build. 120 // should always be at least one settings object in the build.
106 CHECK(!all_settings.empty()); 121 CHECK(!all_settings.empty());
107 const Toolchain* default_toolchain = 122 const Toolchain* default_toolchain =
108 builder_->GetToolchain(all_settings[0]->default_toolchain_label()); 123 builder_->GetToolchain(all_settings[0]->default_toolchain_label());
109 124
110 // Write the root buildfile. 125 // Write the root buildfile.
111 return NinjaBuildWriter::RunAndWriteFile(build_settings_, all_settings, 126 return NinjaBuildWriter::RunAndWriteFile(build_settings_, all_settings,
112 default_toolchain, default_targets, 127 default_toolchain, default_targets,
113 err); 128 all_pools, err);
114 } 129 }
OLDNEW
« tools/gn/functions.cc ('K') | « tools/gn/ninja_writer.h ('k') | tools/gn/pool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698