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