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

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

Issue 1462393003: GN: Manually search path for Python (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 | « no previous file | no next file » | 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 <algorithm> 9 #include <algorithm>
10 #include <sstream> 10 #include <sstream>
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 const base::char16 kPythonExeName[] = L"python.exe";
153
154 base::FilePath FindWindowsPython() {
155 base::char16 current_directory[MAX_PATH];
156 ::GetCurrentDirectory(MAX_PATH, current_directory);
157
158 // First search for python.exe in the current directory.
159 base::FilePath cur_dir_candidate_exe =
160 base::FilePath(current_directory).Append(kPythonExeName);
161 if (base::PathExists(cur_dir_candidate_exe))
162 return cur_dir_candidate_exe;
163
164 // Get the path.
165 const base::char16 kPathEnvVarName[] = L"Path";
166 DWORD path_length = ::GetEnvironmentVariable(kPathEnvVarName, nullptr, 0);
167 if (path_length == 0)
168 return base::FilePath();
169 scoped_ptr<base::char16[]> full_path(new base::char16[path_length]);
170 DWORD actual_path_length =
171 ::GetEnvironmentVariable(kPathEnvVarName, full_path.get(), path_length);
172 CHECK_EQ(path_length, actual_path_length + 1);
173
174 // Search for python.exe in the path.
175 for (const auto& component : base::SplitStringPiece(
176 base::StringPiece16(full_path.get(), path_length), L";",
177 base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) {
178 base::FilePath candidate_exe =
179 base::FilePath(component).Append(kPythonExeName);
180 if (base::PathExists(candidate_exe))
181 return candidate_exe;
182 }
183 return base::FilePath();
184 }
185 #endif
186
151 } // namespace 187 } // namespace
152 188
153 const char Setup::kBuildArgFileName[] = "args.gn"; 189 const char Setup::kBuildArgFileName[] = "args.gn";
154 190
155 Setup::Setup() 191 Setup::Setup()
156 : build_settings_(), 192 : build_settings_(),
157 loader_(new LoaderImpl(&build_settings_)), 193 loader_(new LoaderImpl(&build_settings_)),
158 builder_(new Builder(loader_.get())), 194 builder_(new Builder(loader_.get())),
159 root_build_file_("//BUILD.gn"), 195 root_build_file_("//BUILD.gn"),
160 check_public_headers_(false), 196 check_public_headers_(false),
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 } 507 }
472 508
473 build_settings_.SetBuildDir(resolved); 509 build_settings_.SetBuildDir(resolved);
474 return true; 510 return true;
475 } 511 }
476 512
477 void Setup::FillPythonPath() { 513 void Setup::FillPythonPath() {
478 // Trace this since it tends to be a bit slow on Windows. 514 // Trace this since it tends to be a bit slow on Windows.
479 ScopedTrace setup_trace(TraceItem::TRACE_SETUP, "Fill Python Path"); 515 ScopedTrace setup_trace(TraceItem::TRACE_SETUP, "Fill Python Path");
480 #if defined(OS_WIN) 516 #if defined(OS_WIN)
481 // Find Python on the path so we can use the absolute path in the build. 517 base::FilePath python_path = FindWindowsPython();
482 const base::char16 kGetPython[] = 518 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 " 519 scheduler_.Log("WARNING", "Could not find python on path, using "
491 "just \"python.exe\""); 520 "just \"python.exe\"");
492 python_path = "python.exe"; 521 python_path = base::FilePath(kPythonExeName);
493 } 522 }
494 build_settings_.set_python_path(base::FilePath(base::UTF8ToUTF16(python_path)) 523 build_settings_.set_python_path(python_path.NormalizePathSeparatorsTo('/'));
495 .NormalizePathSeparatorsTo('/'));
496 #else 524 #else
497 build_settings_.set_python_path(base::FilePath("python")); 525 build_settings_.set_python_path(base::FilePath("python"));
498 #endif 526 #endif
499 } 527 }
500 528
501 bool Setup::RunConfigFile() { 529 bool Setup::RunConfigFile() {
502 if (scheduler_.verbose_logging()) 530 if (scheduler_.verbose_logging())
503 scheduler_.Log("Got dotfile", FilePathToUTF8(dotfile_name_)); 531 scheduler_.Log("Got dotfile", FilePathToUTF8(dotfile_name_));
504 532
505 dotfile_input_file_.reset(new InputFile(SourceFile("//.gn"))); 533 dotfile_input_file_.reset(new InputFile(SourceFile("//.gn")));
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 if (err.has_error()) { 650 if (err.has_error()) {
623 err.PrintToStdout(); 651 err.PrintToStdout();
624 return false; 652 return false;
625 } 653 }
626 } 654 }
627 build_settings_.set_exec_script_whitelist(whitelist.Pass()); 655 build_settings_.set_exec_script_whitelist(whitelist.Pass());
628 } 656 }
629 657
630 return true; 658 return true;
631 } 659 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698