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

Side by Side Diff: tools/gn/ninja_build_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_build_writer.h" 5 #include "tools/gn/ninja_build_writer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <fstream> 9 #include <fstream>
10 #include <map> 10 #include <map>
11 #include <sstream> 11 #include <sstream>
12 12
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/process/process_handle.h" 16 #include "base/process/process_handle.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "build/build_config.h" 19 #include "build/build_config.h"
20 #include "tools/gn/build_settings.h" 20 #include "tools/gn/build_settings.h"
21 #include "tools/gn/err.h" 21 #include "tools/gn/err.h"
22 #include "tools/gn/escape.h" 22 #include "tools/gn/escape.h"
23 #include "tools/gn/filesystem_utils.h" 23 #include "tools/gn/filesystem_utils.h"
24 #include "tools/gn/input_file_manager.h" 24 #include "tools/gn/input_file_manager.h"
25 #include "tools/gn/ninja_utils.h" 25 #include "tools/gn/ninja_utils.h"
26 #include "tools/gn/pool.h"
26 #include "tools/gn/scheduler.h" 27 #include "tools/gn/scheduler.h"
27 #include "tools/gn/switches.h" 28 #include "tools/gn/switches.h"
28 #include "tools/gn/target.h" 29 #include "tools/gn/target.h"
29 #include "tools/gn/trace.h" 30 #include "tools/gn/trace.h"
30 31
31 #if defined(OS_WIN) 32 #if defined(OS_WIN)
32 #include <windows.h> 33 #include <windows.h>
33 #endif 34 #endif
34 35
35 namespace { 36 namespace {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 return result; 123 return result;
123 } 124 }
124 125
125 } // namespace 126 } // namespace
126 127
127 NinjaBuildWriter::NinjaBuildWriter( 128 NinjaBuildWriter::NinjaBuildWriter(
128 const BuildSettings* build_settings, 129 const BuildSettings* build_settings,
129 const std::vector<const Settings*>& all_settings, 130 const std::vector<const Settings*>& all_settings,
130 const Toolchain* default_toolchain, 131 const Toolchain* default_toolchain,
131 const std::vector<const Target*>& default_toolchain_targets, 132 const std::vector<const Target*>& default_toolchain_targets,
133 const std::vector<const Pool*>& all_pools,
132 std::ostream& out, 134 std::ostream& out,
133 std::ostream& dep_out) 135 std::ostream& dep_out)
134 : build_settings_(build_settings), 136 : build_settings_(build_settings),
135 all_settings_(all_settings), 137 all_settings_(all_settings),
136 default_toolchain_(default_toolchain), 138 default_toolchain_(default_toolchain),
137 default_toolchain_targets_(default_toolchain_targets), 139 default_toolchain_targets_(default_toolchain_targets),
140 all_pools_(all_pools),
138 out_(out), 141 out_(out),
139 dep_out_(dep_out), 142 dep_out_(dep_out),
140 path_output_(build_settings->build_dir(), 143 path_output_(build_settings->build_dir(),
141 build_settings->root_path_utf8(), ESCAPE_NINJA) { 144 build_settings->root_path_utf8(),
142 } 145 ESCAPE_NINJA) {}
143 146
144 NinjaBuildWriter::~NinjaBuildWriter() { 147 NinjaBuildWriter::~NinjaBuildWriter() {
145 } 148 }
146 149
147 bool NinjaBuildWriter::Run(Err* err) { 150 bool NinjaBuildWriter::Run(Err* err) {
148 WriteNinjaRules(); 151 WriteNinjaRules();
149 WriteLinkPool(); 152 WriteAllPools();
150 WriteSubninjas(); 153 WriteSubninjas();
151 return WritePhonyAndAllRules(err); 154 return WritePhonyAndAllRules(err);
152 } 155 }
153 156
154 // static 157 // static
155 bool NinjaBuildWriter::RunAndWriteFile( 158 bool NinjaBuildWriter::RunAndWriteFile(
156 const BuildSettings* build_settings, 159 const BuildSettings* build_settings,
157 const std::vector<const Settings*>& all_settings, 160 const std::vector<const Settings*>& all_settings,
158 const Toolchain* default_toolchain, 161 const Toolchain* default_toolchain,
159 const std::vector<const Target*>& default_toolchain_targets, 162 const std::vector<const Target*>& default_toolchain_targets,
163 const std::vector<const Pool*>& all_pools,
160 Err* err) { 164 Err* err) {
161 ScopedTrace trace(TraceItem::TRACE_FILE_WRITE, "build.ninja"); 165 ScopedTrace trace(TraceItem::TRACE_FILE_WRITE, "build.ninja");
162 166
163 std::stringstream file; 167 std::stringstream file;
164 std::stringstream depfile; 168 std::stringstream depfile;
165 NinjaBuildWriter gen(build_settings, all_settings, default_toolchain, 169 NinjaBuildWriter gen(build_settings, all_settings, default_toolchain,
166 default_toolchain_targets, file, depfile); 170 default_toolchain_targets, all_pools, file, depfile);
167 if (!gen.Run(err)) 171 if (!gen.Run(err))
168 return false; 172 return false;
169 173
170 // Unconditionally write the build.ninja. Ninja's build-out-of-date checking 174 // Unconditionally write the build.ninja. Ninja's build-out-of-date checking
171 // will re-run GN when any build input is newer than build.ninja, so any time 175 // will re-run GN when any build input is newer than build.ninja, so any time
172 // the build is updated, build.ninja's timestamp needs to updated also, even 176 // the build is updated, build.ninja's timestamp needs to updated also, even
173 // if the contents haven't been changed. 177 // if the contents haven't been changed.
174 base::FilePath ninja_file_name(build_settings->GetFullPath( 178 base::FilePath ninja_file_name(build_settings->GetFullPath(
175 SourceFile(build_settings->build_dir().value() + "build.ninja"))); 179 SourceFile(build_settings->build_dir().value() + "build.ninja")));
176 base::CreateDirectory(ninja_file_name.DirName()); 180 base::CreateDirectory(ninja_file_name.DirName());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // Additionally, remove duplicate filepaths that seem to creep in. 221 // Additionally, remove duplicate filepaths that seem to creep in.
218 std::set<base::FilePath> fileset(input_files.begin(), input_files.end()); 222 std::set<base::FilePath> fileset(input_files.begin(), input_files.end());
219 fileset.insert(other_files.begin(), other_files.end()); 223 fileset.insert(other_files.begin(), other_files.end());
220 224
221 for (const auto& other_file : fileset) 225 for (const auto& other_file : fileset)
222 dep_out_ << " " << FilePathToUTF8(other_file); 226 dep_out_ << " " << FilePathToUTF8(other_file);
223 227
224 out_ << std::endl; 228 out_ << std::endl;
225 } 229 }
226 230
227 void NinjaBuildWriter::WriteLinkPool() { 231 void NinjaBuildWriter::WriteAllPools() {
228 out_ << "pool link_pool\n" 232 out_ << "pool link_pool\n"
229 << " depth = " << default_toolchain_->concurrent_links() << std::endl 233 << " depth = " << default_toolchain_->concurrent_links() << std::endl
230 << std::endl; 234 << std::endl;
235
236 for (const Pool* pool : all_pools_) {
237 std::string pool_name = pool->GetNinjaName(default_toolchain_->label());
238 out_ << "pool " << pool_name << std::endl
239 << " depth = " << pool->depth() << std::endl
240 << std::endl;
241 }
231 } 242 }
232 243
233 void NinjaBuildWriter::WriteSubninjas() { 244 void NinjaBuildWriter::WriteSubninjas() {
234 for (const auto& elem : all_settings_) { 245 for (const auto& elem : all_settings_) {
235 out_ << "subninja "; 246 out_ << "subninja ";
236 path_output_.WriteFile(out_, GetNinjaFileForToolchain(elem)); 247 path_output_.WriteFile(out_, GetNinjaFileForToolchain(elem));
237 out_ << std::endl; 248 out_ << std::endl;
238 } 249 }
239 out_ << std::endl; 250 out_ << std::endl;
240 } 251 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 EscapeOptions ninja_escape; 414 EscapeOptions ninja_escape;
404 ninja_escape.mode = ESCAPE_NINJA; 415 ninja_escape.mode = ESCAPE_NINJA;
405 416
406 // Escape for special chars Ninja will handle. 417 // Escape for special chars Ninja will handle.
407 std::string escaped = EscapeString(phony_name, ninja_escape, nullptr); 418 std::string escaped = EscapeString(phony_name, ninja_escape, nullptr);
408 419
409 out_ << "build " << escaped << ": phony "; 420 out_ << "build " << escaped << ": phony ";
410 path_output_.WriteFile(out_, target->dependency_output_file()); 421 path_output_.WriteFile(out_, target->dependency_output_file());
411 out_ << std::endl; 422 out_ << std::endl;
412 } 423 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698