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 | 10 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 const char kSwitchArgs[] = "args"; | 77 const char kSwitchArgs[] = "args"; |
78 | 78 |
79 // Set root dir. | 79 // Set root dir. |
80 const char kSwitchRoot[] = "root"; | 80 const char kSwitchRoot[] = "root"; |
81 | 81 |
82 // Enable timing. | 82 // Enable timing. |
83 const char kTimeSwitch[] = "time"; | 83 const char kTimeSwitch[] = "time"; |
84 | 84 |
85 const char kTracelogSwitch[] = "tracelog"; | 85 const char kTracelogSwitch[] = "tracelog"; |
86 | 86 |
87 // Set build output directory. | |
88 const char kSwitchBuildOutput[] = "output"; | |
89 | |
90 const char kSecondarySource[] = "secondary"; | 87 const char kSecondarySource[] = "secondary"; |
91 | 88 |
92 const base::FilePath::CharType kGnFile[] = FILE_PATH_LITERAL(".gn"); | 89 const base::FilePath::CharType kGnFile[] = FILE_PATH_LITERAL(".gn"); |
93 | 90 |
94 base::FilePath FindDotFile(const base::FilePath& current_dir) { | 91 base::FilePath FindDotFile(const base::FilePath& current_dir) { |
95 base::FilePath try_this_file = current_dir.Append(kGnFile); | 92 base::FilePath try_this_file = current_dir.Append(kGnFile); |
96 if (base::PathExists(try_this_file)) | 93 if (base::PathExists(try_this_file)) |
97 return try_this_file; | 94 return try_this_file; |
98 | 95 |
99 base::FilePath with_no_slash = current_dir.StripTrailingSeparators(); | 96 base::FilePath with_no_slash = current_dir.StripTrailingSeparators(); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 base::Bind(&ItemDefinedCallback, scheduler_.main_loop(), builder_)); | 186 base::Bind(&ItemDefinedCallback, scheduler_.main_loop(), builder_)); |
190 | 187 |
191 // The scheduler's main loop wasn't created when the Loader was created, so | 188 // The scheduler's main loop wasn't created when the Loader was created, so |
192 // we need to set it now. | 189 // we need to set it now. |
193 loader_->set_main_loop(scheduler_.main_loop()); | 190 loader_->set_main_loop(scheduler_.main_loop()); |
194 } | 191 } |
195 | 192 |
196 Setup::~Setup() { | 193 Setup::~Setup() { |
197 } | 194 } |
198 | 195 |
199 bool Setup::DoSetup() { | 196 bool Setup::DoSetup(const std::string& build_dir) { |
200 CommandLine* cmdline = CommandLine::ForCurrentProcess(); | 197 CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
201 | 198 |
202 scheduler_.set_verbose_logging(cmdline->HasSwitch(kSwitchVerbose)); | 199 scheduler_.set_verbose_logging(cmdline->HasSwitch(kSwitchVerbose)); |
203 if (cmdline->HasSwitch(kTimeSwitch) || | 200 if (cmdline->HasSwitch(kTimeSwitch) || |
204 cmdline->HasSwitch(kTracelogSwitch)) | 201 cmdline->HasSwitch(kTracelogSwitch)) |
205 EnableTracing(); | 202 EnableTracing(); |
206 | 203 |
207 if (!FillArguments(*cmdline)) | 204 if (!FillArguments(*cmdline)) |
208 return false; | 205 return false; |
209 if (!FillSourceDir(*cmdline)) | 206 if (!FillSourceDir(*cmdline)) |
210 return false; | 207 return false; |
211 if (!RunConfigFile()) | 208 if (!RunConfigFile()) |
212 return false; | 209 return false; |
213 if (!FillOtherConfig(*cmdline)) | 210 if (!FillOtherConfig(*cmdline)) |
214 return false; | 211 return false; |
| 212 if (!FillBuildDir(build_dir)) // Must be after FillSourceDir to resolve. |
| 213 return false; |
215 FillPythonPath(); | 214 FillPythonPath(); |
216 | 215 |
217 base::FilePath build_path = cmdline->GetSwitchValuePath(kSwitchBuildOutput); | |
218 if (!build_path.empty()) { | |
219 // We accept either repo paths "//out/Debug" or raw source-root-relative | |
220 // paths "out/Debug". | |
221 std::string build_path_8 = FilePathToUTF8(build_path); | |
222 if (build_path_8.compare(0, 2, "//") != 0) | |
223 build_path_8.insert(0, "//"); | |
224 #if defined(OS_WIN) | |
225 // Canonicalize to forward slashes on Windows. | |
226 std::replace(build_path_8.begin(), build_path_8.end(), '\\', '/'); | |
227 #endif | |
228 build_settings_.SetBuildDir(SourceDir(build_path_8)); | |
229 } else { | |
230 // Default output dir. | |
231 build_settings_.SetBuildDir(SourceDir("//out/Default/")); | |
232 } | |
233 | |
234 return true; | 216 return true; |
235 } | 217 } |
236 | 218 |
237 bool Setup::Run() { | 219 bool Setup::Run() { |
238 RunPreMessageLoop(); | 220 RunPreMessageLoop(); |
239 if (!scheduler_.Run()) | 221 if (!scheduler_.Run()) |
240 return false; | 222 return false; |
241 return RunPostMessageLoop(); | 223 return RunPostMessageLoop(); |
242 } | 224 } |
243 | 225 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 root_path = dotfile_name_.DirName(); | 286 root_path = dotfile_name_.DirName(); |
305 } | 287 } |
306 | 288 |
307 if (scheduler_.verbose_logging()) | 289 if (scheduler_.verbose_logging()) |
308 scheduler_.Log("Using source root", FilePathToUTF8(root_path)); | 290 scheduler_.Log("Using source root", FilePathToUTF8(root_path)); |
309 build_settings_.SetRootPath(root_path); | 291 build_settings_.SetRootPath(root_path); |
310 | 292 |
311 return true; | 293 return true; |
312 } | 294 } |
313 | 295 |
| 296 bool Setup::FillBuildDir(const std::string& build_dir) { |
| 297 SourceDir resolved = |
| 298 SourceDirForCurrentDirectory(build_settings_.root_path()). |
| 299 ResolveRelativeDir(build_dir); |
| 300 if (resolved.is_null()) { |
| 301 Err(Location(), "Couldn't resolve build directory.", |
| 302 "The build directory supplied (\"" + build_dir + "\") was not valid."). |
| 303 PrintToStdout(); |
| 304 return false; |
| 305 } |
| 306 |
| 307 if (scheduler_.verbose_logging()) |
| 308 scheduler_.Log("Using build dir", resolved.value()); |
| 309 build_settings_.SetBuildDir(resolved); |
| 310 return true; |
| 311 } |
| 312 |
314 void Setup::FillPythonPath() { | 313 void Setup::FillPythonPath() { |
315 #if defined(OS_WIN) | 314 #if defined(OS_WIN) |
316 // Find Python on the path so we can use the absolute path in the build. | 315 // Find Python on the path so we can use the absolute path in the build. |
317 const base::char16 kGetPython[] = | 316 const base::char16 kGetPython[] = |
318 L"cmd.exe /c python -c \"import sys; print sys.executable\""; | 317 L"cmd.exe /c python -c \"import sys; print sys.executable\""; |
319 std::string python_path; | 318 std::string python_path; |
320 if (base::GetAppOutput(kGetPython, &python_path)) { | 319 if (base::GetAppOutput(kGetPython, &python_path)) { |
321 TrimWhitespaceASCII(python_path, TRIM_ALL, &python_path); | 320 TrimWhitespaceASCII(python_path, TRIM_ALL, &python_path); |
322 if (scheduler_.verbose_logging()) | 321 if (scheduler_.verbose_logging()) |
323 scheduler_.Log("Found python", python_path); | 322 scheduler_.Log("Found python", python_path); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 } | 431 } |
433 | 432 |
434 void DependentSetup::RunPreMessageLoop() { | 433 void DependentSetup::RunPreMessageLoop() { |
435 CommonSetup::RunPreMessageLoop(); | 434 CommonSetup::RunPreMessageLoop(); |
436 } | 435 } |
437 | 436 |
438 bool DependentSetup::RunPostMessageLoop() { | 437 bool DependentSetup::RunPostMessageLoop() { |
439 return CommonSetup::RunPostMessageLoop(); | 438 return CommonSetup::RunPostMessageLoop(); |
440 } | 439 } |
441 | 440 |
OLD | NEW |