aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar mstaib <mstaib@google.com>2017-09-20 21:49:26 +0200
committerGravatar László Csomor <laszlocsomor@google.com>2017-09-21 11:03:33 +0200
commitbef0c45326281aa0bc55b51044579ea81f96f0ad (patch)
tree737959596a4e84930ce7511f491b2493fb9ea756 /src
parentcf03c3dc8971588e2d5deb9831f2843fd39a2f6e (diff)
Move --build_python_zip into PythonConfiguration.
There's no need for it in the core configuration options, as it's used exclusively by Python rules. RELNOTES: None. PiperOrigin-RevId: 169435643
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java21
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java5
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/python/PyCommon.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/python/PythonConfiguration.java19
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/python/PythonConfigurationLoader.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/python/PythonOptions.java11
6 files changed, 35 insertions, 26 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java
index 9774cb7a56..51e6883457 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java
@@ -994,15 +994,6 @@ public final class BuildConfiguration implements BuildEvent {
public TriState enableRunfiles;
@Option(
- name = "build_python_zip",
- defaultValue = "auto",
- documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
- effectTags = {OptionEffectTag.UNKNOWN},
- help = "Build python executable zip; on on Windows, off on other platforms"
- )
- public TriState buildPythonZip;
-
- @Option(
name = "windows_exe_launcher",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
@@ -1022,7 +1013,6 @@ public final class BuildConfiguration implements BuildEvent {
host.isHost = true;
host.configsMode = configsMode;
host.enableRunfiles = enableRunfiles;
- host.buildPythonZip = buildPythonZip;
host.windowsExeLauncher = windowsExeLauncher;
host.commandLineBuildVariables = commandLineBuildVariables;
host.enforceConstraints = enforceConstraints;
@@ -2030,17 +2020,6 @@ public final class BuildConfiguration implements BuildEvent {
}
}
- public boolean buildPythonZip() {
- switch (options.buildPythonZip) {
- case YES:
- return true;
- case NO:
- return false;
- default:
- return OS.getCurrent() == OS.WINDOWS;
- }
- }
-
public boolean enableWindowsExeLauncher() {
return options.windowsExeLauncher;
}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java
index fff39d2e3b..bf03b95333 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java
@@ -39,6 +39,7 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.rules.cpp.CcLinkParamsStore;
import com.google.devtools.build.lib.rules.python.PyCommon;
+import com.google.devtools.build.lib.rules.python.PythonConfiguration;
import com.google.devtools.build.lib.rules.python.PythonSemantics;
import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.util.FileTypeSet;
@@ -135,7 +136,7 @@ public class BazelPythonSemantics implements PythonSemantics {
BazelPythonConfiguration config = ruleContext.getFragment(BazelPythonConfiguration.class);
String pythonBinary = getPythonBinary(ruleContext, config);
- if (!ruleContext.getConfiguration().buildPythonZip()) {
+ if (!ruleContext.getFragment(PythonConfiguration.class).buildPythonZip()) {
ruleContext.registerAction(
new TemplateExpansionAction(
ruleContext.getActionOwner(),
@@ -225,7 +226,7 @@ public class BazelPythonSemantics implements PythonSemantics {
@Override
public void postInitBinary(RuleContext ruleContext, RunfilesSupport runfilesSupport,
PyCommon common) throws InterruptedException {
- if (ruleContext.getConfiguration().buildPythonZip()) {
+ if (ruleContext.getFragment(PythonConfiguration.class).buildPythonZip()) {
FilesToRunProvider zipper = ruleContext.getExecutablePrerequisite("$zipper", Mode.HOST);
Artifact executable = common.getExecutable();
if (!ruleContext.hasErrors()) {
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 81b4c564c3..8aad3cc53b 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
@@ -135,7 +135,7 @@ public final class PyCommon {
NestedSetBuilder<Artifact> filesToBuildBuilder =
NestedSetBuilder.<Artifact>stableOrder().addAll(srcs).add(executable);
- if (ruleContext.getConfiguration().buildPythonZip()) {
+ if (ruleContext.getFragment(PythonConfiguration.class).buildPythonZip()) {
filesToBuildBuilder.add(getPythonZipArtifact(executable));
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PythonConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/python/PythonConfiguration.java
index f950a585f4..74814cce04 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/python/PythonConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/python/PythonConfiguration.java
@@ -15,6 +15,8 @@ package com.google.devtools.build.lib.rules.python;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
+import com.google.devtools.build.lib.util.OS;
+import com.google.devtools.common.options.TriState;
/**
* The configuration fragment containing information about the various pieces of infrastructure
@@ -24,10 +26,13 @@ import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
public class PythonConfiguration extends BuildConfiguration.Fragment {
private final boolean ignorePythonVersionAttribute;
private final PythonVersion defaultPythonVersion;
+ private final TriState buildPythonZip;
- PythonConfiguration(PythonVersion pythonVersion, boolean ignorePythonVersionAttribute) {
+ PythonConfiguration(
+ PythonVersion pythonVersion, boolean ignorePythonVersionAttribute, TriState buildPythonZip) {
this.ignorePythonVersionAttribute = ignorePythonVersionAttribute;
this.defaultPythonVersion = pythonVersion;
+ this.buildPythonZip = buildPythonZip;
}
/**
@@ -44,5 +49,17 @@ public class PythonConfiguration extends BuildConfiguration.Fragment {
public String getOutputDirectoryName() {
return (defaultPythonVersion == PythonVersion.PY3) ? "py3" : null;
}
+
+ /** Returns whether to build the executable zip file for Python binaries. */
+ public boolean buildPythonZip() {
+ switch (buildPythonZip) {
+ case YES:
+ return true;
+ case NO:
+ return false;
+ default:
+ return OS.getCurrent() == OS.WINDOWS;
+ }
+ }
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PythonConfigurationLoader.java b/src/main/java/com/google/devtools/build/lib/rules/python/PythonConfigurationLoader.java
index d85c586412..3895240b1b 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/python/PythonConfigurationLoader.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/python/PythonConfigurationLoader.java
@@ -36,7 +36,8 @@ public class PythonConfigurationLoader implements ConfigurationFragmentFactory {
PythonOptions pythonOptions = buildOptions.get(PythonOptions.class);
boolean ignorePythonVersionAttribute = pythonOptions.forcePython != null;
PythonVersion pythonVersion = pythonOptions.getPythonVersion();
- return new PythonConfiguration(pythonVersion, ignorePythonVersionAttribute);
+ return new PythonConfiguration(
+ pythonVersion, ignorePythonVersionAttribute, pythonOptions.buildPythonZip);
}
@Override
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PythonOptions.java b/src/main/java/com/google/devtools/build/lib/rules/python/PythonOptions.java
index fa1b8f700e..517ab3dbfa 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/python/PythonOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/python/PythonOptions.java
@@ -18,6 +18,7 @@ import com.google.devtools.common.options.EnumConverter;
import com.google.devtools.common.options.Option;
import com.google.devtools.common.options.OptionDocumentationCategory;
import com.google.devtools.common.options.OptionEffectTag;
+import com.google.devtools.common.options.TriState;
/**
* Python-related command-line options.
@@ -35,6 +36,15 @@ public class PythonOptions extends FragmentOptions {
}
@Option(
+ name = "build_python_zip",
+ defaultValue = "auto",
+ documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
+ effectTags = {OptionEffectTag.UNKNOWN},
+ help = "Build python executable zip; on on Windows, off on other platforms"
+ )
+ public TriState buildPythonZip;
+
+ @Option(
name = "force_python",
defaultValue = "null",
category = "version",
@@ -70,6 +80,7 @@ public class PythonOptions extends FragmentOptions {
} else {
hostPythonOpts.forcePython = PythonVersion.PY2;
}
+ hostPythonOpts.buildPythonZip = buildPythonZip;
return hostPythonOpts;
}
}