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 ( |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 18 | "io/ioutil" |
| 19 | "os" |
| 20 | "path/filepath" |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 21 | "reflect" |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 22 | "strconv" |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 23 | "strings" |
| 24 | "testing" |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 25 | |
Jeongik Cha | 28df257 | 2019-11-11 10:46:36 +0900 | [diff] [blame] | 26 | "github.com/google/blueprint/proptools" |
| 27 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 28 | "android/soong/android" |
| 29 | "android/soong/cc" |
Colin Cross | c28bb0b | 2019-02-25 14:20:47 -0800 | [diff] [blame] | 30 | "android/soong/dexpreopt" |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 31 | "android/soong/genrule" |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 32 | ) |
| 33 | |
| 34 | var buildDir string |
| 35 | |
| 36 | func setUp() { |
| 37 | var err error |
| 38 | buildDir, err = ioutil.TempDir("", "soong_java_test") |
| 39 | if err != nil { |
| 40 | panic(err) |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | func tearDown() { |
| 45 | os.RemoveAll(buildDir) |
| 46 | } |
| 47 | |
| 48 | func TestMain(m *testing.M) { |
| 49 | run := func() int { |
| 50 | setUp() |
| 51 | defer tearDown() |
| 52 | |
| 53 | return m.Run() |
| 54 | } |
| 55 | |
| 56 | os.Exit(run()) |
| 57 | } |
Colin Cross | 527012a | 2017-11-30 22:56:16 -0800 | [diff] [blame] | 58 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 59 | func testConfig(env map[string]string, bp string, fs map[string][]byte) android.Config { |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 60 | bp += dexpreopt.BpToolModulesForTest() |
| 61 | |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 62 | config := TestConfig(buildDir, env, bp, fs) |
| 63 | |
| 64 | // Set up the global Once cache used for dexpreopt.GlobalSoongConfig, so that |
| 65 | // it doesn't create a real one, which would fail. |
| 66 | _ = dexpreopt.GlobalSoongConfigForTests(config) |
| 67 | |
| 68 | return config |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 71 | func testContext() *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() |
Paul Duffin | f9b1da0 | 2019-12-18 19:51:55 +0000 | [diff] [blame] | 74 | RegisterJavaBuildComponents(ctx) |
| 75 | RegisterAppBuildComponents(ctx) |
| 76 | RegisterAARBuildComponents(ctx) |
Paul Duffin | b0f8507 | 2019-12-19 10:28:56 +0000 | [diff] [blame] | 77 | RegisterGenRuleBuildComponents(ctx) |
Paul Duffin | 43dc1cc | 2019-12-19 11:18:54 +0000 | [diff] [blame] | 78 | RegisterSystemModulesBuildComponents(ctx) |
Colin Cross | 4b49b76 | 2019-11-22 15:25:03 -0800 | [diff] [blame] | 79 | ctx.RegisterModuleType("java_plugin", PluginFactory) |
Colin Cross | 4b49b76 | 2019-11-22 15:25:03 -0800 | [diff] [blame] | 80 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
| 81 | ctx.RegisterModuleType("genrule", genrule.GenRuleFactory) |
Paul Duffin | 884363e | 2019-12-19 10:21:09 +0000 | [diff] [blame] | 82 | RegisterDocsBuildComponents(ctx) |
| 83 | RegisterStubsBuildComponents(ctx) |
Paul Duffin | 43dc1cc | 2019-12-19 11:18:54 +0000 | [diff] [blame] | 84 | RegisterSdkLibraryBuildComponents(ctx) |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 85 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
Paul Duffin | a48f758 | 2019-12-19 11:25:19 +0000 | [diff] [blame] | 86 | |
| 87 | RegisterPrebuiltApisBuildComponents(ctx) |
| 88 | |
Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 89 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
Colin Cross | 3bc7ffa | 2017-11-22 16:19:37 -0800 | [diff] [blame] | 90 | ctx.RegisterPreSingletonType("overlay", android.SingletonFactoryAdaptor(OverlaySingletonFactory)) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 91 | ctx.RegisterPreSingletonType("sdk_versions", android.SingletonFactoryAdaptor(sdkPreSingletonFactory)) |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 92 | |
| 93 | // Register module types and mutators from cc needed for JNI testing |
Paul Duffin | 77980a8 | 2019-12-19 16:01:36 +0000 | [diff] [blame] | 94 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 95 | |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 96 | dexpreopt.RegisterToolModulesForTest(ctx) |
| 97 | |
Colin Cross | 527012a | 2017-11-30 22:56:16 -0800 | [diff] [blame] | 98 | return ctx |
| 99 | } |
| 100 | |
| 101 | func run(t *testing.T, ctx *android.TestContext, config android.Config) { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 102 | t.Helper() |
Colin Cross | c28bb0b | 2019-02-25 14:20:47 -0800 | [diff] [blame] | 103 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 104 | pathCtx := android.PathContextForTesting(config) |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 105 | dexpreopt.SetTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx)) |
Colin Cross | c28bb0b | 2019-02-25 14:20:47 -0800 | [diff] [blame] | 106 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 107 | ctx.Register(config) |
Paul Duffin | baccf7e | 2019-06-11 11:58:30 +0100 | [diff] [blame] | 108 | _, errs := ctx.ParseBlueprintsFiles("Android.bp") |
Logan Chien | 4203971 | 2018-03-12 16:29:17 +0800 | [diff] [blame] | 109 | android.FailIfErrored(t, errs) |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 110 | _, errs = ctx.PrepareBuildActions(config) |
Logan Chien | 4203971 | 2018-03-12 16:29:17 +0800 | [diff] [blame] | 111 | android.FailIfErrored(t, errs) |
Colin Cross | 527012a | 2017-11-30 22:56:16 -0800 | [diff] [blame] | 112 | } |
| 113 | |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 114 | func testJavaError(t *testing.T, pattern string, bp string) (*android.TestContext, android.Config) { |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 115 | t.Helper() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 116 | return testJavaErrorWithConfig(t, pattern, testConfig(nil, bp, nil)) |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 117 | } |
| 118 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 119 | func testJavaErrorWithConfig(t *testing.T, pattern string, config android.Config) (*android.TestContext, android.Config) { |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 120 | t.Helper() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 121 | ctx := testContext() |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 122 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 123 | pathCtx := android.PathContextForTesting(config) |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 124 | dexpreopt.SetTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx)) |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 125 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 126 | ctx.Register(config) |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 127 | _, errs := ctx.ParseBlueprintsFiles("Android.bp") |
| 128 | if len(errs) > 0 { |
| 129 | android.FailIfNoMatchingErrors(t, pattern, errs) |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 130 | return ctx, config |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 131 | } |
| 132 | _, errs = ctx.PrepareBuildActions(config) |
| 133 | if len(errs) > 0 { |
| 134 | android.FailIfNoMatchingErrors(t, pattern, errs) |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 135 | return ctx, config |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | t.Fatalf("missing expected error %q (0 errors are returned)", pattern) |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 139 | |
| 140 | return ctx, config |
Jeongik Cha | 538c0d0 | 2019-07-11 15:54:27 +0900 | [diff] [blame] | 141 | } |
| 142 | |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 143 | func testJava(t *testing.T, bp string) (*android.TestContext, android.Config) { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 144 | t.Helper() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 145 | return testJavaWithConfig(t, testConfig(nil, bp, nil)) |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 146 | } |
| 147 | |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 148 | func testJavaWithConfig(t *testing.T, config android.Config) (*android.TestContext, android.Config) { |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 149 | t.Helper() |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 150 | ctx := testContext() |
Colin Cross | 527012a | 2017-11-30 22:56:16 -0800 | [diff] [blame] | 151 | run(t, ctx, config) |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 152 | |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 153 | return ctx, config |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 156 | func moduleToPath(name string) string { |
| 157 | switch { |
| 158 | case name == `""`: |
| 159 | return name |
Colin Cross | fc3674a | 2017-09-18 17:41:52 -0700 | [diff] [blame] | 160 | case strings.HasSuffix(name, ".jar"): |
| 161 | return name |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 162 | default: |
| 163 | return filepath.Join(buildDir, ".intermediates", name, "android_common", "turbine-combined", name+".jar") |
Colin Cross | 2acdae8 | 2017-09-15 19:44:24 -0700 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | |
Jeongik Cha | e403e9e | 2019-12-07 00:16:24 +0900 | [diff] [blame] | 167 | func TestJavaLinkType(t *testing.T) { |
| 168 | testJava(t, ` |
| 169 | java_library { |
| 170 | name: "foo", |
| 171 | srcs: ["a.java"], |
| 172 | libs: ["bar"], |
| 173 | static_libs: ["baz"], |
| 174 | } |
| 175 | |
| 176 | java_library { |
| 177 | name: "bar", |
| 178 | sdk_version: "current", |
| 179 | srcs: ["b.java"], |
| 180 | } |
| 181 | |
| 182 | java_library { |
| 183 | name: "baz", |
| 184 | sdk_version: "system_current", |
| 185 | srcs: ["c.java"], |
| 186 | } |
| 187 | `) |
| 188 | |
| 189 | testJavaError(t, "Adjust sdk_version: property of the source or target module so that target module is built with the same or smaller API set than the source.", ` |
| 190 | java_library { |
| 191 | name: "foo", |
| 192 | srcs: ["a.java"], |
| 193 | libs: ["bar"], |
| 194 | sdk_version: "current", |
| 195 | static_libs: ["baz"], |
| 196 | } |
| 197 | |
| 198 | java_library { |
| 199 | name: "bar", |
| 200 | sdk_version: "current", |
| 201 | srcs: ["b.java"], |
| 202 | } |
| 203 | |
| 204 | java_library { |
| 205 | name: "baz", |
| 206 | sdk_version: "system_current", |
| 207 | srcs: ["c.java"], |
| 208 | } |
| 209 | `) |
| 210 | |
| 211 | testJava(t, ` |
| 212 | java_library { |
| 213 | name: "foo", |
| 214 | srcs: ["a.java"], |
| 215 | libs: ["bar"], |
| 216 | sdk_version: "system_current", |
| 217 | static_libs: ["baz"], |
| 218 | } |
| 219 | |
| 220 | java_library { |
| 221 | name: "bar", |
| 222 | sdk_version: "current", |
| 223 | srcs: ["b.java"], |
| 224 | } |
| 225 | |
| 226 | java_library { |
| 227 | name: "baz", |
| 228 | sdk_version: "system_current", |
| 229 | srcs: ["c.java"], |
| 230 | } |
| 231 | `) |
| 232 | |
| 233 | testJavaError(t, "Adjust sdk_version: property of the source or target module so that target module is built with the same or smaller API set than the source.", ` |
| 234 | java_library { |
| 235 | name: "foo", |
| 236 | srcs: ["a.java"], |
| 237 | libs: ["bar"], |
| 238 | sdk_version: "system_current", |
| 239 | static_libs: ["baz"], |
| 240 | } |
| 241 | |
| 242 | java_library { |
| 243 | name: "bar", |
| 244 | sdk_version: "current", |
| 245 | srcs: ["b.java"], |
| 246 | } |
| 247 | |
| 248 | java_library { |
| 249 | name: "baz", |
| 250 | srcs: ["c.java"], |
| 251 | } |
| 252 | `) |
| 253 | } |
| 254 | |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 255 | func TestSimple(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 256 | ctx, _ := testJava(t, ` |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 257 | java_library { |
| 258 | name: "foo", |
| 259 | srcs: ["a.java"], |
Colin Cross | e8dc34a | 2017-07-19 11:22:16 -0700 | [diff] [blame] | 260 | libs: ["bar"], |
| 261 | static_libs: ["baz"], |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | java_library { |
| 265 | name: "bar", |
| 266 | srcs: ["b.java"], |
| 267 | } |
| 268 | |
| 269 | java_library { |
| 270 | name: "baz", |
| 271 | srcs: ["c.java"], |
| 272 | } |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 273 | `) |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 274 | |
Colin Cross | 4c428df | 2017-09-15 17:36:05 -0700 | [diff] [blame] | 275 | javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 276 | combineJar := ctx.ModuleForTests("foo", "android_common").Description("for javac") |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 277 | |
| 278 | if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "a.java" { |
| 279 | t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs) |
| 280 | } |
| 281 | |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 282 | baz := ctx.ModuleForTests("baz", "android_common").Rule("javac").Output.String() |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 283 | barTurbine := filepath.Join(buildDir, ".intermediates", "bar", "android_common", "turbine-combined", "bar.jar") |
| 284 | bazTurbine := filepath.Join(buildDir, ".intermediates", "baz", "android_common", "turbine-combined", "baz.jar") |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 285 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 286 | if !strings.Contains(javac.Args["classpath"], barTurbine) { |
| 287 | 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] | 288 | } |
| 289 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 290 | if !strings.Contains(javac.Args["classpath"], bazTurbine) { |
| 291 | 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] | 292 | } |
| 293 | |
| 294 | if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != baz { |
| 295 | 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] | 296 | } |
| 297 | } |
| 298 | |
Artur Satayev | 9cf4669 | 2019-11-26 18:08:34 +0000 | [diff] [blame] | 299 | func TestExportedPlugins(t *testing.T) { |
| 300 | type Result struct { |
| 301 | library string |
| 302 | processors string |
| 303 | } |
| 304 | var tests = []struct { |
| 305 | name string |
| 306 | extra string |
| 307 | results []Result |
| 308 | }{ |
| 309 | { |
| 310 | name: "Exported plugin is not a direct plugin", |
| 311 | extra: `java_library { name: "exports", srcs: ["a.java"], exported_plugins: ["plugin"] }`, |
| 312 | results: []Result{{library: "exports", processors: "-proc:none"}}, |
| 313 | }, |
| 314 | { |
| 315 | name: "Exports plugin to dependee", |
| 316 | extra: ` |
| 317 | java_library{name: "exports", exported_plugins: ["plugin"]} |
| 318 | java_library{name: "foo", srcs: ["a.java"], libs: ["exports"]} |
| 319 | java_library{name: "bar", srcs: ["a.java"], static_libs: ["exports"]} |
| 320 | `, |
| 321 | results: []Result{ |
| 322 | {library: "foo", processors: "-processor com.android.TestPlugin"}, |
| 323 | {library: "bar", processors: "-processor com.android.TestPlugin"}, |
| 324 | }, |
| 325 | }, |
| 326 | { |
| 327 | name: "Exports plugin to android_library", |
| 328 | extra: ` |
| 329 | java_library{name: "exports", exported_plugins: ["plugin"]} |
| 330 | android_library{name: "foo", srcs: ["a.java"], libs: ["exports"]} |
| 331 | android_library{name: "bar", srcs: ["a.java"], static_libs: ["exports"]} |
| 332 | `, |
| 333 | results: []Result{ |
| 334 | {library: "foo", processors: "-processor com.android.TestPlugin"}, |
| 335 | {library: "bar", processors: "-processor com.android.TestPlugin"}, |
| 336 | }, |
| 337 | }, |
| 338 | { |
| 339 | name: "Exports plugin is not propagated via transitive deps", |
| 340 | extra: ` |
| 341 | java_library{name: "exports", exported_plugins: ["plugin"]} |
| 342 | java_library{name: "foo", srcs: ["a.java"], libs: ["exports"]} |
| 343 | java_library{name: "bar", srcs: ["a.java"], static_libs: ["foo"]} |
| 344 | `, |
| 345 | results: []Result{ |
| 346 | {library: "foo", processors: "-processor com.android.TestPlugin"}, |
| 347 | {library: "bar", processors: "-proc:none"}, |
| 348 | }, |
| 349 | }, |
| 350 | { |
| 351 | name: "Exports plugin appends to plugins", |
| 352 | extra: ` |
| 353 | java_plugin{name: "plugin2", processor_class: "com.android.TestPlugin2"} |
| 354 | java_library{name: "exports", exported_plugins: ["plugin"]} |
| 355 | java_library{name: "foo", srcs: ["a.java"], libs: ["exports"], plugins: ["plugin2"]} |
| 356 | `, |
| 357 | results: []Result{ |
| 358 | {library: "foo", processors: "-processor com.android.TestPlugin,com.android.TestPlugin2"}, |
| 359 | }, |
| 360 | }, |
| 361 | } |
| 362 | |
| 363 | for _, test := range tests { |
| 364 | t.Run(test.name, func(t *testing.T) { |
| 365 | ctx, _ := testJava(t, ` |
| 366 | java_plugin { |
| 367 | name: "plugin", |
| 368 | processor_class: "com.android.TestPlugin", |
| 369 | } |
| 370 | `+test.extra) |
| 371 | |
| 372 | for _, want := range test.results { |
| 373 | javac := ctx.ModuleForTests(want.library, "android_common").Rule("javac") |
| 374 | if javac.Args["processor"] != want.processors { |
| 375 | t.Errorf("For library %v, expected %v, found %v", want.library, want.processors, javac.Args["processor"]) |
| 376 | } |
| 377 | } |
| 378 | }) |
| 379 | } |
| 380 | } |
| 381 | |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 382 | func TestSdkVersionByPartition(t *testing.T) { |
| 383 | testJavaError(t, "sdk_version must have a value when the module is located at vendor or product", ` |
Jeongik Cha | 6bd33c1 | 2019-06-25 16:26:18 +0900 | [diff] [blame] | 384 | java_library { |
| 385 | name: "foo", |
| 386 | srcs: ["a.java"], |
| 387 | vendor: true, |
| 388 | } |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 389 | `) |
Jeongik Cha | 6bd33c1 | 2019-06-25 16:26:18 +0900 | [diff] [blame] | 390 | |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 391 | testJava(t, ` |
Jeongik Cha | 6bd33c1 | 2019-06-25 16:26:18 +0900 | [diff] [blame] | 392 | java_library { |
| 393 | name: "bar", |
| 394 | srcs: ["b.java"], |
| 395 | } |
| 396 | `) |
| 397 | |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 398 | for _, enforce := range []bool{true, false} { |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 399 | bp := ` |
| 400 | java_library { |
| 401 | name: "foo", |
| 402 | srcs: ["a.java"], |
| 403 | product_specific: true, |
| 404 | } |
| 405 | ` |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 406 | |
| 407 | config := testConfig(nil, bp, nil) |
| 408 | config.TestProductVariables.EnforceProductPartitionInterface = proptools.BoolPtr(enforce) |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 409 | if enforce { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 410 | testJavaErrorWithConfig(t, "sdk_version must have a value when the module is located at vendor or product", config) |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 411 | } else { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 412 | testJavaWithConfig(t, config) |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 413 | } |
Jeongik Cha | 6bd33c1 | 2019-06-25 16:26:18 +0900 | [diff] [blame] | 414 | } |
| 415 | } |
| 416 | |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 417 | func TestArchSpecific(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 418 | ctx, _ := testJava(t, ` |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 419 | java_library { |
| 420 | name: "foo", |
| 421 | srcs: ["a.java"], |
| 422 | target: { |
| 423 | android: { |
| 424 | srcs: ["b.java"], |
| 425 | }, |
| 426 | }, |
| 427 | } |
| 428 | `) |
| 429 | |
| 430 | javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") |
| 431 | if len(javac.Inputs) != 2 || javac.Inputs[0].String() != "a.java" || javac.Inputs[1].String() != "b.java" { |
| 432 | t.Errorf(`foo inputs %v != ["a.java", "b.java"]`, javac.Inputs) |
| 433 | } |
| 434 | } |
| 435 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 436 | func TestBinary(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 437 | ctx, _ := testJava(t, ` |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 438 | java_library_host { |
| 439 | name: "foo", |
| 440 | srcs: ["a.java"], |
| 441 | } |
| 442 | |
| 443 | java_binary_host { |
| 444 | name: "bar", |
| 445 | srcs: ["b.java"], |
| 446 | static_libs: ["foo"], |
| 447 | } |
| 448 | `) |
| 449 | |
| 450 | buildOS := android.BuildOs.String() |
| 451 | |
| 452 | bar := ctx.ModuleForTests("bar", buildOS+"_common") |
| 453 | barJar := bar.Output("bar.jar").Output.String() |
| 454 | barWrapper := ctx.ModuleForTests("bar", buildOS+"_x86_64") |
| 455 | barWrapperDeps := barWrapper.Output("bar").Implicits.Strings() |
| 456 | |
| 457 | // Test that the install binary wrapper depends on the installed jar file |
| 458 | if len(barWrapperDeps) != 1 || barWrapperDeps[0] != barJar { |
| 459 | t.Errorf("expected binary wrapper implicits [%q], got %v", |
| 460 | barJar, barWrapperDeps) |
| 461 | } |
| 462 | |
| 463 | } |
| 464 | |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 465 | func TestPrebuilts(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 466 | ctx, _ := testJava(t, ` |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 467 | java_library { |
| 468 | name: "foo", |
Paul Duffin | 9154718 | 2019-11-12 19:39:36 +0000 | [diff] [blame] | 469 | srcs: ["a.java", ":stubs-source"], |
Paul Duffin | fcfd791 | 2020-01-31 17:54:30 +0000 | [diff] [blame] | 470 | libs: ["bar", "sdklib"], |
Colin Cross | e8dc34a | 2017-07-19 11:22:16 -0700 | [diff] [blame] | 471 | static_libs: ["baz"], |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 474 | java_import { |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 475 | name: "bar", |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 476 | jars: ["a.jar"], |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 479 | java_import { |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 480 | name: "baz", |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 481 | jars: ["b.jar"], |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 482 | } |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 483 | |
| 484 | dex_import { |
| 485 | name: "qux", |
| 486 | jars: ["b.jar"], |
| 487 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 488 | |
| 489 | java_sdk_library_import { |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 490 | name: "sdklib", |
| 491 | public: { |
| 492 | jars: ["c.jar"], |
| 493 | }, |
| 494 | } |
| 495 | |
Paul Duffin | 9154718 | 2019-11-12 19:39:36 +0000 | [diff] [blame] | 496 | prebuilt_stubs_sources { |
| 497 | name: "stubs-source", |
Paul Duffin | 9b478b0 | 2019-12-10 13:41:51 +0000 | [diff] [blame] | 498 | srcs: ["stubs/sources"], |
Paul Duffin | 9154718 | 2019-11-12 19:39:36 +0000 | [diff] [blame] | 499 | } |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 500 | |
| 501 | java_test_import { |
| 502 | name: "test", |
| 503 | jars: ["a.jar"], |
| 504 | test_suites: ["cts"], |
| 505 | test_config: "AndroidTest.xml", |
| 506 | } |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 507 | `) |
| 508 | |
Paul Duffin | 9b478b0 | 2019-12-10 13:41:51 +0000 | [diff] [blame] | 509 | fooModule := ctx.ModuleForTests("foo", "android_common") |
| 510 | javac := fooModule.Rule("javac") |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 511 | combineJar := ctx.ModuleForTests("foo", "android_common").Description("for javac") |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 512 | barJar := ctx.ModuleForTests("bar", "android_common").Rule("combineJar").Output |
| 513 | bazJar := ctx.ModuleForTests("baz", "android_common").Rule("combineJar").Output |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 514 | sdklibStubsJar := ctx.ModuleForTests("sdklib.stubs", "android_common").Rule("combineJar").Output |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 515 | |
Paul Duffin | 9b478b0 | 2019-12-10 13:41:51 +0000 | [diff] [blame] | 516 | fooLibrary := fooModule.Module().(*Library) |
| 517 | assertDeepEquals(t, "foo java sources incorrect", |
| 518 | []string{"a.java"}, fooLibrary.compiledJavaSrcs.Strings()) |
Paul Duffin | 9154718 | 2019-11-12 19:39:36 +0000 | [diff] [blame] | 519 | |
Paul Duffin | 9b478b0 | 2019-12-10 13:41:51 +0000 | [diff] [blame] | 520 | assertDeepEquals(t, "foo java source jars incorrect", |
| 521 | []string{".intermediates/stubs-source/android_common/stubs-source-stubs.srcjar"}, |
| 522 | android.NormalizePathsForTesting(fooLibrary.compiledSrcJars)) |
Paul Duffin | 9154718 | 2019-11-12 19:39:36 +0000 | [diff] [blame] | 523 | |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 524 | if !strings.Contains(javac.Args["classpath"], barJar.String()) { |
| 525 | 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] | 526 | } |
| 527 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 528 | if !strings.Contains(javac.Args["classpath"], sdklibStubsJar.String()) { |
| 529 | t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], sdklibStubsJar.String()) |
| 530 | } |
| 531 | |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 532 | if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != bazJar.String() { |
| 533 | 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] | 534 | } |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 535 | |
| 536 | ctx.ModuleForTests("qux", "android_common").Rule("Cp") |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Paul Duffin | 9b478b0 | 2019-12-10 13:41:51 +0000 | [diff] [blame] | 539 | func assertDeepEquals(t *testing.T, message string, expected interface{}, actual interface{}) { |
| 540 | if !reflect.DeepEqual(expected, actual) { |
| 541 | t.Errorf("%s: expected %q, found %q", message, expected, actual) |
| 542 | } |
| 543 | } |
| 544 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 545 | func TestJavaSdkLibraryImport(t *testing.T) { |
| 546 | ctx, _ := testJava(t, ` |
| 547 | java_library { |
| 548 | name: "foo", |
| 549 | srcs: ["a.java"], |
| 550 | libs: ["sdklib"], |
| 551 | sdk_version: "current", |
| 552 | } |
| 553 | |
| 554 | java_library { |
| 555 | name: "foo.system", |
| 556 | srcs: ["a.java"], |
| 557 | libs: ["sdklib"], |
| 558 | sdk_version: "system_current", |
| 559 | } |
| 560 | |
| 561 | java_library { |
| 562 | name: "foo.test", |
| 563 | srcs: ["a.java"], |
| 564 | libs: ["sdklib"], |
| 565 | sdk_version: "test_current", |
| 566 | } |
| 567 | |
| 568 | java_sdk_library_import { |
| 569 | name: "sdklib", |
| 570 | public: { |
| 571 | jars: ["a.jar"], |
| 572 | }, |
| 573 | system: { |
| 574 | jars: ["b.jar"], |
| 575 | }, |
| 576 | test: { |
| 577 | jars: ["c.jar"], |
| 578 | }, |
| 579 | } |
| 580 | `) |
| 581 | |
| 582 | for _, scope := range []string{"", ".system", ".test"} { |
| 583 | fooModule := ctx.ModuleForTests("foo"+scope, "android_common") |
| 584 | javac := fooModule.Rule("javac") |
| 585 | |
| 586 | sdklibStubsJar := ctx.ModuleForTests("sdklib.stubs"+scope, "android_common").Rule("combineJar").Output |
| 587 | if !strings.Contains(javac.Args["classpath"], sdklibStubsJar.String()) { |
| 588 | t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], sdklibStubsJar.String()) |
| 589 | } |
| 590 | } |
| 591 | } |
| 592 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 593 | func TestDefaults(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 594 | ctx, _ := testJava(t, ` |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 595 | java_defaults { |
| 596 | name: "defaults", |
| 597 | srcs: ["a.java"], |
| 598 | libs: ["bar"], |
| 599 | static_libs: ["baz"], |
Sasha Smundak | 2057f82 | 2019-04-16 17:16:58 -0700 | [diff] [blame] | 600 | optimize: {enabled: false}, |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | java_library { |
| 604 | name: "foo", |
| 605 | defaults: ["defaults"], |
| 606 | } |
| 607 | |
| 608 | java_library { |
| 609 | name: "bar", |
| 610 | srcs: ["b.java"], |
| 611 | } |
| 612 | |
| 613 | java_library { |
| 614 | name: "baz", |
| 615 | srcs: ["c.java"], |
| 616 | } |
Sasha Smundak | 2057f82 | 2019-04-16 17:16:58 -0700 | [diff] [blame] | 617 | |
| 618 | android_test { |
| 619 | name: "atestOptimize", |
| 620 | defaults: ["defaults"], |
| 621 | optimize: {enabled: true}, |
| 622 | } |
| 623 | |
| 624 | android_test { |
| 625 | name: "atestNoOptimize", |
| 626 | defaults: ["defaults"], |
| 627 | } |
| 628 | |
| 629 | android_test { |
| 630 | name: "atestDefault", |
| 631 | srcs: ["a.java"], |
| 632 | } |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 633 | `) |
| 634 | |
Colin Cross | 4c428df | 2017-09-15 17:36:05 -0700 | [diff] [blame] | 635 | javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 636 | combineJar := ctx.ModuleForTests("foo", "android_common").Description("for javac") |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 637 | |
| 638 | if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "a.java" { |
| 639 | t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs) |
| 640 | } |
| 641 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 642 | barTurbine := filepath.Join(buildDir, ".intermediates", "bar", "android_common", "turbine-combined", "bar.jar") |
| 643 | if !strings.Contains(javac.Args["classpath"], barTurbine) { |
| 644 | 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] | 645 | } |
| 646 | |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 647 | baz := ctx.ModuleForTests("baz", "android_common").Rule("javac").Output.String() |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 648 | if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != baz { |
| 649 | 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] | 650 | } |
Sasha Smundak | 2057f82 | 2019-04-16 17:16:58 -0700 | [diff] [blame] | 651 | |
| 652 | atestOptimize := ctx.ModuleForTests("atestOptimize", "android_common").MaybeRule("r8") |
| 653 | if atestOptimize.Output == nil { |
| 654 | t.Errorf("atestOptimize should optimize APK") |
| 655 | } |
| 656 | |
| 657 | atestNoOptimize := ctx.ModuleForTests("atestNoOptimize", "android_common").MaybeRule("d8") |
| 658 | if atestNoOptimize.Output == nil { |
| 659 | t.Errorf("atestNoOptimize should not optimize APK") |
| 660 | } |
| 661 | |
| 662 | atestDefault := ctx.ModuleForTests("atestDefault", "android_common").MaybeRule("r8") |
| 663 | if atestDefault.Output == nil { |
| 664 | t.Errorf("atestDefault should optimize APK") |
| 665 | } |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 666 | } |
| 667 | |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 668 | func TestResources(t *testing.T) { |
| 669 | var table = []struct { |
| 670 | name string |
| 671 | prop string |
| 672 | extra string |
| 673 | args string |
| 674 | }{ |
| 675 | { |
Colin Cross | af9c55b | 2017-10-03 14:50:08 -0700 | [diff] [blame] | 676 | // Test that a module with java_resource_dirs includes the files |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 677 | name: "resource dirs", |
Colin Cross | 824bee3 | 2017-11-22 17:27:51 -0800 | [diff] [blame] | 678 | prop: `java_resource_dirs: ["java-res"]`, |
Colin Cross | 0ead1d7 | 2018-04-10 13:07:42 -0700 | [diff] [blame] | 679 | 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] | 680 | }, |
| 681 | { |
| 682 | // Test that a module with java_resources includes the files |
| 683 | name: "resource files", |
Colin Cross | 0ead1d7 | 2018-04-10 13:07:42 -0700 | [diff] [blame] | 684 | prop: `java_resources: ["java-res/a/a", "java-res/b/b"]`, |
| 685 | args: "-C . -f java-res/a/a -f java-res/b/b", |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 686 | }, |
| 687 | { |
| 688 | // Test that a module with a filegroup in java_resources includes the files with the |
| 689 | // path prefix |
| 690 | name: "resource filegroup", |
| 691 | prop: `java_resources: [":foo-res"]`, |
| 692 | extra: ` |
| 693 | filegroup { |
| 694 | name: "foo-res", |
Colin Cross | 824bee3 | 2017-11-22 17:27:51 -0800 | [diff] [blame] | 695 | path: "java-res", |
Colin Cross | 0ead1d7 | 2018-04-10 13:07:42 -0700 | [diff] [blame] | 696 | srcs: ["java-res/a/a", "java-res/b/b"], |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 697 | }`, |
Colin Cross | 0ead1d7 | 2018-04-10 13:07:42 -0700 | [diff] [blame] | 698 | 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] | 699 | }, |
| 700 | { |
Colin Cross | 0ead1d7 | 2018-04-10 13:07:42 -0700 | [diff] [blame] | 701 | // Test that a module with wildcards in java_resource_dirs has the correct path prefixes |
| 702 | name: "wildcard dirs", |
| 703 | prop: `java_resource_dirs: ["java-res/*"]`, |
| 704 | args: "-C java-res/a -f java-res/a/a -C java-res/b -f java-res/b/b", |
| 705 | }, |
| 706 | { |
| 707 | // Test that a module exclude_java_resource_dirs excludes the files |
| 708 | name: "wildcard dirs", |
| 709 | prop: `java_resource_dirs: ["java-res/*"], exclude_java_resource_dirs: ["java-res/b"]`, |
| 710 | args: "-C java-res/a -f java-res/a/a", |
| 711 | }, |
Colin Cross | cedd476 | 2018-09-13 11:26:19 -0700 | [diff] [blame] | 712 | { |
| 713 | // Test wildcards in java_resources |
| 714 | name: "wildcard files", |
| 715 | prop: `java_resources: ["java-res/**/*"]`, |
| 716 | args: "-C . -f java-res/a/a -f java-res/b/b", |
| 717 | }, |
| 718 | { |
| 719 | // Test exclude_java_resources with java_resources |
| 720 | name: "wildcard files with exclude", |
| 721 | prop: `java_resources: ["java-res/**/*"], exclude_java_resources: ["java-res/b/*"]`, |
| 722 | args: "-C . -f java-res/a/a", |
| 723 | }, |
| 724 | { |
| 725 | // Test exclude_java_resources with java_resource_dirs |
| 726 | name: "resource dirs with exclude files", |
| 727 | prop: `java_resource_dirs: ["java-res"], exclude_java_resources: ["java-res/b/b"]`, |
| 728 | args: "-C java-res -f java-res/a/a", |
| 729 | }, |
| 730 | { |
| 731 | // Test exclude_java_resource_dirs with java_resource_dirs |
| 732 | name: "resource dirs with exclude files", |
| 733 | prop: `java_resource_dirs: ["java-res", "java-res2"], exclude_java_resource_dirs: ["java-res2"]`, |
| 734 | args: "-C java-res -f java-res/a/a -f java-res/b/b", |
| 735 | }, |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | for _, test := range table { |
| 739 | t.Run(test.name, func(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 740 | ctx, _ := testJava(t, ` |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 741 | java_library { |
| 742 | name: "foo", |
| 743 | srcs: [ |
| 744 | "a.java", |
| 745 | "b.java", |
| 746 | "c.java", |
| 747 | ], |
| 748 | `+test.prop+`, |
| 749 | } |
| 750 | `+test.extra) |
| 751 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 752 | foo := ctx.ModuleForTests("foo", "android_common").Output("withres/foo.jar") |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 753 | fooRes := ctx.ModuleForTests("foo", "android_common").Output("res/foo.jar") |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 754 | |
| 755 | if !inList(fooRes.Output.String(), foo.Inputs.Strings()) { |
| 756 | t.Errorf("foo combined jars %v does not contain %q", |
| 757 | foo.Inputs.Strings(), fooRes.Output.String()) |
| 758 | } |
| 759 | |
Colin Cross | af9c55b | 2017-10-03 14:50:08 -0700 | [diff] [blame] | 760 | if fooRes.Args["jarArgs"] != test.args { |
| 761 | t.Errorf("foo resource jar args %q is not %q", |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 762 | fooRes.Args["jarArgs"], test.args) |
| 763 | } |
| 764 | }) |
| 765 | } |
| 766 | } |
| 767 | |
Colin Cross | 0c4ce21 | 2019-05-03 15:28:19 -0700 | [diff] [blame] | 768 | func TestIncludeSrcs(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 769 | ctx, _ := testJava(t, ` |
Colin Cross | 0c4ce21 | 2019-05-03 15:28:19 -0700 | [diff] [blame] | 770 | java_library { |
| 771 | name: "foo", |
| 772 | srcs: [ |
| 773 | "a.java", |
| 774 | "b.java", |
| 775 | "c.java", |
| 776 | ], |
| 777 | include_srcs: true, |
| 778 | } |
| 779 | |
| 780 | java_library { |
| 781 | name: "bar", |
| 782 | srcs: [ |
| 783 | "a.java", |
| 784 | "b.java", |
| 785 | "c.java", |
| 786 | ], |
| 787 | java_resource_dirs: ["java-res"], |
| 788 | include_srcs: true, |
| 789 | } |
| 790 | `) |
| 791 | |
| 792 | // Test a library with include_srcs: true |
| 793 | foo := ctx.ModuleForTests("foo", "android_common").Output("withres/foo.jar") |
| 794 | fooSrcJar := ctx.ModuleForTests("foo", "android_common").Output("foo.srcjar") |
| 795 | |
| 796 | if g, w := fooSrcJar.Output.String(), foo.Inputs.Strings(); !inList(g, w) { |
| 797 | t.Errorf("foo combined jars %v does not contain %q", w, g) |
| 798 | } |
| 799 | |
| 800 | if g, w := fooSrcJar.Args["jarArgs"], "-C . -f a.java -f b.java -f c.java"; g != w { |
| 801 | t.Errorf("foo source jar args %q is not %q", w, g) |
| 802 | } |
| 803 | |
| 804 | // Test a library with include_srcs: true and resources |
| 805 | bar := ctx.ModuleForTests("bar", "android_common").Output("withres/bar.jar") |
| 806 | barResCombined := ctx.ModuleForTests("bar", "android_common").Output("res-combined/bar.jar") |
| 807 | barRes := ctx.ModuleForTests("bar", "android_common").Output("res/bar.jar") |
| 808 | barSrcJar := ctx.ModuleForTests("bar", "android_common").Output("bar.srcjar") |
| 809 | |
| 810 | if g, w := barSrcJar.Output.String(), barResCombined.Inputs.Strings(); !inList(g, w) { |
| 811 | t.Errorf("bar combined resource jars %v does not contain %q", w, g) |
| 812 | } |
| 813 | |
| 814 | if g, w := barRes.Output.String(), barResCombined.Inputs.Strings(); !inList(g, w) { |
| 815 | t.Errorf("bar combined resource jars %v does not contain %q", w, g) |
| 816 | } |
| 817 | |
| 818 | if g, w := barResCombined.Output.String(), bar.Inputs.Strings(); !inList(g, w) { |
| 819 | t.Errorf("bar combined jars %v does not contain %q", w, g) |
| 820 | } |
| 821 | |
| 822 | if g, w := barSrcJar.Args["jarArgs"], "-C . -f a.java -f b.java -f c.java"; g != w { |
| 823 | t.Errorf("bar source jar args %q is not %q", w, g) |
| 824 | } |
| 825 | |
| 826 | if g, w := barRes.Args["jarArgs"], "-C java-res -f java-res/a/a -f java-res/b/b"; g != w { |
| 827 | t.Errorf("bar resource jar args %q is not %q", w, g) |
| 828 | } |
| 829 | } |
| 830 | |
Colin Cross | 54190b3 | 2017-10-09 15:34:10 -0700 | [diff] [blame] | 831 | func TestGeneratedSources(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 832 | ctx, _ := testJava(t, ` |
Colin Cross | 54190b3 | 2017-10-09 15:34:10 -0700 | [diff] [blame] | 833 | java_library { |
| 834 | name: "foo", |
| 835 | srcs: [ |
| 836 | "a*.java", |
| 837 | ":gen", |
| 838 | "b*.java", |
| 839 | ], |
| 840 | } |
| 841 | |
| 842 | genrule { |
| 843 | name: "gen", |
Colin Cross | 824bee3 | 2017-11-22 17:27:51 -0800 | [diff] [blame] | 844 | tool_files: ["java-res/a"], |
Colin Cross | 54190b3 | 2017-10-09 15:34:10 -0700 | [diff] [blame] | 845 | out: ["gen.java"], |
| 846 | } |
| 847 | `) |
| 848 | |
| 849 | javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") |
| 850 | genrule := ctx.ModuleForTests("gen", "").Rule("generator") |
| 851 | |
Colin Cross | 15e86d9 | 2017-10-20 15:07:08 -0700 | [diff] [blame] | 852 | if filepath.Base(genrule.Output.String()) != "gen.java" { |
| 853 | 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] | 854 | } |
| 855 | |
| 856 | if len(javac.Inputs) != 3 || |
| 857 | javac.Inputs[0].String() != "a.java" || |
Colin Cross | 15e86d9 | 2017-10-20 15:07:08 -0700 | [diff] [blame] | 858 | javac.Inputs[1].String() != genrule.Output.String() || |
Colin Cross | 54190b3 | 2017-10-09 15:34:10 -0700 | [diff] [blame] | 859 | javac.Inputs[2].String() != "b.java" { |
| 860 | t.Errorf(`foo inputs %v != ["a.java", ".../gen.java", "b.java"]`, javac.Inputs) |
| 861 | } |
| 862 | } |
| 863 | |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 864 | func TestTurbine(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 865 | ctx, _ := testJava(t, ` |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 866 | java_library { |
| 867 | name: "foo", |
| 868 | srcs: ["a.java"], |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 869 | sdk_version: "14", |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | java_library { |
| 873 | name: "bar", |
Colin Cross | 9bc4343 | 2017-12-15 20:20:39 -0800 | [diff] [blame] | 874 | srcs: ["b.java"], |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 875 | static_libs: ["foo"], |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 876 | sdk_version: "14", |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | java_library { |
| 880 | name: "baz", |
| 881 | srcs: ["c.java"], |
| 882 | libs: ["bar"], |
| 883 | sdk_version: "14", |
| 884 | } |
| 885 | `) |
| 886 | |
| 887 | fooTurbine := ctx.ModuleForTests("foo", "android_common").Rule("turbine") |
| 888 | barTurbine := ctx.ModuleForTests("bar", "android_common").Rule("turbine") |
| 889 | barJavac := ctx.ModuleForTests("bar", "android_common").Rule("javac") |
| 890 | barTurbineCombined := ctx.ModuleForTests("bar", "android_common").Description("for turbine") |
| 891 | bazJavac := ctx.ModuleForTests("baz", "android_common").Rule("javac") |
| 892 | |
| 893 | if len(fooTurbine.Inputs) != 1 || fooTurbine.Inputs[0].String() != "a.java" { |
| 894 | t.Errorf(`foo inputs %v != ["a.java"]`, fooTurbine.Inputs) |
| 895 | } |
| 896 | |
| 897 | fooHeaderJar := filepath.Join(buildDir, ".intermediates", "foo", "android_common", "turbine-combined", "foo.jar") |
| 898 | if !strings.Contains(barTurbine.Args["classpath"], fooHeaderJar) { |
| 899 | t.Errorf("bar turbine classpath %v does not contain %q", barTurbine.Args["classpath"], fooHeaderJar) |
| 900 | } |
| 901 | if !strings.Contains(barJavac.Args["classpath"], fooHeaderJar) { |
| 902 | t.Errorf("bar javac classpath %v does not contain %q", barJavac.Args["classpath"], fooHeaderJar) |
| 903 | } |
| 904 | if len(barTurbineCombined.Inputs) != 2 || barTurbineCombined.Inputs[1].String() != fooHeaderJar { |
| 905 | t.Errorf("bar turbine combineJar inputs %v does not contain %q", barTurbineCombined.Inputs, fooHeaderJar) |
| 906 | } |
Anton Hansson | f66efeb | 2018-04-11 13:57:30 +0100 | [diff] [blame] | 907 | if !strings.Contains(bazJavac.Args["classpath"], "prebuilts/sdk/14/public/android.jar") { |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 908 | 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] | 909 | "prebuilts/sdk/14/public/android.jar") |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 910 | } |
| 911 | } |
| 912 | |
| 913 | func TestSharding(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 914 | ctx, _ := testJava(t, ` |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 915 | java_library { |
| 916 | name: "bar", |
| 917 | srcs: ["a.java","b.java","c.java"], |
| 918 | javac_shard_size: 1 |
| 919 | } |
| 920 | `) |
| 921 | |
| 922 | barHeaderJar := filepath.Join(buildDir, ".intermediates", "bar", "android_common", "turbine-combined", "bar.jar") |
| 923 | for i := 0; i < 3; i++ { |
| 924 | barJavac := ctx.ModuleForTests("bar", "android_common").Description("javac" + strconv.Itoa(i)) |
| 925 | if !strings.Contains(barJavac.Args["classpath"], barHeaderJar) { |
| 926 | t.Errorf("bar javac classpath %v does not contain %q", barJavac.Args["classpath"], barHeaderJar) |
| 927 | } |
| 928 | } |
| 929 | } |
| 930 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 931 | func TestDroiddoc(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 932 | ctx, _ := testJava(t, ` |
Paul Duffin | 884363e | 2019-12-19 10:21:09 +0000 | [diff] [blame] | 933 | droiddoc_exported_dir { |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 934 | name: "droiddoc-templates-sdk", |
| 935 | path: ".", |
| 936 | } |
Jiyong Park | 2907459 | 2019-07-07 16:27:47 +0900 | [diff] [blame] | 937 | filegroup { |
| 938 | name: "bar-doc-aidl-srcs", |
| 939 | srcs: ["bar-doc/IBar.aidl"], |
| 940 | path: "bar-doc", |
| 941 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 942 | droiddoc { |
| 943 | name: "bar-doc", |
| 944 | srcs: [ |
| 945 | "bar-doc/*.java", |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 946 | "bar-doc/IFoo.aidl", |
Jiyong Park | 2907459 | 2019-07-07 16:27:47 +0900 | [diff] [blame] | 947 | ":bar-doc-aidl-srcs", |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 948 | ], |
| 949 | exclude_srcs: [ |
| 950 | "bar-doc/b.java" |
| 951 | ], |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 952 | custom_template: "droiddoc-templates-sdk", |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 953 | hdf: [ |
| 954 | "android.whichdoc offline", |
| 955 | ], |
| 956 | knowntags: [ |
| 957 | "bar-doc/known_oj_tags.txt", |
| 958 | ], |
| 959 | proofread_file: "libcore-proofread.txt", |
| 960 | todo_file: "libcore-docs-todo.html", |
| 961 | args: "-offlinemode -title \"libcore\"", |
| 962 | } |
| 963 | `) |
| 964 | |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 965 | barDoc := ctx.ModuleForTests("bar-doc", "android_common").Rule("javadoc") |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 966 | var javaSrcs []string |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 967 | for _, i := range barDoc.Inputs { |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 968 | javaSrcs = append(javaSrcs, i.Base()) |
| 969 | } |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 970 | if len(javaSrcs) != 1 || javaSrcs[0] != "a.java" { |
| 971 | t.Errorf("inputs of bar-doc must be []string{\"a.java\"}, but was %#v.", javaSrcs) |
Jiyong Park | 2907459 | 2019-07-07 16:27:47 +0900 | [diff] [blame] | 972 | } |
| 973 | |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 974 | aidl := ctx.ModuleForTests("bar-doc", "android_common").Rule("aidl") |
| 975 | if g, w := barDoc.Implicits.Strings(), aidl.Output.String(); !inList(w, g) { |
| 976 | t.Errorf("implicits of bar-doc must contain %q, but was %q.", w, g) |
| 977 | } |
| 978 | |
| 979 | if g, w := aidl.Implicits.Strings(), []string{"bar-doc/IBar.aidl", "bar-doc/IFoo.aidl"}; !reflect.DeepEqual(w, g) { |
| 980 | t.Errorf("aidl inputs must be %q, but was %q", w, g) |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 981 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 982 | } |
| 983 | |
Paul Duffin | 83a2d96 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 984 | func TestDroidstubsWithSystemModules(t *testing.T) { |
| 985 | ctx, _ := testJava(t, ` |
| 986 | droidstubs { |
| 987 | name: "stubs-source-system-modules", |
| 988 | srcs: [ |
| 989 | "bar-doc/*.java", |
| 990 | ], |
| 991 | sdk_version: "none", |
| 992 | system_modules: "source-system-modules", |
| 993 | } |
| 994 | |
| 995 | java_library { |
| 996 | name: "source-jar", |
| 997 | srcs: [ |
| 998 | "a.java", |
| 999 | ], |
| 1000 | } |
| 1001 | |
| 1002 | java_system_modules { |
| 1003 | name: "source-system-modules", |
| 1004 | libs: ["source-jar"], |
| 1005 | } |
| 1006 | |
| 1007 | droidstubs { |
| 1008 | name: "stubs-prebuilt-system-modules", |
| 1009 | srcs: [ |
| 1010 | "bar-doc/*.java", |
| 1011 | ], |
| 1012 | sdk_version: "none", |
| 1013 | system_modules: "prebuilt-system-modules", |
| 1014 | } |
| 1015 | |
| 1016 | java_import { |
| 1017 | name: "prebuilt-jar", |
| 1018 | jars: ["a.jar"], |
| 1019 | } |
| 1020 | |
| 1021 | java_system_modules_import { |
| 1022 | name: "prebuilt-system-modules", |
| 1023 | libs: ["prebuilt-jar"], |
| 1024 | } |
| 1025 | `) |
| 1026 | |
| 1027 | checkSystemModulesUseByDroidstubs(t, ctx, "stubs-source-system-modules", "source-jar.jar") |
| 1028 | |
| 1029 | checkSystemModulesUseByDroidstubs(t, ctx, "stubs-prebuilt-system-modules", "prebuilt-jar.jar") |
| 1030 | } |
| 1031 | |
| 1032 | func checkSystemModulesUseByDroidstubs(t *testing.T, ctx *android.TestContext, moduleName string, systemJar string) { |
| 1033 | metalavaRule := ctx.ModuleForTests(moduleName, "android_common").Rule("metalava") |
| 1034 | var systemJars []string |
| 1035 | for _, i := range metalavaRule.Implicits { |
| 1036 | systemJars = append(systemJars, i.Base()) |
| 1037 | } |
| 1038 | if len(systemJars) != 1 || systemJars[0] != systemJar { |
| 1039 | t.Errorf("inputs of %q must be []string{%q}, but was %#v.", moduleName, systemJar, systemJars) |
| 1040 | } |
| 1041 | } |
| 1042 | |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 1043 | func TestJarGenrules(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1044 | ctx, _ := testJava(t, ` |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 1045 | java_library { |
| 1046 | name: "foo", |
| 1047 | srcs: ["a.java"], |
| 1048 | } |
| 1049 | |
| 1050 | java_genrule { |
| 1051 | name: "jargen", |
| 1052 | tool_files: ["b.java"], |
| 1053 | cmd: "$(location b.java) $(in) $(out)", |
| 1054 | out: ["jargen.jar"], |
| 1055 | srcs: [":foo"], |
| 1056 | } |
| 1057 | |
| 1058 | java_library { |
| 1059 | name: "bar", |
| 1060 | static_libs: ["jargen"], |
| 1061 | srcs: ["c.java"], |
| 1062 | } |
| 1063 | |
| 1064 | java_library { |
| 1065 | name: "baz", |
| 1066 | libs: ["jargen"], |
| 1067 | srcs: ["c.java"], |
| 1068 | } |
| 1069 | `) |
| 1070 | |
| 1071 | foo := ctx.ModuleForTests("foo", "android_common").Output("javac/foo.jar") |
| 1072 | jargen := ctx.ModuleForTests("jargen", "android_common").Output("jargen.jar") |
| 1073 | bar := ctx.ModuleForTests("bar", "android_common").Output("javac/bar.jar") |
| 1074 | baz := ctx.ModuleForTests("baz", "android_common").Output("javac/baz.jar") |
| 1075 | barCombined := ctx.ModuleForTests("bar", "android_common").Output("combined/bar.jar") |
| 1076 | |
| 1077 | if len(jargen.Inputs) != 1 || jargen.Inputs[0].String() != foo.Output.String() { |
| 1078 | t.Errorf("expected jargen inputs [%q], got %q", foo.Output.String(), jargen.Inputs.Strings()) |
| 1079 | } |
| 1080 | |
| 1081 | if !strings.Contains(bar.Args["classpath"], jargen.Output.String()) { |
| 1082 | t.Errorf("bar classpath %v does not contain %q", bar.Args["classpath"], jargen.Output.String()) |
| 1083 | } |
| 1084 | |
| 1085 | if !strings.Contains(baz.Args["classpath"], jargen.Output.String()) { |
| 1086 | t.Errorf("baz classpath %v does not contain %q", baz.Args["classpath"], jargen.Output.String()) |
| 1087 | } |
| 1088 | |
| 1089 | if len(barCombined.Inputs) != 2 || |
| 1090 | barCombined.Inputs[0].String() != bar.Output.String() || |
| 1091 | barCombined.Inputs[1].String() != jargen.Output.String() { |
| 1092 | t.Errorf("bar combined jar inputs %v is not [%q, %q]", |
| 1093 | barCombined.Inputs.Strings(), bar.Output.String(), jargen.Output.String()) |
| 1094 | } |
| 1095 | } |
| 1096 | |
Nan Zhang | 27e284d | 2018-02-09 21:03:53 +0000 | [diff] [blame] | 1097 | func TestExcludeFileGroupInSrcs(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1098 | ctx, _ := testJava(t, ` |
Nan Zhang | 27e284d | 2018-02-09 21:03:53 +0000 | [diff] [blame] | 1099 | java_library { |
| 1100 | name: "foo", |
| 1101 | srcs: ["a.java", ":foo-srcs"], |
| 1102 | exclude_srcs: ["a.java", ":foo-excludes"], |
| 1103 | } |
| 1104 | |
| 1105 | filegroup { |
| 1106 | name: "foo-srcs", |
| 1107 | srcs: ["java-fg/a.java", "java-fg/b.java", "java-fg/c.java"], |
| 1108 | } |
| 1109 | |
| 1110 | filegroup { |
| 1111 | name: "foo-excludes", |
| 1112 | srcs: ["java-fg/a.java", "java-fg/b.java"], |
| 1113 | } |
| 1114 | `) |
| 1115 | |
| 1116 | javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") |
| 1117 | |
| 1118 | if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "java-fg/c.java" { |
| 1119 | t.Errorf(`foo inputs %v != ["java-fg/c.java"]`, javac.Inputs) |
| 1120 | } |
| 1121 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1122 | |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 1123 | func TestJavaLibrary(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 1124 | config := testConfig(nil, "", map[string][]byte{ |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 1125 | "libcore/Android.bp": []byte(` |
| 1126 | java_library { |
| 1127 | name: "core", |
| 1128 | sdk_version: "none", |
| 1129 | system_modules: "none", |
| 1130 | }`), |
| 1131 | }) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 1132 | ctx := testContext() |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 1133 | run(t, ctx, config) |
| 1134 | } |
| 1135 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1136 | func TestJavaSdkLibrary(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1137 | ctx, _ := testJava(t, ` |
Paul Duffin | 884363e | 2019-12-19 10:21:09 +0000 | [diff] [blame] | 1138 | droiddoc_exported_dir { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1139 | name: "droiddoc-templates-sdk", |
| 1140 | path: ".", |
| 1141 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1142 | java_sdk_library { |
| 1143 | name: "foo", |
| 1144 | srcs: ["a.java", "b.java"], |
| 1145 | api_packages: ["foo"], |
| 1146 | } |
| 1147 | java_sdk_library { |
| 1148 | name: "bar", |
| 1149 | srcs: ["a.java", "b.java"], |
| 1150 | api_packages: ["bar"], |
| 1151 | } |
| 1152 | java_library { |
| 1153 | name: "baz", |
| 1154 | srcs: ["c.java"], |
| 1155 | libs: ["foo", "bar"], |
| 1156 | sdk_version: "system_current", |
| 1157 | } |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1158 | java_library { |
| 1159 | name: "qux", |
| 1160 | srcs: ["c.java"], |
| 1161 | libs: ["baz"], |
| 1162 | sdk_version: "system_current", |
| 1163 | } |
Paul Duffin | 726d23c | 2020-01-22 16:30:37 +0000 | [diff] [blame] | 1164 | java_library { |
| 1165 | name: "baz-test", |
| 1166 | srcs: ["c.java"], |
| 1167 | libs: ["foo"], |
| 1168 | sdk_version: "test_current", |
| 1169 | } |
Paul Duffin | a2db18f | 2020-01-22 17:11:15 +0000 | [diff] [blame] | 1170 | java_library { |
| 1171 | name: "baz-29", |
| 1172 | srcs: ["c.java"], |
| 1173 | libs: ["foo"], |
| 1174 | sdk_version: "system_29", |
| 1175 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1176 | `) |
| 1177 | |
| 1178 | // check the existence of the internal modules |
| 1179 | ctx.ModuleForTests("foo", "android_common") |
Paul Duffin | dd9d074 | 2020-05-08 15:52:37 +0100 | [diff] [blame] | 1180 | ctx.ModuleForTests(apiScopePublic.stubsLibraryModuleName("foo"), "android_common") |
| 1181 | ctx.ModuleForTests(apiScopeSystem.stubsLibraryModuleName("foo"), "android_common") |
| 1182 | ctx.ModuleForTests(apiScopeTest.stubsLibraryModuleName("foo"), "android_common") |
| 1183 | ctx.ModuleForTests(apiScopePublic.stubsSourceModuleName("foo"), "android_common") |
| 1184 | ctx.ModuleForTests(apiScopeSystem.stubsSourceModuleName("foo"), "android_common") |
| 1185 | ctx.ModuleForTests(apiScopeTest.stubsSourceModuleName("foo"), "android_common") |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1186 | ctx.ModuleForTests("foo"+sdkXmlFileSuffix, "android_common") |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 1187 | ctx.ModuleForTests("foo.api.public.28", "") |
| 1188 | ctx.ModuleForTests("foo.api.system.28", "") |
| 1189 | ctx.ModuleForTests("foo.api.test.28", "") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1190 | |
| 1191 | bazJavac := ctx.ModuleForTests("baz", "android_common").Rule("javac") |
| 1192 | // tests if baz is actually linked to the stubs lib |
| 1193 | if !strings.Contains(bazJavac.Args["classpath"], "foo.stubs.system.jar") { |
| 1194 | t.Errorf("baz javac classpath %v does not contain %q", bazJavac.Args["classpath"], |
| 1195 | "foo.stubs.system.jar") |
| 1196 | } |
| 1197 | // ... and not to the impl lib |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1198 | if strings.Contains(bazJavac.Args["classpath"], "foo.jar") { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1199 | t.Errorf("baz javac classpath %v should not contain %q", bazJavac.Args["classpath"], |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1200 | "foo.jar") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1201 | } |
| 1202 | // test if baz is not linked to the system variant of foo |
| 1203 | if strings.Contains(bazJavac.Args["classpath"], "foo.stubs.jar") { |
| 1204 | t.Errorf("baz javac classpath %v should not contain %q", bazJavac.Args["classpath"], |
| 1205 | "foo.stubs.jar") |
| 1206 | } |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1207 | |
Paul Duffin | 726d23c | 2020-01-22 16:30:37 +0000 | [diff] [blame] | 1208 | bazTestJavac := ctx.ModuleForTests("baz-test", "android_common").Rule("javac") |
| 1209 | // tests if baz-test is actually linked to the test stubs lib |
| 1210 | if !strings.Contains(bazTestJavac.Args["classpath"], "foo.stubs.test.jar") { |
| 1211 | t.Errorf("baz-test javac classpath %v does not contain %q", bazTestJavac.Args["classpath"], |
| 1212 | "foo.stubs.test.jar") |
| 1213 | } |
| 1214 | |
Paul Duffin | a2db18f | 2020-01-22 17:11:15 +0000 | [diff] [blame] | 1215 | baz29Javac := ctx.ModuleForTests("baz-29", "android_common").Rule("javac") |
| 1216 | // tests if baz-29 is actually linked to the system 29 stubs lib |
| 1217 | if !strings.Contains(baz29Javac.Args["classpath"], "prebuilts/sdk/29/system/foo.jar") { |
| 1218 | t.Errorf("baz-29 javac classpath %v does not contain %q", baz29Javac.Args["classpath"], |
| 1219 | "prebuilts/sdk/29/system/foo.jar") |
| 1220 | } |
| 1221 | |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1222 | // test if baz has exported SDK lib names foo and bar to qux |
| 1223 | qux := ctx.ModuleForTests("qux", "android_common") |
| 1224 | if quxLib, ok := qux.Module().(*Library); ok { |
| 1225 | sdkLibs := quxLib.ExportedSdkLibs() |
| 1226 | if len(sdkLibs) != 2 || !android.InList("foo", sdkLibs) || !android.InList("bar", sdkLibs) { |
| 1227 | t.Errorf("qux should export \"foo\" and \"bar\" but exports %v", sdkLibs) |
| 1228 | } |
| 1229 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1230 | } |
Zoran Jovanovic | 8736ce2 | 2018-08-21 17:10:29 +0200 | [diff] [blame] | 1231 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1232 | func TestJavaSdkLibrary_InvalidScopes(t *testing.T) { |
| 1233 | testJavaError(t, `module "foo": enabled api scope "system" depends on disabled scope "public"`, ` |
| 1234 | java_sdk_library { |
| 1235 | name: "foo", |
| 1236 | srcs: ["a.java", "b.java"], |
| 1237 | api_packages: ["foo"], |
| 1238 | // Explicitly disable public to test the check that ensures the set of enabled |
| 1239 | // scopes is consistent. |
| 1240 | public: { |
| 1241 | enabled: false, |
| 1242 | }, |
| 1243 | system: { |
| 1244 | enabled: true, |
| 1245 | }, |
| 1246 | } |
| 1247 | `) |
| 1248 | } |
| 1249 | |
Paul Duffin | 87a05a3 | 2020-05-12 11:50:28 +0100 | [diff] [blame^] | 1250 | func TestJavaSdkLibrary_SdkVersion_ForScope(t *testing.T) { |
| 1251 | testJava(t, ` |
| 1252 | java_sdk_library { |
| 1253 | name: "foo", |
| 1254 | srcs: ["a.java", "b.java"], |
| 1255 | api_packages: ["foo"], |
| 1256 | system: { |
| 1257 | enabled: true, |
| 1258 | sdk_version: "module_current", |
| 1259 | }, |
| 1260 | } |
| 1261 | `) |
| 1262 | } |
| 1263 | |
Zoran Jovanovic | 8736ce2 | 2018-08-21 17:10:29 +0200 | [diff] [blame] | 1264 | var compilerFlagsTestCases = []struct { |
| 1265 | in string |
| 1266 | out bool |
| 1267 | }{ |
| 1268 | { |
| 1269 | in: "a", |
| 1270 | out: false, |
| 1271 | }, |
| 1272 | { |
| 1273 | in: "-a", |
| 1274 | out: true, |
| 1275 | }, |
| 1276 | { |
| 1277 | in: "-no-jdk", |
| 1278 | out: false, |
| 1279 | }, |
| 1280 | { |
| 1281 | in: "-no-stdlib", |
| 1282 | out: false, |
| 1283 | }, |
| 1284 | { |
| 1285 | in: "-kotlin-home", |
| 1286 | out: false, |
| 1287 | }, |
| 1288 | { |
| 1289 | in: "-kotlin-home /some/path", |
| 1290 | out: false, |
| 1291 | }, |
| 1292 | { |
| 1293 | in: "-include-runtime", |
| 1294 | out: false, |
| 1295 | }, |
| 1296 | { |
| 1297 | in: "-Xintellij-plugin-root", |
| 1298 | out: false, |
| 1299 | }, |
| 1300 | } |
| 1301 | |
| 1302 | type mockContext struct { |
| 1303 | android.ModuleContext |
| 1304 | result bool |
| 1305 | } |
| 1306 | |
| 1307 | func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) { |
| 1308 | // CheckBadCompilerFlags calls this function when the flag should be rejected |
| 1309 | ctx.result = false |
| 1310 | } |
| 1311 | |
| 1312 | func TestCompilerFlags(t *testing.T) { |
| 1313 | for _, testCase := range compilerFlagsTestCases { |
| 1314 | ctx := &mockContext{result: true} |
| 1315 | CheckKotlincFlags(ctx, []string{testCase.in}) |
| 1316 | if ctx.result != testCase.out { |
| 1317 | t.Errorf("incorrect output:") |
| 1318 | t.Errorf(" input: %#v", testCase.in) |
| 1319 | t.Errorf(" expected: %#v", testCase.out) |
| 1320 | t.Errorf(" got: %#v", ctx.result) |
| 1321 | } |
| 1322 | } |
| 1323 | } |
Jaewoong Jung | 38e4fb2 | 2018-12-12 09:01:34 -0800 | [diff] [blame] | 1324 | |
| 1325 | // TODO(jungjw): Consider making this more robust by ignoring path order. |
| 1326 | func checkPatchModuleFlag(t *testing.T, ctx *android.TestContext, moduleName string, expected string) { |
| 1327 | variables := ctx.ModuleForTests(moduleName, "android_common").Module().VariablesForTests() |
| 1328 | flags := strings.Split(variables["javacFlags"], " ") |
| 1329 | got := "" |
| 1330 | for _, flag := range flags { |
| 1331 | keyEnd := strings.Index(flag, "=") |
| 1332 | if keyEnd > -1 && flag[:keyEnd] == "--patch-module" { |
| 1333 | got = flag[keyEnd+1:] |
| 1334 | break |
| 1335 | } |
| 1336 | } |
| 1337 | if expected != got { |
| 1338 | t.Errorf("Unexpected patch-module flag for module %q - expected %q, but got %q", moduleName, expected, got) |
| 1339 | } |
| 1340 | } |
| 1341 | |
| 1342 | func TestPatchModule(t *testing.T) { |
Pete Gillin | 0c2143e | 2019-05-02 15:32:11 +0100 | [diff] [blame] | 1343 | t.Run("Java language level 8", func(t *testing.T) { |
Pete Gillin | 1b3370f | 2019-10-01 13:57:31 +0100 | [diff] [blame] | 1344 | // Test with legacy javac -source 1.8 -target 1.8 |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 1345 | bp := ` |
| 1346 | java_library { |
| 1347 | name: "foo", |
| 1348 | srcs: ["a.java"], |
| 1349 | java_version: "1.8", |
| 1350 | } |
| 1351 | |
| 1352 | java_library { |
| 1353 | name: "bar", |
| 1354 | srcs: ["b.java"], |
| 1355 | sdk_version: "none", |
| 1356 | system_modules: "none", |
| 1357 | patch_module: "java.base", |
| 1358 | java_version: "1.8", |
| 1359 | } |
| 1360 | |
| 1361 | java_library { |
| 1362 | name: "baz", |
| 1363 | srcs: ["c.java"], |
| 1364 | patch_module: "java.base", |
| 1365 | java_version: "1.8", |
| 1366 | } |
| 1367 | ` |
| 1368 | ctx, _ := testJava(t, bp) |
Jaewoong Jung | 38e4fb2 | 2018-12-12 09:01:34 -0800 | [diff] [blame] | 1369 | |
| 1370 | checkPatchModuleFlag(t, ctx, "foo", "") |
| 1371 | checkPatchModuleFlag(t, ctx, "bar", "") |
| 1372 | checkPatchModuleFlag(t, ctx, "baz", "") |
| 1373 | }) |
| 1374 | |
Pete Gillin | 0c2143e | 2019-05-02 15:32:11 +0100 | [diff] [blame] | 1375 | t.Run("Java language level 9", func(t *testing.T) { |
Pete Gillin | 1b3370f | 2019-10-01 13:57:31 +0100 | [diff] [blame] | 1376 | // Test with default javac -source 9 -target 9 |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 1377 | bp := ` |
| 1378 | java_library { |
| 1379 | name: "foo", |
| 1380 | srcs: ["a.java"], |
| 1381 | } |
| 1382 | |
| 1383 | java_library { |
| 1384 | name: "bar", |
| 1385 | srcs: ["b.java"], |
| 1386 | sdk_version: "none", |
| 1387 | system_modules: "none", |
| 1388 | patch_module: "java.base", |
| 1389 | } |
| 1390 | |
| 1391 | java_library { |
| 1392 | name: "baz", |
| 1393 | srcs: ["c.java"], |
| 1394 | patch_module: "java.base", |
| 1395 | } |
| 1396 | ` |
Pete Gillin | 1b3370f | 2019-10-01 13:57:31 +0100 | [diff] [blame] | 1397 | ctx, _ := testJava(t, bp) |
Jaewoong Jung | 38e4fb2 | 2018-12-12 09:01:34 -0800 | [diff] [blame] | 1398 | |
| 1399 | checkPatchModuleFlag(t, ctx, "foo", "") |
| 1400 | expected := "java.base=.:" + buildDir |
| 1401 | checkPatchModuleFlag(t, ctx, "bar", expected) |
Jiyong Park | 231d056 | 2019-12-18 17:28:17 +0900 | [diff] [blame] | 1402 | expected = "java.base=" + strings.Join([]string{".", buildDir, moduleToPath("ext"), moduleToPath("framework")}, ":") |
Jaewoong Jung | 38e4fb2 | 2018-12-12 09:01:34 -0800 | [diff] [blame] | 1403 | checkPatchModuleFlag(t, ctx, "baz", expected) |
| 1404 | }) |
| 1405 | } |
Paul Duffin | a7b9f42 | 2020-01-10 17:12:18 +0000 | [diff] [blame] | 1406 | |
| 1407 | func TestJavaSystemModules(t *testing.T) { |
| 1408 | ctx, _ := testJava(t, ` |
| 1409 | java_system_modules { |
| 1410 | name: "system-modules", |
| 1411 | libs: ["system-module1", "system-module2"], |
| 1412 | } |
| 1413 | java_library { |
| 1414 | name: "system-module1", |
| 1415 | srcs: ["a.java"], |
| 1416 | sdk_version: "none", |
| 1417 | system_modules: "none", |
| 1418 | } |
| 1419 | java_library { |
| 1420 | name: "system-module2", |
| 1421 | srcs: ["b.java"], |
| 1422 | sdk_version: "none", |
| 1423 | system_modules: "none", |
| 1424 | } |
| 1425 | `) |
| 1426 | |
| 1427 | // check the existence of the module |
| 1428 | systemModules := ctx.ModuleForTests("system-modules", "android_common") |
| 1429 | |
| 1430 | cmd := systemModules.Rule("jarsTosystemModules") |
| 1431 | |
| 1432 | // make sure the command compiles against the supplied modules. |
| 1433 | for _, module := range []string{"system-module1.jar", "system-module2.jar"} { |
| 1434 | if !strings.Contains(cmd.Args["classpath"], module) { |
| 1435 | t.Errorf("system modules classpath %v does not contain %q", cmd.Args["classpath"], |
| 1436 | module) |
| 1437 | } |
| 1438 | } |
| 1439 | } |
Paul Duffin | 90169ba | 2020-01-10 17:16:44 +0000 | [diff] [blame] | 1440 | |
| 1441 | func TestJavaSystemModulesImport(t *testing.T) { |
| 1442 | ctx, _ := testJava(t, ` |
| 1443 | java_system_modules_import { |
| 1444 | name: "system-modules", |
| 1445 | libs: ["system-module1", "system-module2"], |
| 1446 | } |
| 1447 | java_import { |
| 1448 | name: "system-module1", |
| 1449 | jars: ["a.jar"], |
| 1450 | } |
| 1451 | java_import { |
| 1452 | name: "system-module2", |
| 1453 | jars: ["b.jar"], |
| 1454 | } |
| 1455 | `) |
| 1456 | |
| 1457 | // check the existence of the module |
| 1458 | systemModules := ctx.ModuleForTests("system-modules", "android_common") |
| 1459 | |
| 1460 | cmd := systemModules.Rule("jarsTosystemModules") |
| 1461 | |
| 1462 | // make sure the command compiles against the supplied modules. |
| 1463 | for _, module := range []string{"system-module1.jar", "system-module2.jar"} { |
| 1464 | if !strings.Contains(cmd.Args["classpath"], module) { |
| 1465 | t.Errorf("system modules classpath %v does not contain %q", cmd.Args["classpath"], |
| 1466 | module) |
| 1467 | } |
| 1468 | } |
| 1469 | } |
Paul Duffin | 83a2d96 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 1470 | |
| 1471 | func TestJavaLibraryWithSystemModules(t *testing.T) { |
| 1472 | ctx, _ := testJava(t, ` |
| 1473 | java_library { |
| 1474 | name: "lib-with-source-system-modules", |
| 1475 | srcs: [ |
| 1476 | "a.java", |
| 1477 | ], |
| 1478 | sdk_version: "none", |
| 1479 | system_modules: "source-system-modules", |
| 1480 | } |
| 1481 | |
| 1482 | java_library { |
| 1483 | name: "source-jar", |
| 1484 | srcs: [ |
| 1485 | "a.java", |
| 1486 | ], |
| 1487 | } |
| 1488 | |
| 1489 | java_system_modules { |
| 1490 | name: "source-system-modules", |
| 1491 | libs: ["source-jar"], |
| 1492 | } |
| 1493 | |
| 1494 | java_library { |
| 1495 | name: "lib-with-prebuilt-system-modules", |
| 1496 | srcs: [ |
| 1497 | "a.java", |
| 1498 | ], |
| 1499 | sdk_version: "none", |
| 1500 | system_modules: "prebuilt-system-modules", |
| 1501 | } |
| 1502 | |
| 1503 | java_import { |
| 1504 | name: "prebuilt-jar", |
| 1505 | jars: ["a.jar"], |
| 1506 | } |
| 1507 | |
| 1508 | java_system_modules_import { |
| 1509 | name: "prebuilt-system-modules", |
| 1510 | libs: ["prebuilt-jar"], |
| 1511 | } |
| 1512 | `) |
| 1513 | |
| 1514 | checkBootClasspathForSystemModule(t, ctx, "lib-with-source-system-modules", "/source-jar.jar") |
| 1515 | |
| 1516 | checkBootClasspathForSystemModule(t, ctx, "lib-with-prebuilt-system-modules", "/prebuilt-jar.jar") |
| 1517 | } |
| 1518 | |
| 1519 | func checkBootClasspathForSystemModule(t *testing.T, ctx *android.TestContext, moduleName string, expectedSuffix string) { |
| 1520 | javacRule := ctx.ModuleForTests(moduleName, "android_common").Rule("javac") |
| 1521 | bootClasspath := javacRule.Args["bootClasspath"] |
| 1522 | if strings.HasPrefix(bootClasspath, "--system ") && strings.HasSuffix(bootClasspath, expectedSuffix) { |
| 1523 | t.Errorf("bootclasspath of %q must start with --system and end with %q, but was %#v.", moduleName, expectedSuffix, bootClasspath) |
| 1524 | } |
| 1525 | } |
Jiyong Park | 19604de | 2020-03-24 16:44:11 +0900 | [diff] [blame] | 1526 | |
| 1527 | func TestAidlExportIncludeDirsFromImports(t *testing.T) { |
| 1528 | ctx, _ := testJava(t, ` |
| 1529 | java_library { |
| 1530 | name: "foo", |
| 1531 | srcs: ["aidl/foo/IFoo.aidl"], |
| 1532 | libs: ["bar"], |
| 1533 | } |
| 1534 | |
| 1535 | java_import { |
| 1536 | name: "bar", |
| 1537 | jars: ["a.jar"], |
| 1538 | aidl: { |
| 1539 | export_include_dirs: ["aidl/bar"], |
| 1540 | }, |
| 1541 | } |
| 1542 | `) |
| 1543 | |
| 1544 | aidlCommand := ctx.ModuleForTests("foo", "android_common").Rule("aidl").RuleParams.Command |
| 1545 | expectedAidlFlag := "-Iaidl/bar" |
| 1546 | if !strings.Contains(aidlCommand, expectedAidlFlag) { |
| 1547 | t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) |
| 1548 | } |
| 1549 | } |