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