blob: 6929bb724fdfb9c1997e2ccbfbbee47d885a39cf [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"
Colin Crossf28329d2020-02-15 11:00:10 -080021 "android/soong/cc"
Colin Crossb1974532019-02-15 10:37:39 -080022)
23
Colin Cross98be1bb2019-12-13 20:41:13 -080024func TestConfig(buildDir string, env map[string]string, bp string, fs map[string][]byte) android.Config {
25 bp += GatherRequiredDepsForTest()
26
27 mockFS := map[string][]byte{
28 "a.java": nil,
29 "b.java": nil,
30 "c.java": nil,
31 "b.kt": nil,
32 "a.jar": nil,
33 "b.jar": nil,
Paul Duffin56d44902020-01-31 13:36:25 +000034 "c.jar": nil,
Colin Cross98be1bb2019-12-13 20:41:13 -080035 "APP_NOTICE": nil,
36 "GENRULE_NOTICE": nil,
37 "LIB_NOTICE": nil,
38 "TOOL_NOTICE": nil,
Paul Duffin1b82e6a2019-12-03 18:06:47 +000039 "AndroidTest.xml": nil,
Colin Cross98be1bb2019-12-13 20:41:13 -080040 "java-res/a/a": nil,
41 "java-res/b/b": nil,
42 "java-res2/a": nil,
43 "java-fg/a.java": nil,
44 "java-fg/b.java": nil,
45 "java-fg/c.java": nil,
46 "api/current.txt": nil,
47 "api/removed.txt": nil,
48 "api/system-current.txt": nil,
49 "api/system-removed.txt": nil,
50 "api/test-current.txt": nil,
51 "api/test-removed.txt": nil,
52 "framework/aidl/a.aidl": nil,
Jiyong Park19604de2020-03-24 16:44:11 +090053 "aidl/foo/IFoo.aidl": nil,
54 "aidl/bar/IBar.aidl": nil,
Jaewoong Jung6431ca72020-01-15 14:15:10 -080055 "assets_a/a": nil,
56 "assets_b/b": nil,
Colin Cross98be1bb2019-12-13 20:41:13 -080057
Colin Cross98be1bb2019-12-13 20:41:13 -080058 "prebuilts/sdk/14/public/android.jar": nil,
59 "prebuilts/sdk/14/public/framework.aidl": nil,
60 "prebuilts/sdk/14/system/android.jar": nil,
61 "prebuilts/sdk/17/public/android.jar": nil,
62 "prebuilts/sdk/17/public/framework.aidl": nil,
63 "prebuilts/sdk/17/system/android.jar": nil,
64 "prebuilts/sdk/29/public/android.jar": nil,
65 "prebuilts/sdk/29/public/framework.aidl": nil,
66 "prebuilts/sdk/29/system/android.jar": nil,
Paul Duffina2db18f2020-01-22 17:11:15 +000067 "prebuilts/sdk/29/system/foo.jar": nil,
Colin Cross98be1bb2019-12-13 20:41:13 -080068 "prebuilts/sdk/current/core/android.jar": nil,
69 "prebuilts/sdk/current/public/android.jar": nil,
70 "prebuilts/sdk/current/public/framework.aidl": nil,
71 "prebuilts/sdk/current/public/core.jar": nil,
72 "prebuilts/sdk/current/system/android.jar": nil,
73 "prebuilts/sdk/current/test/android.jar": nil,
74 "prebuilts/sdk/28/public/api/foo.txt": nil,
75 "prebuilts/sdk/28/system/api/foo.txt": nil,
76 "prebuilts/sdk/28/test/api/foo.txt": nil,
77 "prebuilts/sdk/28/public/api/foo-removed.txt": nil,
78 "prebuilts/sdk/28/system/api/foo-removed.txt": nil,
79 "prebuilts/sdk/28/test/api/foo-removed.txt": nil,
80 "prebuilts/sdk/28/public/api/bar.txt": nil,
81 "prebuilts/sdk/28/system/api/bar.txt": nil,
82 "prebuilts/sdk/28/test/api/bar.txt": nil,
83 "prebuilts/sdk/28/public/api/bar-removed.txt": nil,
84 "prebuilts/sdk/28/system/api/bar-removed.txt": nil,
85 "prebuilts/sdk/28/test/api/bar-removed.txt": nil,
86 "prebuilts/sdk/tools/core-lambda-stubs.jar": nil,
87 "prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["14", "28", "current"],}`),
88
89 "prebuilts/apk/app.apk": nil,
90 "prebuilts/apk/app_arm.apk": nil,
91 "prebuilts/apk/app_arm64.apk": nil,
92 "prebuilts/apk/app_xhdpi.apk": nil,
93 "prebuilts/apk/app_xxhdpi.apk": nil,
94
95 // For framework-res, which is an implicit dependency for framework
96 "AndroidManifest.xml": nil,
97 "build/make/target/product/security/testkey": nil,
98
99 "build/soong/scripts/jar-wrapper.sh": nil,
100
101 "build/make/core/verify_uses_libraries.sh": nil,
102
103 "build/make/core/proguard.flags": nil,
104 "build/make/core/proguard_basic_keeps.flags": nil,
105
106 "jdk8/jre/lib/jce.jar": nil,
107 "jdk8/jre/lib/rt.jar": nil,
108 "jdk8/lib/tools.jar": nil,
109
110 "bar-doc/a.java": nil,
111 "bar-doc/b.java": nil,
112 "bar-doc/IFoo.aidl": nil,
113 "bar-doc/IBar.aidl": nil,
114 "bar-doc/known_oj_tags.txt": nil,
115 "external/doclava/templates-sdk": nil,
116
117 "cert/new_cert.x509.pem": nil,
118 "cert/new_cert.pk8": nil,
119
120 "testdata/data": nil,
121
122 "stubs-sources/foo/Foo.java": nil,
123 "stubs/sources/foo/Foo.java": nil,
124 }
125
Colin Crossf28329d2020-02-15 11:00:10 -0800126 cc.GatherRequiredFilesForTest(mockFS)
127
Colin Cross98be1bb2019-12-13 20:41:13 -0800128 for k, v := range fs {
129 mockFS[k] = v
130 }
131
Colin Crossb1974532019-02-15 10:37:39 -0800132 if env == nil {
133 env = make(map[string]string)
134 }
135 if env["ANDROID_JAVA8_HOME"] == "" {
136 env["ANDROID_JAVA8_HOME"] = "jdk8"
137 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800138 config := android.TestArchConfig(buildDir, env, bp, mockFS)
Colin Crossb1974532019-02-15 10:37:39 -0800139
Colin Crossb1974532019-02-15 10:37:39 -0800140 return config
141}
142
143func GatherRequiredDepsForTest() string {
144 var bp string
145
146 extraModules := []string{
147 "core-lambda-stubs",
Colin Crossb1974532019-02-15 10:37:39 -0800148 "ext",
Colin Crossb1974532019-02-15 10:37:39 -0800149 "android_stubs_current",
150 "android_system_stubs_current",
151 "android_test_stubs_current",
Jiyong Park50146e92020-01-30 18:00:15 +0900152 "android_module_lib_stubs_current",
Anton Hanssonba6ab2e2020-03-19 15:23:38 +0000153 "android_system_server_stubs_current",
Colin Crossb1974532019-02-15 10:37:39 -0800154 "core.current.stubs",
155 "core.platform.api.stubs",
156 "kotlin-stdlib",
Colin Cross0b03d972019-05-13 11:06:25 -0700157 "kotlin-stdlib-jdk7",
158 "kotlin-stdlib-jdk8",
Colin Crossb1974532019-02-15 10:37:39 -0800159 "kotlin-annotations",
160 }
161
162 for _, extra := range extraModules {
163 bp += fmt.Sprintf(`
164 java_library {
165 name: "%s",
166 srcs: ["a.java"],
Paul Duffin52d398a2019-06-11 12:31:14 +0100167 sdk_version: "none",
Colin Crossb1974532019-02-15 10:37:39 -0800168 system_modules: "core-platform-api-stubs-system-modules",
169 }
170 `, extra)
171 }
172
173 bp += `
Colin Cross3047fa22019-04-18 10:56:44 -0700174 java_library {
175 name: "framework",
176 srcs: ["a.java"],
Paul Duffina3d09862019-06-11 13:40:47 +0100177 sdk_version: "none",
Colin Cross3047fa22019-04-18 10:56:44 -0700178 system_modules: "core-platform-api-stubs-system-modules",
179 aidl: {
180 export_include_dirs: ["framework/aidl"],
181 },
182 }
183
Colin Crossb1974532019-02-15 10:37:39 -0800184 android_app {
185 name: "framework-res",
Paul Duffin50c217c2019-06-12 13:25:22 +0100186 sdk_version: "core_platform",
Colin Crossb1974532019-02-15 10:37:39 -0800187 }
Colin Cross50ddcc42019-05-16 12:28:22 -0700188
189 java_library {
190 name: "android.hidl.base-V1.0-java",
191 srcs: ["a.java"],
Paul Duffina3d09862019-06-11 13:40:47 +0100192 sdk_version: "none",
Colin Cross50ddcc42019-05-16 12:28:22 -0700193 system_modules: "core-platform-api-stubs-system-modules",
194 installable: true,
195 }
196
197 java_library {
198 name: "android.hidl.manager-V1.0-java",
199 srcs: ["a.java"],
Paul Duffina3d09862019-06-11 13:40:47 +0100200 sdk_version: "none",
Colin Cross50ddcc42019-05-16 12:28:22 -0700201 system_modules: "core-platform-api-stubs-system-modules",
202 installable: true,
203 }
204
205 java_library {
206 name: "org.apache.http.legacy",
207 srcs: ["a.java"],
Paul Duffina3d09862019-06-11 13:40:47 +0100208 sdk_version: "none",
Colin Cross50ddcc42019-05-16 12:28:22 -0700209 system_modules: "core-platform-api-stubs-system-modules",
210 installable: true,
211 }
Colin Crossb1974532019-02-15 10:37:39 -0800212 `
213
214 systemModules := []string{
Neil Fullerba88c412018-10-21 22:57:26 +0100215 "core-current-stubs-system-modules",
Colin Crossb1974532019-02-15 10:37:39 -0800216 "core-platform-api-stubs-system-modules",
Colin Crossb1974532019-02-15 10:37:39 -0800217 }
218
219 for _, extra := range systemModules {
220 bp += fmt.Sprintf(`
221 java_system_modules {
Paul Duffin68289b02019-09-20 13:50:52 +0100222 name: "%[1]s",
223 libs: ["%[1]s-lib"],
224 }
225 java_library {
226 name: "%[1]s-lib",
227 sdk_version: "none",
228 system_modules: "none",
Colin Crossb1974532019-02-15 10:37:39 -0800229 }
230 `, extra)
231 }
232
233 return bp
234}