diff options
author | ahumesky <ahumesky@google.com> | 2017-11-16 14:59:51 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2017-11-16 15:01:59 -0800 |
commit | 9d92c5af0214e5497c8fb4cc2c69fb28aaa4358d (patch) | |
tree | 431a64838a6b618021bee8921d2197d771d7ba14 /src | |
parent | 8872e359a65199214938a711e34c9b0e6aea876a (diff) |
Deletes unused apk manifest.
RELNOTES: None.
PiperOrigin-RevId: 176025413
Diffstat (limited to 'src')
8 files changed, 1 insertions, 621 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/BUILD b/src/main/java/com/google/devtools/build/lib/BUILD index 37d2db29b1..ca74c10961 100644 --- a/src/main/java/com/google/devtools/build/lib/BUILD +++ b/src/main/java/com/google/devtools/build/lib/BUILD @@ -915,7 +915,6 @@ java_library( "//src/main/java/com/google/devtools/build/lib/vfs", "//src/main/java/com/google/devtools/common/options", "//src/main/protobuf:android_deploy_info_java_proto", - "//src/main/protobuf:apk_manifest_java_proto", "//third_party:android_common_25_0_0", "//third_party:auto_value", "//third_party:guava", 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 917e6ec20d..b021a8977a 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 @@ -15,8 +15,6 @@ package com.google.devtools.build.lib.rules.android; import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Predicates.in; -import static com.google.common.base.Predicates.not; import static com.google.common.collect.ImmutableList.toImmutableList; import com.google.common.base.Function; @@ -29,7 +27,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Multimap; import com.google.common.collect.MultimapBuilder; -import com.google.common.collect.Streams; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.FailAction; import com.google.devtools.build.lib.analysis.ConfiguredTarget; @@ -48,7 +45,6 @@ import com.google.devtools.build.lib.analysis.actions.SpawnAction; import com.google.devtools.build.lib.analysis.actions.SpawnAction.Builder; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode; -import com.google.devtools.build.lib.collect.IterablesChain; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; @@ -219,7 +215,6 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory { // can go away: recompile from android_resources, and recompile from android_binary attributes. ApplicationManifest applicationManifest; ResourceApk resourceApk; - ResourceApk instantRunResourceApk; if (LocalResourceContainer.definesAndroidResources(ruleContext.attributes())) { // Retrieve and compile the resources defined on the android_binary rule. LocalResourceContainer.validateRuleContext(ruleContext); @@ -258,18 +253,6 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory { featureAfterArtifact); ruleContext.assertNoErrors(); - instantRunResourceApk = - applicationManifest - .addInstantRunStubApplication(ruleContext) - .packIncrementalBinaryWithDataAndResources( - ruleContext, - getDxArtifact(ruleContext, "android_instant_run.ap_"), - resourceDeps, - ruleContext.getExpander().withDataLocations().tokenized("nocompress_extensions"), - ruleContext.attributes().get("crunch_png", Type.BOOLEAN), - ProguardHelper.getProguardConfigArtifact(ruleContext, "instant_run")); - ruleContext.assertNoErrors(); - } else { if (!ruleContext.attributes().get("crunch_png", Type.BOOLEAN)) { @@ -303,16 +286,6 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory { ruleContext.assertNoErrors(); } - instantRunResourceApk = applicationManifest - .addInstantRunStubApplication(ruleContext) - .packWithResources( - getDxArtifact(ruleContext, "android_instant_run.ap_"), - ruleContext, - resourceDeps, - false, /* createSource */ - ProguardHelper.getProguardConfigArtifact(ruleContext, "instant_run"), - null /* mainDexProguardConfig */); - ruleContext.assertNoErrors(); } boolean shrinkResources = shouldShrinkResources(ruleContext); @@ -389,7 +362,6 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory { applicationManifest, resourceApk, mobileInstallResourceApks, - instantRunResourceApk, shrinkResources, resourceClasses, ImmutableList.<Artifact>of(), @@ -412,7 +384,6 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory { ApplicationManifest applicationManifest, ResourceApk resourceApk, @Nullable MobileInstallResourceApks mobileInstallResourceApks, - ResourceApk instantRunResourceApk, boolean shrinkResources, JavaTargetAttributes resourceClasses, ImmutableList<Artifact> apksUnderTest, @@ -587,31 +558,6 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory { additionalMergedManifests, ImmutableList.<Artifact>builder().add(zipAlignedApk).addAll(apksUnderTest).build()); - Artifact debugKeystore = AndroidCommon.getApkDebugSigningKey(ruleContext); - Artifact apkManifest = - ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.APK_MANIFEST); - createApkManifestAction( - ruleContext, - apkManifest, - false, // text proto - androidCommon, - resourceClasses, - instantRunResourceApk, - nativeLibs, - debugKeystore); - - Artifact apkManifestText = - ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.APK_MANIFEST_TEXT); - createApkManifestAction( - ruleContext, - apkManifestText, - true, // text proto - androidCommon, - resourceClasses, - instantRunResourceApk, - nativeLibs, - debugKeystore); - RuleConfiguredTargetBuilder builder = new RuleConfiguredTargetBuilder(ruleContext); @@ -687,54 +633,15 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory { unsignedApk, androidCommon.getInstrumentedJar(), applicationManifest.getManifest(), - debugKeystore)) + AndroidCommon.getApkDebugSigningKey(ruleContext))) .addProvider(AndroidPreDexJarProvider.class, AndroidPreDexJarProvider.create(jarToDex)) .addProvider( AndroidFeatureFlagSetProvider.class, AndroidFeatureFlagSetProvider.create( AndroidFeatureFlagSetProvider.getAndValidateFlagMapFromRuleContext(ruleContext))) - .addOutputGroup("apk_manifest", apkManifest) - .addOutputGroup("apk_manifest_text", apkManifestText) .addOutputGroup("android_deploy_info", deployInfo); } - private static void createApkManifestAction( - RuleContext ruleContext, - Artifact apkManifest, - boolean textProto, - final AndroidCommon androidCommon, - JavaTargetAttributes resourceClasses, - ResourceApk resourceApk, - NativeLibs nativeLibs, - Artifact debugKeystore) { - // TODO(bazel-team): Sufficient to use resourceClasses.getRuntimeClasspathForArchive? - // Deleting getArchiveInputs could simplify the implementation of DeployArchiveBuidler.build() - Iterable<Artifact> jars = IterablesChain.concat( - DeployArchiveBuilder.getArchiveInputs(resourceClasses), androidCommon.getRuntimeJars()); - - // The resources jars from android_library rules contain stub ids, so filter those out of the - // transitive jars. - Iterable<Artifact> filteredJars = - Streams.stream(jars) - .filter(not(in(getLibraryResourceJars(ruleContext).toSet()))) - .collect(toImmutableList()); - - AndroidSdkProvider sdk = AndroidSdkProvider.fromRuleContext(ruleContext); - - ApkManifestAction manifestAction = - new ApkManifestAction( - ruleContext.getActionOwner(), - apkManifest, - textProto, - sdk, - filteredJars, - resourceApk, - nativeLibs, - debugKeystore); - - ruleContext.registerAction(manifestAction); - } - private static NestedSet<Artifact> getLibraryResourceJars(RuleContext ruleContext) { Iterable<AndroidLibraryResourceClassJarProvider> libraryResourceJarProviders = AndroidCommon.getTransitivePrerequisites( 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 3ac324855c..22e0385f7b 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 @@ -155,10 +155,6 @@ public final class AndroidRuleClasses { fromTemplates("%{name}_files/split_deploy_marker"); public static final SafeImplicitOutputsFunction MOBILE_INSTALL_ARGS = fromTemplates("%{name}_files/mobile_install_args"); - public static final SafeImplicitOutputsFunction APK_MANIFEST = - fromTemplates("%{name}_files/apk_manifest"); - public static final SafeImplicitOutputsFunction APK_MANIFEST_TEXT = - fromTemplates("%{name}_files/apk_manifest_text"); public static final SafeImplicitOutputsFunction DEPLOY_INFO = fromTemplates("%{name}_files/deploy_info.deployinfo.pb"); public static final SafeImplicitOutputsFunction DEPLOY_INFO_INCREMENTAL = 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 deleted file mode 100644 index 1fff945ae2..0000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/android/ApkManifestAction.java +++ /dev/null @@ -1,250 +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.collect.ImmutableList; -import com.google.common.collect.Iterables; -import com.google.common.primitives.Ints; -import com.google.devtools.build.lib.actions.ActionExecutionContext; -import com.google.devtools.build.lib.actions.ActionOwner; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.analysis.FilesToRunProvider; -import com.google.devtools.build.lib.analysis.actions.AbstractFileWriteAction; -import com.google.devtools.build.lib.analysis.actions.ProtoDeterministicWriter; -import com.google.devtools.build.lib.collect.CollectionUtils; -import com.google.devtools.build.lib.collect.nestedset.NestedSet; -import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; -import com.google.devtools.build.lib.rules.android.apkmanifest.ApkManifestOuterClass; -import com.google.devtools.build.lib.rules.android.apkmanifest.ApkManifestOuterClass.ApkManifest; -import com.google.devtools.build.lib.util.Fingerprint; -import com.google.protobuf.ByteString; -import com.google.protobuf.TextFormat; -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintStream; -import java.util.Map; - -@Immutable -public final class ApkManifestAction extends AbstractFileWriteAction { - - private static Iterable<Artifact> makeInputs( - AndroidSdkProvider sdk, - Iterable<Artifact> jars, - ResourceApk resourceApk, - NativeLibs nativeLibs, - Artifact debugKeystore) { - - return ImmutableList.<Artifact>builder() - .add(sdk.getAapt().getExecutable()) - .add(sdk.getAdb().getExecutable()) - .add(sdk.getAidl().getExecutable()) - .add(sdk.getAndroidJar()) - .add(sdk.getAnnotationsJar()) - .add(sdk.getDx().getExecutable()) - .add(sdk.getFrameworkAidl()) - .add(sdk.getMainDexClasses()) - .add(sdk.getMainDexListCreator().getExecutable()) - .add(sdk.getProguard().getExecutable()) - .add(sdk.getShrinkedAndroidJar()) - .add(sdk.getZipalign().getExecutable()) - .addAll(jars) - .add(resourceApk.getArtifact()) - .add(resourceApk.getManifest()) - .addAll(nativeLibs.getAllNativeLibs()) - .add(debugKeystore) - .build(); - } - - private static final String GUID = "7b6f4858-d1f2-11e5-83b0-cf6ddc5a32d9"; - - private final boolean textOutput; - private final AndroidSdkProvider sdk; - private final Iterable<Artifact> jars; - private final ResourceApk resourceApk; - private final NativeLibs nativeLibs; - private final Artifact debugKeystore; - - /** - * @param owner The action owner. - * @param outputFile The artifact to write the proto to. - * @param textOutput Whether to write the output as a text proto. - * @param sdk The Android SDK. - * @param jars All the jars that would be merged and dexed and put into an APK. - * @param resourceApk The ResourceApk for the .ap_ that contains the resources that would go into - * an APK. - * @param debugKeystore The debug keystore. - * @param nativeLibs The natives libs that would go into an APK. - */ - public ApkManifestAction( - ActionOwner owner, - Artifact outputFile, - boolean textOutput, - AndroidSdkProvider sdk, - Iterable<Artifact> jars, - ResourceApk resourceApk, - NativeLibs nativeLibs, - Artifact debugKeystore) { - super(owner, makeInputs(sdk, jars, resourceApk, nativeLibs, debugKeystore), outputFile, false); - CollectionUtils.checkImmutable(jars); - this.textOutput = textOutput; - this.sdk = sdk; - this.jars = jars; - this.resourceApk = resourceApk; - this.nativeLibs = nativeLibs; - this.debugKeystore = debugKeystore; - } - - @Override - public DeterministicWriter newDeterministicWriter(final ActionExecutionContext ctx) - throws IOException { - - ApkManifestCreator manifestCreator = new ApkManifestCreator(new ArtifactDigester() { - @Override - public byte[] getDigest(Artifact artifact) throws IOException { - return ctx.getActionInputFileCache().getMetadata(artifact).getDigest(); - } - }); - - final ApkManifest manifest = manifestCreator.createManifest(); - - if (textOutput) { - return new DeterministicWriter() { - @Override - public void writeOutputFile(OutputStream out) throws IOException { - TextFormat.print(manifest, new PrintStream(out)); - } - }; - } else { - return new ProtoDeterministicWriter(manifest); - } - } - - @Override - protected String computeKey() { - - // Use fake hashes for the purposes of the action's key, because the hashes are retrieved from - // the MetadataHandler, which is available at only action-execution time. This should be ok - // because if an input artifact changes (and hence its hash changes), the action should be rerun - // anyway. This is more for the purpose of putting the structure of the output data into the - // key. - ApkManifestCreator manifestCreator = new ApkManifestCreator(new ArtifactDigester() { - @Override - public byte[] getDigest(Artifact artifact) { - return Ints.toByteArray(artifact.getExecPathString().hashCode()); - } - }); - - ApkManifest manifest; - try { - manifest = manifestCreator.createManifest(); - } catch (IOException e) { - // The ArtifactDigester shouldn't actually throw IOException, that's just for the - // ArtifactDigester that uses the MetadataHandler. - throw new IllegalStateException(e); - } - - return new Fingerprint() - .addString(GUID) - .addBoolean(textOutput) - .addBytes(manifest.toByteArray()) - .hexDigestAndReset(); - } - - private interface ArtifactDigester { - byte[] getDigest(Artifact artifact) throws IOException; - } - - private class ApkManifestCreator { - - private final ArtifactDigester artifactDigester; - - private ApkManifestCreator(ArtifactDigester artifactDigester) { - this.artifactDigester = artifactDigester; - } - - private ApkManifest createManifest() throws IOException { - ApkManifest.Builder manifestBuilder = ApkManifest.newBuilder(); - - for (Artifact jar : jars) { - manifestBuilder.addJars(makeArtifactProto(jar)); - } - - manifestBuilder.setResourceApk(makeArtifactProto(resourceApk.getArtifact())); - manifestBuilder.setAndroidManifest(makeArtifactProto(resourceApk.getManifest())); - - for (Map.Entry<String, NestedSet<Artifact>> nativeLib : nativeLibs.getMap().entrySet()) { - if (!Iterables.isEmpty(nativeLib.getValue())) { - manifestBuilder.addNativeLibBuilder() - .setArch(nativeLib.getKey()) - .addAllNativeLibs(makeArtifactProtos(nativeLib.getValue())); - } - } - - manifestBuilder.setAndroidSdk(createAndroidSdk(sdk)); - manifestBuilder.setDebugKeystore(makeArtifactProto(debugKeystore)); - return manifestBuilder.build(); - } - - private Iterable<ApkManifestOuterClass.Artifact> makeArtifactProtos( - Iterable<Artifact> artifacts) throws IOException { - - ImmutableList.Builder<ApkManifestOuterClass.Artifact> protoArtifacts = - ImmutableList.builder(); - for (Artifact artifact : artifacts) { - protoArtifacts.add(makeArtifactProto(artifact)); - } - return protoArtifacts.build(); - } - - private ApkManifestOuterClass.Artifact makeArtifactProto(Artifact artifact) throws IOException { - byte[] digest = artifactDigester.getDigest(artifact); - return ApkManifestOuterClass.Artifact.newBuilder() - .setExecRootPath(artifact.getExecPathString()) - .setHash(ByteString.copyFrom(digest)) - .setLabel(artifact.getOwnerLabel().toString()) - .build(); - } - - private String getArtifactPath(Artifact artifact) { - return artifact.getExecPathString(); - } - - private String getArtifactPath(FilesToRunProvider filesToRunProvider) { - return filesToRunProvider.getExecutable().getExecPathString(); - } - - private ApkManifestOuterClass.AndroidSdk createAndroidSdk(AndroidSdkProvider sdk) { - - ApkManifestOuterClass.AndroidSdk.Builder sdkProto = - ApkManifestOuterClass.AndroidSdk.newBuilder(); - - sdkProto.setAapt(getArtifactPath(sdk.getAapt())); - sdkProto.setAdb(getArtifactPath(sdk.getAdb())); - sdkProto.setAidl(getArtifactPath(sdk.getAidl())); - sdkProto.setAndroidJar(getArtifactPath(sdk.getAndroidJar())); - sdkProto.setAnnotationsJar(getArtifactPath(sdk.getAnnotationsJar())); - sdkProto.setDx(getArtifactPath(sdk.getDx())); - sdkProto.setFrameworkAidl(getArtifactPath(sdk.getFrameworkAidl())); - sdkProto.setMainDexClasses(getArtifactPath(sdk.getMainDexClasses())); - sdkProto.setMainDexListCreator(getArtifactPath(sdk.getMainDexListCreator())); - sdkProto.setProguard(getArtifactPath(sdk.getProguard())); - sdkProto.setShrinkedAndroidJar(getArtifactPath(sdk.getShrinkedAndroidJar())); - sdkProto.setZipalign(getArtifactPath(sdk.getZipalign())); - sdkProto.setBuildToolsVersion(sdk.getBuildToolsVersion()); - - return sdkProto.build(); - } - } -} diff --git a/src/main/protobuf/BUILD b/src/main/protobuf/BUILD index 6c9cb92c50..89afb792ee 100644 --- a/src/main/protobuf/BUILD +++ b/src/main/protobuf/BUILD @@ -8,7 +8,6 @@ load("//third_party/grpc:build_defs.bzl", "java_grpc_library") FILES = [ "action_cache", "android_deploy_info", - "apk_manifest", "bazel_flags", "build", "bundlemerge", diff --git a/src/main/protobuf/apk_manifest.proto b/src/main/protobuf/apk_manifest.proto deleted file mode 100644 index 6b8afb1047..0000000000 --- a/src/main/protobuf/apk_manifest.proto +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2016 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. - -syntax = "proto3"; -package blaze.apk_manifest; - -// option java_api_version = 2; -option java_package = "com.google.devtools.build.lib.rules.android.apkmanifest"; - -message Artifact { - // This path is relative to "bazel info execution_root" - string exec_root_path = 1; - bytes hash = 2; - // The label of the rule that produced this artifact. - string label = 3; -} - -message NativeLib { - repeated Artifact native_libs = 1; - string arch = 2; -} - -message AndroidSdk { - string aapt = 1; - string adb = 2; - string aidl = 3; - string android_jar = 4; - string annotations_jar = 5; - string dx = 7; - string framework_aidl = 8; - string main_dex_classes = 11; - string main_dex_list_creator = 12; - string proguard = 13; - string shrinked_android_jar = 15; - string zipalign = 16; - string build_tools_version = 17; // assume latest if not set - string apksigner = 18; - - // Deprecated tag numbers. - reserved 6, 9, 10, 14; -} - -// Information about a resource referenced from AndroidManifest.xml. -message AndroidManifestResource { - - message ValueHash { - - // The qualifier for the value of the resource, e.g. for localization or - // device properties like hdpi, xhdpi, etc. - string qualifier = 1; - - // A hash of the value of the resource (e.g. the hash of the string value - // of a resource if it's a string), or if the resource points to a file, a - // hash of the file (e.g. if the resource is an image, then a hash of the - // image file). - bytes hash = 2; - } - - // The name of the resource, e.g. "app_name" in "@string/app_name". - string name = 1; - - // The type of the resource, e.g. "string" in "@string/app_name". - string type = 2; - - repeated ValueHash value_hashes = 3; -} - -message ApkManifest { - - // Information about the AndroidSdk - AndroidSdk android_sdk = 1; - - // All the jars containing the classes that would be dex and go into the APK - repeated Artifact jars = 2; - - // The .ap_ that contains the resources that go into the APK - Artifact resource_apk = 3; - - // The native library files that go into the APK - repeated NativeLib native_lib = 4; - - // The final merged AndroidManifest.xml file (in text, i.e. non-binary, XML) - Artifact android_manifest = 5; - - // Information about resources referenced from AndroidManifest.xml. - repeated AndroidManifestResource android_manifest_resources = 6; - - // Location of the debug keystore file. - Artifact debug_keystore = 7; -} diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/ApkManifestActionTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/ApkManifestActionTest.java deleted file mode 100644 index 2cc730f931..0000000000 --- a/src/test/java/com/google/devtools/build/lib/rules/android/ApkManifestActionTest.java +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright 2017 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.common.truth.Truth.assertThat; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.actions.Root; -import com.google.devtools.build.lib.actions.util.ActionsTestUtil; -import com.google.devtools.build.lib.actions.util.LabelArtifactOwner; -import com.google.devtools.build.lib.analysis.FilesToRunProvider; -import com.google.devtools.build.lib.cmdline.Label; -import com.google.devtools.build.lib.cmdline.LabelSyntaxException; -import com.google.devtools.build.lib.collect.nestedset.NestedSet; -import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; -import com.google.devtools.build.lib.vfs.FileSystem; -import com.google.devtools.build.lib.vfs.Path; -import com.google.devtools.build.lib.vfs.util.FileSystems; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Tests for {@link ApkManifestAction}. */ -@RunWith(JUnit4.class) -public class ApkManifestActionTest { - - private FileSystem fileSystem; - - @Before - public void setup() { - fileSystem = FileSystems.getJavaIoFileSystem(); - } - - /** A regression test to make sure the action's key changes when the output manifest changes. */ - @Test - public void testActionKey() throws Exception { - Artifact outputFile = createArtifact("/workspace/java/test/manifest"); - AndroidSdkProvider sdk = - AndroidSdkProvider.create( - "24.0.3", - createArtifact("/workspace/androidsdk/frameworkAidl"), - null, // aidlLib, optional - createArtifact("/workspace/androidsdk/androidJar"), - null, // sourceProperties, optional - createArtifact("/workspace/androidsdk/shrinkedAndroidJar"), - createArtifact("/workspace/androidsdk/annotationsJar"), - createArtifact("/workspace/androidsdk/mainDexClasses"), - createFilesToRunProvider("adb"), - createFilesToRunProvider("dx"), - createFilesToRunProvider("mainDexListCreator"), - createFilesToRunProvider("aidl"), - createFilesToRunProvider("aapt"), - createFilesToRunProvider("aapt2"), - null, // apkBuilder, optional - createFilesToRunProvider("apkSigner"), - createFilesToRunProvider("proguard"), - createFilesToRunProvider("zipalign")); - - Iterable<Artifact> jars1 = ImmutableList.of( - createArtifact("/workspace/java/test/output_jar1"), - createArtifact("/workspace/java/test/output_jar2")); - - Iterable<Artifact> jars2 = ImmutableList.of( - createArtifact("/workspace/java/test/output_jar1"), - createArtifact("/workspace/java/test/output_jar2"), - createArtifact("/workspace/java/test/output_jar3")); - - ResourceApk resourceApk = new ResourceApk( - createArtifact("/workspace/java/test/resources.ap_"), // resourceApk - null, // resourceJavaSrcJar - null, // resourceJavaClassJar - null, // resourceDeps - null, // primaryResources - createArtifact("/workspace/java/test/merged_manifest.xml"), // manifest - null, // resourceProguardConfig - null, // mainDexProguardConfig - false /* legacy */); - - NativeLibs nativeLibs = - new NativeLibs( - ImmutableMap.<String, NestedSet<Artifact>>of( - "x86", NestedSetBuilder.<Artifact>stableOrder() - .add(createArtifact("/workspace/java/test/x86.so")) - .build(), - "arm", NestedSetBuilder.<Artifact>stableOrder() - .add(createArtifact("/workspace/java/test/arm.so")) - .build()), - null /* nativeLibsName */); - - Artifact debugKeystore = createArtifact("/workspace/tools/android/debug_keystore"); - - ApkManifestAction action1 = new ApkManifestAction( - ActionsTestUtil.NULL_ACTION_OWNER, - outputFile, - true, /* textOutput */ - sdk, - jars1, - resourceApk, - nativeLibs, - debugKeystore); - - ApkManifestAction action2 = new ApkManifestAction( - ActionsTestUtil.NULL_ACTION_OWNER, - outputFile, - true, /* textOutput */ - sdk, - jars2, - resourceApk, - nativeLibs, - debugKeystore); - - String key1 = action1.computeKey(); - String key2 = action2.computeKey(); - // Action 2 has 1 more jar than Action 1, so their manifests should be different, and therefore - // their keys should also be different. - assertThat(key1).isNotEqualTo(key2); - } - - private Artifact createArtifact(String path) { - Path p = fileSystem.getPath(path); - Root root = Root.asSourceRoot(fileSystem.getRootDirectory()); - try { - return new Artifact( - p, - root, - root.getExecPath().getRelative(p.relativeTo(root.getPath())), - new LabelArtifactOwner(Label.parseAbsolute("//foo:bar"))); - } catch (LabelSyntaxException e) { - throw new IllegalStateException(e); - } - } - - private FilesToRunProvider createFilesToRunProvider(String name) { - return new FilesToRunProvider(null, null, createArtifact("/workspace/androidsdk/" + name)); - } -} - diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/BUILD b/src/test/java/com/google/devtools/build/lib/rules/android/BUILD index 8b359aed15..c7d8cfb24f 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/android/BUILD +++ b/src/test/java/com/google/devtools/build/lib/rules/android/BUILD @@ -42,25 +42,6 @@ java_test( ) java_test( - name = "ApkManifestActionTest", - srcs = ["ApkManifestActionTest.java"], - deps = [ - "//src/main/java/com/google/devtools/build/lib:android-rules", - "//src/main/java/com/google/devtools/build/lib:build-base", - "//src/main/java/com/google/devtools/build/lib/actions", - "//src/main/java/com/google/devtools/build/lib/cmdline", - "//src/main/java/com/google/devtools/build/lib/collect", - "//src/main/java/com/google/devtools/build/lib/collect/nestedset", - "//src/main/java/com/google/devtools/build/lib/vfs", - "//src/test/java/com/google/devtools/build/lib:actions_testutil", - "//src/test/java/com/google/devtools/build/lib:foundations_testutil", - "//third_party:guava", - "//third_party:junit4", - "//third_party:truth", - ], -) - -java_test( name = "AndroidCommonTest", srcs = ["AndroidCommonTest.java"], deps = [ |