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

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

Issue 56433003: GN threading refactor (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/setup.h ('k') | tools/gn/target.h » ('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/setup.h" 5 #include "tools/gn/setup.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include "base/bind.h"
9 #include "base/command_line.h" 10 #include "base/command_line.h"
10 #include "base/file_util.h" 11 #include "base/file_util.h"
11 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
12 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
14 #include "build/build_config.h" 15 #include "build/build_config.h"
15 #include "tools/gn/filesystem_utils.h" 16 #include "tools/gn/filesystem_utils.h"
16 #include "tools/gn/input_file.h" 17 #include "tools/gn/input_file.h"
17 #include "tools/gn/parse_tree.h" 18 #include "tools/gn/parse_tree.h"
18 #include "tools/gn/parser.h" 19 #include "tools/gn/parser.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 base::string16 ending_in1 = L"depot_tools\\"; 135 base::string16 ending_in1 = L"depot_tools\\";
135 base::FilePath::StringType ending_in2 = FILE_PATH_LITERAL("depot_tools"); 136 base::FilePath::StringType ending_in2 = FILE_PATH_LITERAL("depot_tools");
136 137
137 base::FilePath found = GetPathEndingIn(components, ending_in1); 138 base::FilePath found = GetPathEndingIn(components, ending_in1);
138 if (!found.empty()) 139 if (!found.empty())
139 return found; 140 return found;
140 return GetPathEndingIn(components, ending_in2); 141 return GetPathEndingIn(components, ending_in2);
141 } 142 }
142 #endif 143 #endif
143 144
145 // Called on any thread. Post the item to the builder on the main thread.
146 void ItemDefinedCallback(base::MessageLoop* main_loop,
147 scoped_refptr<Builder> builder,
148 scoped_ptr<Item> item) {
149 DCHECK(item);
150 main_loop->PostTask(FROM_HERE, base::Bind(&Builder::ItemDefined, builder,
151 base::Passed(&item)));
152 }
153
154 void DecrementWorkCount() {
155 g_scheduler->DecrementWorkCount();
156 }
157
144 } // namespace 158 } // namespace
145 159
146 // CommonSetup ----------------------------------------------------------------- 160 // CommonSetup -----------------------------------------------------------------
147 161
148 CommonSetup::CommonSetup() 162 CommonSetup::CommonSetup()
149 : check_for_bad_items_(true) { 163 : build_settings_(),
164 loader_(new LoaderImpl(&build_settings_)),
165 builder_(new Builder(loader_.get())),
166 check_for_bad_items_(true) {
167 loader_->set_complete_callback(base::Bind(&DecrementWorkCount));
150 } 168 }
151 169
152 CommonSetup::CommonSetup(const CommonSetup& other) 170 CommonSetup::CommonSetup(const CommonSetup& other)
153 : build_settings_(other.build_settings_), 171 : build_settings_(other.build_settings_),
172 loader_(new LoaderImpl(&build_settings_)),
173 builder_(new Builder(loader_.get())),
154 check_for_bad_items_(other.check_for_bad_items_) { 174 check_for_bad_items_(other.check_for_bad_items_) {
175 loader_->set_complete_callback(base::Bind(&DecrementWorkCount));
155 } 176 }
156 177
157 CommonSetup::~CommonSetup() { 178 CommonSetup::~CommonSetup() {
158 } 179 }
159 180
160 void CommonSetup::RunPreMessageLoop() { 181 void CommonSetup::RunPreMessageLoop() {
161 // Load the root build file. 182 // Load the root build file.
162 build_settings_.toolchain_manager().StartLoadingUnlocked( 183 loader_->Load(SourceFile("//BUILD.gn"), Label());
163 SourceFile("//BUILD.gn")); 184
185 // Will be decremented with the loader is drained.
186 g_scheduler->IncrementWorkCount();
164 } 187 }
165 188
166 bool CommonSetup::RunPostMessageLoop() { 189 bool CommonSetup::RunPostMessageLoop() {
167 Err err; 190 Err err;
168 if (check_for_bad_items_) { 191 if (check_for_bad_items_) {
169 err = build_settings_.item_tree().CheckForBadItems(); 192 if (!builder_->CheckForBadItems(&err)) {
170 if (err.has_error()) {
171 err.PrintToStdout(); 193 err.PrintToStdout();
172 return false; 194 return false;
173 } 195 }
174 } 196 }
175 197
176 if (!build_settings_.build_args().VerifyAllOverridesUsed(&err)) { 198 if (!build_settings_.build_args().VerifyAllOverridesUsed(&err)) {
177 err.PrintToStdout(); 199 err.PrintToStdout();
178 return false; 200 return false;
179 } 201 }
180 202
181 // Write out tracing and timing if requested. 203 // Write out tracing and timing if requested.
182 const CommandLine* cmdline = CommandLine::ForCurrentProcess(); 204 const CommandLine* cmdline = CommandLine::ForCurrentProcess();
183 if (cmdline->HasSwitch(kTimeSwitch)) 205 if (cmdline->HasSwitch(kTimeSwitch))
184 PrintLongHelp(SummarizeTraces()); 206 PrintLongHelp(SummarizeTraces());
185 if (cmdline->HasSwitch(kTracelogSwitch)) 207 if (cmdline->HasSwitch(kTracelogSwitch))
186 SaveTraces(cmdline->GetSwitchValuePath(kTracelogSwitch)); 208 SaveTraces(cmdline->GetSwitchValuePath(kTracelogSwitch));
187 209
188 return true; 210 return true;
189 } 211 }
190 212
191 // Setup ----------------------------------------------------------------------- 213 // Setup -----------------------------------------------------------------------
192 214
193 Setup::Setup() 215 Setup::Setup()
194 : CommonSetup(), 216 : CommonSetup(),
195 empty_settings_(&empty_build_settings_, std::string()), 217 empty_settings_(&empty_build_settings_, std::string()),
196 dotfile_scope_(&empty_settings_) { 218 dotfile_scope_(&empty_settings_) {
197 empty_settings_.set_toolchain_label(Label()); 219 empty_settings_.set_toolchain_label(Label());
220 build_settings_.set_item_defined_callback(
221 base::Bind(&ItemDefinedCallback, scheduler_.main_loop(), builder_));
222
223 // The scheduler's main loop wasn't created when the Loader was created, so
224 // we need to set it now.
225 loader_->set_main_loop(scheduler_.main_loop());
198 } 226 }
199 227
200 Setup::~Setup() { 228 Setup::~Setup() {
201 } 229 }
202 230
203 bool Setup::DoSetup() { 231 bool Setup::DoSetup() {
204 CommandLine* cmdline = CommandLine::ForCurrentProcess(); 232 CommandLine* cmdline = CommandLine::ForCurrentProcess();
205 233
206 scheduler_.set_verbose_logging(cmdline->HasSwitch(kSwitchVerbose)); 234 scheduler_.set_verbose_logging(cmdline->HasSwitch(kSwitchVerbose));
207 if (cmdline->HasSwitch(kTimeSwitch) || 235 if (cmdline->HasSwitch(kTimeSwitch) ||
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 return false; 432 return false;
405 } 433 }
406 build_settings_.set_build_config_file( 434 build_settings_.set_build_config_file(
407 SourceFile(build_config_value->string_value())); 435 SourceFile(build_config_value->string_value()));
408 436
409 return true; 437 return true;
410 } 438 }
411 439
412 // DependentSetup -------------------------------------------------------------- 440 // DependentSetup --------------------------------------------------------------
413 441
414 DependentSetup::DependentSetup(const Setup& main_setup) 442 DependentSetup::DependentSetup(Setup& main_setup)
415 : CommonSetup(main_setup) { 443 : CommonSetup(main_setup) {
444 build_settings_.set_item_defined_callback(
445 base::Bind(&ItemDefinedCallback, main_setup.scheduler().main_loop(),
446 builder_));
416 } 447 }
417 448
418 DependentSetup::~DependentSetup() { 449 DependentSetup::~DependentSetup() {
419 } 450 }
420 451
421 void DependentSetup::RunPreMessageLoop() { 452 void DependentSetup::RunPreMessageLoop() {
422 CommonSetup::RunPreMessageLoop(); 453 CommonSetup::RunPreMessageLoop();
423 } 454 }
424 455
425 bool DependentSetup::RunPostMessageLoop() { 456 bool DependentSetup::RunPostMessageLoop() {
426 return CommonSetup::RunPostMessageLoop(); 457 return CommonSetup::RunPostMessageLoop();
427 } 458 }
428 459
OLDNEW
« no previous file with comments | « tools/gn/setup.h ('k') | tools/gn/target.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698