| 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/setup.h" | 5 #include "tools/gn/setup.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <sstream> | 10 #include <sstream> |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 base::Bind(&ItemDefinedCallback, scheduler_.main_loop(), builder_)); | 218 base::Bind(&ItemDefinedCallback, scheduler_.main_loop(), builder_)); |
| 219 | 219 |
| 220 // The scheduler's main loop wasn't created when the Loader was created, so | 220 // The scheduler's main loop wasn't created when the Loader was created, so |
| 221 // we need to set it now. | 221 // we need to set it now. |
| 222 loader_->set_main_loop(scheduler_.main_loop()); | 222 loader_->set_main_loop(scheduler_.main_loop()); |
| 223 } | 223 } |
| 224 | 224 |
| 225 Setup::~Setup() { | 225 Setup::~Setup() { |
| 226 } | 226 } |
| 227 | 227 |
| 228 bool Setup::DoSetup(const std::string& build_dir) { | 228 bool Setup::DoSetup(const std::string& build_dir, bool force_create) { |
| 229 CommandLine* cmdline = CommandLine::ForCurrentProcess(); | 229 CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
| 230 | 230 |
| 231 scheduler_.set_verbose_logging(cmdline->HasSwitch(kSwitchVerbose)); | 231 scheduler_.set_verbose_logging(cmdline->HasSwitch(kSwitchVerbose)); |
| 232 if (cmdline->HasSwitch(kTimeSwitch) || | 232 if (cmdline->HasSwitch(kTimeSwitch) || |
| 233 cmdline->HasSwitch(kTracelogSwitch)) | 233 cmdline->HasSwitch(kTracelogSwitch)) |
| 234 EnableTracing(); | 234 EnableTracing(); |
| 235 | 235 |
| 236 ScopedTrace setup_trace(TraceItem::TRACE_SETUP, "DoSetup"); | 236 ScopedTrace setup_trace(TraceItem::TRACE_SETUP, "DoSetup"); |
| 237 | 237 |
| 238 if (!FillSourceDir(*cmdline)) | 238 if (!FillSourceDir(*cmdline)) |
| 239 return false; | 239 return false; |
| 240 if (!RunConfigFile()) | 240 if (!RunConfigFile()) |
| 241 return false; | 241 return false; |
| 242 if (!FillOtherConfig(*cmdline)) | 242 if (!FillOtherConfig(*cmdline)) |
| 243 return false; | 243 return false; |
| 244 if (!FillBuildDir(build_dir)) // Must be after FillSourceDir to resolve. | 244 |
| 245 // Must be after FillSourceDir to resolve. |
| 246 if (!FillBuildDir(build_dir, !force_create)) |
| 245 return false; | 247 return false; |
| 248 |
| 246 if (fill_arguments_) { | 249 if (fill_arguments_) { |
| 247 if (!FillArguments(*cmdline)) | 250 if (!FillArguments(*cmdline)) |
| 248 return false; | 251 return false; |
| 249 } | 252 } |
| 250 FillPythonPath(); | 253 FillPythonPath(); |
| 251 | 254 |
| 252 return true; | 255 return true; |
| 253 } | 256 } |
| 254 | 257 |
| 255 bool Setup::Run() { | 258 bool Setup::Run() { |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 root_path = dotfile_name_.DirName(); | 434 root_path = dotfile_name_.DirName(); |
| 432 } | 435 } |
| 433 | 436 |
| 434 if (scheduler_.verbose_logging()) | 437 if (scheduler_.verbose_logging()) |
| 435 scheduler_.Log("Using source root", FilePathToUTF8(root_path)); | 438 scheduler_.Log("Using source root", FilePathToUTF8(root_path)); |
| 436 build_settings_.SetRootPath(root_path); | 439 build_settings_.SetRootPath(root_path); |
| 437 | 440 |
| 438 return true; | 441 return true; |
| 439 } | 442 } |
| 440 | 443 |
| 441 bool Setup::FillBuildDir(const std::string& build_dir) { | 444 bool Setup::FillBuildDir(const std::string& build_dir, bool require_exists) { |
| 442 SourceDir resolved = | 445 SourceDir resolved = |
| 443 SourceDirForCurrentDirectory(build_settings_.root_path()). | 446 SourceDirForCurrentDirectory(build_settings_.root_path()). |
| 444 ResolveRelativeDir(build_dir); | 447 ResolveRelativeDir(build_dir); |
| 445 if (resolved.is_null()) { | 448 if (resolved.is_null()) { |
| 446 Err(Location(), "Couldn't resolve build directory.", | 449 Err(Location(), "Couldn't resolve build directory.", |
| 447 "The build directory supplied (\"" + build_dir + "\") was not valid."). | 450 "The build directory supplied (\"" + build_dir + "\") was not valid."). |
| 448 PrintToStdout(); | 451 PrintToStdout(); |
| 449 return false; | 452 return false; |
| 450 } | 453 } |
| 451 | 454 |
| 452 if (scheduler_.verbose_logging()) | 455 if (scheduler_.verbose_logging()) |
| 453 scheduler_.Log("Using build dir", resolved.value()); | 456 scheduler_.Log("Using build dir", resolved.value()); |
| 457 |
| 458 if (require_exists) { |
| 459 base::FilePath build_dir_path = build_settings_.GetFullPath(resolved); |
| 460 if (!base::PathExists(build_dir_path.Append( |
| 461 FILE_PATH_LITERAL("build.ninja")))) { |
| 462 Err(Location(), "Not a build directory.", |
| 463 "This command requires an existing build directory. I interpreted " |
| 464 "your input\n\"" + build_dir + "\" as:\n " + |
| 465 FilePathToUTF8(build_dir_path) + |
| 466 "\nwhich doesn't seem to contain a previously-generated build.") |
| 467 .PrintToStdout(); |
| 468 return false; |
| 469 } |
| 470 } |
| 471 |
| 454 build_settings_.SetBuildDir(resolved); | 472 build_settings_.SetBuildDir(resolved); |
| 455 return true; | 473 return true; |
| 456 } | 474 } |
| 457 | 475 |
| 458 void Setup::FillPythonPath() { | 476 void Setup::FillPythonPath() { |
| 459 // Trace this since it tends to be a bit slow on Windows. | 477 // Trace this since it tends to be a bit slow on Windows. |
| 460 ScopedTrace setup_trace(TraceItem::TRACE_SETUP, "Fill Python Path"); | 478 ScopedTrace setup_trace(TraceItem::TRACE_SETUP, "Fill Python Path"); |
| 461 #if defined(OS_WIN) | 479 #if defined(OS_WIN) |
| 462 // Find Python on the path so we can use the absolute path in the build. | 480 // Find Python on the path so we can use the absolute path in the build. |
| 463 const base::char16 kGetPython[] = | 481 const base::char16 kGetPython[] = |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 } | 607 } |
| 590 | 608 |
| 591 void DependentSetup::RunPreMessageLoop() { | 609 void DependentSetup::RunPreMessageLoop() { |
| 592 CommonSetup::RunPreMessageLoop(); | 610 CommonSetup::RunPreMessageLoop(); |
| 593 } | 611 } |
| 594 | 612 |
| 595 bool DependentSetup::RunPostMessageLoop() { | 613 bool DependentSetup::RunPostMessageLoop() { |
| 596 return CommonSetup::RunPostMessageLoop(); | 614 return CommonSetup::RunPostMessageLoop(); |
| 597 } | 615 } |
| 598 | 616 |
| OLD | NEW |