1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
// 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.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"),
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("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 FilesToRunProvider createFilesToRunProvider(String name) {
return new FilesToRunProvider(null, null, createArtifact("/workspace/androidsdk/" + name));
}
}
|