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