OLD | NEW |
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 Loading... |
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, |
89 std::ostream& out) | 90 std::ostream& out) |
90 : NinjaTargetWriter(target, out), | 91 : NinjaTargetWriter(target, toolchain, out), |
91 tool_type_(GetToolTypeForTarget(target)){ | 92 tool_type_(GetToolTypeForTarget(target)){ |
92 } | 93 } |
93 | 94 |
94 NinjaBinaryTargetWriter::~NinjaBinaryTargetWriter() { | 95 NinjaBinaryTargetWriter::~NinjaBinaryTargetWriter() { |
95 } | 96 } |
96 | 97 |
97 void NinjaBinaryTargetWriter::Run() { | 98 void NinjaBinaryTargetWriter::Run() { |
98 WriteCompilerVars(); | 99 WriteCompilerVars(); |
99 | 100 |
100 std::vector<OutputFile> obj_files; | 101 std::vector<OutputFile> obj_files; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 #undef WRITE_FLAGS | 139 #undef WRITE_FLAGS |
139 | 140 |
140 out_ << std::endl; | 141 out_ << std::endl; |
141 } | 142 } |
142 | 143 |
143 void NinjaBinaryTargetWriter::WriteSources( | 144 void NinjaBinaryTargetWriter::WriteSources( |
144 std::vector<OutputFile>* object_files) { | 145 std::vector<OutputFile>* object_files) { |
145 const Target::FileList& sources = target_->sources(); | 146 const Target::FileList& sources = target_->sources(); |
146 object_files->reserve(sources.size()); | 147 object_files->reserve(sources.size()); |
147 | 148 |
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_, toolchain, input_file_type); | 159 helper_.GetRuleForSourceType(settings_, 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 Loading... |
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* toolchain = GetToolchain(); | 268 const Toolchain::Tool& tool = toolchain_->GetTool(tool_type_); |
269 const Toolchain::Tool& tool = toolchain->GetTool(tool_type_); | |
270 | 269 |
271 // Followed by library search paths that have been recursively pushed | 270 // Followed by library search paths that have been recursively pushed |
272 // through the dependency tree. | 271 // through the dependency tree. |
273 const OrderedSet<SourceDir> all_lib_dirs = target_->all_lib_dirs(); | 272 const OrderedSet<SourceDir> all_lib_dirs = target_->all_lib_dirs(); |
274 if (!all_lib_dirs.empty()) { | 273 if (!all_lib_dirs.empty()) { |
275 // Since we're passing these on the command line to the linker and not | 274 // Since we're passing these on the command line to the linker and not |
276 // to Ninja, we need to do shell escaping. | 275 // to Ninja, we need to do shell escaping. |
277 PathOutput lib_path_output(path_output_.current_dir(), ESCAPE_NINJA_SHELL, | 276 PathOutput lib_path_output(path_output_.current_dir(), ESCAPE_NINJA_SHELL, |
278 true); | 277 true); |
279 for (size_t i = 0; i < all_lib_dirs.size(); i++) { | 278 for (size_t i = 0; i < all_lib_dirs.size(); i++) { |
(...skipping 19 matching lines...) Expand all Loading... |
299 const OutputFile& external_output_file, | 298 const OutputFile& external_output_file, |
300 const OutputFile& internal_output_file, | 299 const OutputFile& internal_output_file, |
301 const std::vector<OutputFile>& object_files) { | 300 const std::vector<OutputFile>& object_files) { |
302 out_ << "build "; | 301 out_ << "build "; |
303 path_output_.WriteFile(out_, internal_output_file); | 302 path_output_.WriteFile(out_, internal_output_file); |
304 if (external_output_file != internal_output_file) { | 303 if (external_output_file != internal_output_file) { |
305 out_ << " "; | 304 out_ << " "; |
306 path_output_.WriteFile(out_, external_output_file); | 305 path_output_.WriteFile(out_, external_output_file); |
307 } | 306 } |
308 out_ << ": " | 307 out_ << ": " |
309 << helper_.GetRulePrefix(GetToolchain()) | 308 << helper_.GetRulePrefix(target_->settings()) |
310 << Toolchain::ToolTypeToName(tool_type_); | 309 << Toolchain::ToolTypeToName(tool_type_); |
311 | 310 |
312 std::set<OutputFile> extra_object_files; | 311 std::set<OutputFile> extra_object_files; |
313 std::vector<const Target*> linkable_deps; | 312 std::vector<const Target*> linkable_deps; |
314 std::vector<const Target*> non_linkable_deps; | 313 std::vector<const Target*> non_linkable_deps; |
315 GetDeps(&extra_object_files, &linkable_deps, &non_linkable_deps); | 314 GetDeps(&extra_object_files, &linkable_deps, &non_linkable_deps); |
316 | 315 |
317 // Object files. | 316 // Object files. |
318 for (size_t i = 0; i < object_files.size(); i++) { | 317 for (size_t i = 0; i < object_files.size(); i++) { |
319 out_ << " "; | 318 out_ << " "; |
(...skipping 19 matching lines...) Expand all Loading... |
339 | 338 |
340 void NinjaBinaryTargetWriter::WriteSourceSetStamp( | 339 void NinjaBinaryTargetWriter::WriteSourceSetStamp( |
341 const std::vector<OutputFile>& object_files) { | 340 const std::vector<OutputFile>& object_files) { |
342 // The stamp rule for source sets is generally not used, since targets that | 341 // The stamp rule for source sets is generally not used, since targets that |
343 // depend on this will reference the object files directly. However, writing | 342 // depend on this will reference the object files directly. However, writing |
344 // this rule allows the user to type the name of the target and get a build | 343 // this rule allows the user to type the name of the target and get a build |
345 // which can be convenient for development. | 344 // which can be convenient for development. |
346 out_ << "build "; | 345 out_ << "build "; |
347 path_output_.WriteFile(out_, helper_.GetTargetOutputFile(target_)); | 346 path_output_.WriteFile(out_, helper_.GetTargetOutputFile(target_)); |
348 out_ << ": " | 347 out_ << ": " |
349 << helper_.GetRulePrefix(target_->settings()->toolchain()) | 348 << helper_.GetRulePrefix(target_->settings()) |
350 << "stamp"; | 349 << "stamp"; |
351 | 350 |
352 std::set<OutputFile> extra_object_files; | 351 std::set<OutputFile> extra_object_files; |
353 std::vector<const Target*> linkable_deps; | 352 std::vector<const Target*> linkable_deps; |
354 std::vector<const Target*> non_linkable_deps; | 353 std::vector<const Target*> non_linkable_deps; |
355 GetDeps(&extra_object_files, &linkable_deps, &non_linkable_deps); | 354 GetDeps(&extra_object_files, &linkable_deps, &non_linkable_deps); |
356 | 355 |
357 // The classifier should never put extra object files in a source set: | 356 // The classifier should never put extra object files in a source set: |
358 // any source sets that we depend on should appear in our non-linkable | 357 // any source sets that we depend on should appear in our non-linkable |
359 // deps instead. | 358 // deps instead. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 } | 451 } |
453 | 452 |
454 // Data files. | 453 // Data files. |
455 const std::vector<SourceFile>& data = target_->data(); | 454 const std::vector<SourceFile>& data = target_->data(); |
456 for (size_t i = 0; i < data.size(); i++) { | 455 for (size_t i = 0; i < data.size(); i++) { |
457 out_ << " "; | 456 out_ << " "; |
458 path_output_.WriteFile(out_, data[i]); | 457 path_output_.WriteFile(out_, data[i]); |
459 } | 458 } |
460 } | 459 } |
461 } | 460 } |
OLD | NEW |