aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/android
diff options
context:
space:
mode:
authorGravatar Carmi Grushko <carmi@google.com>2017-02-14 01:32:22 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2017-02-14 14:22:49 +0000
commit03d1255df1805ed1e5f7512bf0336f71c595791b (patch)
tree42bade199e70570b2914dda73d1a9ec0cc00e479 /src/main/java/com/google/devtools/build/lib/rules/android
parente835f3b31a4e6bf617ff61400e7e5af5db579852 (diff)
-- PiperOrigin-RevId: 147416635 MOS_MIGRATED_REVID=147416635
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/android')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/DexArchiveAspect.java74
1 files changed, 16 insertions, 58 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/DexArchiveAspect.java b/src/main/java/com/google/devtools/build/lib/rules/android/DexArchiveAspect.java
index 5518692436..2557f50dd3 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/DexArchiveAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/DexArchiveAspect.java
@@ -16,6 +16,7 @@ package com.google.devtools.build.lib.rules.android;
import static com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition.HOST;
import static com.google.devtools.build.lib.packages.Attribute.attr;
import static com.google.devtools.build.lib.packages.BuildType.LABEL;
+import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
import static com.google.devtools.build.lib.packages.BuildType.TRISTATE;
import static com.google.devtools.build.lib.rules.android.AndroidCommon.getAndroidConfig;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
@@ -55,10 +56,6 @@ import com.google.devtools.build.lib.rules.java.JavaCommon;
import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider;
import com.google.devtools.build.lib.rules.java.JavaCompilationInfoProvider;
import com.google.devtools.build.lib.rules.java.JavaRuntimeJarProvider;
-import com.google.devtools.build.lib.rules.java.proto.JavaCompilationArgsAspectProvider;
-import com.google.devtools.build.lib.rules.java.proto.JavaLiteProtoAspect;
-import com.google.devtools.build.lib.rules.proto.ProtoLangToolchainProvider;
-import com.google.devtools.build.lib.rules.proto.ProtoSourcesProvider;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -105,9 +102,7 @@ public final class DexArchiveAspect extends NativeAspectClass implements Configu
/** Aspect-only label for desugaring executable, to avoid name clashes with labels on rules. */
private static final String ASPECT_DESUGAR_PREREQ = "$aspect_desugar";
private static final ImmutableList<String> TRANSITIVE_ATTRIBUTES =
- ImmutableList.of("deps", "exports", "runtime_deps",
- // To get from proto_library through proto_lang_toolchain rule to proto runtime library.
- JavaLiteProtoAspect.PROTO_TOOLCHAIN_ATTR, "runtime");
+ ImmutableList.of("deps", "exports", "runtime_deps");
private final String toolsRepository;
@@ -122,10 +117,6 @@ public final class DexArchiveAspect extends NativeAspectClass implements Configu
ImmutableList.of(
// We care about JavaRuntimeJarProvider, but rules don't advertise that provider.
ImmutableSet.<Class<?>>of(JavaCompilationArgsProvider.class),
- // For proto_library rules, where we care about JavaCompilationArgsAspectProvider.
- ImmutableSet.<Class<?>>of(ProtoSourcesProvider.class),
- // For proto_lang_toolchain rules, where we just want to get at their runtime deps.
- ImmutableSet.<Class<?>>of(ProtoLangToolchainProvider.class),
// Let this aspect "see through" alias targets until b/35213665 is fixed
ImmutableSet.<Class<?>>of(AliasProvider.class)))
// Parse labels since we don't have RuleDefinitionEnvironment.getLabel like in a rule
@@ -170,11 +161,11 @@ public final class DexArchiveAspect extends NativeAspectClass implements Configu
DexArchiveProvider.Builder dexArchives = new DexArchiveProvider.Builder()
.addTransitiveProviders(collectPrerequisites(ruleContext, DexArchiveProvider.class));
- Iterable<Artifact> runtimeJars = getProducedRuntimeJars(base, ruleContext);
- if (runtimeJars != null) {
- boolean basenameClash = checkBasenameClash(runtimeJars);
+ JavaRuntimeJarProvider jarProvider = base.getProvider(JavaRuntimeJarProvider.class);
+ if (jarProvider != null) {
+ boolean basenameClash = checkBasenameClash(jarProvider.getRuntimeJars());
Set<Set<String>> aspectDexopts = aspectDexopts(ruleContext);
- for (Artifact jar : runtimeJars) {
+ for (Artifact jar : jarProvider.getRuntimeJars()) {
for (Set<String> incrementalDexopts : aspectDexopts) {
// Since we're potentially dexing the same jar multiple times with different flags, we
// need to write unique artifacts for each flag combination. Here, it is convenient to
@@ -214,19 +205,13 @@ public final class DexArchiveAspect extends NativeAspectClass implements Configu
}
AndroidRuntimeJarProvider.Builder desugaredJars = new AndroidRuntimeJarProvider.Builder()
.addTransitiveProviders(collectPrerequisites(ruleContext, AndroidRuntimeJarProvider.class));
- if (isProtoLibrary(ruleContext)) {
- // TODO(b/33557068): Desugar protos if needed instead of assuming they don't need desugaring
- result.addProvider(desugaredJars.build());
- return Functions.identity();
- }
-
JavaRuntimeJarProvider jarProvider = base.getProvider(JavaRuntimeJarProvider.class);
if (jarProvider != null) {
// These are all transitive hjars of dependencies and hjar of the jar itself
- NestedSet<Artifact> compileTimeClasspath =
- getJavaCompilationArgsProvider(base, ruleContext)
- .getRecursiveJavaCompilationArgs()
- .getCompileTimeJars();
+ NestedSet<Artifact> compileTimeClasspath = base
+ .getProvider(JavaCompilationArgsProvider.class) // aspect definition requires this
+ .getRecursiveJavaCompilationArgs()
+ .getCompileTimeJars();
// For android_* targets we need to honor their bootclasspath (nicer in general to do so)
ImmutableList<Artifact> bootclasspath = getBootclasspath(base, ruleContext);
@@ -242,37 +227,10 @@ public final class DexArchiveAspect extends NativeAspectClass implements Configu
return Functions.forMap(newlyDesugared);
}
- private static Iterable<Artifact> getProducedRuntimeJars(ConfiguredTarget base,
- RuleContext ruleContext) {
- if (isProtoLibrary(ruleContext)) {
- JavaCompilationArgsAspectProvider javaProtos =
- base.getProvider(JavaCompilationArgsAspectProvider.class);
- if (javaProtos != null && !ruleContext.getPrerequisites("srcs", Mode.TARGET).isEmpty()) {
- return javaProtos.provider.getJavaCompilationArgs().getRuntimeJars();
- }
- } else {
- JavaRuntimeJarProvider jarProvider = base.getProvider(JavaRuntimeJarProvider.class);
- if (jarProvider != null) {
- return jarProvider.getRuntimeJars();
- }
+ private static boolean checkBasenameClash(ImmutableList<Artifact> artifacts) {
+ if (artifacts.size() <= 1) {
+ return false;
}
- return null;
- }
-
- private static JavaCompilationArgsProvider getJavaCompilationArgsProvider(ConfiguredTarget base,
- RuleContext ruleContext) {
- if (isProtoLibrary(ruleContext)) {
- return base.getProvider(JavaCompilationArgsAspectProvider.class).provider;
- } else {
- return base.getProvider(JavaCompilationArgsProvider.class);
- }
- }
-
- private static boolean isProtoLibrary(RuleContext ruleContext) {
- return "proto_library".equals(ruleContext.getRule().getRuleClass());
- }
-
- private static boolean checkBasenameClash(Iterable<Artifact> artifacts) {
HashSet<String> seen = new HashSet<>();
for (Artifact artifact : artifacts) {
if (!seen.add(artifact.getFilename())) {
@@ -286,7 +244,7 @@ public final class DexArchiveAspect extends NativeAspectClass implements Configu
RuleContext ruleContext, Class<T> classType) {
IterablesChain.Builder<T> result = IterablesChain.builder();
for (String attr : TRANSITIVE_ATTRIBUTES) {
- if (ruleContext.attributes().getAttributeType(attr) != null) {
+ if (ruleContext.getRule().getRuleClassObject().hasAttr(attr, LABEL_LIST)) {
result.add(ruleContext.getPrerequisites(attr, Mode.TARGET, classType));
}
}
@@ -325,8 +283,8 @@ public final class DexArchiveAspect extends NativeAspectClass implements Configu
}
/**
- * Desugars the given Jar using an executable prerequisite {@code "$desugar"}.
- * Rules calling this method must declare the appropriate prerequisite, similar to how
+ * Desugars the given Jar using an executable prerequisite {@code "$dexbuilder"}. Rules
+ * calling this method must declare the appropriate prerequisite, similar to how
* {@link #getDefinition} does it for {@link DexArchiveAspect} under a different name.
*
* <p>It's useful to have this action separately since callers need to look up classpath and