aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2017-04-05 19:40:35 +0000
committerGravatar Marcel Hlopko <hlopko@google.com>2017-04-06 11:00:27 +0200
commit459f1300ff234da7d79b1887bd08edb734f79970 (patch)
tree9dcee2da1f3f102298b583bab190facbce02786d /src/main/java/com/google/devtools/build/lib
parentd119f969a30945a1fc29a24a293f6873ff73960d (diff)
Add mechanism to trigger Python type-stripping via a tag.
RELNOTES: none PiperOrigin-RevId: 152291766
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/Attribute.java11
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/python/PyBinary.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/python/PythonSemantics.java3
4 files changed, 18 insertions, 4 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 e4b02626b4..ac6d574c93 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
@@ -24,6 +24,7 @@ import com.google.devtools.build.lib.analysis.FilesToRunProvider;
import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.Runfiles.Builder;
+import com.google.devtools.build.lib.analysis.RunfilesProvider;
import com.google.devtools.build.lib.analysis.RunfilesSupport;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
import com.google.devtools.build.lib.analysis.actions.ParameterFileWriteAction;
@@ -70,6 +71,11 @@ public class BazelPythonSemantics implements PythonSemantics {
}
@Override
+ public void collectDefaultRunfiles(RuleContext ruleContext, Builder builder) {
+ builder.addRunfiles(ruleContext, RunfilesProvider.DEFAULT_RUNFILES);
+ }
+
+ @Override
public InstrumentationSpec getCoverageInstrumentationSpec() {
return PYTHON_COLLECTION_SPEC;
}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java
index 8751696579..ca9547fb87 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/Attribute.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/Attribute.java
@@ -104,7 +104,8 @@ public final class Attribute implements Comparable<Attribute> {
@Override
public Aspect getAspect(Rule rule) {
- return Aspect.forNative(aspectClass, parametersExtractor.apply(rule));
+ AspectParameters params = parametersExtractor.apply(rule);
+ return params == null ? null : Aspect.forNative(aspectClass, params);
}
}
@@ -992,7 +993,8 @@ public final class Attribute implements Comparable<Attribute> {
* Asserts that a particular parameterized aspect probably needs to be computed for all direct
* dependencies through this attribute.
*
- * @param evaluator function that extracts aspect parameters from rule.
+ * @param evaluator function that extracts aspect parameters from rule. If it returns null,
+ * then the aspect will not be attached.
*/
public Builder<TYPE> aspect(
NativeAspectClass aspect, Function<Rule, AspectParameters> evaluator) {
@@ -2050,7 +2052,10 @@ public final class Attribute implements Comparable<Attribute> {
public ImmutableList<Aspect> getAspects(Rule rule) {
ImmutableList.Builder<Aspect> builder = ImmutableList.builder();
for (RuleAspect aspect : aspects) {
- builder.add(aspect.getAspect(rule));
+ Aspect a = aspect.getAspect(rule);
+ if (a != null) {
+ builder.add(a);
+ }
}
return builder.build();
}
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 a04a0eda11..74fdc2fcd8 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
@@ -125,7 +125,7 @@ public abstract class PyBinary implements RuleConfiguredTargetFactory {
} else {
builder.addTransitiveArtifacts(common.getFilesToBuild());
}
- builder.addRunfiles(ruleContext, RunfilesProvider.DEFAULT_RUNFILES);
+ semantics.collectDefaultRunfiles(ruleContext, builder);
builder.add(ruleContext, PythonRunfilesProvider.TO_RUNFILES);
builder.setEmptyFilesSupplier(PythonUtils.GET_INIT_PY_FILES);
semantics.collectRunfilesForBinary(ruleContext, builder, common);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PythonSemantics.java b/src/main/java/com/google/devtools/build/lib/rules/python/PythonSemantics.java
index 08fcb1b465..bbaaa8f423 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/python/PythonSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/python/PythonSemantics.java
@@ -45,6 +45,9 @@ public interface PythonSemantics {
void collectDefaultRunfilesForBinary(RuleContext ruleContext, Runfiles.Builder builder)
throws InterruptedException;
+ /** Collects a rule's default runfiles. */
+ void collectDefaultRunfiles(RuleContext ruleContext, Runfiles.Builder builder);
+
/**
* Returns the coverage instrumentation specification to be used in Python rules.
*/