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

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

Issue 51693002: GN: toolchain threading cleanup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
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
« no previous file with comments | « tools/gn/ninja_target_writer.h ('k') | tools/gn/ninja_toolchain_writer.cc » ('j') | 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_target_writer.h" 5 #include "tools/gn/ninja_target_writer.h"
6 6
7 #include <fstream> 7 #include <fstream>
8 #include <sstream> 8 #include <sstream>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "tools/gn/err.h" 11 #include "tools/gn/err.h"
12 #include "tools/gn/file_template.h" 12 #include "tools/gn/file_template.h"
13 #include "tools/gn/ninja_binary_target_writer.h" 13 #include "tools/gn/ninja_binary_target_writer.h"
14 #include "tools/gn/ninja_copy_target_writer.h" 14 #include "tools/gn/ninja_copy_target_writer.h"
15 #include "tools/gn/ninja_group_target_writer.h" 15 #include "tools/gn/ninja_group_target_writer.h"
16 #include "tools/gn/ninja_script_target_writer.h" 16 #include "tools/gn/ninja_script_target_writer.h"
17 #include "tools/gn/scheduler.h" 17 #include "tools/gn/scheduler.h"
18 #include "tools/gn/string_utils.h" 18 #include "tools/gn/string_utils.h"
19 #include "tools/gn/target.h" 19 #include "tools/gn/target.h"
20 #include "tools/gn/trace.h" 20 #include "tools/gn/trace.h"
21 21
22 NinjaTargetWriter::NinjaTargetWriter(const Target* target, std::ostream& out) 22 NinjaTargetWriter::NinjaTargetWriter(const Target* target,
23 const Toolchain* toolchain,
24 std::ostream& out)
23 : settings_(target->settings()), 25 : settings_(target->settings()),
24 target_(target), 26 target_(target),
27 toolchain_(toolchain),
25 out_(out), 28 out_(out),
26 path_output_(settings_->build_settings()->build_dir(), 29 path_output_(settings_->build_settings()->build_dir(),
27 ESCAPE_NINJA, true), 30 ESCAPE_NINJA, true),
28 helper_(settings_->build_settings()) { 31 helper_(settings_->build_settings()) {
29 } 32 }
30 33
31 NinjaTargetWriter::~NinjaTargetWriter() { 34 NinjaTargetWriter::~NinjaTargetWriter() {
32 } 35 }
33 36
34 // static 37 // static
35 void NinjaTargetWriter::RunAndWriteFile(const Target* target) { 38 void NinjaTargetWriter::RunAndWriteFile(const Target* target) {
36 // External targets don't get written to disk, we assume they're managed by 39 // External targets don't get written to disk, we assume they're managed by
37 // an external program. If we're not using an external generator, this is 40 // an external program. If we're not using an external generator, this is
38 // ignored. 41 // ignored.
39 if (target->settings()->build_settings()->using_external_generator() && 42 if (target->settings()->build_settings()->using_external_generator() &&
40 target->external()) 43 target->external())
41 return; 44 return;
42 45
43 const Settings* settings = target->settings(); 46 const Settings* settings = target->settings();
44 NinjaHelper helper(settings->build_settings()); 47 NinjaHelper helper(settings->build_settings());
45 48
46 ScopedTrace trace(TraceItem::TRACE_FILE_WRITE, 49 ScopedTrace trace(TraceItem::TRACE_FILE_WRITE,
47 target->label().GetUserVisibleName(false)); 50 target->label().GetUserVisibleName(false));
48 trace.SetToolchain(settings->toolchain()->label()); 51 trace.SetToolchain(settings->toolchain_label());
49 52
50 base::FilePath ninja_file(settings->build_settings()->GetFullPath( 53 base::FilePath ninja_file(settings->build_settings()->GetFullPath(
51 helper.GetNinjaFileForTarget(target).GetSourceFile( 54 helper.GetNinjaFileForTarget(target).GetSourceFile(
52 settings->build_settings()))); 55 settings->build_settings())));
53 56
54 if (g_scheduler->verbose_logging()) 57 if (g_scheduler->verbose_logging())
55 g_scheduler->Log("Writing", FilePathToUTF8(ninja_file)); 58 g_scheduler->Log("Writing", FilePathToUTF8(ninja_file));
56 59
60 const Toolchain* tc = settings->build_settings()->toolchain_manager()
61 .GetToolchainDefinitionUnlocked(settings->toolchain_label());
62 CHECK(tc);
63
57 file_util::CreateDirectory(ninja_file.DirName()); 64 file_util::CreateDirectory(ninja_file.DirName());
58 65
59 // It's rediculously faster to write to a string and then write that to 66 // It's rediculously faster to write to a string and then write that to
60 // disk in one operation than to use an fstream here. 67 // disk in one operation than to use an fstream here.
61 std::stringstream file; 68 std::stringstream file;
62 69
63 // Call out to the correct sub-type of writer. 70 // Call out to the correct sub-type of writer.
64 if (target->output_type() == Target::COPY_FILES) { 71 if (target->output_type() == Target::COPY_FILES) {
65 NinjaCopyTargetWriter writer(target, file); 72 NinjaCopyTargetWriter writer(target, tc, file);
66 writer.Run(); 73 writer.Run();
67 } else if (target->output_type() == Target::CUSTOM) { 74 } else if (target->output_type() == Target::CUSTOM) {
68 NinjaScriptTargetWriter writer(target, file); 75 NinjaScriptTargetWriter writer(target, tc, file);
69 writer.Run(); 76 writer.Run();
70 } else if (target->output_type() == Target::GROUP) { 77 } else if (target->output_type() == Target::GROUP) {
71 NinjaGroupTargetWriter writer(target, file); 78 NinjaGroupTargetWriter writer(target, tc, file);
72 writer.Run(); 79 writer.Run();
73 } else if (target->output_type() == Target::EXECUTABLE || 80 } else if (target->output_type() == Target::EXECUTABLE ||
74 target->output_type() == Target::STATIC_LIBRARY || 81 target->output_type() == Target::STATIC_LIBRARY ||
75 target->output_type() == Target::SHARED_LIBRARY || 82 target->output_type() == Target::SHARED_LIBRARY ||
76 target->output_type() == Target::SOURCE_SET) { 83 target->output_type() == Target::SOURCE_SET) {
77 NinjaBinaryTargetWriter writer(target, file); 84 NinjaBinaryTargetWriter writer(target, tc, file);
78 writer.Run(); 85 writer.Run();
79 } else { 86 } else {
80 CHECK(0); 87 CHECK(0);
81 } 88 }
82 89
83 std::string contents = file.str(); 90 std::string contents = file.str();
84 file_util::WriteFile(ninja_file, contents.c_str(), 91 file_util::WriteFile(ninja_file, contents.c_str(),
85 static_cast<int>(contents.size())); 92 static_cast<int>(contents.size()));
86 } 93 }
87 94
88 const Toolchain* NinjaTargetWriter::GetToolchain() const {
89 return target_->settings()->toolchain();
90 }
91
92 std::string NinjaTargetWriter::GetSourcesImplicitDeps() const { 95 std::string NinjaTargetWriter::GetSourcesImplicitDeps() const {
93 std::ostringstream ret; 96 std::ostringstream ret;
94 ret << " |"; 97 ret << " |";
95 98
96 // Input files are order-only deps. 99 // Input files are order-only deps.
97 const Target::FileList& prereqs = target_->source_prereqs(); 100 const Target::FileList& prereqs = target_->source_prereqs();
98 bool has_files = !prereqs.empty(); 101 bool has_files = !prereqs.empty();
99 for (size_t i = 0; i < prereqs.size(); i++) { 102 for (size_t i = 0; i < prereqs.size(); i++) {
100 ret << " "; 103 ret << " ";
101 path_output_.WriteFile(ret, prereqs[i]); 104 path_output_.WriteFile(ret, prereqs[i]);
(...skipping 18 matching lines...) Expand all
120 const Target::FileList& outputs = target_->script_values().outputs(); 123 const Target::FileList& outputs = target_->script_values().outputs();
121 std::vector<std::string> output_template_args; 124 std::vector<std::string> output_template_args;
122 for (size_t i = 0; i < outputs.size(); i++) { 125 for (size_t i = 0; i < outputs.size(); i++) {
123 // All outputs should be in the output dir. 126 // All outputs should be in the output dir.
124 output_template_args.push_back( 127 output_template_args.push_back(
125 RemovePrefix(outputs[i].value(), 128 RemovePrefix(outputs[i].value(),
126 settings_->build_settings()->build_dir().value())); 129 settings_->build_settings()->build_dir().value()));
127 } 130 }
128 return FileTemplate(output_template_args); 131 return FileTemplate(output_template_args);
129 } 132 }
OLDNEW
« no previous file with comments | « tools/gn/ninja_target_writer.h ('k') | tools/gn/ninja_toolchain_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698