aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java
diff options
context:
space:
mode:
authorGravatar Yun Peng <pcloudy@google.com>2017-08-18 17:17:35 +0200
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2017-08-21 14:15:52 +0200
commit3e0277ab880c9126883e73c78c7431e836ebb32e (patch)
treef7d9297021a748093216a3cf04ae03a8deff3025 /src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java
parenta05cda4c068a50807fc1adf7bc84c37c20822d7b (diff)
Windows: Implement python native launcher
Now Bazel build a Windows exe to launch the python self-extracting zip file by default, using --windows_exe_launcher=0 to switch back to cmd wrapper. The extra zip file with shebang preprended is not built on Windows anymore, even when using cmd wrapper. Change-Id: Ic7060326f19ca6e2e73ea8d8211afd1c7618083c PiperOrigin-RevId: 165707076
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java b/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java
index f9d543f4bc..85e2f90098 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java
@@ -81,7 +81,6 @@ public final class PyCommon {
private final RuleContext ruleContext;
private Artifact executable = null;
- private Artifact executableWrapper = null;
private NestedSet<Artifact> transitivePythonSources;
@@ -115,10 +114,18 @@ public final class PyCommon {
Preconditions.checkNotNull(version);
validatePackageName();
- executable = ruleContext.createOutputArtifact();
if (OS.getCurrent() == OS.WINDOWS) {
- executableWrapper =
- ruleContext.getImplicitOutputArtifact(ruleContext.getTarget().getName() + ".cmd");
+ String executableSuffix;
+ if (ruleContext.getConfiguration().enableWindowsExeLauncher()) {
+ executableSuffix = ".exe";
+ } else {
+ executableSuffix = ".cmd";
+ }
+ executable =
+ ruleContext.getImplicitOutputArtifact(
+ ruleContext.getTarget().getName() + executableSuffix);
+ } else {
+ executable = ruleContext.createOutputArtifact();
}
if (this.version == PythonVersion.PY2AND3) {
// TODO(bazel-team): we need to create two actions
@@ -127,9 +134,11 @@ public final class PyCommon {
NestedSetBuilder<Artifact> filesToBuildBuilder =
NestedSetBuilder.<Artifact>stableOrder().addAll(srcs).add(executable);
- if (executableWrapper != null) {
- filesToBuildBuilder.add(executableWrapper);
+
+ if (ruleContext.getConfiguration().buildPythonZip()) {
+ filesToBuildBuilder.add(getPythonZipArtifact(executable));
}
+
filesToBuild = filesToBuildBuilder.build();
if (ruleContext.hasErrors()) {
@@ -139,6 +148,11 @@ public final class PyCommon {
addPyExtraActionPseudoAction();
}
+ /** @return An artifact next to the executable file with ".zip" suffix */
+ public Artifact getPythonZipArtifact(Artifact executable) {
+ return ruleContext.getRelatedArtifact(executable.getRootRelativePath(), ".zip");
+ }
+
public void addCommonTransitiveInfoProviders(RuleConfiguredTargetBuilder builder,
PythonSemantics semantics, NestedSet<Artifact> filesToBuild) {
@@ -456,10 +470,6 @@ public final class PyCommon {
return executable;
}
- public Artifact getExecutableWrapper() {
- return executableWrapper;
- }
-
public Map<PathFragment, Artifact> getConvertedFiles() {
return convertedFiles;
}