aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar pcloudy <pcloudy@google.com>2017-04-04 14:50:51 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2017-04-04 18:39:19 +0200
commita00c6249a7dea381a384e13c336c61211ac83965 (patch)
tree269439a01f0013523fa9690019ef7e149fa773bb /src
parent39e659e690228c07b79b49dcde1b21fc0cd14e9a (diff)
Set default python3_path to python.exe on Windows
When building py_binary for host with --host_force_python=py3, --python3_path is not taken, instead python3.exe is always used. It doesn't work because python3.exe usually doesn't exist on Windows. So here we set the default to python.exe Fixed https://github.com/bazelbuild/bazel/issues/2752 Change-Id: Ie48156d93ae1f28338947ea121ab2071e1b820e1 PiperOrigin-RevId: 152130801
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonConfiguration.java30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonConfiguration.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonConfiguration.java
index d1768e1611..6c1a124d88 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonConfiguration.java
@@ -23,8 +23,9 @@ import com.google.devtools.build.lib.analysis.config.ConfigurationFragmentFactor
import com.google.devtools.build.lib.analysis.config.FragmentOptions;
import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
+import com.google.devtools.build.lib.util.OS;
+import com.google.devtools.common.options.Converter;
import com.google.devtools.common.options.Option;
-
import javax.annotation.Nullable;
/**
@@ -34,6 +35,24 @@ import javax.annotation.Nullable;
public class BazelPythonConfiguration extends BuildConfiguration.Fragment {
/**
+ * A path converter for python3 path
+ */
+ public static class Python3PathConverter implements Converter<String> {
+ @Override
+ public String convert(String input) {
+ if (input.equals("auto")) {
+ return OS.getCurrent() == OS.WINDOWS ? "python" : "python3";
+ }
+ return input;
+ }
+
+ @Override
+ public String getTypeDescription() {
+ return "An option for python3 path";
+ }
+ }
+
+ /**
* Bazel-specific Python configuration options.
*/
public static final class Options extends FragmentOptions {
@@ -43,10 +62,13 @@ public class BazelPythonConfiguration extends BuildConfiguration.Fragment {
help = "Local path to the Python2 executable.")
public String python2Path;
- @Option(name = "python3_path",
- defaultValue = "python3",
+ @Option(
+ name = "python3_path",
+ converter = Python3PathConverter.class,
+ defaultValue = "auto",
category = "version",
- help = "Local path to the Python3 executable.")
+ help = "Local path to the Python3 executable."
+ )
public String python3Path;
@Option(name = "experimental_python_import_all_repositories",