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

Side by Side Diff: trunk/src/tools/gn/ninja_binary_target_writer.cc

Issue 46313006: Revert 232657 "GN: toolchain threading cleanup" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 1 month 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
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_binary_target_writer.h" 5 #include "tools/gn/ninja_binary_target_writer.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "tools/gn/config_values_extractors.h" 10 #include "tools/gn/config_values_extractors.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 case Target::EXECUTABLE: 79 case Target::EXECUTABLE:
80 return Toolchain::TYPE_LINK; 80 return Toolchain::TYPE_LINK;
81 default: 81 default:
82 return Toolchain::TYPE_NONE; 82 return Toolchain::TYPE_NONE;
83 } 83 }
84 } 84 }
85 85
86 } // namespace 86 } // namespace
87 87
88 NinjaBinaryTargetWriter::NinjaBinaryTargetWriter(const Target* target, 88 NinjaBinaryTargetWriter::NinjaBinaryTargetWriter(const Target* target,
89 const Toolchain* toolchain,
90 std::ostream& out) 89 std::ostream& out)
91 : NinjaTargetWriter(target, toolchain, out), 90 : NinjaTargetWriter(target, out),
92 tool_type_(GetToolTypeForTarget(target)){ 91 tool_type_(GetToolTypeForTarget(target)){
93 } 92 }
94 93
95 NinjaBinaryTargetWriter::~NinjaBinaryTargetWriter() { 94 NinjaBinaryTargetWriter::~NinjaBinaryTargetWriter() {
96 } 95 }
97 96
98 void NinjaBinaryTargetWriter::Run() { 97 void NinjaBinaryTargetWriter::Run() {
99 WriteCompilerVars(); 98 WriteCompilerVars();
100 99
101 std::vector<OutputFile> obj_files; 100 std::vector<OutputFile> obj_files;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 #undef WRITE_FLAGS 138 #undef WRITE_FLAGS
140 139
141 out_ << std::endl; 140 out_ << std::endl;
142 } 141 }
143 142
144 void NinjaBinaryTargetWriter::WriteSources( 143 void NinjaBinaryTargetWriter::WriteSources(
145 std::vector<OutputFile>* object_files) { 144 std::vector<OutputFile>* object_files) {
146 const Target::FileList& sources = target_->sources(); 145 const Target::FileList& sources = target_->sources();
147 object_files->reserve(sources.size()); 146 object_files->reserve(sources.size());
148 147
148 const Toolchain* toolchain = GetToolchain();
149 std::string implicit_deps = GetSourcesImplicitDeps(); 149 std::string implicit_deps = GetSourcesImplicitDeps();
150 150
151 for (size_t i = 0; i < sources.size(); i++) { 151 for (size_t i = 0; i < sources.size(); i++) {
152 const SourceFile& input_file = sources[i]; 152 const SourceFile& input_file = sources[i];
153 153
154 SourceFileType input_file_type = GetSourceFileType(input_file, 154 SourceFileType input_file_type = GetSourceFileType(input_file,
155 settings_->target_os()); 155 settings_->target_os());
156 if (input_file_type == SOURCE_UNKNOWN) 156 if (input_file_type == SOURCE_UNKNOWN)
157 continue; // Skip unknown file types. 157 continue; // Skip unknown file types.
158 std::string command = 158 std::string command =
159 helper_.GetRuleForSourceType(settings_, input_file_type); 159 helper_.GetRuleForSourceType(settings_, toolchain, input_file_type);
160 if (command.empty()) 160 if (command.empty())
161 continue; // Skip files not needing compilation. 161 continue; // Skip files not needing compilation.
162 162
163 OutputFile output_file = helper_.GetOutputFileForSource( 163 OutputFile output_file = helper_.GetOutputFileForSource(
164 target_, input_file, input_file_type); 164 target_, input_file, input_file_type);
165 object_files->push_back(output_file); 165 object_files->push_back(output_file);
166 166
167 out_ << "build "; 167 out_ << "build ";
168 path_output_.WriteFile(out_, output_file); 168 path_output_.WriteFile(out_, output_file);
169 out_ << ": " << command << " "; 169 out_ << ": " << command << " ";
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 } 258 }
259 259
260 void NinjaBinaryTargetWriter::WriteLinkerFlags() { 260 void NinjaBinaryTargetWriter::WriteLinkerFlags() {
261 out_ << "ldflags ="; 261 out_ << "ldflags =";
262 262
263 // First the ldflags from the target and its config. 263 // First the ldflags from the target and its config.
264 EscapeOptions flag_options = GetFlagOptions(); 264 EscapeOptions flag_options = GetFlagOptions();
265 RecursiveTargetConfigStringsToStream(target_, &ConfigValues::ldflags, 265 RecursiveTargetConfigStringsToStream(target_, &ConfigValues::ldflags,
266 flag_options, out_); 266 flag_options, out_);
267 267
268 const Toolchain::Tool& tool = toolchain_->GetTool(tool_type_); 268 const Toolchain* toolchain = GetToolchain();
269 const Toolchain::Tool& tool = toolchain->GetTool(tool_type_);
269 270
270 // Followed by library search paths that have been recursively pushed 271 // Followed by library search paths that have been recursively pushed
271 // through the dependency tree. 272 // through the dependency tree.
272 const OrderedSet<SourceDir> all_lib_dirs = target_->all_lib_dirs(); 273 const OrderedSet<SourceDir> all_lib_dirs = target_->all_lib_dirs();
273 if (!all_lib_dirs.empty()) { 274 if (!all_lib_dirs.empty()) {
274 // Since we're passing these on the command line to the linker and not 275 // Since we're passing these on the command line to the linker and not
275 // to Ninja, we need to do shell escaping. 276 // to Ninja, we need to do shell escaping.
276 PathOutput lib_path_output(path_output_.current_dir(), ESCAPE_NINJA_SHELL, 277 PathOutput lib_path_output(path_output_.current_dir(), ESCAPE_NINJA_SHELL,
277 true); 278 true);
278 for (size_t i = 0; i < all_lib_dirs.size(); i++) { 279 for (size_t i = 0; i < all_lib_dirs.size(); i++) {
(...skipping 19 matching lines...) Expand all
298 const OutputFile& external_output_file, 299 const OutputFile& external_output_file,
299 const OutputFile& internal_output_file, 300 const OutputFile& internal_output_file,
300 const std::vector<OutputFile>& object_files) { 301 const std::vector<OutputFile>& object_files) {
301 out_ << "build "; 302 out_ << "build ";
302 path_output_.WriteFile(out_, internal_output_file); 303 path_output_.WriteFile(out_, internal_output_file);
303 if (external_output_file != internal_output_file) { 304 if (external_output_file != internal_output_file) {
304 out_ << " "; 305 out_ << " ";
305 path_output_.WriteFile(out_, external_output_file); 306 path_output_.WriteFile(out_, external_output_file);
306 } 307 }
307 out_ << ": " 308 out_ << ": "
308 << helper_.GetRulePrefix(target_->settings()) 309 << helper_.GetRulePrefix(GetToolchain())
309 << Toolchain::ToolTypeToName(tool_type_); 310 << Toolchain::ToolTypeToName(tool_type_);
310 311
311 std::set<OutputFile> extra_object_files; 312 std::set<OutputFile> extra_object_files;
312 std::vector<const Target*> linkable_deps; 313 std::vector<const Target*> linkable_deps;
313 std::vector<const Target*> non_linkable_deps; 314 std::vector<const Target*> non_linkable_deps;
314 GetDeps(&extra_object_files, &linkable_deps, &non_linkable_deps); 315 GetDeps(&extra_object_files, &linkable_deps, &non_linkable_deps);
315 316
316 // Object files. 317 // Object files.
317 for (size_t i = 0; i < object_files.size(); i++) { 318 for (size_t i = 0; i < object_files.size(); i++) {
318 out_ << " "; 319 out_ << " ";
(...skipping 19 matching lines...) Expand all
338 339
339 void NinjaBinaryTargetWriter::WriteSourceSetStamp( 340 void NinjaBinaryTargetWriter::WriteSourceSetStamp(
340 const std::vector<OutputFile>& object_files) { 341 const std::vector<OutputFile>& object_files) {
341 // The stamp rule for source sets is generally not used, since targets that 342 // The stamp rule for source sets is generally not used, since targets that
342 // depend on this will reference the object files directly. However, writing 343 // depend on this will reference the object files directly. However, writing
343 // this rule allows the user to type the name of the target and get a build 344 // this rule allows the user to type the name of the target and get a build
344 // which can be convenient for development. 345 // which can be convenient for development.
345 out_ << "build "; 346 out_ << "build ";
346 path_output_.WriteFile(out_, helper_.GetTargetOutputFile(target_)); 347 path_output_.WriteFile(out_, helper_.GetTargetOutputFile(target_));
347 out_ << ": " 348 out_ << ": "
348 << helper_.GetRulePrefix(target_->settings()) 349 << helper_.GetRulePrefix(target_->settings()->toolchain())
349 << "stamp"; 350 << "stamp";
350 351
351 std::set<OutputFile> extra_object_files; 352 std::set<OutputFile> extra_object_files;
352 std::vector<const Target*> linkable_deps; 353 std::vector<const Target*> linkable_deps;
353 std::vector<const Target*> non_linkable_deps; 354 std::vector<const Target*> non_linkable_deps;
354 GetDeps(&extra_object_files, &linkable_deps, &non_linkable_deps); 355 GetDeps(&extra_object_files, &linkable_deps, &non_linkable_deps);
355 356
356 // The classifier should never put extra object files in a source set: 357 // The classifier should never put extra object files in a source set:
357 // any source sets that we depend on should appear in our non-linkable 358 // any source sets that we depend on should appear in our non-linkable
358 // deps instead. 359 // deps instead.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 } 452 }
452 453
453 // Data files. 454 // Data files.
454 const std::vector<SourceFile>& data = target_->data(); 455 const std::vector<SourceFile>& data = target_->data();
455 for (size_t i = 0; i < data.size(); i++) { 456 for (size_t i = 0; i < data.size(); i++) {
456 out_ << " "; 457 out_ << " ";
457 path_output_.WriteFile(out_, data[i]); 458 path_output_.WriteFile(out_, data[i]);
458 } 459 }
459 } 460 }
460 } 461 }
OLDNEW
« no previous file with comments | « trunk/src/tools/gn/ninja_binary_target_writer.h ('k') | trunk/src/tools/gn/ninja_binary_target_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698