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`, |
| 721 | // This should be sdklib.stubs but is switched to the prebuilt because it is preferred. |
| 722 | `prebuilt_sdklib.stubs`, |
| 723 | `sdklib.impl`, |
| 724 | `sdklib.stubs.source`, |
| 725 | `sdklib.xml`, |
| 726 | }) |
| 727 | |
| 728 | checkModuleDependencies(t, ctx, "prebuilt_sdklib", "android_common", []string{ |
| 729 | `prebuilt_sdklib.stubs`, |
| 730 | `sdklib.impl`, |
| 731 | `sdklib.xml`, |
| 732 | }) |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 733 | } |
| 734 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 735 | func TestDefaults(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 736 | ctx, _ := testJava(t, ` |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 737 | java_defaults { |
| 738 | name: "defaults", |
| 739 | srcs: ["a.java"], |
| 740 | libs: ["bar"], |
| 741 | static_libs: ["baz"], |
Sasha Smundak | 2057f82 | 2019-04-16 17:16:58 -0700 | [diff] [blame] | 742 | optimize: {enabled: false}, |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | java_library { |
| 746 | name: "foo", |
| 747 | defaults: ["defaults"], |
| 748 | } |
| 749 | |
| 750 | java_library { |
| 751 | name: "bar", |
| 752 | srcs: ["b.java"], |
| 753 | } |
| 754 | |
| 755 | java_library { |
| 756 | name: "baz", |
| 757 | srcs: ["c.java"], |
| 758 | } |
Sasha Smundak | 2057f82 | 2019-04-16 17:16:58 -0700 | [diff] [blame] | 759 | |
| 760 | android_test { |
| 761 | name: "atestOptimize", |
| 762 | defaults: ["defaults"], |
| 763 | optimize: {enabled: true}, |
| 764 | } |
| 765 | |
| 766 | android_test { |
| 767 | name: "atestNoOptimize", |
| 768 | defaults: ["defaults"], |
| 769 | } |
| 770 | |
| 771 | android_test { |
| 772 | name: "atestDefault", |
| 773 | srcs: ["a.java"], |
| 774 | } |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 775 | `) |
| 776 | |
Colin Cross | 4c428df | 2017-09-15 17:36:05 -0700 | [diff] [blame] | 777 | javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 778 | combineJar := ctx.ModuleForTests("foo", "android_common").Description("for javac") |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 779 | |
| 780 | if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "a.java" { |
| 781 | t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs) |
| 782 | } |
| 783 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 784 | barTurbine := filepath.Join(buildDir, ".intermediates", "bar", "android_common", "turbine-combined", "bar.jar") |
| 785 | if !strings.Contains(javac.Args["classpath"], barTurbine) { |
| 786 | 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] | 787 | } |
| 788 | |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 789 | baz := ctx.ModuleForTests("baz", "android_common").Rule("javac").Output.String() |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 790 | if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != baz { |
| 791 | 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] | 792 | } |
Sasha Smundak | 2057f82 | 2019-04-16 17:16:58 -0700 | [diff] [blame] | 793 | |
| 794 | atestOptimize := ctx.ModuleForTests("atestOptimize", "android_common").MaybeRule("r8") |
| 795 | if atestOptimize.Output == nil { |
| 796 | t.Errorf("atestOptimize should optimize APK") |
| 797 | } |
| 798 | |
| 799 | atestNoOptimize := ctx.ModuleForTests("atestNoOptimize", "android_common").MaybeRule("d8") |
| 800 | if atestNoOptimize.Output == nil { |
| 801 | t.Errorf("atestNoOptimize should not optimize APK") |
| 802 | } |
| 803 | |
| 804 | atestDefault := ctx.ModuleForTests("atestDefault", "android_common").MaybeRule("r8") |
| 805 | if atestDefault.Output == nil { |
| 806 | t.Errorf("atestDefault should optimize APK") |
| 807 | } |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 808 | } |
| 809 | |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 810 | func TestResources(t *testing.T) { |
| 811 | var table = []struct { |
| 812 | name string |
| 813 | prop string |
| 814 | extra string |
| 815 | args string |
| 816 | }{ |
| 817 | { |
Colin Cross | af9c55b | 2017-10-03 14:50:08 -0700 | [diff] [blame] | 818 | // Test that a module with java_resource_dirs includes the files |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 819 | name: "resource dirs", |
Colin Cross | 824bee3 | 2017-11-22 17:27:51 -0800 | [diff] [blame] | 820 | prop: `java_resource_dirs: ["java-res"]`, |
Colin Cross | 0ead1d7 | 2018-04-10 13:07:42 -0700 | [diff] [blame] | 821 | 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] | 822 | }, |
| 823 | { |
| 824 | // Test that a module with java_resources includes the files |
| 825 | name: "resource files", |
Colin Cross | 0ead1d7 | 2018-04-10 13:07:42 -0700 | [diff] [blame] | 826 | prop: `java_resources: ["java-res/a/a", "java-res/b/b"]`, |
| 827 | args: "-C . -f java-res/a/a -f java-res/b/b", |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 828 | }, |
| 829 | { |
| 830 | // Test that a module with a filegroup in java_resources includes the files with the |
| 831 | // path prefix |
| 832 | name: "resource filegroup", |
| 833 | prop: `java_resources: [":foo-res"]`, |
| 834 | extra: ` |
| 835 | filegroup { |
| 836 | name: "foo-res", |
Colin Cross | 824bee3 | 2017-11-22 17:27:51 -0800 | [diff] [blame] | 837 | path: "java-res", |
Colin Cross | 0ead1d7 | 2018-04-10 13:07:42 -0700 | [diff] [blame] | 838 | srcs: ["java-res/a/a", "java-res/b/b"], |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 839 | }`, |
Colin Cross | 0ead1d7 | 2018-04-10 13:07:42 -0700 | [diff] [blame] | 840 | 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] | 841 | }, |
| 842 | { |
Colin Cross | 0ead1d7 | 2018-04-10 13:07:42 -0700 | [diff] [blame] | 843 | // Test that a module with wildcards in java_resource_dirs has the correct path prefixes |
| 844 | name: "wildcard dirs", |
| 845 | prop: `java_resource_dirs: ["java-res/*"]`, |
| 846 | args: "-C java-res/a -f java-res/a/a -C java-res/b -f java-res/b/b", |
| 847 | }, |
| 848 | { |
| 849 | // Test that a module exclude_java_resource_dirs excludes the files |
| 850 | name: "wildcard dirs", |
| 851 | prop: `java_resource_dirs: ["java-res/*"], exclude_java_resource_dirs: ["java-res/b"]`, |
| 852 | args: "-C java-res/a -f java-res/a/a", |
| 853 | }, |
Colin Cross | cedd476 | 2018-09-13 11:26:19 -0700 | [diff] [blame] | 854 | { |
| 855 | // Test wildcards in java_resources |
| 856 | name: "wildcard files", |
| 857 | prop: `java_resources: ["java-res/**/*"]`, |
| 858 | args: "-C . -f java-res/a/a -f java-res/b/b", |
| 859 | }, |
| 860 | { |
| 861 | // Test exclude_java_resources with java_resources |
| 862 | name: "wildcard files with exclude", |
| 863 | prop: `java_resources: ["java-res/**/*"], exclude_java_resources: ["java-res/b/*"]`, |
| 864 | args: "-C . -f java-res/a/a", |
| 865 | }, |
| 866 | { |
| 867 | // Test exclude_java_resources with java_resource_dirs |
| 868 | name: "resource dirs with exclude files", |
| 869 | prop: `java_resource_dirs: ["java-res"], exclude_java_resources: ["java-res/b/b"]`, |
| 870 | args: "-C java-res -f java-res/a/a", |
| 871 | }, |
| 872 | { |
| 873 | // Test exclude_java_resource_dirs with java_resource_dirs |
| 874 | name: "resource dirs with exclude files", |
| 875 | prop: `java_resource_dirs: ["java-res", "java-res2"], exclude_java_resource_dirs: ["java-res2"]`, |
| 876 | args: "-C java-res -f java-res/a/a -f java-res/b/b", |
| 877 | }, |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | for _, test := range table { |
| 881 | t.Run(test.name, func(t *testing.T) { |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 882 | ctx, _ := testJavaWithFS(t, ` |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 883 | java_library { |
| 884 | name: "foo", |
| 885 | srcs: [ |
| 886 | "a.java", |
| 887 | "b.java", |
| 888 | "c.java", |
| 889 | ], |
| 890 | `+test.prop+`, |
| 891 | } |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 892 | `+test.extra, |
| 893 | map[string][]byte{ |
| 894 | "java-res/a/a": nil, |
| 895 | "java-res/b/b": nil, |
| 896 | "java-res2/a": nil, |
| 897 | }, |
| 898 | ) |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 899 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 900 | foo := ctx.ModuleForTests("foo", "android_common").Output("withres/foo.jar") |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 901 | fooRes := ctx.ModuleForTests("foo", "android_common").Output("res/foo.jar") |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 902 | |
| 903 | if !inList(fooRes.Output.String(), foo.Inputs.Strings()) { |
| 904 | t.Errorf("foo combined jars %v does not contain %q", |
| 905 | foo.Inputs.Strings(), fooRes.Output.String()) |
| 906 | } |
| 907 | |
Colin Cross | af9c55b | 2017-10-03 14:50:08 -0700 | [diff] [blame] | 908 | if fooRes.Args["jarArgs"] != test.args { |
| 909 | t.Errorf("foo resource jar args %q is not %q", |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 910 | fooRes.Args["jarArgs"], test.args) |
| 911 | } |
| 912 | }) |
| 913 | } |
| 914 | } |
| 915 | |
Colin Cross | 0c4ce21 | 2019-05-03 15:28:19 -0700 | [diff] [blame] | 916 | func TestIncludeSrcs(t *testing.T) { |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 917 | ctx, _ := testJavaWithFS(t, ` |
Colin Cross | 0c4ce21 | 2019-05-03 15:28:19 -0700 | [diff] [blame] | 918 | java_library { |
| 919 | name: "foo", |
| 920 | srcs: [ |
| 921 | "a.java", |
| 922 | "b.java", |
| 923 | "c.java", |
| 924 | ], |
| 925 | include_srcs: true, |
| 926 | } |
| 927 | |
| 928 | java_library { |
| 929 | name: "bar", |
| 930 | srcs: [ |
| 931 | "a.java", |
| 932 | "b.java", |
| 933 | "c.java", |
| 934 | ], |
| 935 | java_resource_dirs: ["java-res"], |
| 936 | include_srcs: true, |
| 937 | } |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 938 | `, map[string][]byte{ |
| 939 | "java-res/a/a": nil, |
| 940 | "java-res/b/b": nil, |
| 941 | "java-res2/a": nil, |
| 942 | }) |
Colin Cross | 0c4ce21 | 2019-05-03 15:28:19 -0700 | [diff] [blame] | 943 | |
| 944 | // Test a library with include_srcs: true |
| 945 | foo := ctx.ModuleForTests("foo", "android_common").Output("withres/foo.jar") |
| 946 | fooSrcJar := ctx.ModuleForTests("foo", "android_common").Output("foo.srcjar") |
| 947 | |
| 948 | if g, w := fooSrcJar.Output.String(), foo.Inputs.Strings(); !inList(g, w) { |
| 949 | t.Errorf("foo combined jars %v does not contain %q", w, g) |
| 950 | } |
| 951 | |
| 952 | if g, w := fooSrcJar.Args["jarArgs"], "-C . -f a.java -f b.java -f c.java"; g != w { |
| 953 | t.Errorf("foo source jar args %q is not %q", w, g) |
| 954 | } |
| 955 | |
| 956 | // Test a library with include_srcs: true and resources |
| 957 | bar := ctx.ModuleForTests("bar", "android_common").Output("withres/bar.jar") |
| 958 | barResCombined := ctx.ModuleForTests("bar", "android_common").Output("res-combined/bar.jar") |
| 959 | barRes := ctx.ModuleForTests("bar", "android_common").Output("res/bar.jar") |
| 960 | barSrcJar := ctx.ModuleForTests("bar", "android_common").Output("bar.srcjar") |
| 961 | |
| 962 | if g, w := barSrcJar.Output.String(), barResCombined.Inputs.Strings(); !inList(g, w) { |
| 963 | t.Errorf("bar combined resource jars %v does not contain %q", w, g) |
| 964 | } |
| 965 | |
| 966 | if g, w := barRes.Output.String(), barResCombined.Inputs.Strings(); !inList(g, w) { |
| 967 | t.Errorf("bar combined resource jars %v does not contain %q", w, g) |
| 968 | } |
| 969 | |
| 970 | if g, w := barResCombined.Output.String(), bar.Inputs.Strings(); !inList(g, w) { |
| 971 | t.Errorf("bar combined jars %v does not contain %q", w, g) |
| 972 | } |
| 973 | |
| 974 | if g, w := barSrcJar.Args["jarArgs"], "-C . -f a.java -f b.java -f c.java"; g != w { |
| 975 | t.Errorf("bar source jar args %q is not %q", w, g) |
| 976 | } |
| 977 | |
| 978 | if g, w := barRes.Args["jarArgs"], "-C java-res -f java-res/a/a -f java-res/b/b"; g != w { |
| 979 | t.Errorf("bar resource jar args %q is not %q", w, g) |
| 980 | } |
| 981 | } |
| 982 | |
Colin Cross | 54190b3 | 2017-10-09 15:34:10 -0700 | [diff] [blame] | 983 | func TestGeneratedSources(t *testing.T) { |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 984 | ctx, _ := testJavaWithFS(t, ` |
Colin Cross | 54190b3 | 2017-10-09 15:34:10 -0700 | [diff] [blame] | 985 | java_library { |
| 986 | name: "foo", |
| 987 | srcs: [ |
| 988 | "a*.java", |
| 989 | ":gen", |
| 990 | "b*.java", |
| 991 | ], |
| 992 | } |
| 993 | |
| 994 | genrule { |
| 995 | name: "gen", |
Colin Cross | 824bee3 | 2017-11-22 17:27:51 -0800 | [diff] [blame] | 996 | tool_files: ["java-res/a"], |
Colin Cross | 54190b3 | 2017-10-09 15:34:10 -0700 | [diff] [blame] | 997 | out: ["gen.java"], |
| 998 | } |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 999 | `, map[string][]byte{ |
| 1000 | "a.java": nil, |
| 1001 | "b.java": nil, |
| 1002 | }) |
Colin Cross | 54190b3 | 2017-10-09 15:34:10 -0700 | [diff] [blame] | 1003 | |
| 1004 | javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") |
| 1005 | genrule := ctx.ModuleForTests("gen", "").Rule("generator") |
| 1006 | |
Colin Cross | 15e86d9 | 2017-10-20 15:07:08 -0700 | [diff] [blame] | 1007 | if filepath.Base(genrule.Output.String()) != "gen.java" { |
| 1008 | 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] | 1009 | } |
| 1010 | |
| 1011 | if len(javac.Inputs) != 3 || |
| 1012 | javac.Inputs[0].String() != "a.java" || |
Colin Cross | 15e86d9 | 2017-10-20 15:07:08 -0700 | [diff] [blame] | 1013 | javac.Inputs[1].String() != genrule.Output.String() || |
Colin Cross | 54190b3 | 2017-10-09 15:34:10 -0700 | [diff] [blame] | 1014 | javac.Inputs[2].String() != "b.java" { |
| 1015 | t.Errorf(`foo inputs %v != ["a.java", ".../gen.java", "b.java"]`, javac.Inputs) |
| 1016 | } |
| 1017 | } |
| 1018 | |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1019 | func TestTurbine(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1020 | ctx, _ := testJava(t, ` |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1021 | java_library { |
| 1022 | name: "foo", |
| 1023 | srcs: ["a.java"], |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 1024 | sdk_version: "14", |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | java_library { |
| 1028 | name: "bar", |
Colin Cross | 9bc4343 | 2017-12-15 20:20:39 -0800 | [diff] [blame] | 1029 | srcs: ["b.java"], |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1030 | static_libs: ["foo"], |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 1031 | sdk_version: "14", |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | java_library { |
| 1035 | name: "baz", |
| 1036 | srcs: ["c.java"], |
| 1037 | libs: ["bar"], |
| 1038 | sdk_version: "14", |
| 1039 | } |
| 1040 | `) |
| 1041 | |
| 1042 | fooTurbine := ctx.ModuleForTests("foo", "android_common").Rule("turbine") |
| 1043 | barTurbine := ctx.ModuleForTests("bar", "android_common").Rule("turbine") |
| 1044 | barJavac := ctx.ModuleForTests("bar", "android_common").Rule("javac") |
| 1045 | barTurbineCombined := ctx.ModuleForTests("bar", "android_common").Description("for turbine") |
| 1046 | bazJavac := ctx.ModuleForTests("baz", "android_common").Rule("javac") |
| 1047 | |
| 1048 | if len(fooTurbine.Inputs) != 1 || fooTurbine.Inputs[0].String() != "a.java" { |
| 1049 | t.Errorf(`foo inputs %v != ["a.java"]`, fooTurbine.Inputs) |
| 1050 | } |
| 1051 | |
| 1052 | fooHeaderJar := filepath.Join(buildDir, ".intermediates", "foo", "android_common", "turbine-combined", "foo.jar") |
| 1053 | if !strings.Contains(barTurbine.Args["classpath"], fooHeaderJar) { |
| 1054 | t.Errorf("bar turbine classpath %v does not contain %q", barTurbine.Args["classpath"], fooHeaderJar) |
| 1055 | } |
| 1056 | if !strings.Contains(barJavac.Args["classpath"], fooHeaderJar) { |
| 1057 | t.Errorf("bar javac classpath %v does not contain %q", barJavac.Args["classpath"], fooHeaderJar) |
| 1058 | } |
| 1059 | if len(barTurbineCombined.Inputs) != 2 || barTurbineCombined.Inputs[1].String() != fooHeaderJar { |
| 1060 | t.Errorf("bar turbine combineJar inputs %v does not contain %q", barTurbineCombined.Inputs, fooHeaderJar) |
| 1061 | } |
Anton Hansson | f66efeb | 2018-04-11 13:57:30 +0100 | [diff] [blame] | 1062 | if !strings.Contains(bazJavac.Args["classpath"], "prebuilts/sdk/14/public/android.jar") { |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1063 | 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] | 1064 | "prebuilts/sdk/14/public/android.jar") |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | func TestSharding(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1069 | ctx, _ := testJava(t, ` |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1070 | java_library { |
| 1071 | name: "bar", |
| 1072 | srcs: ["a.java","b.java","c.java"], |
| 1073 | javac_shard_size: 1 |
| 1074 | } |
| 1075 | `) |
| 1076 | |
| 1077 | barHeaderJar := filepath.Join(buildDir, ".intermediates", "bar", "android_common", "turbine-combined", "bar.jar") |
| 1078 | for i := 0; i < 3; i++ { |
| 1079 | barJavac := ctx.ModuleForTests("bar", "android_common").Description("javac" + strconv.Itoa(i)) |
| 1080 | if !strings.Contains(barJavac.Args["classpath"], barHeaderJar) { |
| 1081 | t.Errorf("bar javac classpath %v does not contain %q", barJavac.Args["classpath"], barHeaderJar) |
| 1082 | } |
| 1083 | } |
| 1084 | } |
| 1085 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1086 | func TestDroiddoc(t *testing.T) { |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 1087 | ctx, _ := testJavaWithFS(t, ` |
Paul Duffin | 884363e | 2019-12-19 10:21:09 +0000 | [diff] [blame] | 1088 | droiddoc_exported_dir { |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1089 | name: "droiddoc-templates-sdk", |
| 1090 | path: ".", |
| 1091 | } |
Jiyong Park | 2907459 | 2019-07-07 16:27:47 +0900 | [diff] [blame] | 1092 | filegroup { |
| 1093 | name: "bar-doc-aidl-srcs", |
| 1094 | srcs: ["bar-doc/IBar.aidl"], |
| 1095 | path: "bar-doc", |
| 1096 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1097 | droiddoc { |
| 1098 | name: "bar-doc", |
| 1099 | srcs: [ |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 1100 | "bar-doc/a.java", |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 1101 | "bar-doc/IFoo.aidl", |
Jiyong Park | 2907459 | 2019-07-07 16:27:47 +0900 | [diff] [blame] | 1102 | ":bar-doc-aidl-srcs", |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1103 | ], |
| 1104 | exclude_srcs: [ |
| 1105 | "bar-doc/b.java" |
| 1106 | ], |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1107 | custom_template: "droiddoc-templates-sdk", |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1108 | hdf: [ |
| 1109 | "android.whichdoc offline", |
| 1110 | ], |
| 1111 | knowntags: [ |
| 1112 | "bar-doc/known_oj_tags.txt", |
| 1113 | ], |
| 1114 | proofread_file: "libcore-proofread.txt", |
| 1115 | todo_file: "libcore-docs-todo.html", |
| 1116 | args: "-offlinemode -title \"libcore\"", |
| 1117 | } |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 1118 | `, |
| 1119 | map[string][]byte{ |
| 1120 | "bar-doc/a.java": nil, |
| 1121 | "bar-doc/b.java": nil, |
| 1122 | }) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1123 | |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 1124 | barDoc := ctx.ModuleForTests("bar-doc", "android_common").Rule("javadoc") |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 1125 | var javaSrcs []string |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 1126 | for _, i := range barDoc.Inputs { |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 1127 | javaSrcs = append(javaSrcs, i.Base()) |
| 1128 | } |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 1129 | if len(javaSrcs) != 1 || javaSrcs[0] != "a.java" { |
| 1130 | 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] | 1131 | } |
| 1132 | |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 1133 | aidl := ctx.ModuleForTests("bar-doc", "android_common").Rule("aidl") |
| 1134 | if g, w := barDoc.Implicits.Strings(), aidl.Output.String(); !inList(w, g) { |
| 1135 | t.Errorf("implicits of bar-doc must contain %q, but was %q.", w, g) |
| 1136 | } |
| 1137 | |
| 1138 | if g, w := aidl.Implicits.Strings(), []string{"bar-doc/IBar.aidl", "bar-doc/IFoo.aidl"}; !reflect.DeepEqual(w, g) { |
| 1139 | t.Errorf("aidl inputs must be %q, but was %q", w, g) |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 1140 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1141 | } |
| 1142 | |
Paul Duffin | 83a2d96 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 1143 | func TestDroidstubsWithSystemModules(t *testing.T) { |
| 1144 | ctx, _ := testJava(t, ` |
| 1145 | droidstubs { |
| 1146 | name: "stubs-source-system-modules", |
| 1147 | srcs: [ |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 1148 | "bar-doc/a.java", |
Paul Duffin | 83a2d96 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 1149 | ], |
| 1150 | sdk_version: "none", |
| 1151 | system_modules: "source-system-modules", |
| 1152 | } |
| 1153 | |
| 1154 | java_library { |
| 1155 | name: "source-jar", |
| 1156 | srcs: [ |
| 1157 | "a.java", |
| 1158 | ], |
| 1159 | } |
| 1160 | |
| 1161 | java_system_modules { |
| 1162 | name: "source-system-modules", |
| 1163 | libs: ["source-jar"], |
| 1164 | } |
| 1165 | |
| 1166 | droidstubs { |
| 1167 | name: "stubs-prebuilt-system-modules", |
| 1168 | srcs: [ |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 1169 | "bar-doc/a.java", |
Paul Duffin | 83a2d96 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 1170 | ], |
| 1171 | sdk_version: "none", |
| 1172 | system_modules: "prebuilt-system-modules", |
| 1173 | } |
| 1174 | |
| 1175 | java_import { |
| 1176 | name: "prebuilt-jar", |
| 1177 | jars: ["a.jar"], |
| 1178 | } |
| 1179 | |
| 1180 | java_system_modules_import { |
| 1181 | name: "prebuilt-system-modules", |
| 1182 | libs: ["prebuilt-jar"], |
| 1183 | } |
| 1184 | `) |
| 1185 | |
| 1186 | checkSystemModulesUseByDroidstubs(t, ctx, "stubs-source-system-modules", "source-jar.jar") |
| 1187 | |
| 1188 | checkSystemModulesUseByDroidstubs(t, ctx, "stubs-prebuilt-system-modules", "prebuilt-jar.jar") |
| 1189 | } |
| 1190 | |
| 1191 | func checkSystemModulesUseByDroidstubs(t *testing.T, ctx *android.TestContext, moduleName string, systemJar string) { |
| 1192 | metalavaRule := ctx.ModuleForTests(moduleName, "android_common").Rule("metalava") |
| 1193 | var systemJars []string |
| 1194 | for _, i := range metalavaRule.Implicits { |
| 1195 | systemJars = append(systemJars, i.Base()) |
| 1196 | } |
Ramy Medhat | c7965cd | 2020-04-30 03:08:37 -0400 | [diff] [blame] | 1197 | if len(systemJars) < 1 || systemJars[0] != systemJar { |
Paul Duffin | 83a2d96 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 1198 | t.Errorf("inputs of %q must be []string{%q}, but was %#v.", moduleName, systemJar, systemJars) |
| 1199 | } |
| 1200 | } |
| 1201 | |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 1202 | func TestJarGenrules(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1203 | ctx, _ := testJava(t, ` |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 1204 | java_library { |
| 1205 | name: "foo", |
| 1206 | srcs: ["a.java"], |
| 1207 | } |
| 1208 | |
| 1209 | java_genrule { |
| 1210 | name: "jargen", |
| 1211 | tool_files: ["b.java"], |
| 1212 | cmd: "$(location b.java) $(in) $(out)", |
| 1213 | out: ["jargen.jar"], |
| 1214 | srcs: [":foo"], |
| 1215 | } |
| 1216 | |
| 1217 | java_library { |
| 1218 | name: "bar", |
| 1219 | static_libs: ["jargen"], |
| 1220 | srcs: ["c.java"], |
| 1221 | } |
| 1222 | |
| 1223 | java_library { |
| 1224 | name: "baz", |
| 1225 | libs: ["jargen"], |
| 1226 | srcs: ["c.java"], |
| 1227 | } |
| 1228 | `) |
| 1229 | |
| 1230 | foo := ctx.ModuleForTests("foo", "android_common").Output("javac/foo.jar") |
| 1231 | jargen := ctx.ModuleForTests("jargen", "android_common").Output("jargen.jar") |
| 1232 | bar := ctx.ModuleForTests("bar", "android_common").Output("javac/bar.jar") |
| 1233 | baz := ctx.ModuleForTests("baz", "android_common").Output("javac/baz.jar") |
| 1234 | barCombined := ctx.ModuleForTests("bar", "android_common").Output("combined/bar.jar") |
| 1235 | |
| 1236 | if len(jargen.Inputs) != 1 || jargen.Inputs[0].String() != foo.Output.String() { |
| 1237 | t.Errorf("expected jargen inputs [%q], got %q", foo.Output.String(), jargen.Inputs.Strings()) |
| 1238 | } |
| 1239 | |
| 1240 | if !strings.Contains(bar.Args["classpath"], jargen.Output.String()) { |
| 1241 | t.Errorf("bar classpath %v does not contain %q", bar.Args["classpath"], jargen.Output.String()) |
| 1242 | } |
| 1243 | |
| 1244 | if !strings.Contains(baz.Args["classpath"], jargen.Output.String()) { |
| 1245 | t.Errorf("baz classpath %v does not contain %q", baz.Args["classpath"], jargen.Output.String()) |
| 1246 | } |
| 1247 | |
| 1248 | if len(barCombined.Inputs) != 2 || |
| 1249 | barCombined.Inputs[0].String() != bar.Output.String() || |
| 1250 | barCombined.Inputs[1].String() != jargen.Output.String() { |
| 1251 | t.Errorf("bar combined jar inputs %v is not [%q, %q]", |
| 1252 | barCombined.Inputs.Strings(), bar.Output.String(), jargen.Output.String()) |
| 1253 | } |
| 1254 | } |
| 1255 | |
Nan Zhang | 27e284d | 2018-02-09 21:03:53 +0000 | [diff] [blame] | 1256 | func TestExcludeFileGroupInSrcs(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1257 | ctx, _ := testJava(t, ` |
Nan Zhang | 27e284d | 2018-02-09 21:03:53 +0000 | [diff] [blame] | 1258 | java_library { |
| 1259 | name: "foo", |
| 1260 | srcs: ["a.java", ":foo-srcs"], |
| 1261 | exclude_srcs: ["a.java", ":foo-excludes"], |
| 1262 | } |
| 1263 | |
| 1264 | filegroup { |
| 1265 | name: "foo-srcs", |
| 1266 | srcs: ["java-fg/a.java", "java-fg/b.java", "java-fg/c.java"], |
| 1267 | } |
| 1268 | |
| 1269 | filegroup { |
| 1270 | name: "foo-excludes", |
| 1271 | srcs: ["java-fg/a.java", "java-fg/b.java"], |
| 1272 | } |
| 1273 | `) |
| 1274 | |
| 1275 | javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") |
| 1276 | |
| 1277 | if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "java-fg/c.java" { |
| 1278 | t.Errorf(`foo inputs %v != ["java-fg/c.java"]`, javac.Inputs) |
| 1279 | } |
| 1280 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1281 | |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 1282 | func TestJavaLibrary(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 1283 | config := testConfig(nil, "", map[string][]byte{ |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 1284 | "libcore/Android.bp": []byte(` |
| 1285 | java_library { |
| 1286 | name: "core", |
| 1287 | sdk_version: "none", |
| 1288 | system_modules: "none", |
| 1289 | }`), |
| 1290 | }) |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 1291 | ctx := testContext() |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 1292 | run(t, ctx, config) |
| 1293 | } |
| 1294 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1295 | func TestJavaSdkLibrary(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1296 | ctx, _ := testJava(t, ` |
Paul Duffin | 884363e | 2019-12-19 10:21:09 +0000 | [diff] [blame] | 1297 | droiddoc_exported_dir { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1298 | name: "droiddoc-templates-sdk", |
| 1299 | path: ".", |
| 1300 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1301 | java_sdk_library { |
| 1302 | name: "foo", |
| 1303 | srcs: ["a.java", "b.java"], |
| 1304 | api_packages: ["foo"], |
| 1305 | } |
| 1306 | java_sdk_library { |
| 1307 | name: "bar", |
| 1308 | srcs: ["a.java", "b.java"], |
| 1309 | api_packages: ["bar"], |
| 1310 | } |
| 1311 | java_library { |
| 1312 | name: "baz", |
| 1313 | srcs: ["c.java"], |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1314 | libs: ["foo", "bar.stubs"], |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1315 | sdk_version: "system_current", |
| 1316 | } |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1317 | java_sdk_library { |
| 1318 | name: "barney", |
| 1319 | srcs: ["c.java"], |
| 1320 | api_only: true, |
| 1321 | } |
| 1322 | java_sdk_library { |
| 1323 | name: "betty", |
| 1324 | srcs: ["c.java"], |
| 1325 | shared_library: false, |
| 1326 | } |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1327 | java_sdk_library_import { |
| 1328 | name: "quuz", |
| 1329 | public: { |
| 1330 | jars: ["c.jar"], |
| 1331 | }, |
| 1332 | } |
| 1333 | java_sdk_library_import { |
| 1334 | name: "fred", |
| 1335 | public: { |
| 1336 | jars: ["b.jar"], |
| 1337 | }, |
| 1338 | } |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1339 | java_sdk_library_import { |
| 1340 | name: "wilma", |
| 1341 | public: { |
| 1342 | jars: ["b.jar"], |
| 1343 | }, |
| 1344 | shared_library: false, |
| 1345 | } |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1346 | java_library { |
| 1347 | name: "qux", |
| 1348 | srcs: ["c.java"], |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1349 | libs: ["baz", "fred", "quuz.stubs", "wilma", "barney", "betty"], |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1350 | sdk_version: "system_current", |
| 1351 | } |
Paul Duffin | 726d23c | 2020-01-22 16:30:37 +0000 | [diff] [blame] | 1352 | java_library { |
| 1353 | name: "baz-test", |
| 1354 | srcs: ["c.java"], |
| 1355 | libs: ["foo"], |
| 1356 | sdk_version: "test_current", |
| 1357 | } |
Paul Duffin | a2db18f | 2020-01-22 17:11:15 +0000 | [diff] [blame] | 1358 | java_library { |
| 1359 | name: "baz-29", |
| 1360 | srcs: ["c.java"], |
| 1361 | libs: ["foo"], |
| 1362 | sdk_version: "system_29", |
| 1363 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1364 | `) |
| 1365 | |
| 1366 | // check the existence of the internal modules |
| 1367 | ctx.ModuleForTests("foo", "android_common") |
Paul Duffin | dd9d074 | 2020-05-08 15:52:37 +0100 | [diff] [blame] | 1368 | ctx.ModuleForTests(apiScopePublic.stubsLibraryModuleName("foo"), "android_common") |
| 1369 | ctx.ModuleForTests(apiScopeSystem.stubsLibraryModuleName("foo"), "android_common") |
| 1370 | ctx.ModuleForTests(apiScopeTest.stubsLibraryModuleName("foo"), "android_common") |
| 1371 | ctx.ModuleForTests(apiScopePublic.stubsSourceModuleName("foo"), "android_common") |
| 1372 | ctx.ModuleForTests(apiScopeSystem.stubsSourceModuleName("foo"), "android_common") |
| 1373 | ctx.ModuleForTests(apiScopeTest.stubsSourceModuleName("foo"), "android_common") |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 1374 | ctx.ModuleForTests("foo"+sdkXmlFileSuffix, "android_common") |
Jiyong Park | 58c518b | 2018-05-12 22:29:12 +0900 | [diff] [blame] | 1375 | ctx.ModuleForTests("foo.api.public.28", "") |
| 1376 | ctx.ModuleForTests("foo.api.system.28", "") |
| 1377 | ctx.ModuleForTests("foo.api.test.28", "") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1378 | |
| 1379 | bazJavac := ctx.ModuleForTests("baz", "android_common").Rule("javac") |
| 1380 | // tests if baz is actually linked to the stubs lib |
| 1381 | if !strings.Contains(bazJavac.Args["classpath"], "foo.stubs.system.jar") { |
| 1382 | t.Errorf("baz javac classpath %v does not contain %q", bazJavac.Args["classpath"], |
| 1383 | "foo.stubs.system.jar") |
| 1384 | } |
| 1385 | // ... and not to the impl lib |
Sundong Ahn | 054b19a | 2018-10-19 13:46:09 +0900 | [diff] [blame] | 1386 | if strings.Contains(bazJavac.Args["classpath"], "foo.jar") { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1387 | 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] | 1388 | "foo.jar") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1389 | } |
| 1390 | // test if baz is not linked to the system variant of foo |
| 1391 | if strings.Contains(bazJavac.Args["classpath"], "foo.stubs.jar") { |
| 1392 | t.Errorf("baz javac classpath %v should not contain %q", bazJavac.Args["classpath"], |
| 1393 | "foo.stubs.jar") |
| 1394 | } |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1395 | |
Paul Duffin | 726d23c | 2020-01-22 16:30:37 +0000 | [diff] [blame] | 1396 | bazTestJavac := ctx.ModuleForTests("baz-test", "android_common").Rule("javac") |
| 1397 | // tests if baz-test is actually linked to the test stubs lib |
| 1398 | if !strings.Contains(bazTestJavac.Args["classpath"], "foo.stubs.test.jar") { |
| 1399 | t.Errorf("baz-test javac classpath %v does not contain %q", bazTestJavac.Args["classpath"], |
| 1400 | "foo.stubs.test.jar") |
| 1401 | } |
| 1402 | |
Paul Duffin | a2db18f | 2020-01-22 17:11:15 +0000 | [diff] [blame] | 1403 | baz29Javac := ctx.ModuleForTests("baz-29", "android_common").Rule("javac") |
| 1404 | // tests if baz-29 is actually linked to the system 29 stubs lib |
| 1405 | if !strings.Contains(baz29Javac.Args["classpath"], "prebuilts/sdk/29/system/foo.jar") { |
| 1406 | t.Errorf("baz-29 javac classpath %v does not contain %q", baz29Javac.Args["classpath"], |
| 1407 | "prebuilts/sdk/29/system/foo.jar") |
| 1408 | } |
| 1409 | |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1410 | // test if baz has exported SDK lib names foo and bar to qux |
| 1411 | qux := ctx.ModuleForTests("qux", "android_common") |
| 1412 | if quxLib, ok := qux.Module().(*Library); ok { |
| 1413 | sdkLibs := quxLib.ExportedSdkLibs() |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1414 | sort.Strings(sdkLibs) |
| 1415 | if w := []string{"bar", "foo", "fred", "quuz"}; !reflect.DeepEqual(w, sdkLibs) { |
| 1416 | t.Errorf("qux should export %q but exports %q", w, sdkLibs) |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1417 | } |
| 1418 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1419 | } |
Zoran Jovanovic | 8736ce2 | 2018-08-21 17:10:29 +0200 | [diff] [blame] | 1420 | |
Paul Duffin | daaa332 | 2020-05-26 18:13:57 +0100 | [diff] [blame] | 1421 | func TestJavaSdkLibrary_DoNotAccessImplWhenItIsNotBuilt(t *testing.T) { |
| 1422 | ctx, _ := testJava(t, ` |
| 1423 | java_sdk_library { |
| 1424 | name: "foo", |
| 1425 | srcs: ["a.java"], |
| 1426 | api_only: true, |
| 1427 | public: { |
| 1428 | enabled: true, |
| 1429 | }, |
| 1430 | } |
| 1431 | |
| 1432 | java_library { |
| 1433 | name: "bar", |
| 1434 | srcs: ["b.java"], |
| 1435 | libs: ["foo"], |
| 1436 | } |
| 1437 | `) |
| 1438 | |
| 1439 | // The bar library should depend on the stubs jar. |
| 1440 | barLibrary := ctx.ModuleForTests("bar", "android_common").Rule("javac") |
| 1441 | if expected, actual := `^-classpath .*:/[^:]*/turbine-combined/foo\.stubs\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 1442 | t.Errorf("expected %q, found %#q", expected, actual) |
| 1443 | } |
| 1444 | } |
| 1445 | |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1446 | func TestJavaSdkLibrary_UseSourcesFromAnotherSdkLibrary(t *testing.T) { |
| 1447 | testJava(t, ` |
| 1448 | java_sdk_library { |
| 1449 | name: "foo", |
| 1450 | srcs: ["a.java"], |
| 1451 | api_packages: ["foo"], |
| 1452 | public: { |
| 1453 | enabled: true, |
| 1454 | }, |
| 1455 | } |
| 1456 | |
| 1457 | java_library { |
| 1458 | name: "bar", |
| 1459 | srcs: ["b.java", ":foo{.public.stubs.source}"], |
| 1460 | } |
| 1461 | `) |
| 1462 | } |
| 1463 | |
| 1464 | func TestJavaSdkLibrary_AccessOutputFiles_MissingScope(t *testing.T) { |
| 1465 | testJavaError(t, `"foo" does not provide api scope system`, ` |
| 1466 | java_sdk_library { |
| 1467 | name: "foo", |
| 1468 | srcs: ["a.java"], |
| 1469 | api_packages: ["foo"], |
| 1470 | public: { |
| 1471 | enabled: true, |
| 1472 | }, |
| 1473 | } |
| 1474 | |
| 1475 | java_library { |
| 1476 | name: "bar", |
| 1477 | srcs: ["b.java", ":foo{.system.stubs.source}"], |
| 1478 | } |
| 1479 | `) |
| 1480 | } |
| 1481 | |
Paul Duffin | ca8d9a5 | 2020-06-26 22:20:25 +0100 | [diff] [blame] | 1482 | func TestJavaSdkLibrary_Deps(t *testing.T) { |
| 1483 | ctx, _ := testJava(t, ` |
| 1484 | java_sdk_library { |
| 1485 | name: "sdklib", |
| 1486 | srcs: ["a.java"], |
| 1487 | sdk_version: "none", |
| 1488 | system_modules: "none", |
| 1489 | public: { |
| 1490 | enabled: true, |
| 1491 | }, |
| 1492 | } |
| 1493 | `) |
| 1494 | |
| 1495 | checkModuleDependencies(t, ctx, "sdklib", "android_common", []string{ |
| 1496 | `dex2oatd`, |
| 1497 | `sdklib.impl`, |
| 1498 | `sdklib.stubs`, |
| 1499 | `sdklib.stubs.source`, |
| 1500 | `sdklib.xml`, |
| 1501 | }) |
| 1502 | } |
| 1503 | |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1504 | func TestJavaSdkLibraryImport_AccessOutputFiles(t *testing.T) { |
| 1505 | testJava(t, ` |
| 1506 | java_sdk_library_import { |
| 1507 | name: "foo", |
| 1508 | public: { |
| 1509 | jars: ["a.jar"], |
| 1510 | stub_srcs: ["a.java"], |
| 1511 | current_api: "api/current.txt", |
| 1512 | removed_api: "api/removed.txt", |
| 1513 | }, |
| 1514 | } |
| 1515 | |
| 1516 | java_library { |
| 1517 | name: "bar", |
| 1518 | srcs: [":foo{.public.stubs.source}"], |
| 1519 | java_resources: [ |
| 1520 | ":foo{.public.api.txt}", |
| 1521 | ":foo{.public.removed-api.txt}", |
| 1522 | ], |
| 1523 | } |
| 1524 | `) |
| 1525 | } |
| 1526 | |
| 1527 | func TestJavaSdkLibraryImport_AccessOutputFiles_Invalid(t *testing.T) { |
| 1528 | bp := ` |
| 1529 | java_sdk_library_import { |
| 1530 | name: "foo", |
| 1531 | public: { |
| 1532 | jars: ["a.jar"], |
| 1533 | }, |
| 1534 | } |
| 1535 | ` |
| 1536 | |
| 1537 | t.Run("stubs.source", func(t *testing.T) { |
| 1538 | testJavaError(t, `stubs.source not available for api scope public`, bp+` |
| 1539 | java_library { |
| 1540 | name: "bar", |
| 1541 | srcs: [":foo{.public.stubs.source}"], |
| 1542 | java_resources: [ |
| 1543 | ":foo{.public.api.txt}", |
| 1544 | ":foo{.public.removed-api.txt}", |
| 1545 | ], |
| 1546 | } |
| 1547 | `) |
| 1548 | }) |
| 1549 | |
| 1550 | t.Run("api.txt", func(t *testing.T) { |
| 1551 | testJavaError(t, `api.txt not available for api scope public`, bp+` |
| 1552 | java_library { |
| 1553 | name: "bar", |
| 1554 | srcs: ["a.java"], |
| 1555 | java_resources: [ |
| 1556 | ":foo{.public.api.txt}", |
| 1557 | ], |
| 1558 | } |
| 1559 | `) |
| 1560 | }) |
| 1561 | |
| 1562 | t.Run("removed-api.txt", func(t *testing.T) { |
| 1563 | testJavaError(t, `removed-api.txt not available for api scope public`, bp+` |
| 1564 | java_library { |
| 1565 | name: "bar", |
| 1566 | srcs: ["a.java"], |
| 1567 | java_resources: [ |
| 1568 | ":foo{.public.removed-api.txt}", |
| 1569 | ], |
| 1570 | } |
| 1571 | `) |
| 1572 | }) |
| 1573 | } |
| 1574 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 1575 | func TestJavaSdkLibrary_InvalidScopes(t *testing.T) { |
| 1576 | testJavaError(t, `module "foo": enabled api scope "system" depends on disabled scope "public"`, ` |
| 1577 | java_sdk_library { |
| 1578 | name: "foo", |
| 1579 | srcs: ["a.java", "b.java"], |
| 1580 | api_packages: ["foo"], |
| 1581 | // Explicitly disable public to test the check that ensures the set of enabled |
| 1582 | // scopes is consistent. |
| 1583 | public: { |
| 1584 | enabled: false, |
| 1585 | }, |
| 1586 | system: { |
| 1587 | enabled: true, |
| 1588 | }, |
| 1589 | } |
| 1590 | `) |
| 1591 | } |
| 1592 | |
Paul Duffin | 87a05a3 | 2020-05-12 11:50:28 +0100 | [diff] [blame] | 1593 | func TestJavaSdkLibrary_SdkVersion_ForScope(t *testing.T) { |
| 1594 | testJava(t, ` |
| 1595 | java_sdk_library { |
| 1596 | name: "foo", |
| 1597 | srcs: ["a.java", "b.java"], |
| 1598 | api_packages: ["foo"], |
| 1599 | system: { |
| 1600 | enabled: true, |
| 1601 | sdk_version: "module_current", |
| 1602 | }, |
| 1603 | } |
| 1604 | `) |
| 1605 | } |
| 1606 | |
Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 1607 | func TestJavaSdkLibrary_ModuleLib(t *testing.T) { |
| 1608 | testJava(t, ` |
| 1609 | java_sdk_library { |
| 1610 | name: "foo", |
| 1611 | srcs: ["a.java", "b.java"], |
| 1612 | api_packages: ["foo"], |
| 1613 | system: { |
| 1614 | enabled: true, |
| 1615 | }, |
| 1616 | module_lib: { |
| 1617 | enabled: true, |
| 1618 | }, |
| 1619 | } |
| 1620 | `) |
| 1621 | } |
| 1622 | |
| 1623 | func TestJavaSdkLibrary_SystemServer(t *testing.T) { |
| 1624 | testJava(t, ` |
| 1625 | java_sdk_library { |
| 1626 | name: "foo", |
| 1627 | srcs: ["a.java", "b.java"], |
| 1628 | api_packages: ["foo"], |
| 1629 | system: { |
| 1630 | enabled: true, |
| 1631 | }, |
| 1632 | system_server: { |
| 1633 | enabled: true, |
| 1634 | }, |
| 1635 | } |
| 1636 | `) |
| 1637 | } |
| 1638 | |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 1639 | func TestJavaSdkLibrary_MissingScope(t *testing.T) { |
| 1640 | testJavaError(t, `requires api scope module-lib from foo but it only has \[\] available`, ` |
| 1641 | java_sdk_library { |
| 1642 | name: "foo", |
| 1643 | srcs: ["a.java"], |
| 1644 | public: { |
| 1645 | enabled: false, |
| 1646 | }, |
| 1647 | } |
| 1648 | |
| 1649 | java_library { |
| 1650 | name: "baz", |
| 1651 | srcs: ["a.java"], |
| 1652 | libs: ["foo"], |
| 1653 | sdk_version: "module_current", |
| 1654 | } |
| 1655 | `) |
| 1656 | } |
| 1657 | |
| 1658 | func TestJavaSdkLibrary_FallbackScope(t *testing.T) { |
| 1659 | testJava(t, ` |
| 1660 | java_sdk_library { |
| 1661 | name: "foo", |
| 1662 | srcs: ["a.java"], |
| 1663 | system: { |
| 1664 | enabled: true, |
| 1665 | }, |
| 1666 | } |
| 1667 | |
| 1668 | java_library { |
| 1669 | name: "baz", |
| 1670 | srcs: ["a.java"], |
| 1671 | libs: ["foo"], |
| 1672 | // foo does not have module-lib scope so it should fallback to system |
| 1673 | sdk_version: "module_current", |
| 1674 | } |
| 1675 | `) |
| 1676 | } |
| 1677 | |
Jiyong Park | 932cdfe | 2020-05-28 00:19:53 +0900 | [diff] [blame] | 1678 | func TestJavaSdkLibrary_DefaultToStubs(t *testing.T) { |
| 1679 | ctx, _ := testJava(t, ` |
| 1680 | java_sdk_library { |
| 1681 | name: "foo", |
| 1682 | srcs: ["a.java"], |
| 1683 | system: { |
| 1684 | enabled: true, |
| 1685 | }, |
| 1686 | default_to_stubs: true, |
| 1687 | } |
| 1688 | |
| 1689 | java_library { |
| 1690 | name: "baz", |
| 1691 | srcs: ["a.java"], |
| 1692 | libs: ["foo"], |
| 1693 | // does not have sdk_version set, should fallback to module, |
| 1694 | // which will then fallback to system because the module scope |
| 1695 | // is not enabled. |
| 1696 | } |
| 1697 | `) |
| 1698 | // The baz library should depend on the system stubs jar. |
| 1699 | bazLibrary := ctx.ModuleForTests("baz", "android_common").Rule("javac") |
| 1700 | if expected, actual := `^-classpath .*:/[^:]*/turbine-combined/foo\.stubs.system\.jar$`, bazLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 1701 | t.Errorf("expected %q, found %#q", expected, actual) |
| 1702 | } |
| 1703 | } |
| 1704 | |
Zoran Jovanovic | 8736ce2 | 2018-08-21 17:10:29 +0200 | [diff] [blame] | 1705 | var compilerFlagsTestCases = []struct { |
| 1706 | in string |
| 1707 | out bool |
| 1708 | }{ |
| 1709 | { |
| 1710 | in: "a", |
| 1711 | out: false, |
| 1712 | }, |
| 1713 | { |
| 1714 | in: "-a", |
| 1715 | out: true, |
| 1716 | }, |
| 1717 | { |
| 1718 | in: "-no-jdk", |
| 1719 | out: false, |
| 1720 | }, |
| 1721 | { |
| 1722 | in: "-no-stdlib", |
| 1723 | out: false, |
| 1724 | }, |
| 1725 | { |
| 1726 | in: "-kotlin-home", |
| 1727 | out: false, |
| 1728 | }, |
| 1729 | { |
| 1730 | in: "-kotlin-home /some/path", |
| 1731 | out: false, |
| 1732 | }, |
| 1733 | { |
| 1734 | in: "-include-runtime", |
| 1735 | out: false, |
| 1736 | }, |
| 1737 | { |
| 1738 | in: "-Xintellij-plugin-root", |
| 1739 | out: false, |
| 1740 | }, |
| 1741 | } |
| 1742 | |
| 1743 | type mockContext struct { |
| 1744 | android.ModuleContext |
| 1745 | result bool |
| 1746 | } |
| 1747 | |
| 1748 | func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) { |
| 1749 | // CheckBadCompilerFlags calls this function when the flag should be rejected |
| 1750 | ctx.result = false |
| 1751 | } |
| 1752 | |
| 1753 | func TestCompilerFlags(t *testing.T) { |
| 1754 | for _, testCase := range compilerFlagsTestCases { |
| 1755 | ctx := &mockContext{result: true} |
| 1756 | CheckKotlincFlags(ctx, []string{testCase.in}) |
| 1757 | if ctx.result != testCase.out { |
| 1758 | t.Errorf("incorrect output:") |
| 1759 | t.Errorf(" input: %#v", testCase.in) |
| 1760 | t.Errorf(" expected: %#v", testCase.out) |
| 1761 | t.Errorf(" got: %#v", ctx.result) |
| 1762 | } |
| 1763 | } |
| 1764 | } |
Jaewoong Jung | 38e4fb2 | 2018-12-12 09:01:34 -0800 | [diff] [blame] | 1765 | |
| 1766 | // TODO(jungjw): Consider making this more robust by ignoring path order. |
| 1767 | func checkPatchModuleFlag(t *testing.T, ctx *android.TestContext, moduleName string, expected string) { |
| 1768 | variables := ctx.ModuleForTests(moduleName, "android_common").Module().VariablesForTests() |
| 1769 | flags := strings.Split(variables["javacFlags"], " ") |
| 1770 | got := "" |
| 1771 | for _, flag := range flags { |
| 1772 | keyEnd := strings.Index(flag, "=") |
| 1773 | if keyEnd > -1 && flag[:keyEnd] == "--patch-module" { |
| 1774 | got = flag[keyEnd+1:] |
| 1775 | break |
| 1776 | } |
| 1777 | } |
| 1778 | if expected != got { |
| 1779 | t.Errorf("Unexpected patch-module flag for module %q - expected %q, but got %q", moduleName, expected, got) |
| 1780 | } |
| 1781 | } |
| 1782 | |
| 1783 | func TestPatchModule(t *testing.T) { |
Pete Gillin | 0c2143e | 2019-05-02 15:32:11 +0100 | [diff] [blame] | 1784 | t.Run("Java language level 8", func(t *testing.T) { |
Pete Gillin | 1b3370f | 2019-10-01 13:57:31 +0100 | [diff] [blame] | 1785 | // Test with legacy javac -source 1.8 -target 1.8 |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 1786 | bp := ` |
| 1787 | java_library { |
| 1788 | name: "foo", |
| 1789 | srcs: ["a.java"], |
| 1790 | java_version: "1.8", |
| 1791 | } |
| 1792 | |
| 1793 | java_library { |
| 1794 | name: "bar", |
| 1795 | srcs: ["b.java"], |
| 1796 | sdk_version: "none", |
| 1797 | system_modules: "none", |
| 1798 | patch_module: "java.base", |
| 1799 | java_version: "1.8", |
| 1800 | } |
| 1801 | |
| 1802 | java_library { |
| 1803 | name: "baz", |
| 1804 | srcs: ["c.java"], |
| 1805 | patch_module: "java.base", |
| 1806 | java_version: "1.8", |
| 1807 | } |
| 1808 | ` |
| 1809 | ctx, _ := testJava(t, bp) |
Jaewoong Jung | 38e4fb2 | 2018-12-12 09:01:34 -0800 | [diff] [blame] | 1810 | |
| 1811 | checkPatchModuleFlag(t, ctx, "foo", "") |
| 1812 | checkPatchModuleFlag(t, ctx, "bar", "") |
| 1813 | checkPatchModuleFlag(t, ctx, "baz", "") |
| 1814 | }) |
| 1815 | |
Pete Gillin | 0c2143e | 2019-05-02 15:32:11 +0100 | [diff] [blame] | 1816 | t.Run("Java language level 9", func(t *testing.T) { |
Pete Gillin | 1b3370f | 2019-10-01 13:57:31 +0100 | [diff] [blame] | 1817 | // Test with default javac -source 9 -target 9 |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 1818 | bp := ` |
| 1819 | java_library { |
| 1820 | name: "foo", |
| 1821 | srcs: ["a.java"], |
| 1822 | } |
| 1823 | |
| 1824 | java_library { |
| 1825 | name: "bar", |
| 1826 | srcs: ["b.java"], |
| 1827 | sdk_version: "none", |
| 1828 | system_modules: "none", |
| 1829 | patch_module: "java.base", |
| 1830 | } |
| 1831 | |
| 1832 | java_library { |
| 1833 | name: "baz", |
| 1834 | srcs: ["c.java"], |
| 1835 | patch_module: "java.base", |
| 1836 | } |
| 1837 | ` |
Pete Gillin | 1b3370f | 2019-10-01 13:57:31 +0100 | [diff] [blame] | 1838 | ctx, _ := testJava(t, bp) |
Jaewoong Jung | 38e4fb2 | 2018-12-12 09:01:34 -0800 | [diff] [blame] | 1839 | |
| 1840 | checkPatchModuleFlag(t, ctx, "foo", "") |
| 1841 | expected := "java.base=.:" + buildDir |
| 1842 | checkPatchModuleFlag(t, ctx, "bar", expected) |
Jiyong Park | 231d056 | 2019-12-18 17:28:17 +0900 | [diff] [blame] | 1843 | expected = "java.base=" + strings.Join([]string{".", buildDir, moduleToPath("ext"), moduleToPath("framework")}, ":") |
Jaewoong Jung | 38e4fb2 | 2018-12-12 09:01:34 -0800 | [diff] [blame] | 1844 | checkPatchModuleFlag(t, ctx, "baz", expected) |
| 1845 | }) |
| 1846 | } |
Paul Duffin | a7b9f42 | 2020-01-10 17:12:18 +0000 | [diff] [blame] | 1847 | |
| 1848 | func TestJavaSystemModules(t *testing.T) { |
| 1849 | ctx, _ := testJava(t, ` |
| 1850 | java_system_modules { |
| 1851 | name: "system-modules", |
| 1852 | libs: ["system-module1", "system-module2"], |
| 1853 | } |
| 1854 | java_library { |
| 1855 | name: "system-module1", |
| 1856 | srcs: ["a.java"], |
| 1857 | sdk_version: "none", |
| 1858 | system_modules: "none", |
| 1859 | } |
| 1860 | java_library { |
| 1861 | name: "system-module2", |
| 1862 | srcs: ["b.java"], |
| 1863 | sdk_version: "none", |
| 1864 | system_modules: "none", |
| 1865 | } |
| 1866 | `) |
| 1867 | |
| 1868 | // check the existence of the module |
| 1869 | systemModules := ctx.ModuleForTests("system-modules", "android_common") |
| 1870 | |
| 1871 | cmd := systemModules.Rule("jarsTosystemModules") |
| 1872 | |
| 1873 | // make sure the command compiles against the supplied modules. |
| 1874 | for _, module := range []string{"system-module1.jar", "system-module2.jar"} { |
| 1875 | if !strings.Contains(cmd.Args["classpath"], module) { |
| 1876 | t.Errorf("system modules classpath %v does not contain %q", cmd.Args["classpath"], |
| 1877 | module) |
| 1878 | } |
| 1879 | } |
| 1880 | } |
Paul Duffin | 90169ba | 2020-01-10 17:16:44 +0000 | [diff] [blame] | 1881 | |
| 1882 | func TestJavaSystemModulesImport(t *testing.T) { |
| 1883 | ctx, _ := testJava(t, ` |
| 1884 | java_system_modules_import { |
| 1885 | name: "system-modules", |
| 1886 | libs: ["system-module1", "system-module2"], |
| 1887 | } |
| 1888 | java_import { |
| 1889 | name: "system-module1", |
| 1890 | jars: ["a.jar"], |
| 1891 | } |
| 1892 | java_import { |
| 1893 | name: "system-module2", |
| 1894 | jars: ["b.jar"], |
| 1895 | } |
| 1896 | `) |
| 1897 | |
| 1898 | // check the existence of the module |
| 1899 | systemModules := ctx.ModuleForTests("system-modules", "android_common") |
| 1900 | |
| 1901 | cmd := systemModules.Rule("jarsTosystemModules") |
| 1902 | |
| 1903 | // make sure the command compiles against the supplied modules. |
| 1904 | for _, module := range []string{"system-module1.jar", "system-module2.jar"} { |
| 1905 | if !strings.Contains(cmd.Args["classpath"], module) { |
| 1906 | t.Errorf("system modules classpath %v does not contain %q", cmd.Args["classpath"], |
| 1907 | module) |
| 1908 | } |
| 1909 | } |
| 1910 | } |
Paul Duffin | 83a2d96 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 1911 | |
| 1912 | func TestJavaLibraryWithSystemModules(t *testing.T) { |
| 1913 | ctx, _ := testJava(t, ` |
| 1914 | java_library { |
| 1915 | name: "lib-with-source-system-modules", |
| 1916 | srcs: [ |
| 1917 | "a.java", |
| 1918 | ], |
| 1919 | sdk_version: "none", |
| 1920 | system_modules: "source-system-modules", |
| 1921 | } |
| 1922 | |
| 1923 | java_library { |
| 1924 | name: "source-jar", |
| 1925 | srcs: [ |
| 1926 | "a.java", |
| 1927 | ], |
| 1928 | } |
| 1929 | |
| 1930 | java_system_modules { |
| 1931 | name: "source-system-modules", |
| 1932 | libs: ["source-jar"], |
| 1933 | } |
| 1934 | |
| 1935 | java_library { |
| 1936 | name: "lib-with-prebuilt-system-modules", |
| 1937 | srcs: [ |
| 1938 | "a.java", |
| 1939 | ], |
| 1940 | sdk_version: "none", |
| 1941 | system_modules: "prebuilt-system-modules", |
| 1942 | } |
| 1943 | |
| 1944 | java_import { |
| 1945 | name: "prebuilt-jar", |
| 1946 | jars: ["a.jar"], |
| 1947 | } |
| 1948 | |
| 1949 | java_system_modules_import { |
| 1950 | name: "prebuilt-system-modules", |
| 1951 | libs: ["prebuilt-jar"], |
| 1952 | } |
| 1953 | `) |
| 1954 | |
| 1955 | checkBootClasspathForSystemModule(t, ctx, "lib-with-source-system-modules", "/source-jar.jar") |
| 1956 | |
| 1957 | checkBootClasspathForSystemModule(t, ctx, "lib-with-prebuilt-system-modules", "/prebuilt-jar.jar") |
| 1958 | } |
| 1959 | |
| 1960 | func checkBootClasspathForSystemModule(t *testing.T, ctx *android.TestContext, moduleName string, expectedSuffix string) { |
| 1961 | javacRule := ctx.ModuleForTests(moduleName, "android_common").Rule("javac") |
| 1962 | bootClasspath := javacRule.Args["bootClasspath"] |
| 1963 | if strings.HasPrefix(bootClasspath, "--system ") && strings.HasSuffix(bootClasspath, expectedSuffix) { |
| 1964 | t.Errorf("bootclasspath of %q must start with --system and end with %q, but was %#v.", moduleName, expectedSuffix, bootClasspath) |
| 1965 | } |
| 1966 | } |
Jiyong Park | 19604de | 2020-03-24 16:44:11 +0900 | [diff] [blame] | 1967 | |
| 1968 | func TestAidlExportIncludeDirsFromImports(t *testing.T) { |
| 1969 | ctx, _ := testJava(t, ` |
| 1970 | java_library { |
| 1971 | name: "foo", |
| 1972 | srcs: ["aidl/foo/IFoo.aidl"], |
| 1973 | libs: ["bar"], |
| 1974 | } |
| 1975 | |
| 1976 | java_import { |
| 1977 | name: "bar", |
| 1978 | jars: ["a.jar"], |
| 1979 | aidl: { |
| 1980 | export_include_dirs: ["aidl/bar"], |
| 1981 | }, |
| 1982 | } |
| 1983 | `) |
| 1984 | |
| 1985 | aidlCommand := ctx.ModuleForTests("foo", "android_common").Rule("aidl").RuleParams.Command |
| 1986 | expectedAidlFlag := "-Iaidl/bar" |
| 1987 | if !strings.Contains(aidlCommand, expectedAidlFlag) { |
| 1988 | t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) |
| 1989 | } |
| 1990 | } |