Colin Cross | b197453 | 2019-02-15 10:37:39 -0800 | [diff] [blame] | 1 | // 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 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
| 19 | |
| 20 | "android/soong/android" |
Colin Cross | f28329d | 2020-02-15 11:00:10 -0800 | [diff] [blame] | 21 | "android/soong/cc" |
Colin Cross | b197453 | 2019-02-15 10:37:39 -0800 | [diff] [blame] | 22 | ) |
| 23 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 24 | func 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 Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 34 | "c.jar": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 35 | "APP_NOTICE": nil, |
| 36 | "GENRULE_NOTICE": nil, |
| 37 | "LIB_NOTICE": nil, |
| 38 | "TOOL_NOTICE": nil, |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 39 | "AndroidTest.xml": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 40 | "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 Park | 19604de | 2020-03-24 16:44:11 +0900 | [diff] [blame] | 53 | "aidl/foo/IFoo.aidl": nil, |
| 54 | "aidl/bar/IBar.aidl": nil, |
Jaewoong Jung | 6431ca7 | 2020-01-15 14:15:10 -0800 | [diff] [blame] | 55 | "assets_a/a": nil, |
| 56 | "assets_b/b": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 57 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 58 | "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 Duffin | a2db18f | 2020-01-22 17:11:15 +0000 | [diff] [blame] | 67 | "prebuilts/sdk/29/system/foo.jar": nil, |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 68 | "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 Cross | f28329d | 2020-02-15 11:00:10 -0800 | [diff] [blame] | 126 | cc.GatherRequiredFilesForTest(mockFS) |
| 127 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 128 | for k, v := range fs { |
| 129 | mockFS[k] = v |
| 130 | } |
| 131 | |
Colin Cross | b197453 | 2019-02-15 10:37:39 -0800 | [diff] [blame] | 132 | if env == nil { |
| 133 | env = make(map[string]string) |
| 134 | } |
| 135 | if env["ANDROID_JAVA8_HOME"] == "" { |
| 136 | env["ANDROID_JAVA8_HOME"] = "jdk8" |
| 137 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 138 | config := android.TestArchConfig(buildDir, env, bp, mockFS) |
Colin Cross | b197453 | 2019-02-15 10:37:39 -0800 | [diff] [blame] | 139 | |
Colin Cross | b197453 | 2019-02-15 10:37:39 -0800 | [diff] [blame] | 140 | return config |
| 141 | } |
| 142 | |
| 143 | func GatherRequiredDepsForTest() string { |
| 144 | var bp string |
| 145 | |
| 146 | extraModules := []string{ |
| 147 | "core-lambda-stubs", |
Colin Cross | b197453 | 2019-02-15 10:37:39 -0800 | [diff] [blame] | 148 | "ext", |
Colin Cross | b197453 | 2019-02-15 10:37:39 -0800 | [diff] [blame] | 149 | "android_stubs_current", |
| 150 | "android_system_stubs_current", |
| 151 | "android_test_stubs_current", |
Jiyong Park | 50146e9 | 2020-01-30 18:00:15 +0900 | [diff] [blame] | 152 | "android_module_lib_stubs_current", |
Anton Hansson | ba6ab2e | 2020-03-19 15:23:38 +0000 | [diff] [blame] | 153 | "android_system_server_stubs_current", |
Colin Cross | b197453 | 2019-02-15 10:37:39 -0800 | [diff] [blame] | 154 | "core.current.stubs", |
| 155 | "core.platform.api.stubs", |
| 156 | "kotlin-stdlib", |
Colin Cross | 0b03d97 | 2019-05-13 11:06:25 -0700 | [diff] [blame] | 157 | "kotlin-stdlib-jdk7", |
| 158 | "kotlin-stdlib-jdk8", |
Colin Cross | b197453 | 2019-02-15 10:37:39 -0800 | [diff] [blame] | 159 | "kotlin-annotations", |
| 160 | } |
| 161 | |
| 162 | for _, extra := range extraModules { |
| 163 | bp += fmt.Sprintf(` |
| 164 | java_library { |
| 165 | name: "%s", |
| 166 | srcs: ["a.java"], |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 167 | sdk_version: "none", |
Colin Cross | b197453 | 2019-02-15 10:37:39 -0800 | [diff] [blame] | 168 | system_modules: "core-platform-api-stubs-system-modules", |
| 169 | } |
| 170 | `, extra) |
| 171 | } |
| 172 | |
| 173 | bp += ` |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 174 | java_library { |
| 175 | name: "framework", |
| 176 | srcs: ["a.java"], |
Paul Duffin | a3d0986 | 2019-06-11 13:40:47 +0100 | [diff] [blame] | 177 | sdk_version: "none", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 178 | system_modules: "core-platform-api-stubs-system-modules", |
| 179 | aidl: { |
| 180 | export_include_dirs: ["framework/aidl"], |
| 181 | }, |
| 182 | } |
| 183 | |
Colin Cross | b197453 | 2019-02-15 10:37:39 -0800 | [diff] [blame] | 184 | android_app { |
| 185 | name: "framework-res", |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 186 | sdk_version: "core_platform", |
Colin Cross | b197453 | 2019-02-15 10:37:39 -0800 | [diff] [blame] | 187 | } |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 188 | |
| 189 | java_library { |
| 190 | name: "android.hidl.base-V1.0-java", |
| 191 | srcs: ["a.java"], |
Paul Duffin | a3d0986 | 2019-06-11 13:40:47 +0100 | [diff] [blame] | 192 | sdk_version: "none", |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 193 | 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 Duffin | a3d0986 | 2019-06-11 13:40:47 +0100 | [diff] [blame] | 200 | sdk_version: "none", |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 201 | 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 Duffin | a3d0986 | 2019-06-11 13:40:47 +0100 | [diff] [blame] | 208 | sdk_version: "none", |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 209 | system_modules: "core-platform-api-stubs-system-modules", |
| 210 | installable: true, |
| 211 | } |
Colin Cross | b197453 | 2019-02-15 10:37:39 -0800 | [diff] [blame] | 212 | ` |
| 213 | |
| 214 | systemModules := []string{ |
Neil Fuller | ba88c41 | 2018-10-21 22:57:26 +0100 | [diff] [blame] | 215 | "core-current-stubs-system-modules", |
Colin Cross | b197453 | 2019-02-15 10:37:39 -0800 | [diff] [blame] | 216 | "core-platform-api-stubs-system-modules", |
Colin Cross | b197453 | 2019-02-15 10:37:39 -0800 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | for _, extra := range systemModules { |
| 220 | bp += fmt.Sprintf(` |
| 221 | java_system_modules { |
Paul Duffin | 68289b0 | 2019-09-20 13:50:52 +0100 | [diff] [blame] | 222 | 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 Cross | b197453 | 2019-02-15 10:37:39 -0800 | [diff] [blame] | 229 | } |
| 230 | `, extra) |
| 231 | } |
| 232 | |
| 233 | return bp |
| 234 | } |