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

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

Issue 508763002: Hook up link pools in GN. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: default to 0 Created 6 years, 3 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
« no previous file with comments | « tools/gn/ninja_build_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_build_writer.h" 5 #include "tools/gn/ninja_build_writer.h"
6 6
7 #include <fstream> 7 #include <fstream>
8 #include <map> 8 #include <map>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 #else 68 #else
69 return cmdline.GetCommandLineString(); 69 return cmdline.GetCommandLineString();
70 #endif 70 #endif
71 } 71 }
72 72
73 } // namespace 73 } // namespace
74 74
75 NinjaBuildWriter::NinjaBuildWriter( 75 NinjaBuildWriter::NinjaBuildWriter(
76 const BuildSettings* build_settings, 76 const BuildSettings* build_settings,
77 const std::vector<const Settings*>& all_settings, 77 const std::vector<const Settings*>& all_settings,
78 const Toolchain* default_toolchain,
78 const std::vector<const Target*>& default_toolchain_targets, 79 const std::vector<const Target*>& default_toolchain_targets,
79 std::ostream& out, 80 std::ostream& out,
80 std::ostream& dep_out) 81 std::ostream& dep_out)
81 : build_settings_(build_settings), 82 : build_settings_(build_settings),
82 all_settings_(all_settings), 83 all_settings_(all_settings),
84 default_toolchain_(default_toolchain),
83 default_toolchain_targets_(default_toolchain_targets), 85 default_toolchain_targets_(default_toolchain_targets),
84 out_(out), 86 out_(out),
85 dep_out_(dep_out), 87 dep_out_(dep_out),
86 path_output_(build_settings->build_dir(), ESCAPE_NINJA) { 88 path_output_(build_settings->build_dir(), ESCAPE_NINJA) {
87 } 89 }
88 90
89 NinjaBuildWriter::~NinjaBuildWriter() { 91 NinjaBuildWriter::~NinjaBuildWriter() {
90 } 92 }
91 93
92 void NinjaBuildWriter::Run() { 94 void NinjaBuildWriter::Run() {
93 WriteNinjaRules(); 95 WriteNinjaRules();
96 WriteLinkPool();
94 WriteSubninjas(); 97 WriteSubninjas();
95 WritePhonyAndAllRules(); 98 WritePhonyAndAllRules();
96 } 99 }
97 100
98 // static 101 // static
99 bool NinjaBuildWriter::RunAndWriteFile( 102 bool NinjaBuildWriter::RunAndWriteFile(
100 const BuildSettings* build_settings, 103 const BuildSettings* build_settings,
101 const std::vector<const Settings*>& all_settings, 104 const std::vector<const Settings*>& all_settings,
105 const Toolchain* default_toolchain,
102 const std::vector<const Target*>& default_toolchain_targets) { 106 const std::vector<const Target*>& default_toolchain_targets) {
103 ScopedTrace trace(TraceItem::TRACE_FILE_WRITE, "build.ninja"); 107 ScopedTrace trace(TraceItem::TRACE_FILE_WRITE, "build.ninja");
104 108
105 base::FilePath ninja_file(build_settings->GetFullPath( 109 base::FilePath ninja_file(build_settings->GetFullPath(
106 SourceFile(build_settings->build_dir().value() + "build.ninja"))); 110 SourceFile(build_settings->build_dir().value() + "build.ninja")));
107 base::CreateDirectory(ninja_file.DirName()); 111 base::CreateDirectory(ninja_file.DirName());
108 112
109 std::ofstream file; 113 std::ofstream file;
110 file.open(FilePathToUTF8(ninja_file).c_str(), 114 file.open(FilePathToUTF8(ninja_file).c_str(),
111 std::ios_base::out | std::ios_base::binary); 115 std::ios_base::out | std::ios_base::binary);
112 if (file.fail()) 116 if (file.fail())
113 return false; 117 return false;
114 118
115 std::ofstream depfile; 119 std::ofstream depfile;
116 depfile.open((FilePathToUTF8(ninja_file) + ".d").c_str(), 120 depfile.open((FilePathToUTF8(ninja_file) + ".d").c_str(),
117 std::ios_base::out | std::ios_base::binary); 121 std::ios_base::out | std::ios_base::binary);
118 if (depfile.fail()) 122 if (depfile.fail())
119 return false; 123 return false;
120 124
121 NinjaBuildWriter gen(build_settings, all_settings, 125 NinjaBuildWriter gen(build_settings, all_settings, default_toolchain,
122 default_toolchain_targets, file, depfile); 126 default_toolchain_targets, file, depfile);
123 gen.Run(); 127 gen.Run();
124 return true; 128 return true;
125 } 129 }
126 130
127 void NinjaBuildWriter::WriteNinjaRules() { 131 void NinjaBuildWriter::WriteNinjaRules() {
128 out_ << "rule gn\n"; 132 out_ << "rule gn\n";
129 out_ << " command = " << GetSelfInvocationCommand(build_settings_) << "\n"; 133 out_ << " command = " << GetSelfInvocationCommand(build_settings_) << "\n";
130 out_ << " description = Regenerating ninja files\n\n"; 134 out_ << " description = Regenerating ninja files\n\n";
131 135
(...skipping 13 matching lines...) Expand all
145 dep_out_ << " " << FilePathToUTF8(input_files[i]); 149 dep_out_ << " " << FilePathToUTF8(input_files[i]);
146 150
147 // Other files read by the build. 151 // Other files read by the build.
148 std::vector<base::FilePath> other_files = g_scheduler->GetGenDependencies(); 152 std::vector<base::FilePath> other_files = g_scheduler->GetGenDependencies();
149 for (size_t i = 0; i < other_files.size(); i++) 153 for (size_t i = 0; i < other_files.size(); i++)
150 dep_out_ << " " << FilePathToUTF8(other_files[i]); 154 dep_out_ << " " << FilePathToUTF8(other_files[i]);
151 155
152 out_ << std::endl; 156 out_ << std::endl;
153 } 157 }
154 158
159 void NinjaBuildWriter::WriteLinkPool() {
160 out_ << "pool link_pool\n"
161 << " depth = " << default_toolchain_->concurrent_links() << std::endl
162 << std::endl;
163 }
164
155 void NinjaBuildWriter::WriteSubninjas() { 165 void NinjaBuildWriter::WriteSubninjas() {
156 for (size_t i = 0; i < all_settings_.size(); i++) { 166 for (size_t i = 0; i < all_settings_.size(); i++) {
157 out_ << "subninja "; 167 out_ << "subninja ";
158 path_output_.WriteFile(out_, GetNinjaFileForToolchain(all_settings_[i])); 168 path_output_.WriteFile(out_, GetNinjaFileForToolchain(all_settings_[i]));
159 out_ << std::endl; 169 out_ << std::endl;
160 } 170 }
161 out_ << std::endl; 171 out_ << std::endl;
162 } 172 }
163 173
164 void NinjaBuildWriter::WritePhonyAndAllRules() { 174 void NinjaBuildWriter::WritePhonyAndAllRules() {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 EscapeOptions ninja_escape; 255 EscapeOptions ninja_escape;
246 ninja_escape.mode = ESCAPE_NINJA; 256 ninja_escape.mode = ESCAPE_NINJA;
247 257
248 // Escape for special chars Ninja will handle. 258 // Escape for special chars Ninja will handle.
249 std::string escaped = EscapeString(phony_name, ninja_escape, NULL); 259 std::string escaped = EscapeString(phony_name, ninja_escape, NULL);
250 260
251 out_ << "build " << escaped << ": phony "; 261 out_ << "build " << escaped << ": phony ";
252 path_output_.WriteFile(out_, target_file); 262 path_output_.WriteFile(out_, target_file);
253 out_ << std::endl; 263 out_ << std::endl;
254 } 264 }
OLDNEW
« no previous file with comments | « tools/gn/ninja_build_writer.h ('k') | tools/gn/ninja_toolchain_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698