diff options
author | 2017-03-17 19:13:01 +0000 | |
---|---|---|
committer | 2017-03-20 11:40:49 +0000 | |
commit | 950ff6639bbdd22f2c1ae9dae91b2893de31de11 (patch) | |
tree | 2b3134c65295d716179224eca0b88dc204c78502 /src | |
parent | 75795fa7f14339fd47390ed349e270d4c36988b7 (diff) |
Open source ApkManifestActionTest.
--
PiperOrigin-RevId: 150468384
MOS_MIGRATED_REVID=150468384
Diffstat (limited to 'src')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/android/ApkManifestActionTest.java | 155 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/android/BUILD | 18 |
2 files changed, 173 insertions, 0 deletions
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 new file mode 100644 index 0000000000..6e30dfe06e --- /dev/null +++ b/src/test/java/com/google/devtools/build/lib/rules/android/ApkManifestActionTest.java @@ -0,0 +1,155 @@ +// 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.collect.nestedset.Order; +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( + "23.0.0", + false, // aapt_supports_main_dex_generation + createArtifact("/workspace/androidsdk/frameworkAidl"), + null, // aidlLib, optional + createArtifact("/workspace/androidsdk/androidJar"), + createArtifact("/workspace/androidsdk/shrinkedAndroidJar"), + createNestedSet(createArtifact("/workspace/androidsdk/androidBaseClasspathForJack")), + createNestedSet(createArtifact("/workspace/androidsdk/javaBaseClasspathForJack")), + createArtifact("/workspace/androidsdk/annotationsJar"), + createArtifact("/workspace/androidsdk/mainDexClasses"), + createFilesToRunProvider("adb"), + createFilesToRunProvider("dx"), + createFilesToRunProvider("mainDexListCreator"), + createFilesToRunProvider("aidl"), + createFilesToRunProvider("aapt"), + createFilesToRunProvider("apkBuilder"), + createFilesToRunProvider("apkSigner"), + createFilesToRunProvider("proguard"), + createFilesToRunProvider("zipalign"), + createFilesToRunProvider("jack"), + createFilesToRunProvider("jill"), + createFilesToRunProvider("resourceExtractor")); + + 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, Iterable<Artifact>>of( + "x86", ImmutableList.of(createArtifact("/workspace/java/test/x86.so")), + "arm", ImmutableList.of(createArtifact("/workspace/java/test/arm.so"))), + 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 NestedSet<Artifact> createNestedSet(Artifact artifact) { + return NestedSetBuilder.create(Order.STABLE_ORDER, artifact); + } + + 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 bc522b90cd..2cb61f507e 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 @@ -19,6 +19,24 @@ 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:collect", + "//src/main/java/com/google/devtools/build/lib:vfs", + "//src/main/java/com/google/devtools/build/lib/actions", + "//src/main/java/com/google/devtools/build/lib/cmdline", + "//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 = [ |