Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 1 | // Copyright 2017 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 | "android/soong/android" |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 19 | "android/soong/genrule" |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 20 | "fmt" |
| 21 | "io/ioutil" |
| 22 | "os" |
| 23 | "path/filepath" |
Colin Cross | 227d436 | 2017-08-30 14:14:52 -0700 | [diff] [blame] | 24 | "reflect" |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 25 | "strconv" |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 26 | "strings" |
| 27 | "testing" |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 28 | |
| 29 | "github.com/google/blueprint/proptools" |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 30 | ) |
| 31 | |
| 32 | var buildDir string |
| 33 | |
| 34 | func setUp() { |
| 35 | var err error |
| 36 | buildDir, err = ioutil.TempDir("", "soong_java_test") |
| 37 | if err != nil { |
| 38 | panic(err) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | func tearDown() { |
| 43 | os.RemoveAll(buildDir) |
| 44 | } |
| 45 | |
| 46 | func TestMain(m *testing.M) { |
| 47 | run := func() int { |
| 48 | setUp() |
| 49 | defer tearDown() |
| 50 | |
| 51 | return m.Run() |
| 52 | } |
| 53 | |
| 54 | os.Exit(run()) |
| 55 | } |
Colin Cross | 527012a | 2017-11-30 22:56:16 -0800 | [diff] [blame] | 56 | |
| 57 | func testConfig(env map[string]string) android.Config { |
Colin Cross | 7fdd2b7 | 2018-01-02 18:14:25 -0800 | [diff] [blame] | 58 | if env == nil { |
| 59 | env = make(map[string]string) |
| 60 | } |
| 61 | if env["ANDROID_JAVA8_HOME"] == "" { |
| 62 | env["ANDROID_JAVA8_HOME"] = "jdk8" |
| 63 | } |
Jiyong Park | 1a5d7b1 | 2018-01-15 15:05:10 +0900 | [diff] [blame] | 64 | config := android.TestArchConfig(buildDir, env) |
Dan Willemsen | 674dc7f | 2018-03-12 18:06:05 -0700 | [diff] [blame] | 65 | config.TestProductVariables.DeviceSystemSdkVersions = &[]string{"14", "15"} |
Jiyong Park | 1a5d7b1 | 2018-01-15 15:05:10 +0900 | [diff] [blame] | 66 | return config |
Colin Cross | 527012a | 2017-11-30 22:56:16 -0800 | [diff] [blame] | 67 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Colin Cross | 527012a | 2017-11-30 22:56:16 -0800 | [diff] [blame] | 70 | func testContext(config android.Config, bp string, |
| 71 | fs map[string][]byte) *android.TestContext { |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 72 | |
Colin Cross | 4c428df | 2017-09-15 17:36:05 -0700 | [diff] [blame] | 73 | ctx := android.NewTestArchContext() |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 74 | ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(AndroidAppFactory)) |
Colin Cross | a97c5d3 | 2018-03-28 14:58:31 -0700 | [diff] [blame] | 75 | ctx.RegisterModuleType("android_library", android.ModuleFactoryAdaptor(AndroidLibraryFactory)) |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 76 | ctx.RegisterModuleType("java_binary_host", android.ModuleFactoryAdaptor(BinaryHostFactory)) |
Colin Cross | 9ae1b92 | 2018-06-26 17:59:05 -0700 | [diff] [blame] | 77 | ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(LibraryFactory)) |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 78 | ctx.RegisterModuleType("java_library_host", android.ModuleFactoryAdaptor(LibraryHostFactory)) |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 79 | ctx.RegisterModuleType("java_import", android.ModuleFactoryAdaptor(ImportFactory)) |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 80 | ctx.RegisterModuleType("java_defaults", android.ModuleFactoryAdaptor(defaultsFactory)) |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 81 | ctx.RegisterModuleType("java_system_modules", android.ModuleFactoryAdaptor(SystemModulesFactory)) |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 82 | ctx.RegisterModuleType("java_genrule", android.ModuleFactoryAdaptor(genRuleFactory)) |
Pirama Arumuga Nainar | 955dc49 | 2018-04-17 14:58:42 -0700 | [diff] [blame] | 83 | ctx.RegisterModuleType("filegroup", android.ModuleFactoryAdaptor(android.FileGroupFactory)) |
Colin Cross | 54190b3 | 2017-10-09 15:34:10 -0700 | [diff] [blame] | 84 | ctx.RegisterModuleType("genrule", android.ModuleFactoryAdaptor(genrule.GenRuleFactory)) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 85 | ctx.RegisterModuleType("droiddoc", android.ModuleFactoryAdaptor(DroiddocFactory)) |
| 86 | ctx.RegisterModuleType("droiddoc_host", android.ModuleFactoryAdaptor(DroiddocHostFactory)) |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 87 | ctx.RegisterModuleType("droiddoc_template", android.ModuleFactoryAdaptor(DroiddocTemplateFactory)) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 88 | ctx.RegisterModuleType("java_sdk_library", android.ModuleFactoryAdaptor(sdkLibraryFactory)) |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 89 | ctx.RegisterModuleType("prebuilt_apis", android.ModuleFactoryAdaptor(prebuiltApisFactory)) |
Colin Cross | 5ea9bcc | 2017-07-27 15:41:32 -0700 | [diff] [blame] | 90 | ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators) |
| 91 | ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators) |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 92 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 93 | ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) { |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 94 | ctx.TopDown("prebuilt_apis", prebuiltApisMutator).Parallel() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 95 | ctx.TopDown("java_sdk_library", sdkLibraryMutator).Parallel() |
| 96 | }) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 97 | ctx.RegisterPreSingletonType("overlay", android.SingletonFactoryAdaptor(OverlaySingletonFactory)) |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 98 | ctx.Register() |
| 99 | |
Colin Cross | 4c428df | 2017-09-15 17:36:05 -0700 | [diff] [blame] | 100 | extraModules := []string{ |
| 101 | "core-oj", |
| 102 | "core-libart", |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 103 | "core-lambda-stubs", |
Colin Cross | 4c428df | 2017-09-15 17:36:05 -0700 | [diff] [blame] | 104 | "framework", |
| 105 | "ext", |
| 106 | "okhttp", |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 107 | "android_stubs_current", |
| 108 | "android_system_stubs_current", |
| 109 | "android_test_stubs_current", |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 110 | "core.current.stubs", |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 111 | "kotlin-stdlib", |
Colin Cross | 4c428df | 2017-09-15 17:36:05 -0700 | [diff] [blame] | 112 | } |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 113 | |
| 114 | for _, extra := range extraModules { |
| 115 | bp += fmt.Sprintf(` |
| 116 | java_library { |
| 117 | name: "%s", |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 118 | srcs: ["a.java"], |
Colin Cross | 76b5f0c | 2017-08-29 16:02:06 -0700 | [diff] [blame] | 119 | no_standard_libs: true, |
Colin Cross | f19b9bb | 2018-03-26 14:42:44 -0700 | [diff] [blame] | 120 | sdk_version: "core_current", |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 121 | system_modules: "core-system-modules", |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 122 | } |
| 123 | `, extra) |
| 124 | } |
| 125 | |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 126 | bp += ` |
| 127 | android_app { |
| 128 | name: "framework-res", |
| 129 | no_framework_libs: true, |
| 130 | } |
| 131 | ` |
| 132 | |
Colin Cross | 527012a | 2017-11-30 22:56:16 -0800 | [diff] [blame] | 133 | systemModules := []string{ |
| 134 | "core-system-modules", |
| 135 | "android_stubs_current_system_modules", |
| 136 | "android_system_stubs_current_system_modules", |
| 137 | "android_test_stubs_current_system_modules", |
| 138 | } |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 139 | |
Colin Cross | 527012a | 2017-11-30 22:56:16 -0800 | [diff] [blame] | 140 | for _, extra := range systemModules { |
| 141 | bp += fmt.Sprintf(` |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 142 | java_system_modules { |
| 143 | name: "%s", |
| 144 | } |
| 145 | `, extra) |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Colin Cross | 824bee3 | 2017-11-22 17:27:51 -0800 | [diff] [blame] | 148 | mockFS := map[string][]byte{ |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 149 | "Android.bp": []byte(bp), |
| 150 | "a.java": nil, |
| 151 | "b.java": nil, |
| 152 | "c.java": nil, |
| 153 | "b.kt": nil, |
| 154 | "a.jar": nil, |
| 155 | "b.jar": nil, |
| 156 | "java-res/a/a": nil, |
| 157 | "java-res/b/b": nil, |
| 158 | "java-res2/a": nil, |
| 159 | "java-fg/a.java": nil, |
| 160 | "java-fg/b.java": nil, |
| 161 | "java-fg/c.java": nil, |
| 162 | "api/current.txt": nil, |
| 163 | "api/removed.txt": nil, |
| 164 | "api/system-current.txt": nil, |
| 165 | "api/system-removed.txt": nil, |
| 166 | "api/test-current.txt": nil, |
| 167 | "api/test-removed.txt": nil, |
Colin Cross | 0532fb0 | 2017-10-02 16:57:40 -0700 | [diff] [blame] | 168 | |
Anton Hansson | f66efeb | 2018-04-11 13:57:30 +0100 | [diff] [blame] | 169 | "prebuilts/sdk/14/public/android.jar": nil, |
| 170 | "prebuilts/sdk/14/public/framework.aidl": nil, |
| 171 | "prebuilts/sdk/14/system/android.jar": nil, |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 172 | "prebuilts/sdk/current/core/android.jar": nil, |
Anton Hansson | f66efeb | 2018-04-11 13:57:30 +0100 | [diff] [blame] | 173 | "prebuilts/sdk/current/public/android.jar": nil, |
| 174 | "prebuilts/sdk/current/public/framework.aidl": nil, |
| 175 | "prebuilts/sdk/current/public/core.jar": nil, |
| 176 | "prebuilts/sdk/current/system/android.jar": nil, |
| 177 | "prebuilts/sdk/current/test/android.jar": nil, |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 178 | "prebuilts/sdk/28/public/api/foo.txt": nil, |
| 179 | "prebuilts/sdk/28/system/api/foo.txt": nil, |
| 180 | "prebuilts/sdk/28/test/api/foo.txt": nil, |
| 181 | "prebuilts/sdk/28/public/api/foo-removed.txt": nil, |
| 182 | "prebuilts/sdk/28/system/api/foo-removed.txt": nil, |
| 183 | "prebuilts/sdk/28/test/api/foo-removed.txt": nil, |
| 184 | "prebuilts/sdk/28/public/api/bar.txt": nil, |
| 185 | "prebuilts/sdk/28/system/api/bar.txt": nil, |
| 186 | "prebuilts/sdk/28/test/api/bar.txt": nil, |
| 187 | "prebuilts/sdk/28/public/api/bar-removed.txt": nil, |
| 188 | "prebuilts/sdk/28/system/api/bar-removed.txt": nil, |
| 189 | "prebuilts/sdk/28/test/api/bar-removed.txt": nil, |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 190 | "prebuilts/sdk/tools/core-lambda-stubs.jar": nil, |
Sundong Ahn | 27eecb9 | 2018-06-21 13:47:17 +0900 | [diff] [blame] | 191 | "prebuilts/sdk/Android.bp": []byte(`prebuilt_apis { name: "sdk", api_dirs: ["14", "28", "current"],}`), |
Colin Cross | 5ab4e6d | 2017-11-22 16:20:45 -0800 | [diff] [blame] | 192 | |
| 193 | // For framework-res, which is an implicit dependency for framework |
| 194 | "AndroidManifest.xml": nil, |
| 195 | "build/target/product/security/testkey": nil, |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 196 | |
| 197 | "build/soong/scripts/jar-wrapper.sh": nil, |
Colin Cross | 7fdd2b7 | 2018-01-02 18:14:25 -0800 | [diff] [blame] | 198 | |
Colin Cross | 66dbc0b | 2017-12-28 12:23:20 -0800 | [diff] [blame] | 199 | "build/make/core/proguard.flags": nil, |
| 200 | "build/make/core/proguard_basic_keeps.flags": nil, |
| 201 | |
Colin Cross | 7fdd2b7 | 2018-01-02 18:14:25 -0800 | [diff] [blame] | 202 | "jdk8/jre/lib/jce.jar": nil, |
| 203 | "jdk8/jre/lib/rt.jar": nil, |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 204 | "jdk8/lib/tools.jar": nil, |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 205 | |
| 206 | "bar-doc/a.java": nil, |
| 207 | "bar-doc/b.java": nil, |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 208 | "bar-doc/IFoo.aidl": nil, |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 209 | "bar-doc/known_oj_tags.txt": nil, |
| 210 | "external/doclava/templates-sdk": nil, |
Przemyslaw Szczepaniak | 66c0c40 | 2018-03-08 13:21:55 +0000 | [diff] [blame] | 211 | |
| 212 | "external/kotlinc/jarjar-rules.txt": nil, |
Colin Cross | 824bee3 | 2017-11-22 17:27:51 -0800 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | for k, v := range fs { |
| 216 | mockFS[k] = v |
| 217 | } |
| 218 | |
| 219 | ctx.MockFileSystem(mockFS) |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 220 | |
Colin Cross | 527012a | 2017-11-30 22:56:16 -0800 | [diff] [blame] | 221 | return ctx |
| 222 | } |
| 223 | |
| 224 | func run(t *testing.T, ctx *android.TestContext, config android.Config) { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 225 | t.Helper() |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 226 | _, errs := ctx.ParseFileList(".", []string{"Android.bp", "prebuilts/sdk/Android.bp"}) |
Logan Chien | 4203971 | 2018-03-12 16:29:17 +0800 | [diff] [blame] | 227 | android.FailIfErrored(t, errs) |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 228 | _, errs = ctx.PrepareBuildActions(config) |
Logan Chien | 4203971 | 2018-03-12 16:29:17 +0800 | [diff] [blame] | 229 | android.FailIfErrored(t, errs) |
Colin Cross | 527012a | 2017-11-30 22:56:16 -0800 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | func testJava(t *testing.T, bp string) *android.TestContext { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 233 | t.Helper() |
Colin Cross | 527012a | 2017-11-30 22:56:16 -0800 | [diff] [blame] | 234 | config := testConfig(nil) |
| 235 | ctx := testContext(config, bp, nil) |
| 236 | run(t, ctx, config) |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 237 | |
| 238 | return ctx |
| 239 | } |
| 240 | |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 241 | func moduleToPath(name string) string { |
| 242 | switch { |
| 243 | case name == `""`: |
| 244 | return name |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 245 | case strings.HasSuffix(name, ".jar"): |
| 246 | return name |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 247 | default: |
| 248 | return filepath.Join(buildDir, ".intermediates", name, "android_common", "turbine-combined", name+".jar") |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 252 | func TestSimple(t *testing.T) { |
| 253 | ctx := testJava(t, ` |
| 254 | java_library { |
| 255 | name: "foo", |
| 256 | srcs: ["a.java"], |
Colin Cross | e8dc34a | 2017-07-19 11:22:16 -0700 | [diff] [blame] | 257 | libs: ["bar"], |
| 258 | static_libs: ["baz"], |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | java_library { |
| 262 | name: "bar", |
| 263 | srcs: ["b.java"], |
| 264 | } |
| 265 | |
| 266 | java_library { |
| 267 | name: "baz", |
| 268 | srcs: ["c.java"], |
| 269 | } |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 270 | `) |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 271 | |
Colin Cross | 4c428df | 2017-09-15 17:36:05 -0700 | [diff] [blame] | 272 | javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 273 | combineJar := ctx.ModuleForTests("foo", "android_common").Description("for javac") |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 274 | |
| 275 | if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "a.java" { |
| 276 | t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs) |
| 277 | } |
| 278 | |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 279 | baz := ctx.ModuleForTests("baz", "android_common").Rule("javac").Output.String() |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 280 | barTurbine := filepath.Join(buildDir, ".intermediates", "bar", "android_common", "turbine-combined", "bar.jar") |
| 281 | bazTurbine := filepath.Join(buildDir, ".intermediates", "baz", "android_common", "turbine-combined", "baz.jar") |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 282 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 283 | if !strings.Contains(javac.Args["classpath"], barTurbine) { |
| 284 | t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], barTurbine) |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 287 | if !strings.Contains(javac.Args["classpath"], bazTurbine) { |
| 288 | t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], bazTurbine) |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != baz { |
| 292 | t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, baz) |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 296 | func TestArchSpecific(t *testing.T) { |
| 297 | ctx := testJava(t, ` |
| 298 | java_library { |
| 299 | name: "foo", |
| 300 | srcs: ["a.java"], |
| 301 | target: { |
| 302 | android: { |
| 303 | srcs: ["b.java"], |
| 304 | }, |
| 305 | }, |
| 306 | } |
| 307 | `) |
| 308 | |
| 309 | javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") |
| 310 | if len(javac.Inputs) != 2 || javac.Inputs[0].String() != "a.java" || javac.Inputs[1].String() != "b.java" { |
| 311 | t.Errorf(`foo inputs %v != ["a.java", "b.java"]`, javac.Inputs) |
| 312 | } |
| 313 | } |
| 314 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 315 | func TestBinary(t *testing.T) { |
| 316 | ctx := testJava(t, ` |
| 317 | java_library_host { |
| 318 | name: "foo", |
| 319 | srcs: ["a.java"], |
| 320 | } |
| 321 | |
| 322 | java_binary_host { |
| 323 | name: "bar", |
| 324 | srcs: ["b.java"], |
| 325 | static_libs: ["foo"], |
| 326 | } |
| 327 | `) |
| 328 | |
| 329 | buildOS := android.BuildOs.String() |
| 330 | |
| 331 | bar := ctx.ModuleForTests("bar", buildOS+"_common") |
| 332 | barJar := bar.Output("bar.jar").Output.String() |
| 333 | barWrapper := ctx.ModuleForTests("bar", buildOS+"_x86_64") |
| 334 | barWrapperDeps := barWrapper.Output("bar").Implicits.Strings() |
| 335 | |
| 336 | // Test that the install binary wrapper depends on the installed jar file |
| 337 | if len(barWrapperDeps) != 1 || barWrapperDeps[0] != barJar { |
| 338 | t.Errorf("expected binary wrapper implicits [%q], got %v", |
| 339 | barJar, barWrapperDeps) |
| 340 | } |
| 341 | |
| 342 | } |
| 343 | |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 344 | var classpathTestcases = []struct { |
| 345 | name string |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 346 | unbundled bool |
Colin Cross | 965714f | 2017-10-03 20:57:01 -0700 | [diff] [blame] | 347 | moduleType string |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 348 | host android.OsClass |
| 349 | properties string |
| 350 | bootclasspath []string |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 351 | system string |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 352 | classpath []string |
| 353 | }{ |
| 354 | { |
| 355 | name: "default", |
Colin Cross | 7cdc22e | 2018-05-30 05:45:09 +0000 | [diff] [blame] | 356 | bootclasspath: []string{"core-oj", "core-libart"}, |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 357 | system: "core-system-modules", |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 358 | classpath: []string{"ext", "framework", "okhttp"}, |
| 359 | }, |
| 360 | { |
| 361 | name: "blank sdk version", |
| 362 | properties: `sdk_version: "",`, |
Colin Cross | 7cdc22e | 2018-05-30 05:45:09 +0000 | [diff] [blame] | 363 | bootclasspath: []string{"core-oj", "core-libart"}, |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 364 | system: "core-system-modules", |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 365 | classpath: []string{"ext", "framework", "okhttp"}, |
| 366 | }, |
| 367 | { |
Colin Cross | 4c428df | 2017-09-15 17:36:05 -0700 | [diff] [blame] | 368 | |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 369 | name: "sdk v14", |
| 370 | properties: `sdk_version: "14",`, |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 371 | bootclasspath: []string{`""`}, |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 372 | system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 373 | classpath: []string{"prebuilts/sdk/14/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 374 | }, |
| 375 | { |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 376 | |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 377 | name: "current", |
| 378 | properties: `sdk_version: "current",`, |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 379 | bootclasspath: []string{"android_stubs_current", "core-lambda-stubs"}, |
Colin Cross | 2ebc476 | 2017-10-20 14:00:31 -0700 | [diff] [blame] | 380 | system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 381 | }, |
| 382 | { |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 383 | |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 384 | name: "system_current", |
| 385 | properties: `sdk_version: "system_current",`, |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 386 | bootclasspath: []string{"android_system_stubs_current", "core-lambda-stubs"}, |
Colin Cross | 2ebc476 | 2017-10-20 14:00:31 -0700 | [diff] [blame] | 387 | system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 388 | }, |
| 389 | { |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 390 | |
Sundong Ahn | 0926fae | 2017-10-17 16:34:51 +0900 | [diff] [blame] | 391 | name: "system_14", |
| 392 | properties: `sdk_version: "system_14",`, |
| 393 | bootclasspath: []string{`""`}, |
| 394 | system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 395 | classpath: []string{"prebuilts/sdk/14/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
Sundong Ahn | 0926fae | 2017-10-17 16:34:51 +0900 | [diff] [blame] | 396 | }, |
| 397 | { |
| 398 | |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 399 | name: "test_current", |
| 400 | properties: `sdk_version: "test_current",`, |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 401 | bootclasspath: []string{"android_test_stubs_current", "core-lambda-stubs"}, |
Colin Cross | 2ebc476 | 2017-10-20 14:00:31 -0700 | [diff] [blame] | 402 | system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 403 | }, |
| 404 | { |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 405 | |
Jiyong Park | 750e557 | 2018-01-31 00:20:13 +0900 | [diff] [blame] | 406 | name: "core_current", |
| 407 | properties: `sdk_version: "core_current",`, |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 408 | bootclasspath: []string{"core.current.stubs", "core-lambda-stubs"}, |
Jiyong Park | 750e557 | 2018-01-31 00:20:13 +0900 | [diff] [blame] | 409 | system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath |
Jiyong Park | 750e557 | 2018-01-31 00:20:13 +0900 | [diff] [blame] | 410 | }, |
| 411 | { |
| 412 | |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 413 | name: "nostdlib", |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 414 | properties: `no_standard_libs: true, system_modules: "none"`, |
| 415 | system: "none", |
| 416 | bootclasspath: []string{`""`}, |
| 417 | classpath: []string{}, |
| 418 | }, |
| 419 | { |
| 420 | |
| 421 | name: "nostdlib system_modules", |
| 422 | properties: `no_standard_libs: true, system_modules: "core-system-modules"`, |
| 423 | system: "core-system-modules", |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 424 | bootclasspath: []string{`""`}, |
| 425 | classpath: []string{}, |
| 426 | }, |
| 427 | { |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 428 | |
Colin Cross | 7fdd2b7 | 2018-01-02 18:14:25 -0800 | [diff] [blame] | 429 | name: "host default", |
| 430 | moduleType: "java_library_host", |
| 431 | properties: ``, |
| 432 | host: android.Host, |
| 433 | bootclasspath: []string{"jdk8/jre/lib/jce.jar", "jdk8/jre/lib/rt.jar"}, |
| 434 | classpath: []string{}, |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 435 | }, |
| 436 | { |
| 437 | name: "host nostdlib", |
Colin Cross | 965714f | 2017-10-03 20:57:01 -0700 | [diff] [blame] | 438 | moduleType: "java_library_host", |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 439 | host: android.Host, |
| 440 | properties: `no_standard_libs: true`, |
| 441 | classpath: []string{}, |
| 442 | }, |
Colin Cross | 965714f | 2017-10-03 20:57:01 -0700 | [diff] [blame] | 443 | { |
| 444 | |
Colin Cross | 7fdd2b7 | 2018-01-02 18:14:25 -0800 | [diff] [blame] | 445 | name: "host supported default", |
| 446 | host: android.Host, |
| 447 | properties: `host_supported: true,`, |
| 448 | classpath: []string{}, |
| 449 | bootclasspath: []string{"jdk8/jre/lib/jce.jar", "jdk8/jre/lib/rt.jar"}, |
Colin Cross | 965714f | 2017-10-03 20:57:01 -0700 | [diff] [blame] | 450 | }, |
| 451 | { |
| 452 | name: "host supported nostdlib", |
| 453 | host: android.Host, |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 454 | properties: `host_supported: true, no_standard_libs: true, system_modules: "none"`, |
Colin Cross | 965714f | 2017-10-03 20:57:01 -0700 | [diff] [blame] | 455 | classpath: []string{}, |
| 456 | }, |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 457 | { |
| 458 | |
| 459 | name: "unbundled sdk v14", |
| 460 | unbundled: true, |
| 461 | properties: `sdk_version: "14",`, |
| 462 | bootclasspath: []string{`""`}, |
| 463 | system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath |
| 464 | classpath: []string{"prebuilts/sdk/14/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 465 | }, |
| 466 | { |
| 467 | |
| 468 | name: "unbundled current", |
| 469 | unbundled: true, |
| 470 | properties: `sdk_version: "current",`, |
| 471 | bootclasspath: []string{`""`}, |
| 472 | system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath |
| 473 | classpath: []string{"prebuilts/sdk/current/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 474 | }, |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 475 | } |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 476 | |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 477 | func TestClasspath(t *testing.T) { |
| 478 | for _, testcase := range classpathTestcases { |
| 479 | t.Run(testcase.name, func(t *testing.T) { |
Colin Cross | 965714f | 2017-10-03 20:57:01 -0700 | [diff] [blame] | 480 | moduleType := "java_library" |
| 481 | if testcase.moduleType != "" { |
| 482 | moduleType = testcase.moduleType |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 483 | } |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 484 | |
| 485 | bp := moduleType + ` { |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 486 | name: "foo", |
| 487 | srcs: ["a.java"], |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 488 | ` + testcase.properties + ` |
| 489 | }` |
| 490 | |
| 491 | variant := "android_common" |
| 492 | if testcase.host == android.Host { |
| 493 | variant = android.BuildOs.String() + "_common" |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 494 | } |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 495 | |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 496 | convertModulesToPaths := func(cp []string) []string { |
| 497 | ret := make([]string, len(cp)) |
| 498 | for i, e := range cp { |
| 499 | ret[i] = moduleToPath(e) |
| 500 | } |
| 501 | return ret |
| 502 | } |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 503 | |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 504 | bootclasspath := convertModulesToPaths(testcase.bootclasspath) |
| 505 | classpath := convertModulesToPaths(testcase.classpath) |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 506 | |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 507 | bc := strings.Join(bootclasspath, ":") |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 508 | if bc != "" { |
| 509 | bc = "-bootclasspath " + bc |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 510 | } |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 511 | |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 512 | c := strings.Join(classpath, ":") |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 513 | if c != "" { |
| 514 | c = "-classpath " + c |
| 515 | } |
| 516 | system := "" |
| 517 | if testcase.system == "none" { |
| 518 | system = "--system=none" |
| 519 | } else if testcase.system != "" { |
| 520 | system = "--system=" + filepath.Join(buildDir, ".intermediates", testcase.system, "android_common", "system") + "/" |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 523 | t.Run("1.8", func(t *testing.T) { |
| 524 | // Test default javac 1.8 |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 525 | config := testConfig(nil) |
| 526 | if testcase.unbundled { |
| 527 | config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) |
| 528 | } |
| 529 | ctx := testContext(config, bp, nil) |
| 530 | run(t, ctx, config) |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 531 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 532 | javac := ctx.ModuleForTests("foo", variant).Rule("javac") |
| 533 | |
| 534 | got := javac.Args["bootClasspath"] |
| 535 | if got != bc { |
| 536 | t.Errorf("bootclasspath expected %q != got %q", bc, got) |
| 537 | } |
| 538 | |
| 539 | got = javac.Args["classpath"] |
| 540 | if got != c { |
| 541 | t.Errorf("classpath expected %q != got %q", c, got) |
| 542 | } |
| 543 | |
| 544 | var deps []string |
| 545 | if len(bootclasspath) > 0 && bootclasspath[0] != `""` { |
| 546 | deps = append(deps, bootclasspath...) |
| 547 | } |
| 548 | deps = append(deps, classpath...) |
| 549 | |
| 550 | if !reflect.DeepEqual(javac.Implicits.Strings(), deps) { |
| 551 | t.Errorf("implicits expected %q != got %q", deps, javac.Implicits.Strings()) |
| 552 | } |
| 553 | }) |
| 554 | |
| 555 | // Test again with javac 1.9 |
| 556 | t.Run("1.9", func(t *testing.T) { |
Colin Cross | 527012a | 2017-11-30 22:56:16 -0800 | [diff] [blame] | 557 | config := testConfig(map[string]string{"EXPERIMENTAL_USE_OPENJDK9": "true"}) |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 558 | if testcase.unbundled { |
| 559 | config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) |
| 560 | } |
Colin Cross | 527012a | 2017-11-30 22:56:16 -0800 | [diff] [blame] | 561 | ctx := testContext(config, bp, nil) |
| 562 | run(t, ctx, config) |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 563 | |
| 564 | javac := ctx.ModuleForTests("foo", variant).Rule("javac") |
| 565 | got := javac.Args["bootClasspath"] |
| 566 | expected := system |
| 567 | if testcase.system == "bootclasspath" { |
| 568 | expected = bc |
| 569 | } |
| 570 | if got != expected { |
| 571 | t.Errorf("bootclasspath expected %q != got %q", expected, got) |
| 572 | } |
| 573 | }) |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 574 | }) |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | func TestPrebuilts(t *testing.T) { |
| 580 | ctx := testJava(t, ` |
| 581 | java_library { |
| 582 | name: "foo", |
| 583 | srcs: ["a.java"], |
Colin Cross | e8dc34a | 2017-07-19 11:22:16 -0700 | [diff] [blame] | 584 | libs: ["bar"], |
| 585 | static_libs: ["baz"], |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 588 | java_import { |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 589 | name: "bar", |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 590 | jars: ["a.jar"], |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 591 | } |
| 592 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 593 | java_import { |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 594 | name: "baz", |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 595 | jars: ["b.jar"], |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 596 | } |
| 597 | `) |
| 598 | |
Colin Cross | 4c428df | 2017-09-15 17:36:05 -0700 | [diff] [blame] | 599 | javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 600 | combineJar := ctx.ModuleForTests("foo", "android_common").Description("for javac") |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 601 | barJar := ctx.ModuleForTests("bar", "android_common").Rule("combineJar").Output |
| 602 | bazJar := ctx.ModuleForTests("baz", "android_common").Rule("combineJar").Output |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 603 | |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 604 | if !strings.Contains(javac.Args["classpath"], barJar.String()) { |
| 605 | t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], barJar.String()) |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 606 | } |
| 607 | |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 608 | if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != bazJar.String() { |
| 609 | t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, bazJar.String()) |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 610 | } |
| 611 | } |
| 612 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 613 | func TestDefaults(t *testing.T) { |
| 614 | ctx := testJava(t, ` |
| 615 | java_defaults { |
| 616 | name: "defaults", |
| 617 | srcs: ["a.java"], |
| 618 | libs: ["bar"], |
| 619 | static_libs: ["baz"], |
| 620 | } |
| 621 | |
| 622 | java_library { |
| 623 | name: "foo", |
| 624 | defaults: ["defaults"], |
| 625 | } |
| 626 | |
| 627 | java_library { |
| 628 | name: "bar", |
| 629 | srcs: ["b.java"], |
| 630 | } |
| 631 | |
| 632 | java_library { |
| 633 | name: "baz", |
| 634 | srcs: ["c.java"], |
| 635 | } |
| 636 | `) |
| 637 | |
Colin Cross | 4c428df | 2017-09-15 17:36:05 -0700 | [diff] [blame] | 638 | javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 639 | combineJar := ctx.ModuleForTests("foo", "android_common").Description("for javac") |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 640 | |
| 641 | if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "a.java" { |
| 642 | t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs) |
| 643 | } |
| 644 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 645 | barTurbine := filepath.Join(buildDir, ".intermediates", "bar", "android_common", "turbine-combined", "bar.jar") |
| 646 | if !strings.Contains(javac.Args["classpath"], barTurbine) { |
| 647 | t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], barTurbine) |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 648 | } |
| 649 | |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 650 | baz := ctx.ModuleForTests("baz", "android_common").Rule("javac").Output.String() |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 651 | if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != baz { |
| 652 | t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, baz) |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 653 | } |
| 654 | } |
| 655 | |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 656 | func TestResources(t *testing.T) { |
| 657 | var table = []struct { |
| 658 | name string |
| 659 | prop string |
| 660 | extra string |
| 661 | args string |
| 662 | }{ |
| 663 | { |
Colin Cross | af9c55b | 2017-10-03 14:50:08 -0700 | [diff] [blame] | 664 | // Test that a module with java_resource_dirs includes the files |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 665 | name: "resource dirs", |
Colin Cross | 824bee3 | 2017-11-22 17:27:51 -0800 | [diff] [blame] | 666 | prop: `java_resource_dirs: ["java-res"]`, |
Colin Cross | 0ead1d7 | 2018-04-10 13:07:42 -0700 | [diff] [blame] | 667 | args: "-C java-res -f java-res/a/a -f java-res/b/b", |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 668 | }, |
| 669 | { |
| 670 | // Test that a module with java_resources includes the files |
| 671 | name: "resource files", |
Colin Cross | 0ead1d7 | 2018-04-10 13:07:42 -0700 | [diff] [blame] | 672 | prop: `java_resources: ["java-res/a/a", "java-res/b/b"]`, |
| 673 | args: "-C . -f java-res/a/a -f java-res/b/b", |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 674 | }, |
| 675 | { |
| 676 | // Test that a module with a filegroup in java_resources includes the files with the |
| 677 | // path prefix |
| 678 | name: "resource filegroup", |
| 679 | prop: `java_resources: [":foo-res"]`, |
| 680 | extra: ` |
| 681 | filegroup { |
| 682 | name: "foo-res", |
Colin Cross | 824bee3 | 2017-11-22 17:27:51 -0800 | [diff] [blame] | 683 | path: "java-res", |
Colin Cross | 0ead1d7 | 2018-04-10 13:07:42 -0700 | [diff] [blame] | 684 | srcs: ["java-res/a/a", "java-res/b/b"], |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 685 | }`, |
Colin Cross | 0ead1d7 | 2018-04-10 13:07:42 -0700 | [diff] [blame] | 686 | args: "-C java-res -f java-res/a/a -f java-res/b/b", |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 687 | }, |
| 688 | { |
| 689 | // Test that a module with "include_srcs: true" includes its source files in the resources jar |
| 690 | name: "include sources", |
| 691 | prop: `include_srcs: true`, |
Colin Cross | af9c55b | 2017-10-03 14:50:08 -0700 | [diff] [blame] | 692 | args: "-C . -f a.java -f b.java -f c.java", |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 693 | }, |
Colin Cross | 0ead1d7 | 2018-04-10 13:07:42 -0700 | [diff] [blame] | 694 | { |
| 695 | // Test that a module with wildcards in java_resource_dirs has the correct path prefixes |
| 696 | name: "wildcard dirs", |
| 697 | prop: `java_resource_dirs: ["java-res/*"]`, |
| 698 | args: "-C java-res/a -f java-res/a/a -C java-res/b -f java-res/b/b", |
| 699 | }, |
| 700 | { |
| 701 | // Test that a module exclude_java_resource_dirs excludes the files |
| 702 | name: "wildcard dirs", |
| 703 | prop: `java_resource_dirs: ["java-res/*"], exclude_java_resource_dirs: ["java-res/b"]`, |
| 704 | args: "-C java-res/a -f java-res/a/a", |
| 705 | }, |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | for _, test := range table { |
| 709 | t.Run(test.name, func(t *testing.T) { |
| 710 | ctx := testJava(t, ` |
| 711 | java_library { |
| 712 | name: "foo", |
| 713 | srcs: [ |
| 714 | "a.java", |
| 715 | "b.java", |
| 716 | "c.java", |
| 717 | ], |
| 718 | `+test.prop+`, |
| 719 | } |
| 720 | `+test.extra) |
| 721 | |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 722 | foo := ctx.ModuleForTests("foo", "android_common").Output("combined/foo.jar") |
| 723 | fooRes := ctx.ModuleForTests("foo", "android_common").Output("res/foo.jar") |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 724 | |
| 725 | if !inList(fooRes.Output.String(), foo.Inputs.Strings()) { |
| 726 | t.Errorf("foo combined jars %v does not contain %q", |
| 727 | foo.Inputs.Strings(), fooRes.Output.String()) |
| 728 | } |
| 729 | |
Colin Cross | af9c55b | 2017-10-03 14:50:08 -0700 | [diff] [blame] | 730 | if fooRes.Args["jarArgs"] != test.args { |
| 731 | t.Errorf("foo resource jar args %q is not %q", |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 732 | fooRes.Args["jarArgs"], test.args) |
| 733 | } |
| 734 | }) |
| 735 | } |
| 736 | } |
| 737 | |
Colin Cross | 0532fb0 | 2017-10-02 16:57:40 -0700 | [diff] [blame] | 738 | func TestExcludeResources(t *testing.T) { |
| 739 | ctx := testJava(t, ` |
| 740 | java_library { |
| 741 | name: "foo", |
| 742 | srcs: ["a.java"], |
Colin Cross | 824bee3 | 2017-11-22 17:27:51 -0800 | [diff] [blame] | 743 | java_resource_dirs: ["java-res", "java-res2"], |
| 744 | exclude_java_resource_dirs: ["java-res2"], |
Colin Cross | 0532fb0 | 2017-10-02 16:57:40 -0700 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | java_library { |
| 748 | name: "bar", |
| 749 | srcs: ["a.java"], |
Colin Cross | 0ead1d7 | 2018-04-10 13:07:42 -0700 | [diff] [blame] | 750 | java_resources: ["java-res/*/*"], |
| 751 | exclude_java_resources: ["java-res/b/*"], |
Colin Cross | 0532fb0 | 2017-10-02 16:57:40 -0700 | [diff] [blame] | 752 | } |
| 753 | `) |
| 754 | |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 755 | fooRes := ctx.ModuleForTests("foo", "android_common").Output("res/foo.jar") |
Colin Cross | 0532fb0 | 2017-10-02 16:57:40 -0700 | [diff] [blame] | 756 | |
Colin Cross | 0ead1d7 | 2018-04-10 13:07:42 -0700 | [diff] [blame] | 757 | expected := "-C java-res -f java-res/a/a -f java-res/b/b" |
Colin Cross | 0532fb0 | 2017-10-02 16:57:40 -0700 | [diff] [blame] | 758 | if fooRes.Args["jarArgs"] != expected { |
| 759 | t.Errorf("foo resource jar args %q is not %q", |
| 760 | fooRes.Args["jarArgs"], expected) |
| 761 | |
| 762 | } |
| 763 | |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 764 | barRes := ctx.ModuleForTests("bar", "android_common").Output("res/bar.jar") |
Colin Cross | 0532fb0 | 2017-10-02 16:57:40 -0700 | [diff] [blame] | 765 | |
Colin Cross | 0ead1d7 | 2018-04-10 13:07:42 -0700 | [diff] [blame] | 766 | expected = "-C . -f java-res/a/a" |
Colin Cross | 0532fb0 | 2017-10-02 16:57:40 -0700 | [diff] [blame] | 767 | if barRes.Args["jarArgs"] != expected { |
| 768 | t.Errorf("bar resource jar args %q is not %q", |
| 769 | barRes.Args["jarArgs"], expected) |
| 770 | |
| 771 | } |
| 772 | } |
| 773 | |
Colin Cross | 54190b3 | 2017-10-09 15:34:10 -0700 | [diff] [blame] | 774 | func TestGeneratedSources(t *testing.T) { |
| 775 | ctx := testJava(t, ` |
| 776 | java_library { |
| 777 | name: "foo", |
| 778 | srcs: [ |
| 779 | "a*.java", |
| 780 | ":gen", |
| 781 | "b*.java", |
| 782 | ], |
| 783 | } |
| 784 | |
| 785 | genrule { |
| 786 | name: "gen", |
Colin Cross | 824bee3 | 2017-11-22 17:27:51 -0800 | [diff] [blame] | 787 | tool_files: ["java-res/a"], |
Colin Cross | 54190b3 | 2017-10-09 15:34:10 -0700 | [diff] [blame] | 788 | out: ["gen.java"], |
| 789 | } |
| 790 | `) |
| 791 | |
| 792 | javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") |
| 793 | genrule := ctx.ModuleForTests("gen", "").Rule("generator") |
| 794 | |
Colin Cross | 15e86d9 | 2017-10-20 15:07:08 -0700 | [diff] [blame] | 795 | if filepath.Base(genrule.Output.String()) != "gen.java" { |
| 796 | t.Fatalf(`gen output file %v is not ".../gen.java"`, genrule.Output.String()) |
Colin Cross | 54190b3 | 2017-10-09 15:34:10 -0700 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | if len(javac.Inputs) != 3 || |
| 800 | javac.Inputs[0].String() != "a.java" || |
Colin Cross | 15e86d9 | 2017-10-20 15:07:08 -0700 | [diff] [blame] | 801 | javac.Inputs[1].String() != genrule.Output.String() || |
Colin Cross | 54190b3 | 2017-10-09 15:34:10 -0700 | [diff] [blame] | 802 | javac.Inputs[2].String() != "b.java" { |
| 803 | t.Errorf(`foo inputs %v != ["a.java", ".../gen.java", "b.java"]`, javac.Inputs) |
| 804 | } |
| 805 | } |
| 806 | |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 807 | func TestKotlin(t *testing.T) { |
| 808 | ctx := testJava(t, ` |
| 809 | java_library { |
| 810 | name: "foo", |
Colin Cross | 9bc4343 | 2017-12-15 20:20:39 -0800 | [diff] [blame] | 811 | srcs: ["a.java", "b.kt"], |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 812 | } |
Colin Cross | 715d711 | 2017-10-25 20:32:18 -0700 | [diff] [blame] | 813 | |
| 814 | java_library { |
| 815 | name: "bar", |
Colin Cross | 9bc4343 | 2017-12-15 20:20:39 -0800 | [diff] [blame] | 816 | srcs: ["b.kt"], |
| 817 | libs: ["foo"], |
| 818 | static_libs: ["baz"], |
| 819 | } |
| 820 | |
| 821 | java_library { |
| 822 | name: "baz", |
| 823 | srcs: ["c.java"], |
Colin Cross | 715d711 | 2017-10-25 20:32:18 -0700 | [diff] [blame] | 824 | } |
Przemyslaw Szczepaniak | 66c0c40 | 2018-03-08 13:21:55 +0000 | [diff] [blame] | 825 | |
| 826 | java_library { |
| 827 | name: "blorg", |
| 828 | renamed_kotlin_stdlib: true, |
| 829 | srcs: ["b.kt"], |
| 830 | } |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 831 | `) |
| 832 | |
Colin Cross | 9bc4343 | 2017-12-15 20:20:39 -0800 | [diff] [blame] | 833 | fooKotlinc := ctx.ModuleForTests("foo", "android_common").Rule("kotlinc") |
| 834 | fooJavac := ctx.ModuleForTests("foo", "android_common").Rule("javac") |
| 835 | fooJar := ctx.ModuleForTests("foo", "android_common").Output("combined/foo.jar") |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 836 | |
Colin Cross | 9bc4343 | 2017-12-15 20:20:39 -0800 | [diff] [blame] | 837 | if len(fooKotlinc.Inputs) != 2 || fooKotlinc.Inputs[0].String() != "a.java" || |
| 838 | fooKotlinc.Inputs[1].String() != "b.kt" { |
| 839 | t.Errorf(`foo kotlinc inputs %v != ["a.java", "b.kt"]`, fooKotlinc.Inputs) |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 840 | } |
| 841 | |
Colin Cross | 9bc4343 | 2017-12-15 20:20:39 -0800 | [diff] [blame] | 842 | if len(fooJavac.Inputs) != 1 || fooJavac.Inputs[0].String() != "a.java" { |
| 843 | t.Errorf(`foo inputs %v != ["a.java"]`, fooJavac.Inputs) |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 844 | } |
| 845 | |
Colin Cross | 9bc4343 | 2017-12-15 20:20:39 -0800 | [diff] [blame] | 846 | if !strings.Contains(fooJavac.Args["classpath"], fooKotlinc.Output.String()) { |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 847 | t.Errorf("foo classpath %v does not contain %q", |
Colin Cross | 9bc4343 | 2017-12-15 20:20:39 -0800 | [diff] [blame] | 848 | fooJavac.Args["classpath"], fooKotlinc.Output.String()) |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 849 | } |
| 850 | |
Colin Cross | 9bc4343 | 2017-12-15 20:20:39 -0800 | [diff] [blame] | 851 | if !inList(fooKotlinc.Output.String(), fooJar.Inputs.Strings()) { |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 852 | t.Errorf("foo jar inputs %v does not contain %q", |
Colin Cross | 9bc4343 | 2017-12-15 20:20:39 -0800 | [diff] [blame] | 853 | fooJar.Inputs.Strings(), fooKotlinc.Output.String()) |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 854 | } |
Colin Cross | 715d711 | 2017-10-25 20:32:18 -0700 | [diff] [blame] | 855 | |
Colin Cross | 9bc4343 | 2017-12-15 20:20:39 -0800 | [diff] [blame] | 856 | fooHeaderJar := ctx.ModuleForTests("foo", "android_common").Output("turbine-combined/foo.jar") |
| 857 | bazHeaderJar := ctx.ModuleForTests("baz", "android_common").Output("turbine-combined/baz.jar") |
| 858 | barKotlinc := ctx.ModuleForTests("bar", "android_common").Rule("kotlinc") |
Colin Cross | 715d711 | 2017-10-25 20:32:18 -0700 | [diff] [blame] | 859 | |
Colin Cross | 9bc4343 | 2017-12-15 20:20:39 -0800 | [diff] [blame] | 860 | if len(barKotlinc.Inputs) != 1 || barKotlinc.Inputs[0].String() != "b.kt" { |
| 861 | t.Errorf(`bar kotlinc inputs %v != ["b.kt"]`, barKotlinc.Inputs) |
| 862 | } |
| 863 | |
| 864 | if !inList(fooHeaderJar.Output.String(), barKotlinc.Implicits.Strings()) { |
| 865 | t.Errorf(`expected %q in bar implicits %v`, |
| 866 | fooHeaderJar.Output.String(), barKotlinc.Implicits.Strings()) |
| 867 | } |
| 868 | |
| 869 | if !inList(bazHeaderJar.Output.String(), barKotlinc.Implicits.Strings()) { |
| 870 | t.Errorf(`expected %q in bar implicits %v`, |
| 871 | bazHeaderJar.Output.String(), barKotlinc.Implicits.Strings()) |
Colin Cross | 715d711 | 2017-10-25 20:32:18 -0700 | [diff] [blame] | 872 | } |
Przemyslaw Szczepaniak | 66c0c40 | 2018-03-08 13:21:55 +0000 | [diff] [blame] | 873 | |
| 874 | blorgRenamedJar := ctx.ModuleForTests("blorg", "android_common").Output("kotlin-renamed/blorg.jar") |
| 875 | if blorgRenamedJar.Implicit.String() != "external/kotlinc/jarjar-rules.txt" { |
| 876 | t.Errorf(`expected external/kotlinc/jarjar-rules.txt in blorg implicit %q`, |
| 877 | blorgRenamedJar.Implicit.String()) |
| 878 | } |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 879 | } |
| 880 | |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 881 | func TestTurbine(t *testing.T) { |
| 882 | ctx := testJava(t, ` |
| 883 | java_library { |
| 884 | name: "foo", |
| 885 | srcs: ["a.java"], |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 886 | sdk_version: "14", |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | java_library { |
| 890 | name: "bar", |
Colin Cross | 9bc4343 | 2017-12-15 20:20:39 -0800 | [diff] [blame] | 891 | srcs: ["b.java"], |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 892 | static_libs: ["foo"], |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 893 | sdk_version: "14", |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | java_library { |
| 897 | name: "baz", |
| 898 | srcs: ["c.java"], |
| 899 | libs: ["bar"], |
| 900 | sdk_version: "14", |
| 901 | } |
| 902 | `) |
| 903 | |
| 904 | fooTurbine := ctx.ModuleForTests("foo", "android_common").Rule("turbine") |
| 905 | barTurbine := ctx.ModuleForTests("bar", "android_common").Rule("turbine") |
| 906 | barJavac := ctx.ModuleForTests("bar", "android_common").Rule("javac") |
| 907 | barTurbineCombined := ctx.ModuleForTests("bar", "android_common").Description("for turbine") |
| 908 | bazJavac := ctx.ModuleForTests("baz", "android_common").Rule("javac") |
| 909 | |
| 910 | if len(fooTurbine.Inputs) != 1 || fooTurbine.Inputs[0].String() != "a.java" { |
| 911 | t.Errorf(`foo inputs %v != ["a.java"]`, fooTurbine.Inputs) |
| 912 | } |
| 913 | |
| 914 | fooHeaderJar := filepath.Join(buildDir, ".intermediates", "foo", "android_common", "turbine-combined", "foo.jar") |
| 915 | if !strings.Contains(barTurbine.Args["classpath"], fooHeaderJar) { |
| 916 | t.Errorf("bar turbine classpath %v does not contain %q", barTurbine.Args["classpath"], fooHeaderJar) |
| 917 | } |
| 918 | if !strings.Contains(barJavac.Args["classpath"], fooHeaderJar) { |
| 919 | t.Errorf("bar javac classpath %v does not contain %q", barJavac.Args["classpath"], fooHeaderJar) |
| 920 | } |
| 921 | if len(barTurbineCombined.Inputs) != 2 || barTurbineCombined.Inputs[1].String() != fooHeaderJar { |
| 922 | t.Errorf("bar turbine combineJar inputs %v does not contain %q", barTurbineCombined.Inputs, fooHeaderJar) |
| 923 | } |
Anton Hansson | f66efeb | 2018-04-11 13:57:30 +0100 | [diff] [blame] | 924 | if !strings.Contains(bazJavac.Args["classpath"], "prebuilts/sdk/14/public/android.jar") { |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 925 | t.Errorf("baz javac classpath %v does not contain %q", bazJavac.Args["classpath"], |
Anton Hansson | f66efeb | 2018-04-11 13:57:30 +0100 | [diff] [blame] | 926 | "prebuilts/sdk/14/public/android.jar") |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 927 | } |
| 928 | } |
| 929 | |
| 930 | func TestSharding(t *testing.T) { |
| 931 | ctx := testJava(t, ` |
| 932 | java_library { |
| 933 | name: "bar", |
| 934 | srcs: ["a.java","b.java","c.java"], |
| 935 | javac_shard_size: 1 |
| 936 | } |
| 937 | `) |
| 938 | |
| 939 | barHeaderJar := filepath.Join(buildDir, ".intermediates", "bar", "android_common", "turbine-combined", "bar.jar") |
| 940 | for i := 0; i < 3; i++ { |
| 941 | barJavac := ctx.ModuleForTests("bar", "android_common").Description("javac" + strconv.Itoa(i)) |
| 942 | if !strings.Contains(barJavac.Args["classpath"], barHeaderJar) { |
| 943 | t.Errorf("bar javac classpath %v does not contain %q", barJavac.Args["classpath"], barHeaderJar) |
| 944 | } |
| 945 | } |
| 946 | } |
| 947 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 948 | func TestDroiddoc(t *testing.T) { |
| 949 | ctx := testJava(t, ` |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 950 | droiddoc_template { |
| 951 | name: "droiddoc-templates-sdk", |
| 952 | path: ".", |
| 953 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 954 | droiddoc { |
| 955 | name: "bar-doc", |
| 956 | srcs: [ |
| 957 | "bar-doc/*.java", |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 958 | "bar-doc/IFoo.aidl", |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 959 | ], |
| 960 | exclude_srcs: [ |
| 961 | "bar-doc/b.java" |
| 962 | ], |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 963 | custom_template: "droiddoc-templates-sdk", |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 964 | hdf: [ |
| 965 | "android.whichdoc offline", |
| 966 | ], |
| 967 | knowntags: [ |
| 968 | "bar-doc/known_oj_tags.txt", |
| 969 | ], |
| 970 | proofread_file: "libcore-proofread.txt", |
| 971 | todo_file: "libcore-docs-todo.html", |
| 972 | args: "-offlinemode -title \"libcore\"", |
| 973 | } |
| 974 | `) |
| 975 | |
Nan Zhang | 3bb1420 | 2018-02-28 10:14:25 -0800 | [diff] [blame] | 976 | stubsJar := filepath.Join(buildDir, ".intermediates", "bar-doc", "android_common", "bar-doc-stubs.srcjar") |
| 977 | barDoc := ctx.ModuleForTests("bar-doc", "android_common").Output("bar-doc-stubs.srcjar") |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 978 | if stubsJar != barDoc.Output.String() { |
| 979 | t.Errorf("expected stubs Jar [%q], got %q", stubsJar, barDoc.Output.String()) |
| 980 | } |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 981 | inputs := ctx.ModuleForTests("bar-doc", "android_common").Rule("javadoc").Inputs |
| 982 | var javaSrcs []string |
| 983 | for _, i := range inputs { |
| 984 | javaSrcs = append(javaSrcs, i.Base()) |
| 985 | } |
| 986 | if len(javaSrcs) != 2 || javaSrcs[0] != "a.java" || javaSrcs[1] != "IFoo.java" { |
| 987 | t.Errorf("inputs of bar-doc must be []string{\"a.java\", \"IFoo.java\", but was %#v.", javaSrcs) |
| 988 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 989 | } |
| 990 | |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 991 | func TestJarGenrules(t *testing.T) { |
| 992 | ctx := testJava(t, ` |
| 993 | java_library { |
| 994 | name: "foo", |
| 995 | srcs: ["a.java"], |
| 996 | } |
| 997 | |
| 998 | java_genrule { |
| 999 | name: "jargen", |
| 1000 | tool_files: ["b.java"], |
| 1001 | cmd: "$(location b.java) $(in) $(out)", |
| 1002 | out: ["jargen.jar"], |
| 1003 | srcs: [":foo"], |
| 1004 | } |
| 1005 | |
| 1006 | java_library { |
| 1007 | name: "bar", |
| 1008 | static_libs: ["jargen"], |
| 1009 | srcs: ["c.java"], |
| 1010 | } |
| 1011 | |
| 1012 | java_library { |
| 1013 | name: "baz", |
| 1014 | libs: ["jargen"], |
| 1015 | srcs: ["c.java"], |
| 1016 | } |
| 1017 | `) |
| 1018 | |
| 1019 | foo := ctx.ModuleForTests("foo", "android_common").Output("javac/foo.jar") |
| 1020 | jargen := ctx.ModuleForTests("jargen", "android_common").Output("jargen.jar") |
| 1021 | bar := ctx.ModuleForTests("bar", "android_common").Output("javac/bar.jar") |
| 1022 | baz := ctx.ModuleForTests("baz", "android_common").Output("javac/baz.jar") |
| 1023 | barCombined := ctx.ModuleForTests("bar", "android_common").Output("combined/bar.jar") |
| 1024 | |
| 1025 | if len(jargen.Inputs) != 1 || jargen.Inputs[0].String() != foo.Output.String() { |
| 1026 | t.Errorf("expected jargen inputs [%q], got %q", foo.Output.String(), jargen.Inputs.Strings()) |
| 1027 | } |
| 1028 | |
| 1029 | if !strings.Contains(bar.Args["classpath"], jargen.Output.String()) { |
| 1030 | t.Errorf("bar classpath %v does not contain %q", bar.Args["classpath"], jargen.Output.String()) |
| 1031 | } |
| 1032 | |
| 1033 | if !strings.Contains(baz.Args["classpath"], jargen.Output.String()) { |
| 1034 | t.Errorf("baz classpath %v does not contain %q", baz.Args["classpath"], jargen.Output.String()) |
| 1035 | } |
| 1036 | |
| 1037 | if len(barCombined.Inputs) != 2 || |
| 1038 | barCombined.Inputs[0].String() != bar.Output.String() || |
| 1039 | barCombined.Inputs[1].String() != jargen.Output.String() { |
| 1040 | t.Errorf("bar combined jar inputs %v is not [%q, %q]", |
| 1041 | barCombined.Inputs.Strings(), bar.Output.String(), jargen.Output.String()) |
| 1042 | } |
| 1043 | } |
| 1044 | |
Nan Zhang | 27e284d | 2018-02-09 21:03:53 +0000 | [diff] [blame] | 1045 | func TestExcludeFileGroupInSrcs(t *testing.T) { |
| 1046 | ctx := testJava(t, ` |
| 1047 | java_library { |
| 1048 | name: "foo", |
| 1049 | srcs: ["a.java", ":foo-srcs"], |
| 1050 | exclude_srcs: ["a.java", ":foo-excludes"], |
| 1051 | } |
| 1052 | |
| 1053 | filegroup { |
| 1054 | name: "foo-srcs", |
| 1055 | srcs: ["java-fg/a.java", "java-fg/b.java", "java-fg/c.java"], |
| 1056 | } |
| 1057 | |
| 1058 | filegroup { |
| 1059 | name: "foo-excludes", |
| 1060 | srcs: ["java-fg/a.java", "java-fg/b.java"], |
| 1061 | } |
| 1062 | `) |
| 1063 | |
| 1064 | javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") |
| 1065 | |
| 1066 | if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "java-fg/c.java" { |
| 1067 | t.Errorf(`foo inputs %v != ["java-fg/c.java"]`, javac.Inputs) |
| 1068 | } |
| 1069 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1070 | |
| 1071 | func TestJavaSdkLibrary(t *testing.T) { |
| 1072 | ctx := testJava(t, ` |
| 1073 | droiddoc_template { |
| 1074 | name: "droiddoc-templates-sdk", |
| 1075 | path: ".", |
| 1076 | } |
| 1077 | java_library { |
| 1078 | name: "conscrypt", |
| 1079 | } |
| 1080 | java_library { |
| 1081 | name: "bouncycastle", |
| 1082 | } |
| 1083 | java_sdk_library { |
| 1084 | name: "foo", |
| 1085 | srcs: ["a.java", "b.java"], |
| 1086 | api_packages: ["foo"], |
| 1087 | } |
| 1088 | java_sdk_library { |
| 1089 | name: "bar", |
| 1090 | srcs: ["a.java", "b.java"], |
| 1091 | api_packages: ["bar"], |
| 1092 | } |
| 1093 | java_library { |
| 1094 | name: "baz", |
| 1095 | srcs: ["c.java"], |
| 1096 | libs: ["foo", "bar"], |
| 1097 | sdk_version: "system_current", |
| 1098 | } |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1099 | java_library { |
| 1100 | name: "qux", |
| 1101 | srcs: ["c.java"], |
| 1102 | libs: ["baz"], |
| 1103 | sdk_version: "system_current", |
| 1104 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1105 | `) |
| 1106 | |
| 1107 | // check the existence of the internal modules |
| 1108 | ctx.ModuleForTests("foo", "android_common") |
| 1109 | ctx.ModuleForTests("foo"+sdkStubsLibrarySuffix, "android_common") |
| 1110 | ctx.ModuleForTests("foo"+sdkStubsLibrarySuffix+sdkSystemApiSuffix, "android_common") |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 1111 | ctx.ModuleForTests("foo"+sdkStubsLibrarySuffix+sdkTestApiSuffix, "android_common") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1112 | ctx.ModuleForTests("foo"+sdkDocsSuffix, "android_common") |
| 1113 | ctx.ModuleForTests("foo"+sdkDocsSuffix+sdkSystemApiSuffix, "android_common") |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 1114 | ctx.ModuleForTests("foo"+sdkDocsSuffix+sdkTestApiSuffix, "android_common") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1115 | ctx.ModuleForTests("foo"+sdkImplLibrarySuffix, "android_common") |
Jiyong Park | 5a8d1be | 2018-04-25 22:57:34 +0900 | [diff] [blame] | 1116 | ctx.ModuleForTests("foo"+sdkXmlFileSuffix, "android_common") |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 1117 | ctx.ModuleForTests("foo.api.public.28", "") |
| 1118 | ctx.ModuleForTests("foo.api.system.28", "") |
| 1119 | ctx.ModuleForTests("foo.api.test.28", "") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1120 | |
| 1121 | bazJavac := ctx.ModuleForTests("baz", "android_common").Rule("javac") |
| 1122 | // tests if baz is actually linked to the stubs lib |
| 1123 | if !strings.Contains(bazJavac.Args["classpath"], "foo.stubs.system.jar") { |
| 1124 | t.Errorf("baz javac classpath %v does not contain %q", bazJavac.Args["classpath"], |
| 1125 | "foo.stubs.system.jar") |
| 1126 | } |
| 1127 | // ... and not to the impl lib |
| 1128 | if strings.Contains(bazJavac.Args["classpath"], "foo.impl.jar") { |
| 1129 | t.Errorf("baz javac classpath %v should not contain %q", bazJavac.Args["classpath"], |
| 1130 | "foo.impl.jar") |
| 1131 | } |
| 1132 | // test if baz is not linked to the system variant of foo |
| 1133 | if strings.Contains(bazJavac.Args["classpath"], "foo.stubs.jar") { |
| 1134 | t.Errorf("baz javac classpath %v should not contain %q", bazJavac.Args["classpath"], |
| 1135 | "foo.stubs.jar") |
| 1136 | } |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1137 | |
| 1138 | // test if baz has exported SDK lib names foo and bar to qux |
| 1139 | qux := ctx.ModuleForTests("qux", "android_common") |
| 1140 | if quxLib, ok := qux.Module().(*Library); ok { |
| 1141 | sdkLibs := quxLib.ExportedSdkLibs() |
| 1142 | if len(sdkLibs) != 2 || !android.InList("foo", sdkLibs) || !android.InList("bar", sdkLibs) { |
| 1143 | t.Errorf("qux should export \"foo\" and \"bar\" but exports %v", sdkLibs) |
| 1144 | } |
| 1145 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1146 | } |