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 #include <algorithm> | 8 #include <algorithm> |
9 #include <sstream> | 9 #include <sstream> |
10 #include <utility> | 10 #include <utility> |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 exec_script_whitelist = [ | 91 exec_script_whitelist = [ |
92 "//base/BUILD.gn", | 92 "//base/BUILD.gn", |
93 "//build/my_config.gni", | 93 "//build/my_config.gni", |
94 ] | 94 ] |
95 | 95 |
96 root [optional] | 96 root [optional] |
97 Label of the root build target. The GN build will start by loading the | 97 Label of the root build target. The GN build will start by loading the |
98 build file containing this target name. This defaults to "//:" which will | 98 build file containing this target name. This defaults to "//:" which will |
99 cause the file //BUILD.gn to be loaded. | 99 cause the file //BUILD.gn to be loaded. |
100 | 100 |
| 101 script_executable [optional] |
| 102 Path to specific Python executable or potentially a different language |
| 103 interpreter that is used to execute scripts in action targets and |
| 104 exec_script calls. |
| 105 |
101 secondary_source [optional] | 106 secondary_source [optional] |
102 Label of an alternate directory tree to find input files. When searching | 107 Label of an alternate directory tree to find input files. When searching |
103 for a BUILD.gn file (or the build config file discussed above), the file | 108 for a BUILD.gn file (or the build config file discussed above), the file |
104 will first be looked for in the source root. If it's not found, the | 109 will first be looked for in the source root. If it's not found, the |
105 secondary source root will be checked (which would contain a parallel | 110 secondary source root will be checked (which would contain a parallel |
106 directory hierarchy). | 111 directory hierarchy). |
107 | 112 |
108 This behavior is intended to be used when BUILD.gn files can't be checked | 113 This behavior is intended to be used when BUILD.gn files can't be checked |
109 in to certain source directories for whatever reason. | 114 in to certain source directories for whatever reason. |
110 | 115 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 return false; | 312 return false; |
308 if (!RunConfigFile()) | 313 if (!RunConfigFile()) |
309 return false; | 314 return false; |
310 if (!FillOtherConfig(*cmdline)) | 315 if (!FillOtherConfig(*cmdline)) |
311 return false; | 316 return false; |
312 | 317 |
313 // Must be after FillSourceDir to resolve. | 318 // Must be after FillSourceDir to resolve. |
314 if (!FillBuildDir(build_dir, !force_create)) | 319 if (!FillBuildDir(build_dir, !force_create)) |
315 return false; | 320 return false; |
316 | 321 |
317 // Check for unused variables in the .gn file. | |
318 Err err; | |
319 if (!dotfile_scope_.CheckForUnusedVars(&err)) { | |
320 err.PrintToStdout(); | |
321 return false; | |
322 } | |
323 | |
324 // Apply project-specific default (if specified). | 322 // Apply project-specific default (if specified). |
325 // Must happen before FillArguments(). | 323 // Must happen before FillArguments(). |
326 if (default_args_) { | 324 if (default_args_) { |
327 Scope::KeyValueMap overrides; | 325 Scope::KeyValueMap overrides; |
328 default_args_->GetCurrentScopeValues(&overrides); | 326 default_args_->GetCurrentScopeValues(&overrides); |
329 build_settings_.build_args().AddArgOverrides(overrides); | 327 build_settings_.build_args().AddArgOverrides(overrides); |
330 } | 328 } |
331 | 329 |
332 if (fill_arguments_) { | 330 if (fill_arguments_) { |
333 if (!FillArguments(*cmdline)) | 331 if (!FillArguments(*cmdline)) |
334 return false; | 332 return false; |
335 } | 333 } |
336 FillPythonPath(*cmdline); | 334 if (!FillPythonPath(*cmdline)) |
| 335 return false; |
| 336 |
| 337 // Check for unused variables in the .gn file. |
| 338 Err err; |
| 339 if (!dotfile_scope_.CheckForUnusedVars(&err)) { |
| 340 err.PrintToStdout(); |
| 341 return false; |
| 342 } |
337 | 343 |
338 return true; | 344 return true; |
339 } | 345 } |
340 | 346 |
341 bool Setup::Run() { | 347 bool Setup::Run() { |
342 RunPreMessageLoop(); | 348 RunPreMessageLoop(); |
343 if (!scheduler_.Run()) | 349 if (!scheduler_.Run()) |
344 return false; | 350 return false; |
345 return RunPostMessageLoop(); | 351 return RunPostMessageLoop(); |
346 } | 352 } |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 "\nwhich doesn't seem to contain a previously-generated build.") | 625 "\nwhich doesn't seem to contain a previously-generated build.") |
620 .PrintToStdout(); | 626 .PrintToStdout(); |
621 return false; | 627 return false; |
622 } | 628 } |
623 } | 629 } |
624 | 630 |
625 build_settings_.SetBuildDir(resolved); | 631 build_settings_.SetBuildDir(resolved); |
626 return true; | 632 return true; |
627 } | 633 } |
628 | 634 |
629 void Setup::FillPythonPath(const base::CommandLine& cmdline) { | 635 bool Setup::FillPythonPath(const base::CommandLine& cmdline) { |
630 // Trace this since it tends to be a bit slow on Windows. | 636 // Trace this since it tends to be a bit slow on Windows. |
631 ScopedTrace setup_trace(TraceItem::TRACE_SETUP, "Fill Python Path"); | 637 ScopedTrace setup_trace(TraceItem::TRACE_SETUP, "Fill Python Path"); |
| 638 const Value* value = dotfile_scope_.GetValue("script_executable", true); |
632 if (cmdline.HasSwitch(switches::kScriptExecutable)) { | 639 if (cmdline.HasSwitch(switches::kScriptExecutable)) { |
633 build_settings_.set_python_path( | 640 build_settings_.set_python_path( |
634 cmdline.GetSwitchValuePath(switches::kScriptExecutable)); | 641 cmdline.GetSwitchValuePath(switches::kScriptExecutable)); |
| 642 } else if (value) { |
| 643 Err err; |
| 644 if (!value->VerifyTypeIs(Value::STRING, &err)) { |
| 645 err.PrintToStdout(); |
| 646 return false; |
| 647 } |
| 648 build_settings_.set_python_path( |
| 649 base::FilePath(UTF8ToFilePath(value->string_value()))); |
635 } else { | 650 } else { |
636 #if defined(OS_WIN) | 651 #if defined(OS_WIN) |
637 base::FilePath python_path = FindWindowsPython(); | 652 base::FilePath python_path = FindWindowsPython(); |
638 if (python_path.empty()) { | 653 if (python_path.empty()) { |
639 scheduler_.Log("WARNING", "Could not find python on path, using " | 654 scheduler_.Log("WARNING", "Could not find python on path, using " |
640 "just \"python.exe\""); | 655 "just \"python.exe\""); |
641 python_path = base::FilePath(kPythonExeName); | 656 python_path = base::FilePath(kPythonExeName); |
642 } | 657 } |
643 build_settings_.set_python_path(python_path.NormalizePathSeparatorsTo('/')); | 658 build_settings_.set_python_path(python_path.NormalizePathSeparatorsTo('/')); |
644 #else | 659 #else |
645 build_settings_.set_python_path(base::FilePath("python")); | 660 build_settings_.set_python_path(base::FilePath("python")); |
646 #endif | 661 #endif |
647 } | 662 } |
| 663 return true; |
648 } | 664 } |
649 | 665 |
650 bool Setup::RunConfigFile() { | 666 bool Setup::RunConfigFile() { |
651 if (scheduler_.verbose_logging()) | 667 if (scheduler_.verbose_logging()) |
652 scheduler_.Log("Got dotfile", FilePathToUTF8(dotfile_name_)); | 668 scheduler_.Log("Got dotfile", FilePathToUTF8(dotfile_name_)); |
653 | 669 |
654 dotfile_input_file_.reset(new InputFile(SourceFile("//.gn"))); | 670 dotfile_input_file_.reset(new InputFile(SourceFile("//.gn"))); |
655 if (!dotfile_input_file_->Load(dotfile_name_)) { | 671 if (!dotfile_input_file_->Load(dotfile_name_)) { |
656 Err(Location(), "Could not load dotfile.", | 672 Err(Location(), "Could not load dotfile.", |
657 "The file \"" + FilePathToUTF8(dotfile_name_) + "\" couldn't be loaded") | 673 "The file \"" + FilePathToUTF8(dotfile_name_) + "\" couldn't be loaded") |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 if (!arg_file_template_value->VerifyTypeIs(Value::STRING, &err)) { | 803 if (!arg_file_template_value->VerifyTypeIs(Value::STRING, &err)) { |
788 err.PrintToStdout(); | 804 err.PrintToStdout(); |
789 return false; | 805 return false; |
790 } | 806 } |
791 SourceFile path(arg_file_template_value->string_value()); | 807 SourceFile path(arg_file_template_value->string_value()); |
792 build_settings_.set_arg_file_template_path(path); | 808 build_settings_.set_arg_file_template_path(path); |
793 } | 809 } |
794 | 810 |
795 return true; | 811 return true; |
796 } | 812 } |
OLD | NEW |