diff options
author | 2017-04-04 14:54:14 +0000 | |
---|---|---|
committer | 2017-04-04 18:39:31 +0200 | |
commit | 0297702d9533142e6c326660f913899d25b89b5d (patch) | |
tree | 3dc2f7e79a783aa1d8a30d31e160971eafef0eed /src/main/java/com/google | |
parent | a00c6249a7dea381a384e13c336c61211ac83965 (diff) |
Remove jack support and make jack/jill attributes of android_sdk optional.
Closes https://github.com/bazelbuild/bazel/issues/1391.
RELNOTES: Removed --experimental_use_jack_for_dexing and libname.jack output of
android_library.
PiperOrigin-RevId: 152131075
Diffstat (limited to 'src/main/java/com/google')
12 files changed, 28 insertions, 1355 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java index 4015a8ff31..e821648cc4 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java @@ -93,7 +93,6 @@ import com.google.devtools.build.lib.rules.android.AndroidNeverlinkAspect; import com.google.devtools.build.lib.rules.android.AndroidRuleClasses; import com.google.devtools.build.lib.rules.android.AndroidSkylarkCommon; import com.google.devtools.build.lib.rules.android.DexArchiveAspect; -import com.google.devtools.build.lib.rules.android.JackAspect; import com.google.devtools.build.lib.rules.apple.AppleCommandLineOptions; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; import com.google.devtools.build.lib.rules.apple.AppleToolchain; @@ -582,10 +581,8 @@ public class BazelRuleClassProvider { AndroidNeverlinkAspect androidNeverlinkAspect = new AndroidNeverlinkAspect(); DexArchiveAspect dexArchiveAspect = new DexArchiveAspect(toolsRepository); - JackAspect jackAspect = new JackAspect(toolsRepository); builder.addNativeAspectClass(androidNeverlinkAspect); builder.addNativeAspectClass(dexArchiveAspect); - builder.addNativeAspectClass(jackAspect); builder.addRuleDefinition(new AndroidRuleClasses.AndroidSdkRule()); builder.addRuleDefinition(new BazelAndroidToolsDefaultsJarRule()); @@ -594,9 +591,9 @@ public class BazelRuleClassProvider { builder.addRuleDefinition(new AndroidRuleClasses.AndroidResourceSupportRule()); builder.addRuleDefinition( new AndroidRuleClasses.AndroidBinaryBaseRule( - androidNeverlinkAspect, dexArchiveAspect, jackAspect)); + androidNeverlinkAspect, dexArchiveAspect)); builder.addRuleDefinition(new AndroidBinaryOnlyRule()); - builder.addRuleDefinition(new AndroidLibraryBaseRule(androidNeverlinkAspect, jackAspect)); + builder.addRuleDefinition(new AndroidLibraryBaseRule(androidNeverlinkAspect)); builder.addRuleDefinition(new BazelAndroidLibraryRule()); builder.addRuleDefinition(new BazelAndroidBinaryRule()); builder.addRuleDefinition(new AarImportBaseRule()); diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java index bc6d3e2603..8c9887d365 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java @@ -493,19 +493,17 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory { Artifact jarToDex = proguardOutput.getOutputJar(); DexingOutput dexingOutput = - shouldDexWithJack(ruleContext) - ? dexWithJack(ruleContext, androidCommon, proguardSpecs) - : dex( - ruleContext, - androidSemantics, - binaryJar, - jarToDex, - isBinaryJarFiltered, - androidCommon, - resourceApk.getMainDexProguardConfig(), - resourceClasses, - derivedJarFunction, - proguardOutputMap); + dex( + ruleContext, + androidSemantics, + binaryJar, + jarToDex, + isBinaryJarFiltered, + androidCommon, + resourceApk.getMainDexProguardConfig(), + resourceClasses, + derivedJarFunction, + proguardOutputMap); NestedSet<Artifact> nativeLibsZips = AndroidCommon.collectTransitiveNativeLibsZips(ruleContext).build(); @@ -1194,23 +1192,6 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory { } } - static boolean shouldDexWithJack(RuleContext ruleContext) { - return ruleContext - .getFragment(AndroidConfiguration.class) - .isJackUsedForDexing(); - } - - static DexingOutput dexWithJack( - RuleContext ruleContext, AndroidCommon androidCommon, ImmutableList<Artifact> proguardSpecs) { - Artifact classesDexZip = - androidCommon.compileDexWithJack( - getMultidexMode(ruleContext), - Optional.fromNullable( - ruleContext.getPrerequisiteArtifact("main_dex_list", Mode.TARGET)), - proguardSpecs); - return new DexingOutput(classesDexZip, null, ImmutableList.of(classesDexZip)); - } - /** Creates one or more classes.dex files that correspond to {@code proguardedJar}. */ private static DexingOutput dex( RuleContext ruleContext, diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java index 20e34940d1..c917b5dd06 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java @@ -13,7 +13,6 @@ // limitations under the License. package com.google.devtools.build.lib.rules.android; -import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.actions.Artifact; @@ -40,7 +39,6 @@ import com.google.devtools.build.lib.packages.AggregatingAttributeMapper; import com.google.devtools.build.lib.packages.AttributeMap; import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.Rule; -import com.google.devtools.build.lib.rules.android.AndroidRuleClasses.MultidexMode; import com.google.devtools.build.lib.rules.android.ResourceContainer.ResourceType; import com.google.devtools.build.lib.rules.cpp.CcLinkParams; import com.google.devtools.build.lib.rules.cpp.CcLinkParamsProvider; @@ -119,7 +117,6 @@ public class AndroidCommon { NestedSetBuilder.emptySet(Order.STABLE_ORDER); private JavaCompilationArgs javaCompilationArgs = JavaCompilationArgs.EMPTY_ARGS; private JavaCompilationArgs recursiveJavaCompilationArgs = JavaCompilationArgs.EMPTY_ARGS; - private JackCompilationHelper jackCompilationHelper; private NestedSet<Artifact> jarsProducedForRuntime; private Artifact classJar; private Artifact iJar; @@ -374,11 +371,6 @@ public class AndroidCommon { return transitiveAarNativeLibs; } - Artifact compileDexWithJack( - MultidexMode mode, Optional<Artifact> mainDexList, Collection<Artifact> proguardSpecs) { - return jackCompilationHelper.compileAsDex(mode, mainDexList, proguardSpecs); - } - private void compileResources( JavaSemantics javaSemantics, ResourceApk resourceApk, @@ -575,11 +567,6 @@ public class AndroidCommon { } } - jackCompilationHelper = initJack(helper.getAttributes()); - if (ruleContext.hasErrors()) { - return null; - } - initJava( javaSemantics, helper, @@ -614,32 +601,6 @@ public class AndroidCommon { return helper; } - JackCompilationHelper initJack(JavaTargetAttributes attributes) throws InterruptedException { - AndroidSdkProvider sdk = AndroidSdkProvider.fromRuleContext(ruleContext); - return new JackCompilationHelper.Builder() - // blaze infrastructure - .setRuleContext(ruleContext) - // configuration - .setOutputArtifact( - ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_LIBRARY_JACK_FILE)) - // tools - .setJackBinary(sdk.getJack()) - .setJillBinary(sdk.getJill()) - .setResourceExtractorBinary(sdk.getResourceExtractor()) - .setJackBaseClasspath(sdk.getAndroidBaseClasspathForJack()) - // sources - .addJavaSources(attributes.getSourceFiles()) - .addSourceJars(attributes.getSourceJars()) - .addResources(attributes.getResources()) - .addResourceJars(attributes.getResourceJars()) - .addProcessorNames(attributes.getProcessorNames()) - .addProcessorClasspathJars(attributes.getProcessorPath()) - .addExports(JavaCommon.getExports(ruleContext)) - .addClasspathDeps(javaCommon.targetsTreatedAsDeps(ClasspathType.COMPILE_ONLY)) - .addRuntimeDeps(javaCommon.targetsTreatedAsDeps(ClasspathType.RUNTIME_ONLY)) - .build(); - } - private void initJava( JavaSemantics javaSemantics, JavaCompilationHelper helper, @@ -790,11 +751,6 @@ public class AndroidCommon { zipAlignedApk, apksUnderTest)) .add(JavaCompilationArgsProvider.class, compilationArgsProvider) - .add( - JackLibraryProvider.class, - asNeverLink - ? jackCompilationHelper.compileAsNeverlinkLibrary() - : jackCompilationHelper.compileAsLibrary()) .addSkylarkTransitiveInfo(AndroidSkylarkApiProvider.NAME, new AndroidSkylarkApiProvider()) .addOutputGroup( OutputGroupProvider.HIDDEN_TOP_LEVEL, collectHiddenTopLevelArtifacts(ruleContext)) diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java index 1f4510161c..70ec909825 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java @@ -261,18 +261,6 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { + "android_binary rules.") public List<String> fatApkCpus; - @Option(name = "experimental_android_use_jack_for_dexing", - defaultValue = "false", - category = "semantics", - help = "Switches to the Jack and Jill toolchain for dexing instead of javac and dx.") - public boolean useJackForDexing; - - @Option(name = "experimental_android_jack_sanity_checks", - defaultValue = "false", - category = "semantics", - help = "Enables sanity checks for Jack and Jill compilation.") - public boolean jackSanityChecks; - // For desugaring lambdas when compiling Java 8 sources. Do not use on the command line. // The idea is that once this option works, we'll flip the default value in a config file, then // once it is proven that it works, remove it from Bazel and said config file. @@ -285,9 +273,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { @Option(name = "incremental_dexing", defaultValue = "false", category = "semantics", - implicitRequirements = "--noexperimental_android_use_jack_for_dexing", - help = "Does most of the work for dexing separately for each Jar file. Incompatible with " - + "Jack and Jill.") + help = "Does most of the work for dexing separately for each Jar file.") public boolean incrementalDexing; @Option(name = "host_incremental_dexing", @@ -510,8 +496,6 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { private final String cpu; private final boolean incrementalNativeLibs; private final ConfigurationDistinguisher configurationDistinguisher; - private final boolean useJackForDexing; - private final boolean jackSanityChecks; private final ImmutableSet<AndroidBinaryType> incrementalDexingBinaries; private final boolean incrementalDexingForLiteProtos; private final boolean incrementalDexingErrorOnMissedJars; @@ -535,8 +519,6 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { this.incrementalNativeLibs = options.incrementalNativeLibs; this.cpu = options.cpu; this.configurationDistinguisher = options.configurationDistinguisher; - this.useJackForDexing = options.useJackForDexing; - this.jackSanityChecks = options.jackSanityChecks; if (options.incrementalDexing) { this.incrementalDexingBinaries = ImmutableSet.copyOf(options.incrementalDexingBinaries); } else { @@ -571,31 +553,15 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { return sdk; } - /** - * Returns true if Jack should be used in place of javac/dx for Android compilation. - */ - public boolean isJackUsedForDexing() { - return useJackForDexing; - } - - /** - * Returns true if Jack sanity checks should be enabled. Only relevant if isJackUsedForDexing() - * also returns true. - */ - public boolean isJackSanityChecked() { - return jackSanityChecks; - } - public boolean useIncrementalNativeLibs() { return incrementalNativeLibs; } /** - * Returns when to use incremental dexing using {@link DexArchiveProvider}. Note this is disabled - * if {@link #isJackUsedForDexing()}. + * Returns when to use incremental dexing using {@link DexArchiveProvider}. */ public ImmutableSet<AndroidBinaryType> getIncrementalDexingBinaries() { - return isJackUsedForDexing() ? ImmutableSet.<AndroidBinaryType>of() : incrementalDexingBinaries; + return incrementalDexingBinaries; } /** diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibraryBaseRule.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibraryBaseRule.java index bf91e64c95..a8a589bc6c 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibraryBaseRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibraryBaseRule.java @@ -37,12 +37,9 @@ import com.google.devtools.build.lib.util.FileTypeSet; */ public final class AndroidLibraryBaseRule implements RuleDefinition { private final AndroidNeverlinkAspect androidNeverlinkAspect; - private final JackAspect jackAspect; - public AndroidLibraryBaseRule(AndroidNeverlinkAspect androidNeverlinkAspect, - JackAspect jackAspect) { + public AndroidLibraryBaseRule(AndroidNeverlinkAspect androidNeverlinkAspect) { this.androidNeverlinkAspect = androidNeverlinkAspect; - this.jackAspect = jackAspect; } @Override @@ -83,7 +80,6 @@ public final class AndroidLibraryBaseRule implements RuleDefinition { .override(builder.copy("deps") .allowedRuleClasses(AndroidRuleClasses.ALLOWED_DEPENDENCIES) .allowedFileTypes() - .aspect(jackAspect) .aspect(androidNeverlinkAspect)) /* <!-- #BLAZE_RULE(android_library).ATTRIBUTE(exports) --> The closure of all rules reached via <code>exports</code> attributes @@ -94,7 +90,6 @@ public final class AndroidLibraryBaseRule implements RuleDefinition { .add(attr("exports", LABEL_LIST) .allowedRuleClasses(AndroidRuleClasses.ALLOWED_DEPENDENCIES) .allowedFileTypes(/*May not have files in exports!*/) - .aspect(jackAspect) .aspect(androidNeverlinkAspect)) /* <!-- #BLAZE_RULE(android_library).ATTRIBUTE(exports_manifest) --> Whether to export manifest entries to <code>android_binary</code> targets diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java index 6e2ec6e798..7a05c36d0c 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java @@ -55,7 +55,6 @@ import com.google.devtools.build.lib.skylarkinterface.SkylarkValue; import com.google.devtools.build.lib.syntax.Printer; import com.google.devtools.build.lib.util.FileType; import java.util.List; -import javax.annotation.Nullable; /** * Rule definitions for Android rules. @@ -73,8 +72,6 @@ public final class AndroidRuleClasses { */ public static final SafeImplicitOutputsFunction ANDROID_LIBRARY_CLASS_JAR = JavaSemantics.JAVA_LIBRARY_CLASS_JAR; - public static final SafeImplicitOutputsFunction ANDROID_LIBRARY_JACK_FILE = - fromTemplates("lib%{name}.jack"); public static final SafeImplicitOutputsFunction ANDROID_LIBRARY_AAR = fromTemplates("%{name}.aar"); /** @@ -333,7 +330,6 @@ public final class AndroidRuleClasses { implicitOutputs.add( AndroidRuleClasses.ANDROID_LIBRARY_CLASS_JAR, AndroidRuleClasses.ANDROID_LIBRARY_SOURCE_JAR, - AndroidRuleClasses.ANDROID_LIBRARY_JACK_FILE, AndroidRuleClasses.ANDROID_LIBRARY_AAR); if (LocalResourceContainer.definesAndroidResources(attributes)) { @@ -381,14 +377,12 @@ public final class AndroidRuleClasses { attr("jack", LABEL) .cfg(HOST) .allowedFileTypes(ANY_FILE) - .exec() - .mandatory()) + .exec()) .add( attr("jill", LABEL) .cfg(HOST) .allowedFileTypes(ANY_FILE) - .exec() - .mandatory()) + .exec()) .add( attr("resource_extractor", LABEL) .cfg(HOST) @@ -569,14 +563,11 @@ public final class AndroidRuleClasses { private final AndroidNeverlinkAspect androidNeverlinkAspect; private final DexArchiveAspect dexArchiveAspect; - private final JackAspect jackAspect; - public AndroidBinaryBaseRule(AndroidNeverlinkAspect androidNeverlinkAspect, - DexArchiveAspect dexArchiveAspect, - JackAspect jackAspect) { + public AndroidBinaryBaseRule( + AndroidNeverlinkAspect androidNeverlinkAspect, DexArchiveAspect dexArchiveAspect) { this.androidNeverlinkAspect = androidNeverlinkAspect; this.dexArchiveAspect = dexArchiveAspect; - this.jackAspect = jackAspect; } @Override @@ -615,8 +606,7 @@ public final class AndroidRuleClasses { .allowedRuleClasses(ALLOWED_DEPENDENCIES) .allowedFileTypes() .aspect(androidNeverlinkAspect) - .aspect(dexArchiveAspect, DexArchiveAspect.PARAM_EXTRACTOR) - .aspect(jackAspect)) + .aspect(dexArchiveAspect, DexArchiveAspect.PARAM_EXTRACTOR)) .add( attr("feature_of", LABEL) .allowedRuleClasses("android_binary") @@ -827,19 +817,13 @@ public final class AndroidRuleClasses { */ public static enum MultidexMode { // Build dexes with multidex, assuming native platform support for multidex. - NATIVE("native"), + NATIVE, // Build dexes with multidex and implement support at the application level. - LEGACY("legacy"), + LEGACY, // Build dexes with multidex, main dex list needs to be manually specified. - MANUAL_MAIN_DEX("legacy"), + MANUAL_MAIN_DEX, // Build all dex code into a single classes.dex file. - OFF("none"); - - @Nullable private final String jackFlagValue; - - private MultidexMode(String jackFlagValue) { - this.jackFlagValue = jackFlagValue; - } + OFF; /** * Returns the attribute value that specifies this mode. @@ -849,26 +833,6 @@ public final class AndroidRuleClasses { } /** - * Returns whether or not this multidex mode can be passed to Jack. - */ - public boolean isSupportedByJack() { - return jackFlagValue != null; - } - - /** - * Returns the value that should be passed to Jack's --multi-dex flag. - * - * @throws UnsupportedOperationException if the dex mode is not supported by Jack - * ({@link #isSupportedByJack()} returns false) - */ - public String getJackFlagValue() { - if (!isSupportedByJack()) { - throw new UnsupportedOperationException(); - } - return jackFlagValue; - } - - /** * Returns the name of the output dex classes file. In multidex mode, this is an archive * of (possibly) multiple files. */ diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdk.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdk.java index ca9d8460f0..dc7164fb87 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdk.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdk.java @@ -15,7 +15,6 @@ package com.google.devtools.build.lib.rules.android; import com.android.repository.Revision; import com.google.common.base.Strings; -import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.FilesToRunProvider; @@ -24,16 +23,12 @@ import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.RunfilesProvider; import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; -import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.collect.nestedset.Order; import com.google.devtools.build.lib.packages.AggregatingAttributeMapper; import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory; -import com.google.devtools.build.lib.rules.java.JavaCompilationHelper; import com.google.devtools.build.lib.rules.java.JavaConfiguration; -import com.google.devtools.build.lib.rules.java.JavaToolchainProvider; import com.google.devtools.build.lib.syntax.Type; -import java.util.Collection; /** * Implementation of the {@code android_sdk} rule. @@ -74,8 +69,6 @@ public class AndroidSdk implements RuleConfiguredTargetFactory { FilesToRunProvider mainDexListCreator = ruleContext.getExecutablePrerequisite( "main_dex_list_creator", Mode.HOST); FilesToRunProvider zipalign = ruleContext.getExecutablePrerequisite("zipalign", Mode.HOST); - FilesToRunProvider jack = ruleContext.getExecutablePrerequisite("jack", Mode.HOST); - FilesToRunProvider jill = ruleContext.getExecutablePrerequisite("jill", Mode.HOST); FilesToRunProvider resourceExtractor = ruleContext.getExecutablePrerequisite("resource_extractor", Mode.HOST); Artifact frameworkAidl = ruleContext.getPrerequisiteArtifact("framework_aidl", Mode.HOST); @@ -83,20 +76,6 @@ public class AndroidSdk implements RuleConfiguredTargetFactory { Artifact androidJar = ruleContext.getPrerequisiteArtifact("android_jar", Mode.HOST); Artifact shrinkedAndroidJar = ruleContext.getPrerequisiteArtifact("shrinked_android_jar", Mode.HOST); - // Because all Jack actions using this android_sdk will need Jack versions of the Android and - // Java classpaths, pre-translate the jars for Android and Java targets here. (They will only - // be run if needed, as usual for Bazel.) - NestedSet<Artifact> androidBaseClasspathForJack = - convertClasspathJarsToJack( - ruleContext, jack, jill, resourceExtractor, ImmutableList.of(androidJar)); - NestedSet<Artifact> javaBaseClasspathForJack = - convertClasspathJarsToJack( - ruleContext, - jack, - jill, - resourceExtractor, - JavaCompilationHelper.getBootClasspath( - JavaToolchainProvider.fromRuleContext(ruleContext))); Artifact annotationsJar = ruleContext.getPrerequisiteArtifact("annotations_jar", Mode.HOST); Artifact mainDexClasses = ruleContext.getPrerequisiteArtifact("main_dex_classes", Mode.HOST); @@ -105,7 +84,7 @@ public class AndroidSdk implements RuleConfiguredTargetFactory { } return new RuleConfiguredTargetBuilder(ruleContext) - .add( + .addProvider( AndroidSdkProvider.class, AndroidSdkProvider.create( buildToolsVersion, @@ -114,8 +93,6 @@ public class AndroidSdk implements RuleConfiguredTargetFactory { aidlLib, androidJar, shrinkedAndroidJar, - androidBaseClasspathForJack, - javaBaseClasspathForJack, annotationsJar, mainDexClasses, adb, @@ -127,34 +104,9 @@ public class AndroidSdk implements RuleConfiguredTargetFactory { apkSigner, proguard, zipalign, - jack, - jill, resourceExtractor)) - .add(RunfilesProvider.class, RunfilesProvider.EMPTY) + .addProvider(RunfilesProvider.class, RunfilesProvider.EMPTY) .setFilesToBuild(NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER)) .build(); } - - private NestedSet<Artifact> convertClasspathJarsToJack( - RuleContext ruleContext, - FilesToRunProvider jack, - FilesToRunProvider jill, - FilesToRunProvider resourceExtractor, - Collection<Artifact> jars) { - return new JackCompilationHelper.Builder() - // bazel infrastructure - .setRuleContext(ruleContext) - // configuration - .setTolerant() - // tools - .setJackBinary(jack) - .setJillBinary(jill) - .setResourceExtractorBinary(resourceExtractor) - .setJackBaseClasspath(NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER)) - // sources - .addCompiledJars(jars) - .build() - .compileAsLibrary() - .getTransitiveJackClasspathLibraries(); - } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdkProvider.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdkProvider.java index c01545dece..982b7e2073 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdkProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdkProvider.java @@ -20,7 +20,6 @@ import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; -import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import javax.annotation.Nullable; @@ -36,8 +35,6 @@ public abstract class AndroidSdkProvider implements TransitiveInfoProvider { @Nullable TransitiveInfoCollection aidlLib, Artifact androidJar, Artifact shrinkedAndroidJar, - NestedSet<Artifact> androidBaseClasspathForJack, - NestedSet<Artifact> javaBaseClasspathForJack, Artifact annotationsJar, Artifact mainDexClasses, FilesToRunProvider adb, @@ -49,8 +46,6 @@ public abstract class AndroidSdkProvider implements TransitiveInfoProvider { FilesToRunProvider apkSigner, FilesToRunProvider proguard, FilesToRunProvider zipalign, - FilesToRunProvider jack, - FilesToRunProvider jill, FilesToRunProvider resourceExtractor) { return new AutoValue_AndroidSdkProvider( @@ -60,8 +55,6 @@ public abstract class AndroidSdkProvider implements TransitiveInfoProvider { aidlLib, androidJar, shrinkedAndroidJar, - androidBaseClasspathForJack, - javaBaseClasspathForJack, annotationsJar, mainDexClasses, adb, @@ -73,8 +66,6 @@ public abstract class AndroidSdkProvider implements TransitiveInfoProvider { apkSigner, proguard, zipalign, - jack, - jill, resourceExtractor); } @@ -118,18 +109,6 @@ public abstract class AndroidSdkProvider implements TransitiveInfoProvider { public abstract Artifact getShrinkedAndroidJar(); - /** - * Returns the set of jack files to be used as a base classpath for jack compilation of Android - * rules, typically a Jack translation of the jar returned by {@link getAndroidJar}. - */ - public abstract NestedSet<Artifact> getAndroidBaseClasspathForJack(); - - /** - * Returns the set of jack files to be used as a base classpath for jack compilation of Java - * rules, typically a Jack translation of the jars in the Java bootclasspath. - */ - public abstract NestedSet<Artifact> getJavaBaseClasspathForJack(); - public abstract Artifact getAnnotationsJar(); public abstract Artifact getMainDexClasses(); @@ -153,10 +132,6 @@ public abstract class AndroidSdkProvider implements TransitiveInfoProvider { public abstract FilesToRunProvider getZipalign(); - public abstract FilesToRunProvider getJack(); - - public abstract FilesToRunProvider getJill(); - public abstract FilesToRunProvider getResourceExtractor(); AndroidSdkProvider() {} diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ApkManifestAction.java b/src/main/java/com/google/devtools/build/lib/rules/android/ApkManifestAction.java index f6a8fbafd8..e8753ce543 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/ApkManifestAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/ApkManifestAction.java @@ -53,8 +53,6 @@ public final class ApkManifestAction extends AbstractFileWriteAction { .add(sdk.getAnnotationsJar()) .add(sdk.getDx().getExecutable()) .add(sdk.getFrameworkAidl()) - .add(sdk.getJack().getExecutable()) - .add(sdk.getJill().getExecutable()) .add(sdk.getMainDexClasses()) .add(sdk.getMainDexListCreator().getExecutable()) .add(sdk.getProguard().getExecutable()) @@ -240,8 +238,6 @@ public final class ApkManifestAction extends AbstractFileWriteAction { sdkProto.setAnnotationsJar(getArtifactPath(sdk.getAnnotationsJar())); sdkProto.setDx(getArtifactPath(sdk.getDx())); sdkProto.setFrameworkAidl(getArtifactPath(sdk.getFrameworkAidl())); - sdkProto.setJack(getArtifactPath(sdk.getJack())); - sdkProto.setJill(getArtifactPath(sdk.getJill())); sdkProto.setMainDexClasses(getArtifactPath(sdk.getMainDexClasses())); sdkProto.setMainDexListCreator(getArtifactPath(sdk.getMainDexListCreator())); sdkProto.setProguard(getArtifactPath(sdk.getProguard())); diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/JackAspect.java b/src/main/java/com/google/devtools/build/lib/rules/android/JackAspect.java deleted file mode 100644 index 877da92602..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/android/JackAspect.java +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright 2015 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package com.google.devtools.build.lib.rules.android; - -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 com.google.common.collect.ImmutableList; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.analysis.ConfiguredAspect; -import com.google.devtools.build.lib.analysis.ConfiguredAspectFactory; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; -import com.google.devtools.build.lib.analysis.RuleContext; -import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; -import com.google.devtools.build.lib.cmdline.Label; -import com.google.devtools.build.lib.cmdline.LabelSyntaxException; -import com.google.devtools.build.lib.packages.AspectDefinition; -import com.google.devtools.build.lib.packages.AspectParameters; -import com.google.devtools.build.lib.packages.NativeAspectClass; -import com.google.devtools.build.lib.rules.android.AndroidRuleClasses.AndroidSdkLabel; -import com.google.devtools.build.lib.rules.java.JavaCommon; -import com.google.devtools.build.lib.rules.java.JavaSourceInfoProvider; -import com.google.devtools.build.lib.vfs.PathFragment; -import java.util.List; - -/** Aspect to provide Jack support to rules which have java sources. */ -public final class JackAspect extends NativeAspectClass implements ConfiguredAspectFactory { - public static final String NAME = "JackAspect"; - private final String toolsRepository; - - /** - * Creates a JackAspect using the provided tools repository path. - * - * @param toolsRepository the path to the tools repository - */ - public JackAspect(String toolsRepository) { - this.toolsRepository = toolsRepository; - } - - @Override - public AspectDefinition getDefinition(AspectParameters params) { - Label androidSdk; - try { - androidSdk = Label.parseAbsolute(toolsRepository + AndroidRuleClasses.DEFAULT_SDK); - } catch (LabelSyntaxException e) { - throw new IllegalStateException(e); - } - - return new AspectDefinition.Builder(this) - .requireProviders(JavaSourceInfoProvider.class) - .add(attr(":android_sdk", LABEL) - .allowedRuleClasses("android_sdk") - .value(new AndroidSdkLabel(androidSdk))) - .propagateAlongAttribute("deps") - .propagateAlongAttribute("exports") - .propagateAlongAttribute("runtime_deps") - .requiresConfigurationFragments(AndroidConfiguration.class) - .build(); - } - - @Override - public ConfiguredAspect create( - ConfiguredTarget base, RuleContext ruleContext, AspectParameters params) { - if (base.getProvider(JackLibraryProvider.class) != null) { - return new ConfiguredAspect.Builder(this, params, ruleContext).build(); - } - JavaSourceInfoProvider sourceProvider = base.getProvider(JavaSourceInfoProvider.class); - PathFragment rulePath = ruleContext.getLabel().toPathFragment(); - PathFragment jackLibraryPath = rulePath.replaceName("lib" + rulePath.getBaseName() + ".jack"); - Artifact jackLibraryOutput = - ruleContext - .getAnalysisEnvironment() - .getDerivedArtifact(jackLibraryPath, ruleContext.getBinOrGenfilesDirectory()); - if (!AndroidSdkProvider.verifyPresence(ruleContext)) { - return null; - } - AndroidSdkProvider androidSdk = AndroidSdkProvider.fromRuleContext(ruleContext); - JackCompilationHelper jackHelper = - new JackCompilationHelper.Builder() - // blaze infrastructure - .setRuleContext(ruleContext) - // configuration - .setOutputArtifact(jackLibraryOutput) - // tools - .setJackBinary(androidSdk.getJack()) - .setJillBinary(androidSdk.getJill()) - .setResourceExtractorBinary(androidSdk.getResourceExtractor()) - .setJackBaseClasspath(androidSdk.getJavaBaseClasspathForJack()) - // sources - .addJavaSources(sourceProvider.getSourceFiles()) - .addSourceJars(sourceProvider.getSourceJars()) - .addCompiledJars(sourceProvider.getJarFiles()) - .addResources(sourceProvider.getResources()) - .addProcessorNames(sourceProvider.getProcessorNames()) - .addProcessorClasspathJars(sourceProvider.getProcessorPath()) - // dependencies - .addExports(getPotentialDependency(ruleContext, "exports")) - .addDeps(getPotentialDependency(ruleContext, "deps")) - .addRuntimeDeps(getPotentialDependency(ruleContext, "runtime_deps")) - .build(); - JackLibraryProvider result = - JavaCommon.isNeverLink(ruleContext) - ? jackHelper.compileAsNeverlinkLibrary() - : jackHelper.compileAsLibrary(); - return new ConfiguredAspect.Builder(this, params, ruleContext).addProvider(result).build(); - } - - /** Gets a list of targets on the given LABEL_LIST attribute if it exists, else an empty list. */ - private static List<? extends TransitiveInfoCollection> getPotentialDependency( - RuleContext context, String attribute) { - if (!context.getRule().getRuleClassObject().hasAttr(attribute, LABEL_LIST)) { - return ImmutableList.of(); - } - return context.getPrerequisites(attribute, Mode.TARGET); - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/JackCompilationHelper.java b/src/main/java/com/google/devtools/build/lib/rules/android/JackCompilationHelper.java deleted file mode 100644 index efc8da71c8..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/android/JackCompilationHelper.java +++ /dev/null @@ -1,900 +0,0 @@ -// Copyright 2015 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package com.google.devtools.build.lib.rules.android; - -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.base.Optional; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.analysis.FileProvider; -import com.google.devtools.build.lib.analysis.FilesToRunProvider; -import com.google.devtools.build.lib.analysis.RuleContext; -import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; -import com.google.devtools.build.lib.analysis.actions.CustomCommandLine; -import com.google.devtools.build.lib.analysis.actions.SpawnAction; -import com.google.devtools.build.lib.collect.nestedset.NestedSet; -import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; -import com.google.devtools.build.lib.collect.nestedset.Order; -import com.google.devtools.build.lib.rules.android.AndroidRuleClasses.MultidexMode; -import com.google.devtools.build.lib.rules.java.JavaSemantics; -import com.google.devtools.build.lib.util.FileType; -import com.google.devtools.build.lib.util.Preconditions; -import com.google.devtools.build.lib.vfs.FileSystemUtils; -import com.google.devtools.build.lib.vfs.PathFragment; -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Map.Entry; -import javax.annotation.Nullable; - -/** - * Builds Jack actions for a Java or Android target. - * - * <p>Jack is the new Android toolchain which integrates proguard-compatible code minification - * et al. and has an intermediate library format to front-load the dexing work. - * - * @see <a href="http://tools.android.com/tech-docs/jackandjill">Jack documentation</a> - * @see JackLibraryProvider - */ -public final class JackCompilationHelper { - - private static final String PARTIAL_JACK_DIRECTORY = "_jill"; - - private static final String JACK_DIRECTORY = "_jack"; - - /** Filetype for the intermediate library created by Jack. */ - public static final FileType JACK_LIBRARY_TYPE = FileType.of(".jack"); - - /** Flag to indicate that the next argument is a Jack property. */ - static final String JACK_PROPERTY = "-D"; - /** Flag to indicate that resource conflicts should be resolved by taking the first element. */ - static final String PROPERTY_KEEP_FIRST_RESOURCE = "jack.import.resource.policy=keep-first"; - /** Flag to indicate that type conflicts should be resolved by taking the first element. */ - static final String PROPERTY_KEEP_FIRST_TYPE = "jack.import.type.policy=keep-first"; - /** Flag to turn on/off sanity checks in Jack. */ - static final String SANITY_CHECKS = "--sanity-checks"; - /** Value of the sanity checks flag which disables sanity checks. */ - static final String SANITY_CHECKS_OFF = "off"; - /** Value of the sanity checks flag which enables sanity checks. */ - static final String SANITY_CHECKS_ON = "on"; - /** Flag to enable tolerant mode in Jill, for compiling special jars (e.g., bootclasspath). */ - static final String TOLERANT = "--tolerant"; - - /** Flag to indicate the classpath of Jack libraries, separated by semicolons. */ - static final String CLASSPATH = "-cp"; - /** Flag to load a Jack library into the Jack compiler so it will be part of the output. */ - static final String IMPORT_JACK_LIBRARY = "--import"; - /** Flag to import a zip file of Java sources into a Jack library. */ - static final String IMPORT_SOURCE_ZIP = "--import-source-zip"; - /** Flag to import a single file into a Jack library's resources. */ - static final String IMPORT_RESOURCE_FILE = "--import-resource-file"; - /** Flag to add a zip file full of resources to the Jack library. */ - static final String IMPORT_RESOURCE_ZIP = "--import-resource-zip"; - /** Flag to add the names of annotation processors. */ - static final String PROCESSOR_NAMES = "--processor"; - /** Flag to add the classpath of annotation processors. */ - static final String PROCESSOR_CLASSPATH = "--processorpath"; - /** Flag to include a Proguard configuration. */ - static final String CONFIG_PROGUARD = "--config-proguard"; - /** Flag to set the multidex mode when compiling to dex with Jack. */ - static final String MULTI_DEX = "--multi-dex"; - /** Flag to specify the path to the main dex list in manual main dex mode. */ - static final String MAIN_DEX_LIST = "--main-dex-list"; - - /** Flag indicating the filename Jill should output the converted jar to. */ - static final String JILL_OUTPUT = "--output"; - /** Flag to output a jack library. */ - static final String OUTPUT_JACK = "--output-jack"; - /** Flag to output a zip file containing dex files and resources for packaging. */ - static final String OUTPUT_DEX_ZIP = "--output-dex-zip"; - /** Name of the zip file containing the dex files and java resources for packaging. */ - static final String ZIP_OUTPUT_FILENAME = "classes.dex.zip"; - - /** Rule context used to build and register actions. */ - private final RuleContext ruleContext; - - /** True to use Jack's internal sanity checks, trading speed for crash-on-bugs. */ - private final boolean useSanityChecks; - /** True to make Jill more tolerant, when compiling special jars (e.g., bootclasspath) */ - private final boolean useTolerant; - - /** Binary used to extract resources from a jar file. */ - private final FilesToRunProvider resourceExtractorBinary; - /** Binary used to build Jack libraries and dex files. */ - private final FilesToRunProvider jackBinary; - /** Binary used to convert jars to Jack libraries. */ - private final FilesToRunProvider jillBinary; - /** - * Jack libraries containing Android/Java base classes. - * - * <p>These will be placed first on the classpath. - */ - private final NestedSet<Artifact> baseClasspath; - - /** The destination for the Jack artifact to be created, or null to skip this. */ - @Nullable private final Artifact outputArtifact; - - /** Java files for the rule's Jack library. */ - private final ImmutableSet<Artifact> javaSources; - /** Zip files of java sources for the rule's Jack library. */ - private final ImmutableSet<Artifact> sourceJars; - - /** Java resources for the rule's Jack library. */ - private final ImmutableMap<PathFragment, Artifact> resources; - - /** Jars that contain resources to be added to the Jack library. */ - private final NestedSet<Artifact> resourceJars; - - /** Jack libraries to be provided to depending rules on the classpath, from srcs and exports. */ - private final NestedSet<Artifact> exportedJacks; - /** - * Jar libraries to be provided to depending rules on the classpath, from srcs and exports. - * These will be placed after the jack files from exportedJacks and before this rule's jack file. - */ - private final ImmutableSet<Artifact> exportedJars; - - /** Jack libraries to be provided only to this rule on the classpath, from srcs and deps. */ - private final NestedSet<Artifact> classpathJacks; - /** - * Jar libraries to be provided only to this rule on the classpath, from srcs and deps. - * These will be placed after the jack files from classpathJacks. - */ - private final ImmutableSet<Artifact> classpathJars; - - /** - * Jack libraries from dependency libraries to be included in dexing. - * Does not include the library generated by this rule or any reached only through neverlink libs. - */ - private final NestedSet<Artifact> dexJacks; - /** Jar libraries from dependency libraries to be included in dexing. */ - private final ImmutableSet<Artifact> dexJars; - - /** Minimal state used only to give nice error messages in case of oopses. */ - private JackLibraryProvider alreadyCompiledLibrary; - - private boolean wasDexBuilt; - - /** The classpath to be used for annotation processors. */ - private final NestedSet<Artifact> processorClasspathJars; - - /** The names of classes to be used as annotation processors. */ - private final ImmutableSet<String> processorNames; - - /** Creates a new JackCompilationHelper. Called from {@link Builder#build()}. */ - private JackCompilationHelper( - RuleContext ruleContext, - boolean useSanityChecks, - boolean useTolerant, - FilesToRunProvider resourceExtractorBinary, - FilesToRunProvider jackBinary, - FilesToRunProvider jillBinary, - NestedSet<Artifact> baseClasspath, - @Nullable Artifact outputArtifact, - ImmutableSet<Artifact> javaSources, - ImmutableSet<Artifact> sourceJars, - ImmutableMap<PathFragment, Artifact> resources, - NestedSet<Artifact> resourceJars, - NestedSet<Artifact> processorClasspathJars, - ImmutableSet<String> processorNames, - NestedSet<Artifact> exportedJacks, - ImmutableSet<Artifact> exportedJars, - NestedSet<Artifact> classpathJacks, - ImmutableSet<Artifact> classpathJars, - NestedSet<Artifact> dexJacks, - ImmutableSet<Artifact> dexJars) { - this.ruleContext = ruleContext; - this.useSanityChecks = useSanityChecks; - this.useTolerant = useTolerant; - this.resourceExtractorBinary = resourceExtractorBinary; - this.jackBinary = jackBinary; - this.jillBinary = jillBinary; - this.baseClasspath = baseClasspath; - this.outputArtifact = outputArtifact; - this.javaSources = javaSources; - this.sourceJars = sourceJars; - this.resources = resources; - this.resourceJars = resourceJars; - this.processorClasspathJars = processorClasspathJars; - this.processorNames = processorNames; - this.exportedJacks = exportedJacks; - this.exportedJars = exportedJars; - this.classpathJacks = classpathJacks; - this.classpathJars = classpathJars; - this.dexJacks = dexJacks; - this.dexJars = dexJars; - } - - /** - * Builds one or more dex files from the jack libraries in the transitive closure of this rule. - * - * <p>This method should only be called once, as it will generate the same artifact each time. - * It will fail if called a second time. - * - * @param multidexMode The multidex flag to send to Jack. - * @param manualMainDexList Iff multidexMode is MANUAL_MAIN_DEX, an artifact representing the file - * with the list of class filenames which should go in the main dex. Else, absent. - * @param proguardSpecs A collection of Proguard configuration files to be used to process the - * Jack libraries before building a dex out of them. - * @returns A zip file containing the dex file(s) and Java resource(s) generated by Jack. - */ - // TODO(bazel-team): this method (compile to jack library, compile all transitive jacks to dex) - // may be too much overhead for manydex (dex per library) mode. - // Instead, consider running jack --output-dex right on the source files, bypassing the - // intermediate jack library format. - public Artifact compileAsDex( - MultidexMode multidexMode, - Optional<Artifact> manualMainDexList, - Collection<Artifact> proguardSpecs) { - Preconditions.checkNotNull(multidexMode); - Preconditions.checkNotNull(manualMainDexList); - Preconditions.checkNotNull(proguardSpecs); - Preconditions.checkArgument( - multidexMode.isSupportedByJack(), - "Multidex mode '%s' is not supported by Jack", - multidexMode); - Preconditions.checkArgument( - manualMainDexList.isPresent() == (multidexMode == MultidexMode.MANUAL_MAIN_DEX), - "The main dex list must be supplied if and only if the multidex mode is 'manual_main_dex'"); - Preconditions.checkState(!wasDexBuilt, "A dex file has already been built."); - - Artifact outputZip = AndroidBinary.getDxArtifact(ruleContext, ZIP_OUTPUT_FILENAME); - - NestedSet<Artifact> transitiveJackLibraries = - compileAsLibrary().getTransitiveJackLibrariesToLink(); - CustomCommandLine.Builder builder = - CustomCommandLine.builder() - // Have jack double-check its behavior and crash rather than producing invalid output - .add(SANITY_CHECKS) - .add(useSanityChecks ? SANITY_CHECKS_ON : SANITY_CHECKS_OFF) - // Have jack take the first match in the event of a class or resource name collision. - .add(JACK_PROPERTY) - .add(PROPERTY_KEEP_FIRST_RESOURCE) - .add(JACK_PROPERTY) - .add(PROPERTY_KEEP_FIRST_TYPE); - - for (Artifact jackLibrary : transitiveJackLibraries) { - builder.addExecPath(IMPORT_JACK_LIBRARY, jackLibrary); - } - for (Artifact proguardSpec : proguardSpecs) { - builder.addExecPath(CONFIG_PROGUARD, proguardSpec); - } - builder.add(MULTI_DEX).add(multidexMode.getJackFlagValue()); - if (manualMainDexList.isPresent()) { - builder.addExecPath(MAIN_DEX_LIST, manualMainDexList.get()); - } - builder.addExecPath(OUTPUT_DEX_ZIP, outputZip); - ruleContext.registerAction( - new SpawnAction.Builder() - .setExecutable(jackBinary) - .addTransitiveInputs(transitiveJackLibraries) - .addInputs(proguardSpecs) - .addInputs(manualMainDexList.asSet()) - .addOutput(outputZip) - .setCommandLine(builder.build()) - .setProgressMessage("Dexing " + ruleContext.getLabel() + " with Jack") - .setMnemonic("AndroidJackDex") - .build(ruleContext)); - return outputZip; - } - - /** - * Constructs the actions to compile a jack library for a neverlink lib. - * - * @returns a {@link JackLibraryProvider} containing the resulting transitive jack libraries. - */ - public JackLibraryProvider compileAsNeverlinkLibrary() { - JackLibraryProvider nonNeverlink = compileAsLibrary(); - return JackLibraryProvider.create( - /* transitiveJackLibrariesToLink */ - NestedSetBuilder.<Artifact>emptySet(Order.NAIVE_LINK_ORDER), - nonNeverlink.getTransitiveJackClasspathLibraries()); - } - - /** - * Constructs the actions to compile a jack library for a non-neverlink lib. - * - * @returns a {@link JackLibraryProvider} containing the resulting transitive jack libraries. - */ - public JackLibraryProvider compileAsLibrary() { - if (alreadyCompiledLibrary != null) { - // Because the JackCompilationHelper is immutable, compileAsLibrary will always produce the - // same result for the life of the helper. The resulting library may be needed by clients - // which also need to build a dex, e.g., AndroidBinary. - return alreadyCompiledLibrary; - } - Function<Artifact, Artifact> nonLibraryFileConverter = - CacheBuilder.newBuilder() - .initialCapacity(exportedJars.size() + classpathJars.size()) - .build( - new CacheLoader<Artifact, Artifact>() { - @Override - public Artifact load(Artifact artifact) throws Exception { - if (JavaSemantics.JAR.matches(artifact.getFilename())) { - return postprocessPartialJackAndAddResources( - convertJarToPartialJack(artifact), extractResourcesFromJar(artifact)); - } else if (JACK_LIBRARY_TYPE.matches(artifact.getFilename())) { - return artifact; - } - throw new AssertionError("Invalid type for library file: " + artifact); - } - }); - - NestedSet<Artifact> transitiveClasspath = - new NestedSetBuilder<Artifact>(Order.NAIVE_LINK_ORDER) - .addAll(Iterables.transform(classpathJars, nonLibraryFileConverter)) - .addTransitive(classpathJacks) - .build(); - - // The base classpath needs to be first in the set's iteration order. - // Then any jars or jack files specified directly, then dependencies from providers. - NestedSet<Artifact> classpath = - new NestedSetBuilder<Artifact>(Order.NAIVE_LINK_ORDER) - .addTransitive(baseClasspath) - .addTransitive(transitiveClasspath) - .build(); - - NestedSetBuilder<Artifact> exports = new NestedSetBuilder<>(Order.NAIVE_LINK_ORDER); - NestedSetBuilder<Artifact> dexContents = new NestedSetBuilder<>(Order.NAIVE_LINK_ORDER); - - if (outputArtifact != null) { - if (javaSources.isEmpty() && sourceJars.isEmpty() && resources.isEmpty() - && resourceJars.isEmpty()) { - // We still have to create SOMETHING to fulfill the artifact, but man, screw it - buildEmptyJackAction(); - } else { - buildJackAction(javaSources, sourceJars, resources, resourceJars, classpath); - exports.add(outputArtifact); - dexContents.add(outputArtifact); - } - } - - // These need to be added now so that they can be after the outputArtifact (if present). - exports - .addAll(Iterables.transform(exportedJars, nonLibraryFileConverter)) - .addTransitive(exportedJacks) - .addTransitive(transitiveClasspath); - dexContents - .addAll(Iterables.transform(dexJars, nonLibraryFileConverter)) - .addTransitive(dexJacks); - - alreadyCompiledLibrary = JackLibraryProvider.create(dexContents.build(), exports.build()); - return alreadyCompiledLibrary; - } - - /** - * Generates an action which converts the jar to partial Jack format and returns the Jack file. - * - * <p>Partial Jack format does not contain resources or pre-dex files. - * - * @see #postprocessPartialJackAndAddResources(Artifact,Artifact) - */ - private Artifact convertJarToPartialJack(Artifact jar) { - Artifact result = ruleContext.getUniqueDirectoryArtifact( - PARTIAL_JACK_DIRECTORY, - FileSystemUtils.replaceExtension(jar.getRootRelativePath(), ".jack"), - ruleContext.getBinOrGenfilesDirectory()); - SpawnAction.Builder builder = - new SpawnAction.Builder() - .setExecutable(jillBinary); - if (useTolerant) { - builder.addArgument(TOLERANT); - } - ruleContext.registerAction( - builder - .addArgument(JILL_OUTPUT) - .addOutputArgument(result) - .addInputArgument(jar) - .setProgressMessage( - "Converting " + jar.getExecPath().getBaseName() + " to Jack library with Jill") - .setMnemonic("AndroidJill") - .build(ruleContext)); - return result; - } - - /** - * Generates an action which creates a zip file from the contents of the input jar, filtering out - * non-resource files and returning a zip file containing only resources. - */ - private Artifact extractResourcesFromJar(Artifact jar) { - Artifact result = ruleContext.getUniqueDirectoryArtifact( - PARTIAL_JACK_DIRECTORY, - FileSystemUtils.replaceExtension(jar.getRootRelativePath(), "-resources.zip"), - ruleContext.getBinOrGenfilesDirectory()); - - ruleContext.registerAction( - new SpawnAction.Builder() - .setExecutable(resourceExtractorBinary) - .addInputArgument(jar) - .addOutputArgument(result) - .setProgressMessage("Extracting resources from " + jar.getExecPath().getBaseName()) - .setMnemonic("AndroidJillResources") - .build(ruleContext)); - return result; - } - - /** - * Generates an action to finish processing a partial Jack library generated by - * {@link #convertJarToPartialJack(Artifact)} and add resources from - * {@link #extractResourcesFromJar(Artifact)}, then returns the final library. - */ - private Artifact postprocessPartialJackAndAddResources( - Artifact partialJackLibrary, Artifact resources) { - Artifact result = ruleContext.getUniqueDirectoryArtifact( - JACK_DIRECTORY, - partialJackLibrary.getRootRelativePath().relativeTo( - ruleContext.getUniqueDirectory(PARTIAL_JACK_DIRECTORY)), - ruleContext.getBinOrGenfilesDirectory()); - CustomCommandLine.Builder builder = - CustomCommandLine.builder() - // Have jack double-check its behavior and crash rather than producing invalid output - .add(SANITY_CHECKS) - .add(useSanityChecks ? SANITY_CHECKS_ON : SANITY_CHECKS_OFF) - .addExecPath(IMPORT_JACK_LIBRARY, partialJackLibrary) - .addExecPath(IMPORT_RESOURCE_ZIP, resources) - .addExecPath(OUTPUT_JACK, result); - ruleContext.registerAction( - new SpawnAction.Builder() - .setExecutable(jackBinary) - .addInput(partialJackLibrary) - .addInput(resources) - .addOutput(result) - .setCommandLine(builder.build()) - .setProgressMessage( - "Processing " + partialJackLibrary.getExecPath().getBaseName() + " as Jack library") - .setMnemonic("AndroidJillPostprocess") - .build(ruleContext)); - return result; - } - - /** - * Creates an action to build an empty jack library given by outputArtifact. - */ - private void buildEmptyJackAction() { - ruleContext.registerAction( - new SpawnAction.Builder() - .setExecutable(jackBinary) - .addArgument(OUTPUT_JACK) - .addOutputArgument(outputArtifact) - .setProgressMessage("Compiling " + ruleContext.getLabel() + " as Jack library") - .setMnemonic("AndroidJackLibraryNull") - .build(ruleContext)); - } - - /** - * Creates an action to compile the given sources as a jack library given by outputArtifact. - * - * @param javaSources Iterable of .java files to compile using jack. - * @param sourceJars Iterable of .srcjar files to unpack and compile using jack. - * @param resources Mapping from library paths to resource files to be imported into the jack - * library. - * @param classpathJackLibraries Libraries used for compilation. - * @returns An artifact representing the combined jack library, or null if none was created. - */ - private void buildJackAction( - Iterable<Artifact> javaSources, - Iterable<Artifact> sourceJars, - Map<PathFragment, Artifact> resources, - NestedSet<Artifact> resourceJars, - NestedSet<Artifact> classpathJackLibraries) { - CustomCommandLine.Builder builder = - CustomCommandLine.builder() - // Have jack double-check its behavior and crash rather than producing invalid output - .add(SANITY_CHECKS) - .add(useSanityChecks ? SANITY_CHECKS_ON : SANITY_CHECKS_OFF) - .addExecPath(OUTPUT_JACK, outputArtifact) - .addJoinExecPaths(CLASSPATH, ":", classpathJackLibraries); - if (!processorNames.isEmpty()) { - builder.add(PROCESSOR_NAMES).add(Joiner.on(',').join(processorNames)); - } - if (!processorClasspathJars.isEmpty()) { - builder.addJoinExecPaths(PROCESSOR_CLASSPATH, ":", processorClasspathJars); - } - for (Entry<PathFragment, Artifact> resource : resources.entrySet()) { - builder.add(IMPORT_RESOURCE_FILE); - // Splits paths at the appropriate root (java root, if present; source/genfiles/etc. if not). - // The part of the path after the : is used as the path to the resource within the jack/apk, - // while the part of the path before the : is the remainder of the path to the resource file. - // In cases where the path to the file and the path within the jack/apk are the same, - // such as when a source file is not under a java root, this prefix will be empty. - PathFragment execPath = resource.getValue().getExecPath(); - PathFragment resourcePath = resource.getKey(); - if (execPath.equals(resourcePath)) { - builder.addPaths(":%s", resourcePath); - } else { - // execPath must end with resourcePath in all cases - PathFragment rootPrefix = - execPath.subFragment(0, execPath.segmentCount() - resourcePath.segmentCount()); - builder.addPaths("%s:%s", rootPrefix, resourcePath); - } - } - if (!resourceJars.isEmpty()) { - builder.addJoinExecPaths(IMPORT_RESOURCE_ZIP, ":", resourceJars); - } - builder.addBeforeEachExecPath(IMPORT_SOURCE_ZIP, sourceJars).addExecPaths(javaSources); - ruleContext.registerAction( - new SpawnAction.Builder() - .setExecutable(jackBinary) - .addTransitiveInputs(classpathJackLibraries) - .addOutput(outputArtifact) - .addTransitiveInputs(processorClasspathJars) - .addInputs(resources.values()) - .addTransitiveInputs(resourceJars) - .addInputs(sourceJars) - .addInputs(javaSources) - .setCommandLine(builder.build()) - .setProgressMessage("Compiling " + ruleContext.getLabel() + " as Jack library") - .setMnemonic("AndroidJackLibrary") - .build(ruleContext)); - } - - /** - * Builder for JackCompilationHelper to configure all of its tools and sources. - */ - public static final class Builder { - - /** Rule context used to build and register actions. */ - @Nullable private RuleContext ruleContext; - - /** Whether to enable tolerant mode in Jill, e.g., when compiling a bootclasspath. */ - private boolean useTolerant; - - /** Binary used to extract resources from a jar file. */ - @Nullable private FilesToRunProvider resourceExtractorBinary; - /** Binary used to build Jack libraries and dex files. */ - @Nullable private FilesToRunProvider jackBinary; - /** Binary used to convert jars to Jack libraries. */ - @Nullable private FilesToRunProvider jillBinary; - /** - * Set of Jack libraries containing Android/Java base classes. - * - * <p>These will be placed first on the classpath. - */ - @Nullable private NestedSet<Artifact> baseClasspath; - - /** The destination for the Jack artifact to be created. */ - @Nullable private Artifact outputArtifact; - - /** Java files for the rule's Jack library. */ - private final LinkedHashSet<Artifact> javaSources = new LinkedHashSet<>(); - /** Zip files of java sources for the rule's Jack library. */ - private final LinkedHashSet<Artifact> sourceJars = new LinkedHashSet<>(); - /** Map from paths within the Jack library to Java resources for the rule's Jack library. */ - private final LinkedHashMap<PathFragment, Artifact> resources = new LinkedHashMap<>(); - - /** Set of resource jars that contain Java resources. */ - private final NestedSetBuilder<Artifact> resourceJars = NestedSetBuilder.stableOrder(); - - /** Jack libraries to be provided to depending rules on the classpath, from srcs and exports. */ - private final NestedSetBuilder<Artifact> exportedJackLibraries = - new NestedSetBuilder<>(Order.NAIVE_LINK_ORDER); - /** - * Jar libraries to be provided to depending rules on the classpath, from srcs and exports. - * These will be placed after the jack files from exportedJacks and before this rule's jack - * file. - */ - private final LinkedHashSet<Artifact> exportedNonLibraryFiles = new LinkedHashSet<>(); - - /** Jack libraries to be provided only to this rule on the classpath, from srcs and deps. */ - private final NestedSetBuilder<Artifact> classpathJackLibraries = - new NestedSetBuilder<>(Order.NAIVE_LINK_ORDER); - /** - * Jar libraries to be provided only to this rule on the classpath, from srcs and deps. - * These will be placed after the jack files from classpathJacks. - */ - private final LinkedHashSet<Artifact> classpathNonLibraryFiles = new LinkedHashSet<>(); - - /** The names of classes to be used as annotation processors. */ - private final LinkedHashSet<String> processorNames = new LinkedHashSet<>(); - - /** Jar libraries to be provided as annotation processors' classpath, from plugin deps. */ - private final NestedSetBuilder<Artifact> processorClasspathJars = - new NestedSetBuilder<>(Order.NAIVE_LINK_ORDER); - - /** - * Jack libraries from dependency libraries to be included in dexing. - * Does not include the library generated by this rule or any reached only through neverlink - * libs. - */ - private final NestedSetBuilder<Artifact> dexJacks = - new NestedSetBuilder<>(Order.NAIVE_LINK_ORDER); - /** Jar libraries from dependency libraries to be included in dexing. */ - private final LinkedHashSet<Artifact> dexJars = new LinkedHashSet<>(); - - /** - * Sets the rule context in which this compilation helper will operate. - * - * <p>The compilation tools will be loaded automatically from the appropriate attributes: - * Jack as $jack, Jill as $jill, and the resource extractor as $resource_extractor. - * - * <p>Jack's sanity checks will be enabled or disabled according to the AndroidConfiguration - * accessed through this context. - */ - public JackCompilationHelper.Builder setRuleContext(RuleContext ruleContext) { - this.ruleContext = Preconditions.checkNotNull(ruleContext); - return this; - } - - /** - * Sets the artifact the final Jack library should be output to. - * - * <p>The artifact specified will always be generated, although it may be empty if there are no - * sources. - * - * <p>This method must be called if any of addJavaSources, addSourceJars, or addResources is. - */ - public JackCompilationHelper.Builder setOutputArtifact(Artifact outputArtifact) { - this.outputArtifact = Preconditions.checkNotNull(outputArtifact); - return this; - } - - /** - * Sets the Jack binary used to perform operations on Jack libraries. - */ - public JackCompilationHelper.Builder setJackBinary(FilesToRunProvider jackBinary) { - this.jackBinary = Preconditions.checkNotNull(jackBinary); - return this; - } - - /** - * Sets the Jill binary used to translate jars to jack files. - */ - public JackCompilationHelper.Builder setJillBinary(FilesToRunProvider jillBinary) { - this.jillBinary = Preconditions.checkNotNull(jillBinary); - return this; - } - - /** - * Sets the resource extractor binary used to extract resources from jars. - */ - public JackCompilationHelper.Builder setResourceExtractorBinary( - FilesToRunProvider resourceExtractorBinary) { - this.resourceExtractorBinary = Preconditions.checkNotNull(resourceExtractorBinary); - return this; - } - - /** - * Sets the base classpath, containing core classes (android.jar or Java bootclasspath). - */ - public JackCompilationHelper.Builder setJackBaseClasspath(NestedSet<Artifact> baseClasspath) { - this.baseClasspath = Preconditions.checkNotNull(baseClasspath); - return this; - } - - /** - * Sets Jill to be tolerant, e.g., when translating a jar from the Java bootclasspath to jack. - */ - public JackCompilationHelper.Builder setTolerant() { - this.useTolerant = true; - return this; - } - - /** - * Adds a collection of Java source files to be compiled by Jack. - */ - public JackCompilationHelper.Builder addJavaSources(Collection<Artifact> javaSources) { - this.javaSources.addAll(Preconditions.checkNotNull(javaSources)); - return this; - } - - /** - * Adds a collection of zip files containing Java sources to be compiled by Jack. - */ - public JackCompilationHelper.Builder addSourceJars(Collection<Artifact> sourceJars) { - this.sourceJars.addAll(Preconditions.checkNotNull(sourceJars)); - return this; - } - - /** - * Adds a collection of jar files to be converted to Jack libraries. - * - * <p>The Jack libraries created from these jar files will be used both as - * dependencies on the classpath of this rule and exports to the classpath of depending rules, - * as with jar files in the sources of a Java rule. - * They will also be available to the compilation of the final dex file(s). - * It has an identical effect as if these jars were specified in both deps and exports. - */ - public JackCompilationHelper.Builder addCompiledJars(Collection<Artifact> compiledJars) { - this.exportedNonLibraryFiles.addAll(Preconditions.checkNotNull(compiledJars)); - this.classpathNonLibraryFiles.addAll(compiledJars); - this.dexJars.addAll(compiledJars); - return this; - } - - /** - * Adds Java resources as a map keyed by the paths where they will be added to the Jack package - * and the final APK. The resource path for an artifact must be a suffix of its exec path. - */ - public JackCompilationHelper.Builder addResources(Map<PathFragment, Artifact> resources) { - this.resources.putAll(Preconditions.checkNotNull(resources)); - return this; - } - - public JackCompilationHelper.Builder addResourceJars(NestedSet<Artifact> resourceJars) { - this.resourceJars.addTransitive(resourceJars); - return this; - } - - /** - * Adds a set of class names which will be used as annotation processors. - */ - public JackCompilationHelper.Builder addProcessorNames(Collection<String> processorNames) { - this.processorNames.addAll(Preconditions.checkNotNull(processorNames)); - return this; - } - - /** - * Adds a set of jars which will be used as the classpath for annotation processors. - */ - public JackCompilationHelper.Builder addProcessorClasspathJars( - Iterable<Artifact> processorClasspathJars) { - this.processorClasspathJars.addAll(Preconditions.checkNotNull(processorClasspathJars)); - return this; - } - - /** - * Adds a set of normal dependencies. - * - * <p>These dependencies will be considered direct dependencies of this rule, - * and indirect dependencies of any rules depending on this one. - * They will also be available to the compilation of the final dex file(s). - */ - public JackCompilationHelper.Builder addDeps( - Iterable<? extends TransitiveInfoCollection> deps) { - return addClasspathDeps(deps).addRuntimeDeps(deps); - } - - /** - * Adds a set of dependencies which will be exported to Jack rules which depend on this one. - * - * <p>These dependencies will be considered direct dependencies of rules depending on this one, - * but not of this rule itself, in line with Java rule semantics. - * They will also be available to the compilation of the final dex file(s). - */ - public JackCompilationHelper.Builder addExports( - Iterable<? extends TransitiveInfoCollection> exports) { - return addExportedDeps(exports).addRuntimeDeps(exports); - } - - /** - * Adds a set of dependencies which will be used in dexing. - * - * <p>Unless {@link #addClasspathDeps} or {@link #addExportedDeps} are also called, - * runtimeDeps will not be provided on the classpath of this rule or rules which depend on it. - */ - public JackCompilationHelper.Builder addRuntimeDeps( - Iterable<? extends TransitiveInfoCollection> runtimeDeps) { - for (TransitiveInfoCollection dep : Preconditions.checkNotNull(runtimeDeps)) { - JackLibraryProvider jackLibraryProvider = dep.getProvider(JackLibraryProvider.class); - if (jackLibraryProvider != null) { - dexJacks.addTransitive(jackLibraryProvider.getTransitiveJackLibrariesToLink()); - } else { - NestedSet<Artifact> filesToBuild = dep.getProvider(FileProvider.class).getFilesToBuild(); - for (Artifact file : - FileType.filter(filesToBuild, JavaSemantics.JAR, JACK_LIBRARY_TYPE)) { - dexJars.add(file); - } - } - } - return this; - } - - /** - * Adds a set of dependencies which will be placed on the classpath of this rule. - * - * <p>Unless {@link #addRuntimeDeps} is also called, classpathDeps will only be used for - * compilation of this rule and will not be built into the final dex. - * - * @see #addDeps - */ - public JackCompilationHelper.Builder addClasspathDeps( - Iterable<? extends TransitiveInfoCollection> classpathDeps) { - return addDependenciesInternal( - Preconditions.checkNotNull(classpathDeps), - classpathNonLibraryFiles, - classpathJackLibraries); - } - - /** - * Adds a set of dependencies to be placed on the classpath of rules depending on this rule. - * - * <p>Unless {@link #addRuntimeDeps} is also called, exportedDeps will only be used for - * compilation of depending rules and will not be built into the final dex. - * - * @see #addExports - */ - public JackCompilationHelper.Builder addExportedDeps( - Iterable<? extends TransitiveInfoCollection> exportedDeps) { - return addDependenciesInternal( - Preconditions.checkNotNull(exportedDeps), exportedNonLibraryFiles, exportedJackLibraries); - } - - /** - * Adds all libraries from deps to nonLibraryFiles and jackLibs based on their type. - * - * <p>Those exporting JackLibraryProvider have their jackClasspathLibraries added to jackLibs. - * Others will have any jars or jacks in their filesToBuild added to nonLibraryFiles. - * - * <p>{@link #addRuntimeDeps} should also be called on deps for dependencies which will be built - * into the final dex file(s). - */ - private JackCompilationHelper.Builder addDependenciesInternal( - Iterable<? extends TransitiveInfoCollection> deps, - Collection<Artifact> nonLibraryFiles, - NestedSetBuilder<Artifact> jackLibs) { - for (TransitiveInfoCollection dep : deps) { - JackLibraryProvider jackLibraryProvider = dep.getProvider(JackLibraryProvider.class); - if (jackLibraryProvider != null) { - jackLibs.addTransitive(jackLibraryProvider.getTransitiveJackClasspathLibraries()); - } else { - NestedSet<Artifact> filesToBuild = dep.getProvider(FileProvider.class).getFilesToBuild(); - for (Artifact file : - FileType.filter(filesToBuild, JavaSemantics.JAR, JACK_LIBRARY_TYPE)) { - nonLibraryFiles.add(file); - } - } - } - return this; - } - - /** - * Constructs the JackCompilationHelper. - * - * <p>It's not recommended to call build() more than once, as the resulting - * JackCompilationHelpers will attempt to generate the same actions. - */ - public JackCompilationHelper build() { - Preconditions.checkNotNull(ruleContext); - - boolean useSanityChecks = - ruleContext - .getFragment(AndroidConfiguration.class) - .isJackSanityChecked(); - - // It's okay not to have an outputArtifact if there is nothing to build. - // e.g., if only translating jars with Jill, no final jack library will be created. - // But if there is something to build, enforce that one has been specified. - if (!javaSources.isEmpty() || !sourceJars.isEmpty() || !resources.isEmpty()) { - Preconditions.checkNotNull(outputArtifact); - } - - return new JackCompilationHelper( - ruleContext, - useSanityChecks, - useTolerant, - Preconditions.checkNotNull(resourceExtractorBinary), - Preconditions.checkNotNull(jackBinary), - Preconditions.checkNotNull(jillBinary), - Preconditions.checkNotNull(baseClasspath), - outputArtifact, - ImmutableSet.copyOf(javaSources), - ImmutableSet.copyOf(sourceJars), - ImmutableMap.copyOf(resources), - resourceJars.build(), - processorClasspathJars.build(), - ImmutableSet.copyOf(processorNames), - exportedJackLibraries.build(), - ImmutableSet.copyOf(exportedNonLibraryFiles), - classpathJackLibraries.build(), - ImmutableSet.copyOf(classpathNonLibraryFiles), - dexJacks.build(), - ImmutableSet.copyOf(dexJars)); - } - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/JackLibraryProvider.java b/src/main/java/com/google/devtools/build/lib/rules/android/JackLibraryProvider.java deleted file mode 100644 index cb209f5b30..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/android/JackLibraryProvider.java +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2015 The Bazel Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package com.google.devtools.build.lib.rules.android; - -import com.google.auto.value.AutoValue; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; -import com.google.devtools.build.lib.collect.nestedset.NestedSet; -import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; -import com.google.devtools.build.lib.collect.nestedset.Order; -import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; - -/** - * Configured targets implementing this provider can contribute Jack libraries to the compilation of - * an Android APK using the Jack toolchain or another Jack library. - * - * @see <a href="http://tools.android.com/tech-docs/jackandjill">Jack documentation</a> - * @see JackCompilationHelper - */ -@AutoValue -@Immutable -public abstract class JackLibraryProvider implements TransitiveInfoProvider { - public static final JackLibraryProvider EMPTY = - JackLibraryProvider.create( - NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER), - NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER)); - - public static JackLibraryProvider create( - NestedSet<Artifact> transitiveJackLibrariesToLink, - NestedSet<Artifact> transitiveJackClasspathLibraries) { - return new AutoValue_JackLibraryProvider( - transitiveJackLibrariesToLink, transitiveJackClasspathLibraries); - } - - /** - * Gets the Jack libraries in the transitive closure which should be added to the final dex file. - */ - public abstract NestedSet<Artifact> getTransitiveJackLibrariesToLink(); - - /** - * Gets the Jack libraries which should be added to the classpath of any Jack action depending on - * this provider. - */ - public abstract NestedSet<Artifact> getTransitiveJackClasspathLibraries(); - - /** - * Builder class to combine multiple JackLibraryProviders into a single one. - */ - public static final class Builder { - private final NestedSetBuilder<Artifact> transitiveJackLibrariesToLink = - NestedSetBuilder.<Artifact>stableOrder(); - private final NestedSetBuilder<Artifact> transitiveJackClasspathLibraries = - NestedSetBuilder.<Artifact>stableOrder(); - - public Builder merge(JackLibraryProvider other) { - transitiveJackLibrariesToLink.addTransitive(other.getTransitiveJackLibrariesToLink()); - transitiveJackClasspathLibraries.addTransitive(other.getTransitiveJackClasspathLibraries()); - return this; - } - - public JackLibraryProvider build() { - return JackLibraryProvider.create( - transitiveJackLibrariesToLink.build(), transitiveJackClasspathLibraries.build()); - } - } - - JackLibraryProvider() {} -} |