GN: Allow setting the path to Python
This allows setting the path to Python executable used by GN through
a command line argument so that it can be overriden by the user.
Review-Url: https://codereview.chromium.org/1978693002
Cr-Original-Commit-Position: refs/heads/master@{#393683}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 325472663a3576438dd275b2981d59764ea362fb
diff --git a/tools/gn/docs/reference.md b/tools/gn/docs/reference.md
index 6216791..c596b27 100644
--- a/tools/gn/docs/reference.md
+++ b/tools/gn/docs/reference.md
@@ -176,6 +176,16 @@
```
+## **\--script-executable**: Set the executable used to execute scripts.
+
+```
+ By default GN searches the PATH for Python to execute scripts in
+ action targets and exec_script calls. This flag allows the
+ specification of a specific Python executable or potentially
+ a different language interpreter.
+
+
+```
## **\--threads**: Specify number of worker threads.
```
@@ -681,16 +691,53 @@
(default Visual Studio version: 2015)
"vs2013" - Visual Studio 2013 project/solution files.
"vs2015" - Visual Studio 2015 project/solution files.
-
- --sln=<file_name>
- Override default sln file name ("all"). Solution file is written
- to the root build directory. Only for Visual Studio.
+ "xcode" - Xcode workspace/solution files.
+ "qtcreator" - QtCreator project files.
--filters=<path_prefixes>
Semicolon-separated list of label patterns used to limit the set
of generated projects (see "gn help label_pattern"). Only
- matching targets will be included to the solution. Only for Visual
- Studio.
+ matching targets will be included to the solution. Only used for
+ Visual Studio and Xcode.
+
+```
+
+### **Visual Studio Flags**
+
+```
+ --sln=<file_name>
+ Override default sln file name ("all"). Solution file is written
+ to the root build directory.
+
+```
+
+### **Xcode Flags**
+
+```
+ --workspace=<file_name>
+ Override defaut workspace file name ("all"). The workspace file
+ is written to the root build directory.
+
+ --ninja-extra-args=<string>
+ This string is passed without any quoting to the ninja invocation
+ command-line. Can be used to configure ninja flags, like "-j" if
+ using goma for example.
+
+ --root-target=<target_name>
+ Name of the target corresponding to "All" target in Xcode.
+ If unset, "All" invokes ninja without any target
+ and builds everything.
+
+```
+
+### **QtCreator Flags**
+
+```
+ --root-target=<target_name>
+ Name of the root target for which the QtCreator project will be
+ generated to contain files of it and its dependencies. If unset,
+ the whole build graph will be omitted.
+
```
@@ -1377,7 +1424,8 @@
```
bundle_root_dir*, bundle_resources_dir*, bundle_executable_dir*,
- bundle_plugins_dir*, deps, data_deps, public_deps, visibility
+ bundle_plugins_dir*, deps, data_deps, public_deps, visibility,
+ product_type
* = required
```
@@ -1427,6 +1475,7 @@
}
create_bundle("${app_name}.app") {
+ product_type = "com.apple.product-type.application"
deps = [
":${app_name}_bundle_executable",
":${app_name}_bundle_info_plist",
@@ -4989,6 +5038,18 @@
```
+## **product_type**: Product type for Xcode projects.
+
+```
+ Correspond to the type of the product of a create_bundle target. Only
+ meaningful to Xcode (used as part of the Xcode project generation).
+
+ When generating Xcode project files, only create_bundle target with
+ a non-empty product_type will have a corresponding target in Xcode
+ project.
+
+
+```
## **public**: Declare public header files for a target.
```
@@ -5966,6 +6027,7 @@
** -q**: Quiet mode. Don't print output on success.
** \--root**: Explicitly specify source root.
** \--runtime-deps-list-file**: Save runtime dependencies for targets in file.
+** \--script-executable**: Set the executable used to execute scripts.
** \--threads**: Specify number of worker threads.
** \--time**: Outputs a summary of how long everything took.
** \--tracelog**: Writes a Chrome-compatible trace log to the given file.
diff --git a/tools/gn/setup.cc b/tools/gn/setup.cc
index 7f8e286..ea7cb24 100644
--- a/tools/gn/setup.cc
+++ b/tools/gn/setup.cc
@@ -299,7 +299,7 @@
if (!FillArguments(*cmdline))
return false;
}
- FillPythonPath();
+ FillPythonPath(*cmdline);
return true;
}
@@ -594,20 +594,25 @@
return true;
}
-void Setup::FillPythonPath() {
+void Setup::FillPythonPath(const base::CommandLine& cmdline) {
// Trace this since it tends to be a bit slow on Windows.
ScopedTrace setup_trace(TraceItem::TRACE_SETUP, "Fill Python Path");
+ if (cmdline.HasSwitch(switches::kScriptExecutable)) {
+ build_settings_.set_python_path(
+ cmdline.GetSwitchValuePath(switches::kScriptExecutable));
+ } else {
#if defined(OS_WIN)
- base::FilePath python_path = FindWindowsPython();
- if (python_path.empty()) {
- scheduler_.Log("WARNING", "Could not find python on path, using "
- "just \"python.exe\"");
- python_path = base::FilePath(kPythonExeName);
- }
- build_settings_.set_python_path(python_path.NormalizePathSeparatorsTo('/'));
+ base::FilePath python_path = FindWindowsPython();
+ if (python_path.empty()) {
+ scheduler_.Log("WARNING", "Could not find python on path, using "
+ "just \"python.exe\"");
+ python_path = base::FilePath(kPythonExeName);
+ }
+ build_settings_.set_python_path(python_path.NormalizePathSeparatorsTo('/'));
#else
- build_settings_.set_python_path(base::FilePath("python"));
+ build_settings_.set_python_path(base::FilePath("python"));
#endif
+ }
}
bool Setup::RunConfigFile() {
diff --git a/tools/gn/setup.h b/tools/gn/setup.h
index 4f2d885..22e6557 100644
--- a/tools/gn/setup.h
+++ b/tools/gn/setup.h
@@ -119,7 +119,7 @@
// Fills the python path portion of the command line. On failure, sets
// it to just "python".
- void FillPythonPath();
+ void FillPythonPath(const base::CommandLine& cmdline);
// Run config file.
bool RunConfigFile();
diff --git a/tools/gn/switches.cc b/tools/gn/switches.cc
index 48b191e..8884634 100644
--- a/tools/gn/switches.cc
+++ b/tools/gn/switches.cc
@@ -103,6 +103,17 @@
"--nocolor: Force non-colored output.";
const char kNoColor_Help[] = COLOR_HELP_LONG;
+const char kScriptExecutable[] = "script-executable";
+const char kScriptExecutable_HelpShort[] =
+ "--script-executable: Set the executable used to execute scripts.";
+const char kScriptExecutable_Help[] =
+ "--script-executable: Set the executable used to execute scripts.\n"
+ "\n"
+ " By default GN searches the PATH for Python to execute scripts in\n"
+ " action targets and exec_script calls. This flag allows the\n"
+ " specification of a specific Python executable or potentially\n"
+ " a different language interpreter.\n";
+
const char kQuiet[] = "q";
const char kQuiet_HelpShort[] =
"-q: Quiet mode. Don't print output on success.";
@@ -254,6 +265,7 @@
INSERT_VARIABLE(Root)
INSERT_VARIABLE(Quiet)
INSERT_VARIABLE(RuntimeDepsListFile)
+ INSERT_VARIABLE(ScriptExecutable)
INSERT_VARIABLE(Threads)
INSERT_VARIABLE(Time)
INSERT_VARIABLE(Tracelog)
diff --git a/tools/gn/switches.h b/tools/gn/switches.h
index b86bf33..effaa25 100644
--- a/tools/gn/switches.h
+++ b/tools/gn/switches.h
@@ -52,6 +52,10 @@
extern const char kNoColor_HelpShort[];
extern const char kNoColor_Help[];
+extern const char kScriptExecutable[];
+extern const char kScriptExecutable_HelpShort[];
+extern const char kScriptExecutable_Help[];
+
extern const char kQuiet[];
extern const char kQuiet_HelpShort[];
extern const char kQuiet_Help[];