blob: 08bae4407caa295208ed5f956cdaa918b52103c5 [file] [log] [blame]
Colin Crossb1974532019-02-15 10:37:39 -08001// Copyright 2019 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17import (
18 "fmt"
19
20 "android/soong/android"
21)
22
Colin Cross98be1bb2019-12-13 20:41:13 -080023func TestConfig(buildDir string, env map[string]string, bp string, fs map[string][]byte) android.Config {
24 bp += GatherRequiredDepsForTest()
25
26 mockFS := map[string][]byte{
27 "a.java": nil,
28 "b.java": nil,
29 "c.java": nil,
30 "b.kt": nil,
31 "a.jar": nil,
32 "b.jar": nil,
33 "APP_NOTICE": nil,
34 "GENRULE_NOTICE": nil,
35 "LIB_NOTICE": nil,
36 "TOOL_NOTICE": nil,
Paul Duffin1b82e6a2019-12-03 18:06:47 +000037 "AndroidTest.xml": nil,
Colin Cross98be1bb2019-12-13 20:41:13 -080038 "java-res/a/a": nil,
39 "java-res/b/b": nil,
40 "java-res2/a": nil,
41 "java-fg/a.java": nil,
42 "java-fg/b.java": nil,
43 "java-fg/c.java": nil,
44 "api/current.txt": nil,
45 "api/removed.txt": nil,
46 "api/system-current.txt": nil,
47 "api/system-removed.txt": nil,
48 "api/test-current.txt": nil,
49 "api/test-removed.txt": nil,
50 "framework/aidl/a.aidl": nil,
51
52 "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so": nil,
53
54 "prebuilts/sdk/14/public/android.jar": nil,
55 "prebuilts/sdk/14/public/framework.aidl": nil,
56 "prebuilts/sdk/14/system/android.jar": nil,
57 "prebuilts/sdk/17/public/android.jar": nil,
58 "prebuilts/sdk/17/public/framework.aidl": nil,
59 "prebuilts/sdk/17/system/android.jar": nil,
60 "prebuilts/sdk/29/public/android.jar": nil,
61 "prebuilts/sdk/29/public/framework.aidl": nil,
62 "prebuilts/sdk/29/system/android.jar": nil,
63 "prebuilts/sdk/current/core/android.jar": nil,
64 "prebuilts/sdk/current/public/android.jar": nil,
65 "prebuilts/sdk/current/public/framework.aidl": nil,
66 "prebuilts/sdk/current/public/core.jar": nil,
67 "prebuilts/sdk/current/system/android.jar": nil,
68 "prebuilts/sdk/current/test/android.jar": nil,
69 "prebuilts/sdk/28/public/api/foo.txt": nil,
70 "prebuilts/sdk/28/system/api/foo.txt": nil,
71 "prebuilts/sdk/28/test/api/foo.txt": nil,
72 "prebuilts/sdk/28/public/api/foo-removed.txt": nil,
73 "prebuilts/sdk/28/system/api/foo-removed.txt": nil,
74 "prebuilts/sdk/28/test/api/foo-removed.txt": nil,
75 "prebuilts/sdk/28/public/api/bar.txt": nil,
76 "prebuilts/sdk/28/system/api/bar.txt": nil,
77 "prebuilts/sdk/28/test/api/bar.txt": nil,
78 "prebuilts/sdk/28/public/api/bar-removed.txt": nil,
79 "prebuilts/sdk/28/system/api/bar-removed.txt": nil,
80 "prebuilts/sdk/28/test/api/bar-removed.txt": nil,
81 "prebuilts/sdk/tools/core-lambda-stubs.jar": nil,
82 "prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["14", "28", "current"],}`),
83
84 "prebuilts/apk/app.apk": nil,
85 "prebuilts/apk/app_arm.apk": nil,
86 "prebuilts/apk/app_arm64.apk": nil,
87 "prebuilts/apk/app_xhdpi.apk": nil,
88 "prebuilts/apk/app_xxhdpi.apk": nil,
89
90 // For framework-res, which is an implicit dependency for framework
91 "AndroidManifest.xml": nil,
92 "build/make/target/product/security/testkey": nil,
93
94 "build/soong/scripts/jar-wrapper.sh": nil,
95
96 "build/make/core/verify_uses_libraries.sh": nil,
97
98 "build/make/core/proguard.flags": nil,
99 "build/make/core/proguard_basic_keeps.flags": nil,
100
101 "jdk8/jre/lib/jce.jar": nil,
102 "jdk8/jre/lib/rt.jar": nil,
103 "jdk8/lib/tools.jar": nil,
104
105 "bar-doc/a.java": nil,
106 "bar-doc/b.java": nil,
107 "bar-doc/IFoo.aidl": nil,
108 "bar-doc/IBar.aidl": nil,
109 "bar-doc/known_oj_tags.txt": nil,
110 "external/doclava/templates-sdk": nil,
111
112 "cert/new_cert.x509.pem": nil,
113 "cert/new_cert.pk8": nil,
114
115 "testdata/data": nil,
116
117 "stubs-sources/foo/Foo.java": nil,
118 "stubs/sources/foo/Foo.java": nil,
119 }
120
121 for k, v := range fs {
122 mockFS[k] = v
123 }
124
Colin Crossb1974532019-02-15 10:37:39 -0800125 if env == nil {
126 env = make(map[string]string)
127 }
128 if env["ANDROID_JAVA8_HOME"] == "" {
129 env["ANDROID_JAVA8_HOME"] = "jdk8"
130 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800131 config := android.TestArchConfig(buildDir, env, bp, mockFS)
Colin Crossb1974532019-02-15 10:37:39 -0800132
Colin Crossb1974532019-02-15 10:37:39 -0800133 return config
134}
135
136func GatherRequiredDepsForTest() string {
137 var bp string
138
139 extraModules := []string{
140 "core-lambda-stubs",
Colin Crossb1974532019-02-15 10:37:39 -0800141 "ext",
Colin Crossb1974532019-02-15 10:37:39 -0800142 "android_stubs_current",
143 "android_system_stubs_current",
144 "android_test_stubs_current",
145 "core.current.stubs",
146 "core.platform.api.stubs",
147 "kotlin-stdlib",
Colin Cross0b03d972019-05-13 11:06:25 -0700148 "kotlin-stdlib-jdk7",
149 "kotlin-stdlib-jdk8",
Colin Crossb1974532019-02-15 10:37:39 -0800150 "kotlin-annotations",
151 }
152
153 for _, extra := range extraModules {
154 bp += fmt.Sprintf(`
155 java_library {
156 name: "%s",
157 srcs: ["a.java"],
Paul Duffin52d398a2019-06-11 12:31:14 +0100158 sdk_version: "none",
Colin Crossb1974532019-02-15 10:37:39 -0800159 system_modules: "core-platform-api-stubs-system-modules",
160 }
161 `, extra)
162 }
163
164 bp += `
Colin Cross3047fa22019-04-18 10:56:44 -0700165 java_library {
166 name: "framework",
167 srcs: ["a.java"],
Paul Duffina3d09862019-06-11 13:40:47 +0100168 sdk_version: "none",
Colin Cross3047fa22019-04-18 10:56:44 -0700169 system_modules: "core-platform-api-stubs-system-modules",
170 aidl: {
171 export_include_dirs: ["framework/aidl"],
172 },
173 }
174
Colin Crossb1974532019-02-15 10:37:39 -0800175 android_app {
176 name: "framework-res",
Paul Duffin50c217c2019-06-12 13:25:22 +0100177 sdk_version: "core_platform",
Colin Crossb1974532019-02-15 10:37:39 -0800178 }
Colin Cross50ddcc42019-05-16 12:28:22 -0700179
180 java_library {
181 name: "android.hidl.base-V1.0-java",
182 srcs: ["a.java"],
Paul Duffina3d09862019-06-11 13:40:47 +0100183 sdk_version: "none",
Colin Cross50ddcc42019-05-16 12:28:22 -0700184 system_modules: "core-platform-api-stubs-system-modules",
185 installable: true,
186 }
187
188 java_library {
189 name: "android.hidl.manager-V1.0-java",
190 srcs: ["a.java"],
Paul Duffina3d09862019-06-11 13:40:47 +0100191 sdk_version: "none",
Colin Cross50ddcc42019-05-16 12:28:22 -0700192 system_modules: "core-platform-api-stubs-system-modules",
193 installable: true,
194 }
195
196 java_library {
197 name: "org.apache.http.legacy",
198 srcs: ["a.java"],
Paul Duffina3d09862019-06-11 13:40:47 +0100199 sdk_version: "none",
Colin Cross50ddcc42019-05-16 12:28:22 -0700200 system_modules: "core-platform-api-stubs-system-modules",
201 installable: true,
202 }
Colin Crossb1974532019-02-15 10:37:39 -0800203 `
204
205 systemModules := []string{
Neil Fullerba88c412018-10-21 22:57:26 +0100206 "core-current-stubs-system-modules",
Colin Crossb1974532019-02-15 10:37:39 -0800207 "core-platform-api-stubs-system-modules",
Colin Crossb1974532019-02-15 10:37:39 -0800208 }
209
210 for _, extra := range systemModules {
211 bp += fmt.Sprintf(`
212 java_system_modules {
Paul Duffin68289b02019-09-20 13:50:52 +0100213 name: "%[1]s",
214 libs: ["%[1]s-lib"],
215 }
216 java_library {
217 name: "%[1]s-lib",
218 sdk_version: "none",
219 system_modules: "none",
Colin Crossb1974532019-02-15 10:37:39 -0800220 }
221 `, extra)
222 }
223
224 return bp
225}