Chromium Code Reviews| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 scoped_ptr<Item> item) { | 141 scoped_ptr<Item> item) { |
| 142 DCHECK(item); | 142 DCHECK(item); |
| 143 main_loop->PostTask(FROM_HERE, base::Bind(&Builder::ItemDefined, builder, | 143 main_loop->PostTask(FROM_HERE, base::Bind(&Builder::ItemDefined, builder, |
| 144 base::Passed(&item))); | 144 base::Passed(&item))); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void DecrementWorkCount() { | 147 void DecrementWorkCount() { |
| 148 g_scheduler->DecrementWorkCount(); | 148 g_scheduler->DecrementWorkCount(); |
| 149 } | 149 } |
| 150 | 150 |
| 151 #if defined(OS_WIN) | |
| 152 base::FilePath FindWindowsPython() { | |
| 153 const base::char16 kPythonExeName[] = L"python.exe"; | |
|
scottmg
2015/11/21 00:23:34
Could hoist this out so that the failure case can
| |
| 154 base::char16 current_directory[MAX_PATH]; | |
| 155 ::GetCurrentDirectory(MAX_PATH, current_directory); | |
| 156 | |
| 157 // First search for python.exe in the current directory. | |
| 158 base::FilePath cur_dir_candidate_exe = | |
| 159 base::FilePath(current_directory).Append(kPythonExeName); | |
| 160 if (base::PathExists(cur_dir_candidate_exe)) | |
| 161 return cur_dir_candidate_exe; | |
| 162 | |
| 163 // Get the path. | |
| 164 const base::char16 kPathEnvVarName[] = L"Path"; | |
| 165 DWORD path_length = ::GetEnvironmentVariable(kPathEnvVarName, NULL, 0); | |
|
scottmg
2015/11/21 00:23:34
nullptr
| |
| 166 if (path_length == 0) | |
| 167 return base::FilePath(); | |
| 168 scoped_ptr<base::char16[]> full_path(new base::char16[path_length]); | |
| 169 ::GetEnvironmentVariable(kPathEnvVarName, full_path.get(), path_length); | |
|
scottmg
2015/11/21 00:23:34
DCHECK return value == path_length - 1 maybe.
| |
| 170 | |
| 171 // Search for python.exe in the path. | |
| 172 for (const auto& component : base::SplitStringPiece( | |
| 173 base::StringPiece16(full_path.get(), path_length), L";", | |
| 174 base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) { | |
| 175 base::FilePath candidate_exe = | |
| 176 base::FilePath(component).Append(kPythonExeName); | |
| 177 if (base::PathExists(candidate_exe)) | |
| 178 return candidate_exe; | |
| 179 } | |
| 180 return base::FilePath(); | |
| 181 } | |
| 182 #endif | |
| 183 | |
| 151 } // namespace | 184 } // namespace |
| 152 | 185 |
| 153 const char Setup::kBuildArgFileName[] = "args.gn"; | 186 const char Setup::kBuildArgFileName[] = "args.gn"; |
| 154 | 187 |
| 155 Setup::Setup() | 188 Setup::Setup() |
| 156 : build_settings_(), | 189 : build_settings_(), |
| 157 loader_(new LoaderImpl(&build_settings_)), | 190 loader_(new LoaderImpl(&build_settings_)), |
| 158 builder_(new Builder(loader_.get())), | 191 builder_(new Builder(loader_.get())), |
| 159 root_build_file_("//BUILD.gn"), | 192 root_build_file_("//BUILD.gn"), |
| 160 check_public_headers_(false), | 193 check_public_headers_(false), |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 } | 504 } |
| 472 | 505 |
| 473 build_settings_.SetBuildDir(resolved); | 506 build_settings_.SetBuildDir(resolved); |
| 474 return true; | 507 return true; |
| 475 } | 508 } |
| 476 | 509 |
| 477 void Setup::FillPythonPath() { | 510 void Setup::FillPythonPath() { |
| 478 // Trace this since it tends to be a bit slow on Windows. | 511 // Trace this since it tends to be a bit slow on Windows. |
| 479 ScopedTrace setup_trace(TraceItem::TRACE_SETUP, "Fill Python Path"); | 512 ScopedTrace setup_trace(TraceItem::TRACE_SETUP, "Fill Python Path"); |
| 480 #if defined(OS_WIN) | 513 #if defined(OS_WIN) |
| 481 // Find Python on the path so we can use the absolute path in the build. | 514 base::FilePath python_path = FindWindowsPython(); |
| 482 const base::char16 kGetPython[] = | 515 if (python_path.empty()) { |
| 483 L"cmd.exe /c python -c \"import sys; print sys.executable\""; | |
| 484 std::string python_path; | |
| 485 if (base::GetAppOutput(kGetPython, &python_path)) { | |
| 486 base::TrimWhitespaceASCII(python_path, base::TRIM_ALL, &python_path); | |
| 487 if (scheduler_.verbose_logging()) | |
| 488 scheduler_.Log("Found python", python_path); | |
| 489 } else { | |
| 490 scheduler_.Log("WARNING", "Could not find python on path, using " | 516 scheduler_.Log("WARNING", "Could not find python on path, using " |
| 491 "just \"python.exe\""); | 517 "just \"python.exe\""); |
| 492 python_path = "python.exe"; | 518 python_path = base::FilePath(L"python.exe"); |
| 493 } | 519 } |
| 494 build_settings_.set_python_path(base::FilePath(base::UTF8ToUTF16(python_path)) | 520 build_settings_.set_python_path(python_path.NormalizePathSeparatorsTo('/')); |
| 495 .NormalizePathSeparatorsTo('/')); | |
| 496 #else | 521 #else |
| 497 build_settings_.set_python_path(base::FilePath("python")); | 522 build_settings_.set_python_path(base::FilePath("python")); |
| 498 #endif | 523 #endif |
| 499 } | 524 } |
| 500 | 525 |
| 501 bool Setup::RunConfigFile() { | 526 bool Setup::RunConfigFile() { |
| 502 if (scheduler_.verbose_logging()) | 527 if (scheduler_.verbose_logging()) |
| 503 scheduler_.Log("Got dotfile", FilePathToUTF8(dotfile_name_)); | 528 scheduler_.Log("Got dotfile", FilePathToUTF8(dotfile_name_)); |
| 504 | 529 |
| 505 dotfile_input_file_.reset(new InputFile(SourceFile("//.gn"))); | 530 dotfile_input_file_.reset(new InputFile(SourceFile("//.gn"))); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 622 if (err.has_error()) { | 647 if (err.has_error()) { |
| 623 err.PrintToStdout(); | 648 err.PrintToStdout(); |
| 624 return false; | 649 return false; |
| 625 } | 650 } |
| 626 } | 651 } |
| 627 build_settings_.set_exec_script_whitelist(whitelist.Pass()); | 652 build_settings_.set_exec_script_whitelist(whitelist.Pass()); |
| 628 } | 653 } |
| 629 | 654 |
| 630 return true; | 655 return true; |
| 631 } | 656 } |
| OLD | NEW |