aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2015-11-09 14:31:50 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-11-10 10:22:28 +0000
commit4171208f957b78638313219d1858c9a4f1263b1a (patch)
tree7a4706b5ce47393dd5f4bec441aa331ee178874b /src
parenta9dd72a7eda6dadf9448e68d4462aaebab429b89 (diff)
Description redacted.
-- MOS_MIGRATED_REVID=107379349
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/python/PrecompilePythonMode.java28
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/python/PyBinary.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/python/PyLibrary.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java7
5 files changed, 30 insertions, 15 deletions
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 ff70179531..abff076bb0 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
@@ -60,7 +60,7 @@ public class BazelPythonSemantics implements PythonSemantics {
@Override
public Collection<Artifact> precompiledPythonFiles(
RuleContext ruleContext, Collection<Artifact> sources, PyCommon common) {
- return ImmutableList.of();
+ return ImmutableList.copyOf(sources);
}
@Override
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PrecompilePythonMode.java b/src/main/java/com/google/devtools/build/lib/rules/python/PrecompilePythonMode.java
index bcb6f483f2..a65e9a6088 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/python/PrecompilePythonMode.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/python/PrecompilePythonMode.java
@@ -14,13 +14,25 @@
package com.google.devtools.build.lib.rules.python;
-/**
- * Enumerates the different modes of Python precompilation.
- *
- * <p>NONE denotes that no precompilation should take place, and PROTO causes
- * only the generated _pb/_pb2.py files to be precompiled. ALL compiles all
- * Python files.
- */
+/** Enumerates the different modes of Python precompilation. */
public enum PrecompilePythonMode {
- NONE, PROTO, ALL;
+ /** No Python precompilation should take place. */
+ NONE,
+
+ /** Only the _pb/_pb2.py files generated from protocol buffers should be precompiled. */
+ PROTO,
+
+ /** Compiles all Python files, but removes the .py sources from the runfiles. */
+ ONLY,
+
+ /** Compiles all Python files, and leaves the .py sources in the runfiles. */
+ ALL;
+
+ public boolean shouldPrecompileProtos() {
+ return this != NONE;
+ };
+
+ public boolean shouldPrecompilePythonSources() {
+ return this == ONLY || this == ALL;
+ };
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PyBinary.java b/src/main/java/com/google/devtools/build/lib/rules/python/PyBinary.java
index 63f6e0108f..01829b670f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/python/PyBinary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/python/PyBinary.java
@@ -56,8 +56,8 @@ public abstract class PyBinary implements RuleConfiguredTargetFactory {
CcLinkParamsStore ccLinkParamsStore = initializeCcLinkParamStore(ruleContext);
List<Artifact> srcs = common.validateSrcs();
- List<Artifact> allOutputs = new ArrayList<>(srcs);
- allOutputs.addAll(semantics.precompiledPythonFiles(ruleContext, srcs, common));
+ List<Artifact> allOutputs =
+ new ArrayList<>(semantics.precompiledPythonFiles(ruleContext, srcs, common));
common.initBinary(allOutputs);
semantics.validate(ruleContext, common);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PyLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/python/PyLibrary.java
index 202313f4d1..1de2be734d 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/python/PyLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/python/PyLibrary.java
@@ -50,8 +50,8 @@ public abstract class PyLibrary implements RuleConfiguredTargetFactory {
common.validatePackageName();
List<Artifact> srcs = common.validateSrcs();
- List<Artifact> allOutputs = new ArrayList<>(srcs);
- allOutputs.addAll(semantics.precompiledPythonFiles(ruleContext, srcs, common));
+ List<Artifact> allOutputs =
+ new ArrayList<>(semantics.precompiledPythonFiles(ruleContext, srcs, common));
NestedSet<Artifact> filesToBuild =
NestedSetBuilder.wrap(Order.STABLE_ORDER, allOutputs);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java b/src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java
index 2c70ef540a..b1102800c1 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java
@@ -36,6 +36,7 @@ import java.util.Set;
*/
public final class PythonUtils {
public static final PathFragment INIT_PY = new PathFragment("__init__.py");
+ public static final PathFragment INIT_PYC = new PathFragment("__init__.pyc");
private static final FileType REQUIRES_INIT_PY = FileType.of(".py", ".so", ".pyc");
@@ -52,7 +53,7 @@ public final class PythonUtils {
}
/**
- * Returns the set of empty __init__.py files to be added to a given set of files to allow
+ * Returns the set of empty __init__.py(c) files to be added to a given set of files to allow
* the Python runtime to find the <code>.py</code> and <code>.so</code> files present in the
* tree.
*/
@@ -66,7 +67,9 @@ public final class PythonUtils {
while (source.segmentCount() > 1) {
source = source.getParentDirectory();
PathFragment initpy = source.getRelative(INIT_PY);
- if (!manifestFiles.contains(initpy)) {
+ PathFragment initpyc = source.getRelative(INIT_PYC);
+
+ if (!manifestFiles.contains(initpy) && !manifestFiles.contains(initpyc)) {
result.add(initpy);
}
}