blob: 5b6a39b2ac7ac3ef4eca688a068959c1fe1639b7 [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,
Jaewoong Jung6431ca72020-01-15 14:15:10 -080053 "assets_a/a": nil,
54 "assets_b/b": nil,
Colin Cross98be1bb2019-12-13 20:41:13 -080055
Colin Cross98be1bb2019-12-13 20:41:13 -080056 "prebuilts/sdk/14/public/android.jar": nil,
57 "prebuilts/sdk/14/public/framework.aidl": nil,
58 "prebuilts/sdk/14/system/android.jar": nil,
59 "prebuilts/sdk/17/public/android.jar": nil,
60 "prebuilts/sdk/17/public/framework.aidl": nil,
61 "prebuilts/sdk/17/system/android.jar": nil,
62 "prebuilts/sdk/29/public/android.jar": nil,
63 "prebuilts/sdk/29/public/framework.aidl": nil,
64 "prebuilts/sdk/29/system/android.jar": nil,
Paul Duffina2db18f2020-01-22 17:11:15 +000065 "prebuilts/sdk/29/system/foo.jar": nil,
Colin Cross98be1bb2019-12-13 20:41:13 -080066 "prebuilts/sdk/current/core/android.jar": nil,
67 "prebuilts/sdk/current/public/android.jar": nil,
68 "prebuilts/sdk/current/public/framework.aidl": nil,
69 "prebuilts/sdk/current/public/core.jar": nil,
70 "prebuilts/sdk/current/system/android.jar": nil,
71 "prebuilts/sdk/current/test/android.jar": nil,
72 "prebuilts/sdk/28/public/api/foo.txt": nil,
73 "prebuilts/sdk/28/system/api/foo.txt": nil,
74 "prebuilts/sdk/28/test/api/foo.txt": nil,
75 "prebuilts/sdk/28/public/api/foo-removed.txt": nil,
76 "prebuilts/sdk/28/system/api/foo-removed.txt": nil,
77 "prebuilts/sdk/28/test/api/foo-removed.txt": nil,
78 "prebuilts/sdk/28/public/api/bar.txt": nil,
79 "prebuilts/sdk/28/system/api/bar.txt": nil,
80 "prebuilts/sdk/28/test/api/bar.txt": nil,
81 "prebuilts/sdk/28/public/api/bar-removed.txt": nil,
82 "prebuilts/sdk/28/system/api/bar-removed.txt": nil,
83 "prebuilts/sdk/28/test/api/bar-removed.txt": nil,
84 "prebuilts/sdk/tools/core-lambda-stubs.jar": nil,
85 "prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["14", "28", "current"],}`),
86
87 "prebuilts/apk/app.apk": nil,
88 "prebuilts/apk/app_arm.apk": nil,
89 "prebuilts/apk/app_arm64.apk": nil,
90 "prebuilts/apk/app_xhdpi.apk": nil,
91 "prebuilts/apk/app_xxhdpi.apk": nil,
92
93 // For framework-res, which is an implicit dependency for framework
94 "AndroidManifest.xml": nil,
95 "build/make/target/product/security/testkey": nil,
96
97 "build/soong/scripts/jar-wrapper.sh": nil,
98
99 "build/make/core/verify_uses_libraries.sh": nil,
100
101 "build/make/core/proguard.flags": nil,
102 "build/make/core/proguard_basic_keeps.flags": nil,
103
104 "jdk8/jre/lib/jce.jar": nil,
105 "jdk8/jre/lib/rt.jar": nil,
106 "jdk8/lib/tools.jar": nil,
107
108 "bar-doc/a.java": nil,
109 "bar-doc/b.java": nil,
110 "bar-doc/IFoo.aidl": nil,
111 "bar-doc/IBar.aidl": nil,
112 "bar-doc/known_oj_tags.txt": nil,
113 "external/doclava/templates-sdk": nil,
114
115 "cert/new_cert.x509.pem": nil,
116 "cert/new_cert.pk8": nil,
117
118 "testdata/data": nil,
119
120 "stubs-sources/foo/Foo.java": nil,
121 "stubs/sources/foo/Foo.java": nil,
122 }
123
Colin Crossf28329d2020-02-15 11:00:10 -0800124 cc.GatherRequiredFilesForTest(mockFS)
125
Colin Cross98be1bb2019-12-13 20:41:13 -0800126 for k, v := range fs {
127 mockFS[k] = v
128 }
129
Colin Crossb1974532019-02-15 10:37:39 -0800130 if env == nil {
131 env = make(map[string]string)
132 }
133 if env["ANDROID_JAVA8_HOME"] == "" {
134 env["ANDROID_JAVA8_HOME"] = "jdk8"
135 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800136 config := android.TestArchConfig(buildDir, env, bp, mockFS)
Colin Crossb1974532019-02-15 10:37:39 -0800137
Colin Crossb1974532019-02-15 10:37:39 -0800138 return config
139}
140
141func GatherRequiredDepsForTest() string {
142 var bp string
143
144 extraModules := []string{
145 "core-lambda-stubs",
Colin Crossb1974532019-02-15 10:37:39 -0800146 "ext",
Colin Crossb1974532019-02-15 10:37:39 -0800147 "android_stubs_current",
148 "android_system_stubs_current",
149 "android_test_stubs_current",
Jiyong Park50146e92020-01-30 18:00:15 +0900150 "android_module_lib_stubs_current",
Jiyong Parkaae9bd12020-02-12 04:36:43 +0900151 "services-stubs",
Colin Crossb1974532019-02-15 10:37:39 -0800152 "core.current.stubs",
153 "core.platform.api.stubs",
154 "kotlin-stdlib",
Colin Cross0b03d972019-05-13 11:06:25 -0700155 "kotlin-stdlib-jdk7",
156 "kotlin-stdlib-jdk8",
Colin Crossb1974532019-02-15 10:37:39 -0800157 "kotlin-annotations",
158 }
159
160 for _, extra := range extraModules {
161 bp += fmt.Sprintf(`
162 java_library {
163 name: "%s",
164 srcs: ["a.java"],
Paul Duffin52d398a2019-06-11 12:31:14 +0100165 sdk_version: "none",
Colin Crossb1974532019-02-15 10:37:39 -0800166 system_modules: "core-platform-api-stubs-system-modules",
167 }
168 `, extra)
169 }
170
171 bp += `
Colin Cross3047fa22019-04-18 10:56:44 -0700172 java_library {
173 name: "framework",
174 srcs: ["a.java"],
Paul Duffina3d09862019-06-11 13:40:47 +0100175 sdk_version: "none",
Colin Cross3047fa22019-04-18 10:56:44 -0700176 system_modules: "core-platform-api-stubs-system-modules",
177 aidl: {
178 export_include_dirs: ["framework/aidl"],
179 },
180 }
181
Colin Crossb1974532019-02-15 10:37:39 -0800182 android_app {
183 name: "framework-res",
Paul Duffin50c217c2019-06-12 13:25:22 +0100184 sdk_version: "core_platform",
Colin Crossb1974532019-02-15 10:37:39 -0800185 }
Colin Cross50ddcc42019-05-16 12:28:22 -0700186
187 java_library {
188 name: "android.hidl.base-V1.0-java",
189 srcs: ["a.java"],
Paul Duffina3d09862019-06-11 13:40:47 +0100190 sdk_version: "none",
Colin Cross50ddcc42019-05-16 12:28:22 -0700191 system_modules: "core-platform-api-stubs-system-modules",
192 installable: true,
193 }
194
195 java_library {
196 name: "android.hidl.manager-V1.0-java",
197 srcs: ["a.java"],
Paul Duffina3d09862019-06-11 13:40:47 +0100198 sdk_version: "none",
Colin Cross50ddcc42019-05-16 12:28:22 -0700199 system_modules: "core-platform-api-stubs-system-modules",
200 installable: true,
201 }
202
203 java_library {
204 name: "org.apache.http.legacy",
205 srcs: ["a.java"],
Paul Duffina3d09862019-06-11 13:40:47 +0100206 sdk_version: "none",
Colin Cross50ddcc42019-05-16 12:28:22 -0700207 system_modules: "core-platform-api-stubs-system-modules",
208 installable: true,
209 }
Colin Crossb1974532019-02-15 10:37:39 -0800210 `
211
212 systemModules := []string{
Neil Fullerba88c412018-10-21 22:57:26 +0100213 "core-current-stubs-system-modules",
Colin Crossb1974532019-02-15 10:37:39 -0800214 "core-platform-api-stubs-system-modules",
Colin Crossb1974532019-02-15 10:37:39 -0800215 }
216
217 for _, extra := range systemModules {
218 bp += fmt.Sprintf(`
219 java_system_modules {
Paul Duffin68289b02019-09-20 13:50:52 +0100220 name: "%[1]s",
221 libs: ["%[1]s-lib"],
222 }
223 java_library {
224 name: "%[1]s-lib",
225 sdk_version: "none",
226 system_modules: "none",
Colin Crossb1974532019-02-15 10:37:39 -0800227 }
228 `, extra)
229 }
230
231 return bp
232}