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 ( |
Paul Duffin | 1a39332 | 2020-11-18 16:36:47 +0000 | [diff] [blame] | 18 | "fmt" |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 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" |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 23 | "strconv" |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 24 | "strings" |
| 25 | "testing" |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 26 | |
Jeongik Cha | 28df257 | 2019-11-11 10:46:36 +0900 | [diff] [blame] | 27 | "github.com/google/blueprint/proptools" |
| 28 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 29 | "android/soong/android" |
| 30 | "android/soong/cc" |
Colin Cross | c28bb0b | 2019-02-25 14:20:47 -0800 | [diff] [blame] | 31 | "android/soong/dexpreopt" |
Colin Cross | 1661aff | 2021-03-12 17:56:51 -0800 | [diff] [blame] | 32 | "android/soong/genrule" |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 33 | "android/soong/python" |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 34 | ) |
| 35 | |
Paul Duffin | 70d3bee | 2021-03-21 11:26:05 +0000 | [diff] [blame] | 36 | // Legacy preparer used for running tests within the java package. |
| 37 | // |
| 38 | // This includes everything that was needed to run any test in the java package prior to the |
| 39 | // introduction of the test fixtures. Tests that are being converted to use fixtures directly |
| 40 | // rather than through the testJava...() methods should avoid using this and instead use the |
| 41 | // various preparers directly, using android.GroupFixturePreparers(...) to group them when |
| 42 | // necessary. |
| 43 | // |
| 44 | // deprecated |
| 45 | var prepareForJavaTest = android.GroupFixturePreparers( |
Paul Duffin | 95bdab4 | 2021-03-08 21:48:46 +0000 | [diff] [blame] | 46 | genrule.PrepareForTestWithGenRuleBuildComponents, |
| 47 | // Get the CC build components but not default modules. |
| 48 | cc.PrepareForTestWithCcBuildComponents, |
| 49 | // Include all the default java modules. |
| 50 | PrepareForTestWithJavaDefaultModules, |
Paul Duffin | 42da69d | 2021-03-22 13:41:36 +0000 | [diff] [blame] | 51 | PrepareForTestWithOverlayBuildComponents, |
Paul Duffin | 220ddd7 | 2021-03-17 23:54:30 +0000 | [diff] [blame] | 52 | python.PrepareForTestWithPythonBuildComponents, |
Paul Duffin | 95bdab4 | 2021-03-08 21:48:46 +0000 | [diff] [blame] | 53 | android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { |
Paul Duffin | 95bdab4 | 2021-03-08 21:48:46 +0000 | [diff] [blame] | 54 | ctx.RegisterPreSingletonType("sdk_versions", sdkPreSingletonFactory) |
| 55 | }), |
Paul Duffin | 95bdab4 | 2021-03-08 21:48:46 +0000 | [diff] [blame] | 56 | dexpreopt.PrepareForTestWithDexpreopt, |
| 57 | ) |
| 58 | |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 59 | func TestMain(m *testing.M) { |
Paul Duffin | d6339af | 2021-03-22 18:05:04 +0000 | [diff] [blame] | 60 | os.Exit(m.Run()) |
Colin Cross | 527012a | 2017-11-30 22:56:16 -0800 | [diff] [blame] | 61 | } |
| 62 | |
Paul Duffin | 95bdab4 | 2021-03-08 21:48:46 +0000 | [diff] [blame] | 63 | // testJavaError is a legacy way of running tests of java modules that expect errors. |
| 64 | // |
| 65 | // See testJava for an explanation as to how to stop using this deprecated method. |
| 66 | // |
| 67 | // deprecated |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 68 | 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] | 69 | t.Helper() |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 70 | result := android.GroupFixturePreparers( |
| 71 | prepareForJavaTest, dexpreopt.PrepareForTestWithDexpreopt). |
Paul Duffin | 6bac49c | 2021-03-12 21:28:15 +0000 | [diff] [blame] | 72 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)). |
| 73 | RunTestWithBp(t, bp) |
| 74 | return result.TestContext, result.Config |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 75 | } |
| 76 | |
Paul Duffin | 95bdab4 | 2021-03-08 21:48:46 +0000 | [diff] [blame] | 77 | // testJavaErrorWithConfig is a legacy way of running tests of java modules that expect errors. |
| 78 | // |
| 79 | // See testJava for an explanation as to how to stop using this deprecated method. |
| 80 | // |
| 81 | // deprecated |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 82 | 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] | 83 | t.Helper() |
Paul Duffin | 95bdab4 | 2021-03-08 21:48:46 +0000 | [diff] [blame] | 84 | // This must be done on the supplied config and not as part of the fixture because any changes to |
| 85 | // the fixture's config will be ignored when RunTestWithConfig replaces it. |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 86 | pathCtx := android.PathContextForTesting(config) |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 87 | dexpreopt.SetTestGlobalConfig(config, dexpreopt.GlobalConfigForTests(pathCtx)) |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 88 | result := prepareForJavaTest. |
Paul Duffin | 95bdab4 | 2021-03-08 21:48:46 +0000 | [diff] [blame] | 89 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)). |
| 90 | RunTestWithConfig(t, config) |
| 91 | return result.TestContext, result.Config |
Paul Duffin | ec0fe17 | 2021-02-25 15:34:13 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 94 | // testJavaWithFS runs tests using the prepareForJavaTest |
Paul Duffin | 95bdab4 | 2021-03-08 21:48:46 +0000 | [diff] [blame] | 95 | // |
| 96 | // See testJava for an explanation as to how to stop using this deprecated method. |
| 97 | // |
| 98 | // deprecated |
| 99 | func testJavaWithFS(t *testing.T, bp string, fs android.MockFS) (*android.TestContext, android.Config) { |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 100 | t.Helper() |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 101 | result := android.GroupFixturePreparers( |
| 102 | prepareForJavaTest, fs.AddToFixture()).RunTestWithBp(t, bp) |
Paul Duffin | 95bdab4 | 2021-03-08 21:48:46 +0000 | [diff] [blame] | 103 | return result.TestContext, result.Config |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 106 | // testJava runs tests using the prepareForJavaTest |
Paul Duffin | 95bdab4 | 2021-03-08 21:48:46 +0000 | [diff] [blame] | 107 | // |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 108 | // Do not add any new usages of this, instead use the prepareForJavaTest directly as it makes it |
Paul Duffin | 95bdab4 | 2021-03-08 21:48:46 +0000 | [diff] [blame] | 109 | // much easier to customize the test behavior. |
| 110 | // |
| 111 | // If it is necessary to customize the behavior of an existing test that uses this then please first |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 112 | // convert the test to using prepareForJavaTest first and then in a following change add the |
Paul Duffin | 95bdab4 | 2021-03-08 21:48:46 +0000 | [diff] [blame] | 113 | // appropriate fixture preparers. Keeping the conversion change separate makes it easy to verify |
| 114 | // that it did not change the test behavior unexpectedly. |
| 115 | // |
| 116 | // deprecated |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 117 | func testJava(t *testing.T, bp string) (*android.TestContext, android.Config) { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 118 | t.Helper() |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 119 | result := prepareForJavaTest.RunTestWithBp(t, bp) |
Paul Duffin | 95bdab4 | 2021-03-08 21:48:46 +0000 | [diff] [blame] | 120 | return result.TestContext, result.Config |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 121 | } |
| 122 | |
Paul Duffin | 95bdab4 | 2021-03-08 21:48:46 +0000 | [diff] [blame] | 123 | // defaultModuleToPath constructs a path to the turbine generate jar for a default test module that |
| 124 | // is defined in PrepareForIntegrationTestWithJava |
| 125 | func defaultModuleToPath(name string) string { |
Paul Duffin | 76101fa | 2021-03-13 09:55:25 +0000 | [diff] [blame] | 126 | switch { |
| 127 | case name == `""`: |
| 128 | return name |
| 129 | case strings.HasSuffix(name, ".jar"): |
| 130 | return name |
| 131 | default: |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 132 | return filepath.Join("out", "soong", ".intermediates", defaultJavaDir, name, "android_common", "turbine-combined", name+".jar") |
Paul Duffin | 76101fa | 2021-03-13 09:55:25 +0000 | [diff] [blame] | 133 | } |
Paul Duffin | 95bdab4 | 2021-03-08 21:48:46 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Jeongik Cha | e403e9e | 2019-12-07 00:16:24 +0900 | [diff] [blame] | 136 | func TestJavaLinkType(t *testing.T) { |
| 137 | testJava(t, ` |
| 138 | java_library { |
| 139 | name: "foo", |
| 140 | srcs: ["a.java"], |
| 141 | libs: ["bar"], |
| 142 | static_libs: ["baz"], |
| 143 | } |
| 144 | |
| 145 | java_library { |
| 146 | name: "bar", |
| 147 | sdk_version: "current", |
| 148 | srcs: ["b.java"], |
| 149 | } |
| 150 | |
| 151 | java_library { |
| 152 | name: "baz", |
| 153 | sdk_version: "system_current", |
| 154 | srcs: ["c.java"], |
| 155 | } |
| 156 | `) |
| 157 | |
Steven Moreland | 0029898 | 2020-11-17 21:44:36 +0000 | [diff] [blame] | 158 | testJavaError(t, "consider adjusting sdk_version: OR platform_apis:", ` |
Jeongik Cha | e403e9e | 2019-12-07 00:16:24 +0900 | [diff] [blame] | 159 | java_library { |
| 160 | name: "foo", |
| 161 | srcs: ["a.java"], |
| 162 | libs: ["bar"], |
| 163 | sdk_version: "current", |
| 164 | static_libs: ["baz"], |
| 165 | } |
| 166 | |
| 167 | java_library { |
| 168 | name: "bar", |
| 169 | sdk_version: "current", |
| 170 | srcs: ["b.java"], |
| 171 | } |
| 172 | |
| 173 | java_library { |
| 174 | name: "baz", |
| 175 | sdk_version: "system_current", |
| 176 | srcs: ["c.java"], |
| 177 | } |
| 178 | `) |
| 179 | |
| 180 | testJava(t, ` |
| 181 | java_library { |
| 182 | name: "foo", |
| 183 | srcs: ["a.java"], |
| 184 | libs: ["bar"], |
| 185 | sdk_version: "system_current", |
| 186 | static_libs: ["baz"], |
| 187 | } |
| 188 | |
| 189 | java_library { |
| 190 | name: "bar", |
| 191 | sdk_version: "current", |
| 192 | srcs: ["b.java"], |
| 193 | } |
| 194 | |
| 195 | java_library { |
| 196 | name: "baz", |
| 197 | sdk_version: "system_current", |
| 198 | srcs: ["c.java"], |
| 199 | } |
| 200 | `) |
| 201 | |
Steven Moreland | 0029898 | 2020-11-17 21:44:36 +0000 | [diff] [blame] | 202 | testJavaError(t, "consider adjusting sdk_version: OR platform_apis:", ` |
Jeongik Cha | e403e9e | 2019-12-07 00:16:24 +0900 | [diff] [blame] | 203 | java_library { |
| 204 | name: "foo", |
| 205 | srcs: ["a.java"], |
| 206 | libs: ["bar"], |
| 207 | sdk_version: "system_current", |
| 208 | static_libs: ["baz"], |
| 209 | } |
| 210 | |
| 211 | java_library { |
| 212 | name: "bar", |
| 213 | sdk_version: "current", |
| 214 | srcs: ["b.java"], |
| 215 | } |
| 216 | |
| 217 | java_library { |
| 218 | name: "baz", |
| 219 | srcs: ["c.java"], |
| 220 | } |
| 221 | `) |
| 222 | } |
| 223 | |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 224 | func TestSimple(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 225 | ctx, _ := testJava(t, ` |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 226 | java_library { |
| 227 | name: "foo", |
| 228 | srcs: ["a.java"], |
Colin Cross | e8dc34a | 2017-07-19 11:22:16 -0700 | [diff] [blame] | 229 | libs: ["bar"], |
| 230 | static_libs: ["baz"], |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | java_library { |
| 234 | name: "bar", |
| 235 | srcs: ["b.java"], |
| 236 | } |
| 237 | |
| 238 | java_library { |
| 239 | name: "baz", |
| 240 | srcs: ["c.java"], |
| 241 | } |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 242 | `) |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 243 | |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 244 | javac := ctx.ModuleForTests("foo", "android_common").Rule("javac").RelativeToTop() |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 245 | combineJar := ctx.ModuleForTests("foo", "android_common").Description("for javac") |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 246 | |
| 247 | if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "a.java" { |
| 248 | t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs) |
| 249 | } |
| 250 | |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 251 | baz := ctx.ModuleForTests("baz", "android_common").Rule("javac").Output.String() |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 252 | barTurbine := filepath.Join("out", "soong", ".intermediates", "bar", "android_common", "turbine-combined", "bar.jar") |
| 253 | bazTurbine := filepath.Join("out", "soong", ".intermediates", "baz", "android_common", "turbine-combined", "baz.jar") |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 254 | |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 255 | android.AssertStringDoesContain(t, "foo classpath", javac.Args["classpath"], barTurbine) |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 256 | |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 257 | android.AssertStringDoesContain(t, "foo classpath", javac.Args["classpath"], bazTurbine) |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 258 | |
| 259 | if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != baz { |
| 260 | 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] | 261 | } |
| 262 | } |
| 263 | |
Artur Satayev | 9cf4669 | 2019-11-26 18:08:34 +0000 | [diff] [blame] | 264 | func TestExportedPlugins(t *testing.T) { |
| 265 | type Result struct { |
Colin Cross | c9fe10f | 2020-11-19 18:06:03 -0800 | [diff] [blame] | 266 | library string |
| 267 | processors string |
| 268 | disableTurbine bool |
Artur Satayev | 9cf4669 | 2019-11-26 18:08:34 +0000 | [diff] [blame] | 269 | } |
| 270 | var tests = []struct { |
| 271 | name string |
| 272 | extra string |
| 273 | results []Result |
| 274 | }{ |
| 275 | { |
| 276 | name: "Exported plugin is not a direct plugin", |
| 277 | extra: `java_library { name: "exports", srcs: ["a.java"], exported_plugins: ["plugin"] }`, |
| 278 | results: []Result{{library: "exports", processors: "-proc:none"}}, |
| 279 | }, |
| 280 | { |
| 281 | name: "Exports plugin to dependee", |
| 282 | extra: ` |
| 283 | java_library{name: "exports", exported_plugins: ["plugin"]} |
| 284 | java_library{name: "foo", srcs: ["a.java"], libs: ["exports"]} |
| 285 | java_library{name: "bar", srcs: ["a.java"], static_libs: ["exports"]} |
| 286 | `, |
| 287 | results: []Result{ |
| 288 | {library: "foo", processors: "-processor com.android.TestPlugin"}, |
| 289 | {library: "bar", processors: "-processor com.android.TestPlugin"}, |
| 290 | }, |
| 291 | }, |
| 292 | { |
| 293 | name: "Exports plugin to android_library", |
| 294 | extra: ` |
| 295 | java_library{name: "exports", exported_plugins: ["plugin"]} |
| 296 | android_library{name: "foo", srcs: ["a.java"], libs: ["exports"]} |
| 297 | android_library{name: "bar", srcs: ["a.java"], static_libs: ["exports"]} |
| 298 | `, |
| 299 | results: []Result{ |
| 300 | {library: "foo", processors: "-processor com.android.TestPlugin"}, |
| 301 | {library: "bar", processors: "-processor com.android.TestPlugin"}, |
| 302 | }, |
| 303 | }, |
| 304 | { |
| 305 | name: "Exports plugin is not propagated via transitive deps", |
| 306 | extra: ` |
| 307 | java_library{name: "exports", exported_plugins: ["plugin"]} |
| 308 | java_library{name: "foo", srcs: ["a.java"], libs: ["exports"]} |
| 309 | java_library{name: "bar", srcs: ["a.java"], static_libs: ["foo"]} |
| 310 | `, |
| 311 | results: []Result{ |
| 312 | {library: "foo", processors: "-processor com.android.TestPlugin"}, |
| 313 | {library: "bar", processors: "-proc:none"}, |
| 314 | }, |
| 315 | }, |
| 316 | { |
| 317 | name: "Exports plugin appends to plugins", |
| 318 | extra: ` |
| 319 | java_plugin{name: "plugin2", processor_class: "com.android.TestPlugin2"} |
| 320 | java_library{name: "exports", exported_plugins: ["plugin"]} |
| 321 | java_library{name: "foo", srcs: ["a.java"], libs: ["exports"], plugins: ["plugin2"]} |
| 322 | `, |
| 323 | results: []Result{ |
| 324 | {library: "foo", processors: "-processor com.android.TestPlugin,com.android.TestPlugin2"}, |
| 325 | }, |
| 326 | }, |
Colin Cross | c9fe10f | 2020-11-19 18:06:03 -0800 | [diff] [blame] | 327 | { |
| 328 | name: "Exports plugin to with generates_api to dependee", |
| 329 | extra: ` |
| 330 | java_library{name: "exports", exported_plugins: ["plugin_generates_api"]} |
| 331 | java_library{name: "foo", srcs: ["a.java"], libs: ["exports"]} |
| 332 | java_library{name: "bar", srcs: ["a.java"], static_libs: ["exports"]} |
| 333 | `, |
| 334 | results: []Result{ |
| 335 | {library: "foo", processors: "-processor com.android.TestPlugin", disableTurbine: true}, |
| 336 | {library: "bar", processors: "-processor com.android.TestPlugin", disableTurbine: true}, |
| 337 | }, |
| 338 | }, |
Artur Satayev | 9cf4669 | 2019-11-26 18:08:34 +0000 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | for _, test := range tests { |
| 342 | t.Run(test.name, func(t *testing.T) { |
| 343 | ctx, _ := testJava(t, ` |
| 344 | java_plugin { |
| 345 | name: "plugin", |
| 346 | processor_class: "com.android.TestPlugin", |
| 347 | } |
Colin Cross | c9fe10f | 2020-11-19 18:06:03 -0800 | [diff] [blame] | 348 | java_plugin { |
| 349 | name: "plugin_generates_api", |
| 350 | generates_api: true, |
| 351 | processor_class: "com.android.TestPlugin", |
| 352 | } |
Artur Satayev | 9cf4669 | 2019-11-26 18:08:34 +0000 | [diff] [blame] | 353 | `+test.extra) |
| 354 | |
| 355 | for _, want := range test.results { |
| 356 | javac := ctx.ModuleForTests(want.library, "android_common").Rule("javac") |
| 357 | if javac.Args["processor"] != want.processors { |
| 358 | t.Errorf("For library %v, expected %v, found %v", want.library, want.processors, javac.Args["processor"]) |
| 359 | } |
Colin Cross | c9fe10f | 2020-11-19 18:06:03 -0800 | [diff] [blame] | 360 | turbine := ctx.ModuleForTests(want.library, "android_common").MaybeRule("turbine") |
| 361 | disableTurbine := turbine.BuildParams.Rule == nil |
| 362 | if disableTurbine != want.disableTurbine { |
| 363 | t.Errorf("For library %v, expected disableTurbine %v, found %v", want.library, want.disableTurbine, disableTurbine) |
| 364 | } |
Artur Satayev | 9cf4669 | 2019-11-26 18:08:34 +0000 | [diff] [blame] | 365 | } |
| 366 | }) |
| 367 | } |
| 368 | } |
| 369 | |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 370 | func TestSdkVersionByPartition(t *testing.T) { |
| 371 | 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] | 372 | java_library { |
| 373 | name: "foo", |
| 374 | srcs: ["a.java"], |
| 375 | vendor: true, |
| 376 | } |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 377 | `) |
Jeongik Cha | 6bd33c1 | 2019-06-25 16:26:18 +0900 | [diff] [blame] | 378 | |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 379 | testJava(t, ` |
Jeongik Cha | 6bd33c1 | 2019-06-25 16:26:18 +0900 | [diff] [blame] | 380 | java_library { |
| 381 | name: "bar", |
| 382 | srcs: ["b.java"], |
| 383 | } |
| 384 | `) |
| 385 | |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 386 | for _, enforce := range []bool{true, false} { |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 387 | bp := ` |
| 388 | java_library { |
| 389 | name: "foo", |
| 390 | srcs: ["a.java"], |
| 391 | product_specific: true, |
| 392 | } |
| 393 | ` |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 394 | |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 395 | errorHandler := android.FixtureExpectsNoErrors |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 396 | if enforce { |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 397 | errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern("sdk_version must have a value when the module is located at vendor or product") |
Jeongik Cha | 2cc570d | 2019-10-29 15:44:45 +0900 | [diff] [blame] | 398 | } |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 399 | |
| 400 | android.GroupFixturePreparers( |
| 401 | PrepareForTestWithJavaDefaultModules, |
| 402 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 403 | variables.EnforceProductPartitionInterface = proptools.BoolPtr(enforce) |
| 404 | }), |
| 405 | ). |
| 406 | ExtendWithErrorHandler(errorHandler). |
| 407 | RunTestWithBp(t, bp) |
Jeongik Cha | 6bd33c1 | 2019-06-25 16:26:18 +0900 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 411 | func TestArchSpecific(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 412 | ctx, _ := testJava(t, ` |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 413 | java_library { |
| 414 | name: "foo", |
| 415 | srcs: ["a.java"], |
| 416 | target: { |
| 417 | android: { |
| 418 | srcs: ["b.java"], |
| 419 | }, |
| 420 | }, |
| 421 | } |
| 422 | `) |
| 423 | |
| 424 | javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") |
| 425 | if len(javac.Inputs) != 2 || javac.Inputs[0].String() != "a.java" || javac.Inputs[1].String() != "b.java" { |
| 426 | t.Errorf(`foo inputs %v != ["a.java", "b.java"]`, javac.Inputs) |
| 427 | } |
| 428 | } |
| 429 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 430 | func TestBinary(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 431 | ctx, _ := testJava(t, ` |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 432 | java_library_host { |
| 433 | name: "foo", |
| 434 | srcs: ["a.java"], |
| 435 | } |
| 436 | |
| 437 | java_binary_host { |
| 438 | name: "bar", |
| 439 | srcs: ["b.java"], |
| 440 | static_libs: ["foo"], |
Colin Cross | 89226d9 | 2020-10-09 19:00:54 -0700 | [diff] [blame] | 441 | jni_libs: ["libjni"], |
| 442 | } |
| 443 | |
| 444 | cc_library_shared { |
| 445 | name: "libjni", |
| 446 | host_supported: true, |
| 447 | device_supported: false, |
| 448 | stl: "none", |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 449 | } |
| 450 | `) |
| 451 | |
| 452 | buildOS := android.BuildOs.String() |
| 453 | |
| 454 | bar := ctx.ModuleForTests("bar", buildOS+"_common") |
| 455 | barJar := bar.Output("bar.jar").Output.String() |
| 456 | barWrapper := ctx.ModuleForTests("bar", buildOS+"_x86_64") |
| 457 | barWrapperDeps := barWrapper.Output("bar").Implicits.Strings() |
| 458 | |
Colin Cross | 89226d9 | 2020-10-09 19:00:54 -0700 | [diff] [blame] | 459 | libjni := ctx.ModuleForTests("libjni", buildOS+"_x86_64_shared") |
| 460 | libjniSO := libjni.Rule("Cp").Output.String() |
| 461 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 462 | // Test that the install binary wrapper depends on the installed jar file |
Colin Cross | c179ea6 | 2020-10-09 10:54:15 -0700 | [diff] [blame] | 463 | if g, w := barWrapperDeps, barJar; !android.InList(w, g) { |
| 464 | t.Errorf("expected binary wrapper implicits to contain %q, got %q", w, g) |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 465 | } |
Colin Cross | 89226d9 | 2020-10-09 19:00:54 -0700 | [diff] [blame] | 466 | |
| 467 | // Test that the install binary wrapper depends on the installed JNI libraries |
| 468 | if g, w := barWrapperDeps, libjniSO; !android.InList(w, g) { |
| 469 | t.Errorf("expected binary wrapper implicits to contain %q, got %q", w, g) |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 470 | } |
Alex Humesky | 2070e32 | 2020-06-09 20:23:08 -0400 | [diff] [blame] | 471 | } |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 472 | |
Alex Humesky | 2070e32 | 2020-06-09 20:23:08 -0400 | [diff] [blame] | 473 | func TestHostBinaryNoJavaDebugInfoOverride(t *testing.T) { |
| 474 | bp := ` |
| 475 | java_library { |
| 476 | name: "target_library", |
| 477 | srcs: ["a.java"], |
| 478 | } |
| 479 | |
| 480 | java_binary_host { |
| 481 | name: "host_binary", |
| 482 | srcs: ["b.java"], |
| 483 | } |
| 484 | ` |
Alex Humesky | 2070e32 | 2020-06-09 20:23:08 -0400 | [diff] [blame] | 485 | |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 486 | result := android.GroupFixturePreparers( |
| 487 | PrepareForTestWithJavaDefaultModules, |
| 488 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 489 | variables.MinimizeJavaDebugInfo = proptools.BoolPtr(true) |
| 490 | }), |
| 491 | ).RunTestWithBp(t, bp) |
Alex Humesky | 2070e32 | 2020-06-09 20:23:08 -0400 | [diff] [blame] | 492 | |
Liz Kammer | 7941b30 | 2020-07-28 13:27:34 -0700 | [diff] [blame] | 493 | // first, check that the -g flag is added to target modules |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 494 | targetLibrary := result.ModuleForTests("target_library", "android_common") |
Alex Humesky | 2070e32 | 2020-06-09 20:23:08 -0400 | [diff] [blame] | 495 | targetJavaFlags := targetLibrary.Module().VariablesForTests()["javacFlags"] |
| 496 | if !strings.Contains(targetJavaFlags, "-g:source,lines") { |
| 497 | t.Errorf("target library javac flags %v should contain "+ |
| 498 | "-g:source,lines override with MinimizeJavaDebugInfo", targetJavaFlags) |
| 499 | } |
| 500 | |
| 501 | // check that -g is not overridden for host modules |
| 502 | buildOS := android.BuildOs.String() |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 503 | hostBinary := result.ModuleForTests("host_binary", buildOS+"_common") |
Alex Humesky | 2070e32 | 2020-06-09 20:23:08 -0400 | [diff] [blame] | 504 | hostJavaFlags := hostBinary.Module().VariablesForTests()["javacFlags"] |
| 505 | if strings.Contains(hostJavaFlags, "-g:source,lines") { |
| 506 | t.Errorf("java_binary_host javac flags %v should not have "+ |
| 507 | "-g:source,lines override with MinimizeJavaDebugInfo", hostJavaFlags) |
| 508 | } |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 509 | } |
| 510 | |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 511 | func TestPrebuilts(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 512 | ctx, _ := testJava(t, ` |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 513 | java_library { |
| 514 | name: "foo", |
Paul Duffin | 9154718 | 2019-11-12 19:39:36 +0000 | [diff] [blame] | 515 | srcs: ["a.java", ":stubs-source"], |
Paul Duffin | fcfd791 | 2020-01-31 17:54:30 +0000 | [diff] [blame] | 516 | libs: ["bar", "sdklib"], |
Colin Cross | e8dc34a | 2017-07-19 11:22:16 -0700 | [diff] [blame] | 517 | static_libs: ["baz"], |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 518 | } |
| 519 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 520 | java_import { |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 521 | name: "bar", |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 522 | jars: ["a.jar"], |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 523 | } |
| 524 | |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 525 | java_import { |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 526 | name: "baz", |
Colin Cross | 74d73e2 | 2017-08-02 11:05:49 -0700 | [diff] [blame] | 527 | jars: ["b.jar"], |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 528 | sdk_version: "current", |
| 529 | compile_dex: true, |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 530 | } |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 531 | |
| 532 | dex_import { |
| 533 | name: "qux", |
| 534 | jars: ["b.jar"], |
| 535 | } |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 536 | |
| 537 | java_sdk_library_import { |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 538 | name: "sdklib", |
| 539 | public: { |
| 540 | jars: ["c.jar"], |
| 541 | }, |
| 542 | } |
| 543 | |
Paul Duffin | 9154718 | 2019-11-12 19:39:36 +0000 | [diff] [blame] | 544 | prebuilt_stubs_sources { |
| 545 | name: "stubs-source", |
Paul Duffin | 9b478b0 | 2019-12-10 13:41:51 +0000 | [diff] [blame] | 546 | srcs: ["stubs/sources"], |
Paul Duffin | 9154718 | 2019-11-12 19:39:36 +0000 | [diff] [blame] | 547 | } |
Paul Duffin | 1b82e6a | 2019-12-03 18:06:47 +0000 | [diff] [blame] | 548 | |
| 549 | java_test_import { |
| 550 | name: "test", |
| 551 | jars: ["a.jar"], |
| 552 | test_suites: ["cts"], |
| 553 | test_config: "AndroidTest.xml", |
| 554 | } |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 555 | `) |
| 556 | |
Paul Duffin | 9b478b0 | 2019-12-10 13:41:51 +0000 | [diff] [blame] | 557 | fooModule := ctx.ModuleForTests("foo", "android_common") |
| 558 | javac := fooModule.Rule("javac") |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 559 | combineJar := ctx.ModuleForTests("foo", "android_common").Description("for javac") |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 560 | barModule := ctx.ModuleForTests("bar", "android_common") |
| 561 | barJar := barModule.Rule("combineJar").Output |
| 562 | bazModule := ctx.ModuleForTests("baz", "android_common") |
| 563 | bazJar := bazModule.Rule("combineJar").Output |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 564 | sdklibStubsJar := ctx.ModuleForTests("sdklib.stubs", "android_common").Rule("combineJar").Output |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 565 | |
Paul Duffin | 9b478b0 | 2019-12-10 13:41:51 +0000 | [diff] [blame] | 566 | fooLibrary := fooModule.Module().(*Library) |
| 567 | assertDeepEquals(t, "foo java sources incorrect", |
| 568 | []string{"a.java"}, fooLibrary.compiledJavaSrcs.Strings()) |
Paul Duffin | 9154718 | 2019-11-12 19:39:36 +0000 | [diff] [blame] | 569 | |
Paul Duffin | 9b478b0 | 2019-12-10 13:41:51 +0000 | [diff] [blame] | 570 | assertDeepEquals(t, "foo java source jars incorrect", |
| 571 | []string{".intermediates/stubs-source/android_common/stubs-source-stubs.srcjar"}, |
| 572 | android.NormalizePathsForTesting(fooLibrary.compiledSrcJars)) |
Paul Duffin | 9154718 | 2019-11-12 19:39:36 +0000 | [diff] [blame] | 573 | |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 574 | if !strings.Contains(javac.Args["classpath"], barJar.String()) { |
| 575 | 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] | 576 | } |
| 577 | |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 578 | barDexJar := barModule.Module().(*Import).DexJarBuildPath() |
| 579 | if barDexJar != nil { |
| 580 | t.Errorf("bar dex jar build path expected to be nil, got %q", barDexJar) |
| 581 | } |
| 582 | |
Colin Cross | 79c7c26 | 2019-04-17 11:11:46 -0700 | [diff] [blame] | 583 | if !strings.Contains(javac.Args["classpath"], sdklibStubsJar.String()) { |
| 584 | t.Errorf("foo classpath %v does not contain %q", javac.Args["classpath"], sdklibStubsJar.String()) |
| 585 | } |
| 586 | |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 587 | if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != bazJar.String() { |
| 588 | 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] | 589 | } |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 590 | |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 591 | bazDexJar := bazModule.Module().(*Import).DexJarBuildPath() |
| 592 | expectedDexJar := "out/soong/.intermediates/baz/android_common/dex/baz.jar" |
| 593 | android.AssertPathRelativeToTopEquals(t, "baz dex jar build path", expectedDexJar, bazDexJar) |
Liz Kammer | d6c31d2 | 2020-08-05 15:40:41 -0700 | [diff] [blame] | 594 | |
Colin Cross | 42be761 | 2019-02-21 18:12:14 -0800 | [diff] [blame] | 595 | ctx.ModuleForTests("qux", "android_common").Rule("Cp") |
Colin Cross | 72bb363 | 2017-07-13 16:23:21 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Paul Duffin | 9b478b0 | 2019-12-10 13:41:51 +0000 | [diff] [blame] | 598 | func assertDeepEquals(t *testing.T, message string, expected interface{}, actual interface{}) { |
| 599 | if !reflect.DeepEqual(expected, actual) { |
| 600 | t.Errorf("%s: expected %q, found %q", message, expected, actual) |
| 601 | } |
| 602 | } |
| 603 | |
Paul Duffin | 1a39332 | 2020-11-18 16:36:47 +0000 | [diff] [blame] | 604 | func TestPrebuiltStubsSources(t *testing.T) { |
| 605 | test := func(t *testing.T, sourcesPath string, expectedInputs []string) { |
| 606 | ctx, _ := testJavaWithFS(t, fmt.Sprintf(` |
| 607 | prebuilt_stubs_sources { |
| 608 | name: "stubs-source", |
| 609 | srcs: ["%s"], |
| 610 | }`, sourcesPath), map[string][]byte{ |
| 611 | "stubs/sources/pkg/A.java": nil, |
| 612 | "stubs/sources/pkg/B.java": nil, |
| 613 | }) |
| 614 | |
| 615 | zipSrc := ctx.ModuleForTests("stubs-source", "android_common").Rule("zip_src") |
| 616 | if expected, actual := expectedInputs, zipSrc.Inputs.Strings(); !reflect.DeepEqual(expected, actual) { |
| 617 | t.Errorf("mismatch of inputs to soong_zip: expected %q, actual %q", expected, actual) |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | t.Run("empty/missing directory", func(t *testing.T) { |
| 622 | test(t, "empty-directory", []string{}) |
| 623 | }) |
| 624 | |
| 625 | t.Run("non-empty set of sources", func(t *testing.T) { |
| 626 | test(t, "stubs/sources", []string{ |
| 627 | "stubs/sources/pkg/A.java", |
| 628 | "stubs/sources/pkg/B.java", |
| 629 | }) |
| 630 | }) |
| 631 | } |
| 632 | |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 633 | func TestJavaSdkLibraryImport(t *testing.T) { |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 634 | result := prepareForJavaTest.RunTestWithBp(t, ` |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 635 | java_library { |
| 636 | name: "foo", |
| 637 | srcs: ["a.java"], |
| 638 | libs: ["sdklib"], |
| 639 | sdk_version: "current", |
| 640 | } |
| 641 | |
| 642 | java_library { |
| 643 | name: "foo.system", |
| 644 | srcs: ["a.java"], |
| 645 | libs: ["sdklib"], |
| 646 | sdk_version: "system_current", |
| 647 | } |
| 648 | |
| 649 | java_library { |
| 650 | name: "foo.test", |
| 651 | srcs: ["a.java"], |
| 652 | libs: ["sdklib"], |
| 653 | sdk_version: "test_current", |
| 654 | } |
| 655 | |
| 656 | java_sdk_library_import { |
| 657 | name: "sdklib", |
| 658 | public: { |
| 659 | jars: ["a.jar"], |
| 660 | }, |
| 661 | system: { |
| 662 | jars: ["b.jar"], |
| 663 | }, |
| 664 | test: { |
| 665 | jars: ["c.jar"], |
Paul Duffin | 0f8faff | 2020-05-20 16:18:00 +0100 | [diff] [blame] | 666 | stub_srcs: ["c.java"], |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 667 | }, |
| 668 | } |
| 669 | `) |
| 670 | |
| 671 | for _, scope := range []string{"", ".system", ".test"} { |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 672 | fooModule := result.ModuleForTests("foo"+scope, "android_common") |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 673 | javac := fooModule.Rule("javac") |
| 674 | |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 675 | sdklibStubsJar := result.ModuleForTests("sdklib.stubs"+scope, "android_common").Rule("combineJar").Output |
| 676 | android.AssertStringDoesContain(t, "foo classpath", javac.Args["classpath"], sdklibStubsJar.String()) |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 677 | } |
Paul Duffin | ca8d9a5 | 2020-06-26 22:20:25 +0100 | [diff] [blame] | 678 | |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 679 | CheckModuleDependencies(t, result.TestContext, "sdklib", "android_common", []string{ |
Paul Duffin | ca8d9a5 | 2020-06-26 22:20:25 +0100 | [diff] [blame] | 680 | `prebuilt_sdklib.stubs`, |
| 681 | `prebuilt_sdklib.stubs.source.test`, |
| 682 | `prebuilt_sdklib.stubs.system`, |
| 683 | `prebuilt_sdklib.stubs.test`, |
| 684 | }) |
| 685 | } |
| 686 | |
| 687 | func TestJavaSdkLibraryImport_WithSource(t *testing.T) { |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 688 | result := android.GroupFixturePreparers( |
| 689 | prepareForJavaTest, |
Paul Duffin | 163043d | 2021-03-12 19:18:49 +0000 | [diff] [blame] | 690 | PrepareForTestWithJavaSdkLibraryFiles, |
| 691 | FixtureWithLastReleaseApis("sdklib"), |
| 692 | ).RunTestWithBp(t, ` |
Paul Duffin | ca8d9a5 | 2020-06-26 22:20:25 +0100 | [diff] [blame] | 693 | java_sdk_library { |
| 694 | name: "sdklib", |
| 695 | srcs: ["a.java"], |
| 696 | sdk_version: "none", |
| 697 | system_modules: "none", |
| 698 | public: { |
| 699 | enabled: true, |
| 700 | }, |
| 701 | } |
| 702 | |
| 703 | java_sdk_library_import { |
| 704 | name: "sdklib", |
| 705 | public: { |
| 706 | jars: ["a.jar"], |
| 707 | }, |
| 708 | } |
| 709 | `) |
| 710 | |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 711 | CheckModuleDependencies(t, result.TestContext, "sdklib", "android_common", []string{ |
Paul Duffin | ca8d9a5 | 2020-06-26 22:20:25 +0100 | [diff] [blame] | 712 | `dex2oatd`, |
| 713 | `prebuilt_sdklib`, |
| 714 | `sdklib.impl`, |
| 715 | `sdklib.stubs`, |
| 716 | `sdklib.stubs.source`, |
| 717 | `sdklib.xml`, |
| 718 | }) |
| 719 | |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 720 | CheckModuleDependencies(t, result.TestContext, "prebuilt_sdklib", "android_common", []string{ |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 721 | `prebuilt_sdklib.stubs`, |
Paul Duffin | ca8d9a5 | 2020-06-26 22:20:25 +0100 | [diff] [blame] | 722 | `sdklib.impl`, |
| 723 | // This should be prebuilt_sdklib.stubs but is set to sdklib.stubs because the |
| 724 | // dependency is added after prebuilts may have been renamed and so has to use |
| 725 | // the renamed name. |
Paul Duffin | ca8d9a5 | 2020-06-26 22:20:25 +0100 | [diff] [blame] | 726 | `sdklib.xml`, |
| 727 | }) |
| 728 | } |
| 729 | |
| 730 | func TestJavaSdkLibraryImport_Preferred(t *testing.T) { |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 731 | result := android.GroupFixturePreparers( |
| 732 | prepareForJavaTest, |
Paul Duffin | 163043d | 2021-03-12 19:18:49 +0000 | [diff] [blame] | 733 | PrepareForTestWithJavaSdkLibraryFiles, |
| 734 | FixtureWithLastReleaseApis("sdklib"), |
| 735 | ).RunTestWithBp(t, ` |
Paul Duffin | ca8d9a5 | 2020-06-26 22:20:25 +0100 | [diff] [blame] | 736 | java_sdk_library { |
| 737 | name: "sdklib", |
| 738 | srcs: ["a.java"], |
| 739 | sdk_version: "none", |
| 740 | system_modules: "none", |
| 741 | public: { |
| 742 | enabled: true, |
| 743 | }, |
| 744 | } |
| 745 | |
| 746 | java_sdk_library_import { |
| 747 | name: "sdklib", |
| 748 | prefer: true, |
| 749 | public: { |
| 750 | jars: ["a.jar"], |
| 751 | }, |
| 752 | } |
| 753 | `) |
| 754 | |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 755 | CheckModuleDependencies(t, result.TestContext, "sdklib", "android_common", []string{ |
Paul Duffin | ca8d9a5 | 2020-06-26 22:20:25 +0100 | [diff] [blame] | 756 | `dex2oatd`, |
| 757 | `prebuilt_sdklib`, |
Paul Duffin | ca8d9a5 | 2020-06-26 22:20:25 +0100 | [diff] [blame] | 758 | `sdklib.impl`, |
Paul Duffin | 80342d7 | 2020-06-26 22:08:43 +0100 | [diff] [blame] | 759 | `sdklib.stubs`, |
Paul Duffin | ca8d9a5 | 2020-06-26 22:20:25 +0100 | [diff] [blame] | 760 | `sdklib.stubs.source`, |
| 761 | `sdklib.xml`, |
| 762 | }) |
| 763 | |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 764 | CheckModuleDependencies(t, result.TestContext, "prebuilt_sdklib", "android_common", []string{ |
Paul Duffin | ca8d9a5 | 2020-06-26 22:20:25 +0100 | [diff] [blame] | 765 | `prebuilt_sdklib.stubs`, |
| 766 | `sdklib.impl`, |
| 767 | `sdklib.xml`, |
| 768 | }) |
Paul Duffin | 56d4490 | 2020-01-31 13:36:25 +0000 | [diff] [blame] | 769 | } |
| 770 | |
JaeMan Park | ff71556 | 2020-10-19 17:25:58 +0900 | [diff] [blame] | 771 | func TestJavaSdkLibraryEnforce(t *testing.T) { |
| 772 | partitionToBpOption := func(partition string) string { |
| 773 | switch partition { |
| 774 | case "system": |
| 775 | return "" |
| 776 | case "vendor": |
| 777 | return "soc_specific: true," |
| 778 | case "product": |
| 779 | return "product_specific: true," |
| 780 | default: |
| 781 | panic("Invalid partition group name: " + partition) |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | type testConfigInfo struct { |
| 786 | libraryType string |
| 787 | fromPartition string |
| 788 | toPartition string |
| 789 | enforceVendorInterface bool |
| 790 | enforceProductInterface bool |
| 791 | enforceJavaSdkLibraryCheck bool |
| 792 | allowList []string |
| 793 | } |
| 794 | |
Paul Duffin | 05f72de | 2021-03-12 21:28:51 +0000 | [diff] [blame] | 795 | createPreparer := func(info testConfigInfo) android.FixturePreparer { |
JaeMan Park | ff71556 | 2020-10-19 17:25:58 +0900 | [diff] [blame] | 796 | bpFileTemplate := ` |
| 797 | java_library { |
| 798 | name: "foo", |
| 799 | srcs: ["foo.java"], |
| 800 | libs: ["bar"], |
| 801 | sdk_version: "current", |
| 802 | %s |
| 803 | } |
| 804 | |
| 805 | %s { |
| 806 | name: "bar", |
| 807 | srcs: ["bar.java"], |
| 808 | sdk_version: "current", |
| 809 | %s |
| 810 | } |
| 811 | ` |
| 812 | |
| 813 | bpFile := fmt.Sprintf(bpFileTemplate, |
| 814 | partitionToBpOption(info.fromPartition), |
| 815 | info.libraryType, |
| 816 | partitionToBpOption(info.toPartition)) |
| 817 | |
Paul Duffin | 05f72de | 2021-03-12 21:28:51 +0000 | [diff] [blame] | 818 | return android.GroupFixturePreparers( |
Paul Duffin | 163043d | 2021-03-12 19:18:49 +0000 | [diff] [blame] | 819 | PrepareForTestWithJavaSdkLibraryFiles, |
| 820 | FixtureWithLastReleaseApis("bar"), |
Paul Duffin | 05f72de | 2021-03-12 21:28:51 +0000 | [diff] [blame] | 821 | android.FixtureWithRootAndroidBp(bpFile), |
| 822 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 823 | variables.EnforceProductPartitionInterface = proptools.BoolPtr(info.enforceProductInterface) |
| 824 | if info.enforceVendorInterface { |
| 825 | variables.DeviceVndkVersion = proptools.StringPtr("current") |
| 826 | } |
| 827 | variables.EnforceInterPartitionJavaSdkLibrary = proptools.BoolPtr(info.enforceJavaSdkLibraryCheck) |
| 828 | variables.InterPartitionJavaLibraryAllowList = info.allowList |
| 829 | }), |
| 830 | ) |
JaeMan Park | ff71556 | 2020-10-19 17:25:58 +0900 | [diff] [blame] | 831 | } |
| 832 | |
Paul Duffin | aa6caa7 | 2021-03-13 16:50:15 +0000 | [diff] [blame] | 833 | runTest := func(t *testing.T, info testConfigInfo, expectedErrorPattern string) { |
| 834 | t.Run(fmt.Sprintf("%#v", info), func(t *testing.T) { |
Paul Duffin | 05f72de | 2021-03-12 21:28:51 +0000 | [diff] [blame] | 835 | errorHandler := android.FixtureExpectsNoErrors |
| 836 | if expectedErrorPattern != "" { |
| 837 | errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(expectedErrorPattern) |
Paul Duffin | aa6caa7 | 2021-03-13 16:50:15 +0000 | [diff] [blame] | 838 | } |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 839 | prepareForJavaTest.ExtendWithErrorHandler(errorHandler).RunTest(t, createPreparer(info)) |
Paul Duffin | aa6caa7 | 2021-03-13 16:50:15 +0000 | [diff] [blame] | 840 | }) |
| 841 | } |
| 842 | |
JaeMan Park | ff71556 | 2020-10-19 17:25:58 +0900 | [diff] [blame] | 843 | errorMessage := "is not allowed across the partitions" |
| 844 | |
Paul Duffin | aa6caa7 | 2021-03-13 16:50:15 +0000 | [diff] [blame] | 845 | runTest(t, testConfigInfo{ |
JaeMan Park | 90e7535 | 2021-01-14 11:56:56 +0900 | [diff] [blame] | 846 | libraryType: "java_library", |
| 847 | fromPartition: "product", |
| 848 | toPartition: "system", |
| 849 | enforceVendorInterface: true, |
| 850 | enforceProductInterface: true, |
| 851 | enforceJavaSdkLibraryCheck: false, |
Paul Duffin | aa6caa7 | 2021-03-13 16:50:15 +0000 | [diff] [blame] | 852 | }, "") |
JaeMan Park | ff71556 | 2020-10-19 17:25:58 +0900 | [diff] [blame] | 853 | |
Paul Duffin | aa6caa7 | 2021-03-13 16:50:15 +0000 | [diff] [blame] | 854 | runTest(t, testConfigInfo{ |
JaeMan Park | 90e7535 | 2021-01-14 11:56:56 +0900 | [diff] [blame] | 855 | libraryType: "java_library", |
| 856 | fromPartition: "product", |
| 857 | toPartition: "system", |
| 858 | enforceVendorInterface: true, |
| 859 | enforceProductInterface: false, |
| 860 | enforceJavaSdkLibraryCheck: true, |
Paul Duffin | aa6caa7 | 2021-03-13 16:50:15 +0000 | [diff] [blame] | 861 | }, "") |
JaeMan Park | ff71556 | 2020-10-19 17:25:58 +0900 | [diff] [blame] | 862 | |
Paul Duffin | aa6caa7 | 2021-03-13 16:50:15 +0000 | [diff] [blame] | 863 | runTest(t, testConfigInfo{ |
JaeMan Park | 90e7535 | 2021-01-14 11:56:56 +0900 | [diff] [blame] | 864 | libraryType: "java_library", |
| 865 | fromPartition: "product", |
| 866 | toPartition: "system", |
| 867 | enforceVendorInterface: true, |
| 868 | enforceProductInterface: true, |
| 869 | enforceJavaSdkLibraryCheck: true, |
Paul Duffin | aa6caa7 | 2021-03-13 16:50:15 +0000 | [diff] [blame] | 870 | }, errorMessage) |
JaeMan Park | ff71556 | 2020-10-19 17:25:58 +0900 | [diff] [blame] | 871 | |
Paul Duffin | aa6caa7 | 2021-03-13 16:50:15 +0000 | [diff] [blame] | 872 | runTest(t, testConfigInfo{ |
JaeMan Park | 90e7535 | 2021-01-14 11:56:56 +0900 | [diff] [blame] | 873 | libraryType: "java_library", |
| 874 | fromPartition: "vendor", |
| 875 | toPartition: "system", |
| 876 | enforceVendorInterface: true, |
| 877 | enforceProductInterface: true, |
| 878 | enforceJavaSdkLibraryCheck: true, |
Paul Duffin | aa6caa7 | 2021-03-13 16:50:15 +0000 | [diff] [blame] | 879 | }, errorMessage) |
JaeMan Park | ff71556 | 2020-10-19 17:25:58 +0900 | [diff] [blame] | 880 | |
Paul Duffin | aa6caa7 | 2021-03-13 16:50:15 +0000 | [diff] [blame] | 881 | runTest(t, testConfigInfo{ |
JaeMan Park | ff71556 | 2020-10-19 17:25:58 +0900 | [diff] [blame] | 882 | libraryType: "java_library", |
| 883 | fromPartition: "vendor", |
| 884 | toPartition: "system", |
| 885 | enforceVendorInterface: true, |
| 886 | enforceProductInterface: true, |
| 887 | enforceJavaSdkLibraryCheck: true, |
| 888 | allowList: []string{"bar"}, |
Paul Duffin | aa6caa7 | 2021-03-13 16:50:15 +0000 | [diff] [blame] | 889 | }, "") |
JaeMan Park | ff71556 | 2020-10-19 17:25:58 +0900 | [diff] [blame] | 890 | |
Paul Duffin | aa6caa7 | 2021-03-13 16:50:15 +0000 | [diff] [blame] | 891 | runTest(t, testConfigInfo{ |
JaeMan Park | ff71556 | 2020-10-19 17:25:58 +0900 | [diff] [blame] | 892 | libraryType: "java_library", |
| 893 | fromPartition: "vendor", |
JaeMan Park | 90e7535 | 2021-01-14 11:56:56 +0900 | [diff] [blame] | 894 | toPartition: "product", |
| 895 | enforceVendorInterface: true, |
| 896 | enforceProductInterface: true, |
| 897 | enforceJavaSdkLibraryCheck: true, |
Paul Duffin | aa6caa7 | 2021-03-13 16:50:15 +0000 | [diff] [blame] | 898 | }, errorMessage) |
JaeMan Park | 90e7535 | 2021-01-14 11:56:56 +0900 | [diff] [blame] | 899 | |
Paul Duffin | aa6caa7 | 2021-03-13 16:50:15 +0000 | [diff] [blame] | 900 | runTest(t, testConfigInfo{ |
JaeMan Park | 90e7535 | 2021-01-14 11:56:56 +0900 | [diff] [blame] | 901 | libraryType: "java_sdk_library", |
| 902 | fromPartition: "product", |
JaeMan Park | ff71556 | 2020-10-19 17:25:58 +0900 | [diff] [blame] | 903 | toPartition: "system", |
| 904 | enforceVendorInterface: true, |
| 905 | enforceProductInterface: true, |
| 906 | enforceJavaSdkLibraryCheck: true, |
Paul Duffin | aa6caa7 | 2021-03-13 16:50:15 +0000 | [diff] [blame] | 907 | }, "") |
JaeMan Park | 90e7535 | 2021-01-14 11:56:56 +0900 | [diff] [blame] | 908 | |
Paul Duffin | aa6caa7 | 2021-03-13 16:50:15 +0000 | [diff] [blame] | 909 | runTest(t, testConfigInfo{ |
JaeMan Park | 90e7535 | 2021-01-14 11:56:56 +0900 | [diff] [blame] | 910 | libraryType: "java_sdk_library", |
| 911 | fromPartition: "vendor", |
| 912 | toPartition: "system", |
| 913 | enforceVendorInterface: true, |
| 914 | enforceProductInterface: true, |
| 915 | enforceJavaSdkLibraryCheck: true, |
Paul Duffin | aa6caa7 | 2021-03-13 16:50:15 +0000 | [diff] [blame] | 916 | }, "") |
JaeMan Park | 90e7535 | 2021-01-14 11:56:56 +0900 | [diff] [blame] | 917 | |
Paul Duffin | aa6caa7 | 2021-03-13 16:50:15 +0000 | [diff] [blame] | 918 | runTest(t, testConfigInfo{ |
JaeMan Park | 90e7535 | 2021-01-14 11:56:56 +0900 | [diff] [blame] | 919 | libraryType: "java_sdk_library", |
| 920 | fromPartition: "vendor", |
| 921 | toPartition: "product", |
| 922 | enforceVendorInterface: true, |
| 923 | enforceProductInterface: true, |
| 924 | enforceJavaSdkLibraryCheck: true, |
Paul Duffin | aa6caa7 | 2021-03-13 16:50:15 +0000 | [diff] [blame] | 925 | }, "") |
JaeMan Park | ff71556 | 2020-10-19 17:25:58 +0900 | [diff] [blame] | 926 | } |
| 927 | |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 928 | func TestDefaults(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 929 | ctx, _ := testJava(t, ` |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 930 | java_defaults { |
| 931 | name: "defaults", |
| 932 | srcs: ["a.java"], |
| 933 | libs: ["bar"], |
| 934 | static_libs: ["baz"], |
Sasha Smundak | 2057f82 | 2019-04-16 17:16:58 -0700 | [diff] [blame] | 935 | optimize: {enabled: false}, |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | java_library { |
| 939 | name: "foo", |
| 940 | defaults: ["defaults"], |
| 941 | } |
| 942 | |
| 943 | java_library { |
| 944 | name: "bar", |
| 945 | srcs: ["b.java"], |
| 946 | } |
| 947 | |
| 948 | java_library { |
| 949 | name: "baz", |
| 950 | srcs: ["c.java"], |
| 951 | } |
Sasha Smundak | 2057f82 | 2019-04-16 17:16:58 -0700 | [diff] [blame] | 952 | |
| 953 | android_test { |
| 954 | name: "atestOptimize", |
| 955 | defaults: ["defaults"], |
| 956 | optimize: {enabled: true}, |
| 957 | } |
| 958 | |
| 959 | android_test { |
| 960 | name: "atestNoOptimize", |
| 961 | defaults: ["defaults"], |
| 962 | } |
| 963 | |
| 964 | android_test { |
| 965 | name: "atestDefault", |
| 966 | srcs: ["a.java"], |
| 967 | } |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 968 | `) |
| 969 | |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 970 | javac := ctx.ModuleForTests("foo", "android_common").Rule("javac").RelativeToTop() |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 971 | combineJar := ctx.ModuleForTests("foo", "android_common").Description("for javac") |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 972 | |
| 973 | if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "a.java" { |
| 974 | t.Errorf(`foo inputs %v != ["a.java"]`, javac.Inputs) |
| 975 | } |
| 976 | |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 977 | barTurbine := filepath.Join("out", "soong", ".intermediates", "bar", "android_common", "turbine-combined", "bar.jar") |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 978 | if !strings.Contains(javac.Args["classpath"], barTurbine) { |
| 979 | 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] | 980 | } |
| 981 | |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 982 | baz := ctx.ModuleForTests("baz", "android_common").Rule("javac").Output.String() |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 983 | if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != baz { |
| 984 | 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] | 985 | } |
Sasha Smundak | 2057f82 | 2019-04-16 17:16:58 -0700 | [diff] [blame] | 986 | |
| 987 | atestOptimize := ctx.ModuleForTests("atestOptimize", "android_common").MaybeRule("r8") |
| 988 | if atestOptimize.Output == nil { |
| 989 | t.Errorf("atestOptimize should optimize APK") |
| 990 | } |
| 991 | |
| 992 | atestNoOptimize := ctx.ModuleForTests("atestNoOptimize", "android_common").MaybeRule("d8") |
| 993 | if atestNoOptimize.Output == nil { |
| 994 | t.Errorf("atestNoOptimize should not optimize APK") |
| 995 | } |
| 996 | |
| 997 | atestDefault := ctx.ModuleForTests("atestDefault", "android_common").MaybeRule("r8") |
| 998 | if atestDefault.Output == nil { |
| 999 | t.Errorf("atestDefault should optimize APK") |
| 1000 | } |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 1003 | func TestResources(t *testing.T) { |
| 1004 | var table = []struct { |
| 1005 | name string |
| 1006 | prop string |
| 1007 | extra string |
| 1008 | args string |
| 1009 | }{ |
| 1010 | { |
Colin Cross | af9c55b | 2017-10-03 14:50:08 -0700 | [diff] [blame] | 1011 | // Test that a module with java_resource_dirs includes the files |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 1012 | name: "resource dirs", |
Colin Cross | 824bee3 | 2017-11-22 17:27:51 -0800 | [diff] [blame] | 1013 | prop: `java_resource_dirs: ["java-res"]`, |
Colin Cross | 0ead1d7 | 2018-04-10 13:07:42 -0700 | [diff] [blame] | 1014 | 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] | 1015 | }, |
| 1016 | { |
| 1017 | // Test that a module with java_resources includes the files |
| 1018 | name: "resource files", |
Colin Cross | 0ead1d7 | 2018-04-10 13:07:42 -0700 | [diff] [blame] | 1019 | prop: `java_resources: ["java-res/a/a", "java-res/b/b"]`, |
| 1020 | args: "-C . -f java-res/a/a -f java-res/b/b", |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 1021 | }, |
| 1022 | { |
| 1023 | // Test that a module with a filegroup in java_resources includes the files with the |
| 1024 | // path prefix |
| 1025 | name: "resource filegroup", |
| 1026 | prop: `java_resources: [":foo-res"]`, |
| 1027 | extra: ` |
| 1028 | filegroup { |
| 1029 | name: "foo-res", |
Colin Cross | 824bee3 | 2017-11-22 17:27:51 -0800 | [diff] [blame] | 1030 | path: "java-res", |
Colin Cross | 0ead1d7 | 2018-04-10 13:07:42 -0700 | [diff] [blame] | 1031 | srcs: ["java-res/a/a", "java-res/b/b"], |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 1032 | }`, |
Colin Cross | 0ead1d7 | 2018-04-10 13:07:42 -0700 | [diff] [blame] | 1033 | 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] | 1034 | }, |
| 1035 | { |
Colin Cross | 0ead1d7 | 2018-04-10 13:07:42 -0700 | [diff] [blame] | 1036 | // Test that a module with wildcards in java_resource_dirs has the correct path prefixes |
| 1037 | name: "wildcard dirs", |
| 1038 | prop: `java_resource_dirs: ["java-res/*"]`, |
| 1039 | args: "-C java-res/a -f java-res/a/a -C java-res/b -f java-res/b/b", |
| 1040 | }, |
| 1041 | { |
| 1042 | // Test that a module exclude_java_resource_dirs excludes the files |
| 1043 | name: "wildcard dirs", |
| 1044 | prop: `java_resource_dirs: ["java-res/*"], exclude_java_resource_dirs: ["java-res/b"]`, |
| 1045 | args: "-C java-res/a -f java-res/a/a", |
| 1046 | }, |
Colin Cross | cedd476 | 2018-09-13 11:26:19 -0700 | [diff] [blame] | 1047 | { |
| 1048 | // Test wildcards in java_resources |
| 1049 | name: "wildcard files", |
| 1050 | prop: `java_resources: ["java-res/**/*"]`, |
| 1051 | args: "-C . -f java-res/a/a -f java-res/b/b", |
| 1052 | }, |
| 1053 | { |
| 1054 | // Test exclude_java_resources with java_resources |
| 1055 | name: "wildcard files with exclude", |
| 1056 | prop: `java_resources: ["java-res/**/*"], exclude_java_resources: ["java-res/b/*"]`, |
| 1057 | args: "-C . -f java-res/a/a", |
| 1058 | }, |
| 1059 | { |
| 1060 | // Test exclude_java_resources with java_resource_dirs |
| 1061 | name: "resource dirs with exclude files", |
| 1062 | prop: `java_resource_dirs: ["java-res"], exclude_java_resources: ["java-res/b/b"]`, |
| 1063 | args: "-C java-res -f java-res/a/a", |
| 1064 | }, |
| 1065 | { |
| 1066 | // Test exclude_java_resource_dirs with java_resource_dirs |
| 1067 | name: "resource dirs with exclude files", |
| 1068 | prop: `java_resource_dirs: ["java-res", "java-res2"], exclude_java_resource_dirs: ["java-res2"]`, |
| 1069 | args: "-C java-res -f java-res/a/a -f java-res/b/b", |
| 1070 | }, |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | for _, test := range table { |
| 1074 | t.Run(test.name, func(t *testing.T) { |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 1075 | ctx, _ := testJavaWithFS(t, ` |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 1076 | java_library { |
| 1077 | name: "foo", |
| 1078 | srcs: [ |
| 1079 | "a.java", |
| 1080 | "b.java", |
| 1081 | "c.java", |
| 1082 | ], |
| 1083 | `+test.prop+`, |
| 1084 | } |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 1085 | `+test.extra, |
| 1086 | map[string][]byte{ |
| 1087 | "java-res/a/a": nil, |
| 1088 | "java-res/b/b": nil, |
| 1089 | "java-res2/a": nil, |
| 1090 | }, |
| 1091 | ) |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 1092 | |
Colin Cross | 331a121 | 2018-08-15 20:40:52 -0700 | [diff] [blame] | 1093 | foo := ctx.ModuleForTests("foo", "android_common").Output("withres/foo.jar") |
Colin Cross | 1ee2317 | 2017-10-18 14:44:18 -0700 | [diff] [blame] | 1094 | fooRes := ctx.ModuleForTests("foo", "android_common").Output("res/foo.jar") |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 1095 | |
| 1096 | if !inList(fooRes.Output.String(), foo.Inputs.Strings()) { |
| 1097 | t.Errorf("foo combined jars %v does not contain %q", |
| 1098 | foo.Inputs.Strings(), fooRes.Output.String()) |
| 1099 | } |
| 1100 | |
Colin Cross | af9c55b | 2017-10-03 14:50:08 -0700 | [diff] [blame] | 1101 | if fooRes.Args["jarArgs"] != test.args { |
| 1102 | t.Errorf("foo resource jar args %q is not %q", |
Colin Cross | 0f37af0 | 2017-09-27 17:42:05 -0700 | [diff] [blame] | 1103 | fooRes.Args["jarArgs"], test.args) |
| 1104 | } |
| 1105 | }) |
| 1106 | } |
| 1107 | } |
| 1108 | |
Colin Cross | 0c4ce21 | 2019-05-03 15:28:19 -0700 | [diff] [blame] | 1109 | func TestIncludeSrcs(t *testing.T) { |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 1110 | ctx, _ := testJavaWithFS(t, ` |
Colin Cross | 0c4ce21 | 2019-05-03 15:28:19 -0700 | [diff] [blame] | 1111 | java_library { |
| 1112 | name: "foo", |
| 1113 | srcs: [ |
| 1114 | "a.java", |
| 1115 | "b.java", |
| 1116 | "c.java", |
| 1117 | ], |
| 1118 | include_srcs: true, |
| 1119 | } |
| 1120 | |
| 1121 | java_library { |
| 1122 | name: "bar", |
| 1123 | srcs: [ |
| 1124 | "a.java", |
| 1125 | "b.java", |
| 1126 | "c.java", |
| 1127 | ], |
| 1128 | java_resource_dirs: ["java-res"], |
| 1129 | include_srcs: true, |
| 1130 | } |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 1131 | `, map[string][]byte{ |
| 1132 | "java-res/a/a": nil, |
| 1133 | "java-res/b/b": nil, |
| 1134 | "java-res2/a": nil, |
| 1135 | }) |
Colin Cross | 0c4ce21 | 2019-05-03 15:28:19 -0700 | [diff] [blame] | 1136 | |
| 1137 | // Test a library with include_srcs: true |
| 1138 | foo := ctx.ModuleForTests("foo", "android_common").Output("withres/foo.jar") |
| 1139 | fooSrcJar := ctx.ModuleForTests("foo", "android_common").Output("foo.srcjar") |
| 1140 | |
| 1141 | if g, w := fooSrcJar.Output.String(), foo.Inputs.Strings(); !inList(g, w) { |
| 1142 | t.Errorf("foo combined jars %v does not contain %q", w, g) |
| 1143 | } |
| 1144 | |
| 1145 | if g, w := fooSrcJar.Args["jarArgs"], "-C . -f a.java -f b.java -f c.java"; g != w { |
| 1146 | t.Errorf("foo source jar args %q is not %q", w, g) |
| 1147 | } |
| 1148 | |
| 1149 | // Test a library with include_srcs: true and resources |
| 1150 | bar := ctx.ModuleForTests("bar", "android_common").Output("withres/bar.jar") |
| 1151 | barResCombined := ctx.ModuleForTests("bar", "android_common").Output("res-combined/bar.jar") |
| 1152 | barRes := ctx.ModuleForTests("bar", "android_common").Output("res/bar.jar") |
| 1153 | barSrcJar := ctx.ModuleForTests("bar", "android_common").Output("bar.srcjar") |
| 1154 | |
| 1155 | if g, w := barSrcJar.Output.String(), barResCombined.Inputs.Strings(); !inList(g, w) { |
| 1156 | t.Errorf("bar combined resource jars %v does not contain %q", w, g) |
| 1157 | } |
| 1158 | |
| 1159 | if g, w := barRes.Output.String(), barResCombined.Inputs.Strings(); !inList(g, w) { |
| 1160 | t.Errorf("bar combined resource jars %v does not contain %q", w, g) |
| 1161 | } |
| 1162 | |
| 1163 | if g, w := barResCombined.Output.String(), bar.Inputs.Strings(); !inList(g, w) { |
| 1164 | t.Errorf("bar combined jars %v does not contain %q", w, g) |
| 1165 | } |
| 1166 | |
| 1167 | if g, w := barSrcJar.Args["jarArgs"], "-C . -f a.java -f b.java -f c.java"; g != w { |
| 1168 | t.Errorf("bar source jar args %q is not %q", w, g) |
| 1169 | } |
| 1170 | |
| 1171 | if g, w := barRes.Args["jarArgs"], "-C java-res -f java-res/a/a -f java-res/b/b"; g != w { |
| 1172 | t.Errorf("bar resource jar args %q is not %q", w, g) |
| 1173 | } |
| 1174 | } |
| 1175 | |
Pedro Loureiro | 5d190cc | 2021-02-15 15:41:33 +0000 | [diff] [blame] | 1176 | func TestJavaLint(t *testing.T) { |
| 1177 | ctx, _ := testJavaWithFS(t, ` |
| 1178 | java_library { |
| 1179 | name: "foo", |
| 1180 | srcs: [ |
| 1181 | "a.java", |
| 1182 | "b.java", |
| 1183 | "c.java", |
| 1184 | ], |
| 1185 | min_sdk_version: "29", |
| 1186 | sdk_version: "system_current", |
| 1187 | } |
| 1188 | `, map[string][]byte{ |
| 1189 | "lint-baseline.xml": nil, |
| 1190 | }) |
| 1191 | |
| 1192 | foo := ctx.ModuleForTests("foo", "android_common") |
Pedro Loureiro | 5d190cc | 2021-02-15 15:41:33 +0000 | [diff] [blame] | 1193 | |
Colin Cross | 1661aff | 2021-03-12 17:56:51 -0800 | [diff] [blame] | 1194 | sboxProto := android.RuleBuilderSboxProtoForTests(t, foo.Output("lint.sbox.textproto")) |
| 1195 | if !strings.Contains(*sboxProto.Commands[0].Command, "--baseline lint-baseline.xml") { |
Pedro Loureiro | 5d190cc | 2021-02-15 15:41:33 +0000 | [diff] [blame] | 1196 | t.Error("did not pass --baseline flag") |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | func TestJavaLintWithoutBaseline(t *testing.T) { |
| 1201 | ctx, _ := testJavaWithFS(t, ` |
| 1202 | java_library { |
| 1203 | name: "foo", |
| 1204 | srcs: [ |
| 1205 | "a.java", |
| 1206 | "b.java", |
| 1207 | "c.java", |
| 1208 | ], |
| 1209 | min_sdk_version: "29", |
| 1210 | sdk_version: "system_current", |
| 1211 | } |
| 1212 | `, map[string][]byte{}) |
| 1213 | |
| 1214 | foo := ctx.ModuleForTests("foo", "android_common") |
Pedro Loureiro | 5d190cc | 2021-02-15 15:41:33 +0000 | [diff] [blame] | 1215 | |
Colin Cross | 1661aff | 2021-03-12 17:56:51 -0800 | [diff] [blame] | 1216 | sboxProto := android.RuleBuilderSboxProtoForTests(t, foo.Output("lint.sbox.textproto")) |
| 1217 | if strings.Contains(*sboxProto.Commands[0].Command, "--baseline") { |
Pedro Loureiro | 5d190cc | 2021-02-15 15:41:33 +0000 | [diff] [blame] | 1218 | t.Error("passed --baseline flag for non existent file") |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | func TestJavaLintRequiresCustomLintFileToExist(t *testing.T) { |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1223 | config := TestConfig(t.TempDir(), |
Pedro Loureiro | 5d190cc | 2021-02-15 15:41:33 +0000 | [diff] [blame] | 1224 | nil, |
| 1225 | ` |
| 1226 | java_library { |
| 1227 | name: "foo", |
| 1228 | srcs: [ |
| 1229 | ], |
| 1230 | min_sdk_version: "29", |
| 1231 | sdk_version: "system_current", |
| 1232 | lint: { |
| 1233 | baseline_filename: "mybaseline.xml", |
| 1234 | }, |
| 1235 | } |
| 1236 | `, map[string][]byte{ |
| 1237 | "build/soong/java/lint_defaults.txt": nil, |
| 1238 | "prebuilts/cmdline-tools/tools/bin/lint": nil, |
| 1239 | "prebuilts/cmdline-tools/tools/lib/lint-classpath.jar": nil, |
| 1240 | "framework/aidl": nil, |
| 1241 | "a.java": nil, |
| 1242 | "AndroidManifest.xml": nil, |
| 1243 | "build/make/target/product/security": nil, |
| 1244 | }) |
| 1245 | config.TestAllowNonExistentPaths = false |
| 1246 | testJavaErrorWithConfig(t, |
| 1247 | "source path \"mybaseline.xml\" does not exist", |
| 1248 | config, |
| 1249 | ) |
| 1250 | } |
| 1251 | |
| 1252 | func TestJavaLintUsesCorrectBpConfig(t *testing.T) { |
| 1253 | ctx, _ := testJavaWithFS(t, ` |
| 1254 | java_library { |
| 1255 | name: "foo", |
| 1256 | srcs: [ |
| 1257 | "a.java", |
| 1258 | "b.java", |
| 1259 | "c.java", |
| 1260 | ], |
| 1261 | min_sdk_version: "29", |
| 1262 | sdk_version: "system_current", |
| 1263 | lint: { |
| 1264 | error_checks: ["SomeCheck"], |
| 1265 | baseline_filename: "mybaseline.xml", |
| 1266 | }, |
| 1267 | } |
| 1268 | `, map[string][]byte{ |
| 1269 | "mybaseline.xml": nil, |
| 1270 | }) |
| 1271 | |
| 1272 | foo := ctx.ModuleForTests("foo", "android_common") |
Pedro Loureiro | 5d190cc | 2021-02-15 15:41:33 +0000 | [diff] [blame] | 1273 | |
Colin Cross | 1661aff | 2021-03-12 17:56:51 -0800 | [diff] [blame] | 1274 | sboxProto := android.RuleBuilderSboxProtoForTests(t, foo.Output("lint.sbox.textproto")) |
| 1275 | if !strings.Contains(*sboxProto.Commands[0].Command, "--baseline mybaseline.xml") { |
Pedro Loureiro | 5d190cc | 2021-02-15 15:41:33 +0000 | [diff] [blame] | 1276 | t.Error("did not use the correct file for baseline") |
| 1277 | } |
| 1278 | } |
| 1279 | |
Colin Cross | 54190b3 | 2017-10-09 15:34:10 -0700 | [diff] [blame] | 1280 | func TestGeneratedSources(t *testing.T) { |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 1281 | ctx, _ := testJavaWithFS(t, ` |
Colin Cross | 54190b3 | 2017-10-09 15:34:10 -0700 | [diff] [blame] | 1282 | java_library { |
| 1283 | name: "foo", |
| 1284 | srcs: [ |
| 1285 | "a*.java", |
| 1286 | ":gen", |
| 1287 | "b*.java", |
| 1288 | ], |
| 1289 | } |
| 1290 | |
| 1291 | genrule { |
| 1292 | name: "gen", |
Colin Cross | 824bee3 | 2017-11-22 17:27:51 -0800 | [diff] [blame] | 1293 | tool_files: ["java-res/a"], |
Colin Cross | 54190b3 | 2017-10-09 15:34:10 -0700 | [diff] [blame] | 1294 | out: ["gen.java"], |
| 1295 | } |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 1296 | `, map[string][]byte{ |
| 1297 | "a.java": nil, |
| 1298 | "b.java": nil, |
| 1299 | }) |
Colin Cross | 54190b3 | 2017-10-09 15:34:10 -0700 | [diff] [blame] | 1300 | |
| 1301 | javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") |
| 1302 | genrule := ctx.ModuleForTests("gen", "").Rule("generator") |
| 1303 | |
Colin Cross | 15e86d9 | 2017-10-20 15:07:08 -0700 | [diff] [blame] | 1304 | if filepath.Base(genrule.Output.String()) != "gen.java" { |
| 1305 | 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] | 1306 | } |
| 1307 | |
| 1308 | if len(javac.Inputs) != 3 || |
| 1309 | javac.Inputs[0].String() != "a.java" || |
Colin Cross | 15e86d9 | 2017-10-20 15:07:08 -0700 | [diff] [blame] | 1310 | javac.Inputs[1].String() != genrule.Output.String() || |
Colin Cross | 54190b3 | 2017-10-09 15:34:10 -0700 | [diff] [blame] | 1311 | javac.Inputs[2].String() != "b.java" { |
| 1312 | t.Errorf(`foo inputs %v != ["a.java", ".../gen.java", "b.java"]`, javac.Inputs) |
| 1313 | } |
| 1314 | } |
| 1315 | |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1316 | func TestTurbine(t *testing.T) { |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 1317 | result := android.GroupFixturePreparers( |
| 1318 | prepareForJavaTest, FixtureWithPrebuiltApis(map[string][]string{"14": {"foo"}})). |
Paul Duffin | 3d9f268 | 2021-03-13 09:47:16 +0000 | [diff] [blame] | 1319 | RunTestWithBp(t, ` |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1320 | java_library { |
| 1321 | name: "foo", |
| 1322 | srcs: ["a.java"], |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 1323 | sdk_version: "14", |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | java_library { |
| 1327 | name: "bar", |
Colin Cross | 9bc4343 | 2017-12-15 20:20:39 -0800 | [diff] [blame] | 1328 | srcs: ["b.java"], |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1329 | static_libs: ["foo"], |
Jiyong Park | 2d49294 | 2018-03-05 17:44:10 +0900 | [diff] [blame] | 1330 | sdk_version: "14", |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1331 | } |
| 1332 | |
| 1333 | java_library { |
| 1334 | name: "baz", |
| 1335 | srcs: ["c.java"], |
| 1336 | libs: ["bar"], |
| 1337 | sdk_version: "14", |
| 1338 | } |
| 1339 | `) |
| 1340 | |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1341 | fooTurbine := result.ModuleForTests("foo", "android_common").Rule("turbine").RelativeToTop() |
| 1342 | barTurbine := result.ModuleForTests("bar", "android_common").Rule("turbine").RelativeToTop() |
| 1343 | barJavac := result.ModuleForTests("bar", "android_common").Rule("javac").RelativeToTop() |
| 1344 | barTurbineCombined := result.ModuleForTests("bar", "android_common").Description("for turbine").RelativeToTop() |
| 1345 | bazJavac := result.ModuleForTests("baz", "android_common").Rule("javac").RelativeToTop() |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1346 | |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1347 | android.AssertPathsRelativeToTopEquals(t, "foo inputs", []string{"a.java"}, fooTurbine.Inputs) |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1348 | |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1349 | fooHeaderJar := filepath.Join("out", "soong", ".intermediates", "foo", "android_common", "turbine-combined", "foo.jar") |
| 1350 | barTurbineJar := filepath.Join("out", "soong", ".intermediates", "bar", "android_common", "turbine", "bar.jar") |
Paul Duffin | 3d9f268 | 2021-03-13 09:47:16 +0000 | [diff] [blame] | 1351 | android.AssertStringDoesContain(t, "bar turbine classpath", barTurbine.Args["classpath"], fooHeaderJar) |
| 1352 | android.AssertStringDoesContain(t, "bar javac classpath", barJavac.Args["classpath"], fooHeaderJar) |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1353 | android.AssertPathsRelativeToTopEquals(t, "bar turbine combineJar", []string{barTurbineJar, fooHeaderJar}, barTurbineCombined.Inputs) |
Paul Duffin | 3d9f268 | 2021-03-13 09:47:16 +0000 | [diff] [blame] | 1354 | android.AssertStringDoesContain(t, "baz javac classpath", bazJavac.Args["classpath"], "prebuilts/sdk/14/public/android.jar") |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | func TestSharding(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1358 | ctx, _ := testJava(t, ` |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1359 | java_library { |
| 1360 | name: "bar", |
| 1361 | srcs: ["a.java","b.java","c.java"], |
| 1362 | javac_shard_size: 1 |
| 1363 | } |
| 1364 | `) |
| 1365 | |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1366 | barHeaderJar := filepath.Join("out", "soong", ".intermediates", "bar", "android_common", "turbine-combined", "bar.jar") |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1367 | for i := 0; i < 3; i++ { |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1368 | barJavac := ctx.ModuleForTests("bar", "android_common").Description("javac" + strconv.Itoa(i)).RelativeToTop() |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 1369 | if !strings.Contains(barJavac.Args["classpath"], barHeaderJar) { |
| 1370 | t.Errorf("bar javac classpath %v does not contain %q", barJavac.Args["classpath"], barHeaderJar) |
| 1371 | } |
| 1372 | } |
| 1373 | } |
| 1374 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1375 | func TestDroiddoc(t *testing.T) { |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 1376 | ctx, _ := testJavaWithFS(t, ` |
Paul Duffin | 884363e | 2019-12-19 10:21:09 +0000 | [diff] [blame] | 1377 | droiddoc_exported_dir { |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1378 | name: "droiddoc-templates-sdk", |
| 1379 | path: ".", |
| 1380 | } |
Jiyong Park | 2907459 | 2019-07-07 16:27:47 +0900 | [diff] [blame] | 1381 | filegroup { |
| 1382 | name: "bar-doc-aidl-srcs", |
| 1383 | srcs: ["bar-doc/IBar.aidl"], |
| 1384 | path: "bar-doc", |
| 1385 | } |
Liz Kammer | e1ab250 | 2020-09-10 15:29:25 +0000 | [diff] [blame] | 1386 | droidstubs { |
| 1387 | name: "bar-stubs", |
Liz Kammer | 3a55c91 | 2020-08-14 12:14:02 -0700 | [diff] [blame] | 1388 | srcs: [ |
Steve Kim | 3666c70 | 2020-09-01 17:58:01 +0000 | [diff] [blame] | 1389 | "bar-doc/a.java", |
Liz Kammer | 3a55c91 | 2020-08-14 12:14:02 -0700 | [diff] [blame] | 1390 | ], |
Steve Kim | 3666c70 | 2020-09-01 17:58:01 +0000 | [diff] [blame] | 1391 | exclude_srcs: [ |
| 1392 | "bar-doc/b.java" |
| 1393 | ], |
Liz Kammer | e1ab250 | 2020-09-10 15:29:25 +0000 | [diff] [blame] | 1394 | api_levels_annotations_dirs: [ |
| 1395 | "droiddoc-templates-sdk", |
| 1396 | ], |
| 1397 | api_levels_annotations_enabled: true, |
| 1398 | } |
| 1399 | droiddoc { |
| 1400 | name: "bar-doc", |
| 1401 | srcs: [ |
| 1402 | ":bar-stubs", |
| 1403 | "bar-doc/IFoo.aidl", |
| 1404 | ":bar-doc-aidl-srcs", |
| 1405 | ], |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1406 | custom_template: "droiddoc-templates-sdk", |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1407 | hdf: [ |
| 1408 | "android.whichdoc offline", |
| 1409 | ], |
| 1410 | knowntags: [ |
| 1411 | "bar-doc/known_oj_tags.txt", |
| 1412 | ], |
| 1413 | proofread_file: "libcore-proofread.txt", |
| 1414 | todo_file: "libcore-docs-todo.html", |
Liz Kammer | 585cac2 | 2020-07-06 09:12:57 -0700 | [diff] [blame] | 1415 | flags: ["-offlinemode -title \"libcore\""], |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1416 | } |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 1417 | `, |
| 1418 | map[string][]byte{ |
| 1419 | "bar-doc/a.java": nil, |
| 1420 | "bar-doc/b.java": nil, |
| 1421 | }) |
Liz Kammer | e1ab250 | 2020-09-10 15:29:25 +0000 | [diff] [blame] | 1422 | barStubs := ctx.ModuleForTests("bar-stubs", "android_common") |
| 1423 | barStubsOutputs, err := barStubs.Module().(*Droidstubs).OutputFiles("") |
| 1424 | if err != nil { |
| 1425 | t.Errorf("Unexpected error %q retrieving \"bar-stubs\" output file", err) |
| 1426 | } |
| 1427 | if len(barStubsOutputs) != 1 { |
| 1428 | t.Errorf("Expected one output from \"bar-stubs\" got %s", barStubsOutputs) |
Liz Kammer | 1e2ee12 | 2020-07-30 15:07:22 -0700 | [diff] [blame] | 1429 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1430 | |
Liz Kammer | e1ab250 | 2020-09-10 15:29:25 +0000 | [diff] [blame] | 1431 | barStubsOutput := barStubsOutputs[0] |
| 1432 | barDoc := ctx.ModuleForTests("bar-doc", "android_common") |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1433 | javaDoc := barDoc.Rule("javadoc").RelativeToTop() |
Liz Kammer | e1ab250 | 2020-09-10 15:29:25 +0000 | [diff] [blame] | 1434 | if g, w := javaDoc.Implicits.Strings(), barStubsOutput.String(); !inList(w, g) { |
| 1435 | t.Errorf("implicits of bar-doc must contain %q, but was %q.", w, g) |
Jiyong Park | 2907459 | 2019-07-07 16:27:47 +0900 | [diff] [blame] | 1436 | } |
| 1437 | |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1438 | expected := "-sourcepath out/soong/.intermediates/bar-doc/android_common/srcjars " |
Liz Kammer | e1ab250 | 2020-09-10 15:29:25 +0000 | [diff] [blame] | 1439 | if !strings.Contains(javaDoc.RuleParams.Command, expected) { |
| 1440 | t.Errorf("bar-doc command does not contain flag %q, but should\n%q", expected, javaDoc.RuleParams.Command) |
| 1441 | } |
| 1442 | |
| 1443 | aidl := barDoc.Rule("aidl") |
| 1444 | if g, w := javaDoc.Implicits.Strings(), aidl.Output.String(); !inList(w, g) { |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 1445 | t.Errorf("implicits of bar-doc must contain %q, but was %q.", w, g) |
| 1446 | } |
| 1447 | |
| 1448 | if g, w := aidl.Implicits.Strings(), []string{"bar-doc/IBar.aidl", "bar-doc/IFoo.aidl"}; !reflect.DeepEqual(w, g) { |
| 1449 | t.Errorf("aidl inputs must be %q, but was %q", w, g) |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 1450 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1451 | } |
| 1452 | |
Liz Kammer | 585cac2 | 2020-07-06 09:12:57 -0700 | [diff] [blame] | 1453 | func TestDroiddocArgsAndFlagsCausesError(t *testing.T) { |
| 1454 | testJavaError(t, "flags is set. Cannot set args", ` |
| 1455 | droiddoc_exported_dir { |
| 1456 | name: "droiddoc-templates-sdk", |
| 1457 | path: ".", |
| 1458 | } |
| 1459 | filegroup { |
| 1460 | name: "bar-doc-aidl-srcs", |
| 1461 | srcs: ["bar-doc/IBar.aidl"], |
| 1462 | path: "bar-doc", |
| 1463 | } |
Liz Kammer | e1ab250 | 2020-09-10 15:29:25 +0000 | [diff] [blame] | 1464 | droidstubs { |
| 1465 | name: "bar-stubs", |
Liz Kammer | 3a55c91 | 2020-08-14 12:14:02 -0700 | [diff] [blame] | 1466 | srcs: [ |
Steve Kim | 3666c70 | 2020-09-01 17:58:01 +0000 | [diff] [blame] | 1467 | "bar-doc/a.java", |
Liz Kammer | 3a55c91 | 2020-08-14 12:14:02 -0700 | [diff] [blame] | 1468 | ], |
Steve Kim | 3666c70 | 2020-09-01 17:58:01 +0000 | [diff] [blame] | 1469 | exclude_srcs: [ |
| 1470 | "bar-doc/b.java" |
| 1471 | ], |
Liz Kammer | e1ab250 | 2020-09-10 15:29:25 +0000 | [diff] [blame] | 1472 | api_levels_annotations_dirs: [ |
| 1473 | "droiddoc-templates-sdk", |
| 1474 | ], |
| 1475 | api_levels_annotations_enabled: true, |
| 1476 | } |
| 1477 | droiddoc { |
| 1478 | name: "bar-doc", |
| 1479 | srcs: [ |
| 1480 | ":bar-stubs", |
| 1481 | "bar-doc/IFoo.aidl", |
| 1482 | ":bar-doc-aidl-srcs", |
| 1483 | ], |
Liz Kammer | 585cac2 | 2020-07-06 09:12:57 -0700 | [diff] [blame] | 1484 | custom_template: "droiddoc-templates-sdk", |
| 1485 | hdf: [ |
| 1486 | "android.whichdoc offline", |
| 1487 | ], |
| 1488 | knowntags: [ |
| 1489 | "bar-doc/known_oj_tags.txt", |
| 1490 | ], |
| 1491 | proofread_file: "libcore-proofread.txt", |
| 1492 | todo_file: "libcore-docs-todo.html", |
| 1493 | flags: ["-offlinemode -title \"libcore\""], |
| 1494 | args: "-offlinemode -title \"libcore\"", |
| 1495 | } |
| 1496 | `) |
| 1497 | } |
| 1498 | |
Liz Kammer | 3d894b7 | 2020-08-04 09:55:13 -0700 | [diff] [blame] | 1499 | func TestDroidstubs(t *testing.T) { |
| 1500 | ctx, _ := testJavaWithFS(t, ` |
| 1501 | droiddoc_exported_dir { |
Anton Hansson | 52ac73d | 2020-10-26 09:57:40 +0000 | [diff] [blame] | 1502 | name: "droiddoc-templates-sdk", |
| 1503 | path: ".", |
Liz Kammer | 3d894b7 | 2020-08-04 09:55:13 -0700 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | droidstubs { |
Anton Hansson | 52ac73d | 2020-10-26 09:57:40 +0000 | [diff] [blame] | 1507 | name: "bar-stubs", |
| 1508 | srcs: ["bar-doc/a.java"], |
| 1509 | api_levels_annotations_dirs: ["droiddoc-templates-sdk"], |
| 1510 | api_levels_annotations_enabled: true, |
Liz Kammer | 3d894b7 | 2020-08-04 09:55:13 -0700 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | droidstubs { |
Anton Hansson | 52ac73d | 2020-10-26 09:57:40 +0000 | [diff] [blame] | 1514 | name: "bar-stubs-other", |
| 1515 | srcs: ["bar-doc/a.java"], |
| 1516 | high_mem: true, |
| 1517 | api_levels_annotations_dirs: ["droiddoc-templates-sdk"], |
| 1518 | api_levels_annotations_enabled: true, |
| 1519 | api_levels_jar_filename: "android.other.jar", |
Liz Kammer | 3d894b7 | 2020-08-04 09:55:13 -0700 | [diff] [blame] | 1520 | } |
| 1521 | `, |
| 1522 | map[string][]byte{ |
| 1523 | "bar-doc/a.java": nil, |
| 1524 | }) |
| 1525 | testcases := []struct { |
| 1526 | moduleName string |
| 1527 | expectedJarFilename string |
Anton Hansson | 52ac73d | 2020-10-26 09:57:40 +0000 | [diff] [blame] | 1528 | high_mem bool |
Liz Kammer | 3d894b7 | 2020-08-04 09:55:13 -0700 | [diff] [blame] | 1529 | }{ |
| 1530 | { |
| 1531 | moduleName: "bar-stubs", |
| 1532 | expectedJarFilename: "android.jar", |
Anton Hansson | 52ac73d | 2020-10-26 09:57:40 +0000 | [diff] [blame] | 1533 | high_mem: false, |
Liz Kammer | 3d894b7 | 2020-08-04 09:55:13 -0700 | [diff] [blame] | 1534 | }, |
| 1535 | { |
| 1536 | moduleName: "bar-stubs-other", |
| 1537 | expectedJarFilename: "android.other.jar", |
Anton Hansson | 52ac73d | 2020-10-26 09:57:40 +0000 | [diff] [blame] | 1538 | high_mem: true, |
Liz Kammer | 3d894b7 | 2020-08-04 09:55:13 -0700 | [diff] [blame] | 1539 | }, |
| 1540 | } |
| 1541 | for _, c := range testcases { |
| 1542 | m := ctx.ModuleForTests(c.moduleName, "android_common") |
| 1543 | metalava := m.Rule("metalava") |
Anton Hansson | 52ac73d | 2020-10-26 09:57:40 +0000 | [diff] [blame] | 1544 | rp := metalava.RuleParams |
Liz Kammer | 3d894b7 | 2020-08-04 09:55:13 -0700 | [diff] [blame] | 1545 | expected := "--android-jar-pattern ./%/public/" + c.expectedJarFilename |
Anton Hansson | 52ac73d | 2020-10-26 09:57:40 +0000 | [diff] [blame] | 1546 | if actual := rp.Command; !strings.Contains(actual, expected) { |
Liz Kammer | 3d894b7 | 2020-08-04 09:55:13 -0700 | [diff] [blame] | 1547 | t.Errorf("For %q, expected metalava argument %q, but was not found %q", c.moduleName, expected, actual) |
| 1548 | } |
Anton Hansson | 52ac73d | 2020-10-26 09:57:40 +0000 | [diff] [blame] | 1549 | |
| 1550 | if actual := rp.Pool != nil && strings.Contains(rp.Pool.String(), "highmem"); actual != c.high_mem { |
| 1551 | t.Errorf("Expected %q high_mem to be %v, was %v", c.moduleName, c.high_mem, actual) |
| 1552 | } |
Liz Kammer | 3d894b7 | 2020-08-04 09:55:13 -0700 | [diff] [blame] | 1553 | } |
| 1554 | } |
| 1555 | |
Paul Duffin | 83a2d96 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 1556 | func TestDroidstubsWithSystemModules(t *testing.T) { |
| 1557 | ctx, _ := testJava(t, ` |
| 1558 | droidstubs { |
| 1559 | name: "stubs-source-system-modules", |
| 1560 | srcs: [ |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 1561 | "bar-doc/a.java", |
Paul Duffin | 83a2d96 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 1562 | ], |
| 1563 | sdk_version: "none", |
| 1564 | system_modules: "source-system-modules", |
| 1565 | } |
| 1566 | |
| 1567 | java_library { |
| 1568 | name: "source-jar", |
| 1569 | srcs: [ |
| 1570 | "a.java", |
| 1571 | ], |
| 1572 | } |
| 1573 | |
| 1574 | java_system_modules { |
| 1575 | name: "source-system-modules", |
| 1576 | libs: ["source-jar"], |
| 1577 | } |
| 1578 | |
| 1579 | droidstubs { |
| 1580 | name: "stubs-prebuilt-system-modules", |
| 1581 | srcs: [ |
Colin Cross | 238c1f3 | 2020-06-07 16:58:18 -0700 | [diff] [blame] | 1582 | "bar-doc/a.java", |
Paul Duffin | 83a2d96 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 1583 | ], |
| 1584 | sdk_version: "none", |
| 1585 | system_modules: "prebuilt-system-modules", |
| 1586 | } |
| 1587 | |
| 1588 | java_import { |
| 1589 | name: "prebuilt-jar", |
| 1590 | jars: ["a.jar"], |
| 1591 | } |
| 1592 | |
| 1593 | java_system_modules_import { |
| 1594 | name: "prebuilt-system-modules", |
| 1595 | libs: ["prebuilt-jar"], |
| 1596 | } |
| 1597 | `) |
| 1598 | |
| 1599 | checkSystemModulesUseByDroidstubs(t, ctx, "stubs-source-system-modules", "source-jar.jar") |
| 1600 | |
| 1601 | checkSystemModulesUseByDroidstubs(t, ctx, "stubs-prebuilt-system-modules", "prebuilt-jar.jar") |
| 1602 | } |
| 1603 | |
| 1604 | func checkSystemModulesUseByDroidstubs(t *testing.T, ctx *android.TestContext, moduleName string, systemJar string) { |
| 1605 | metalavaRule := ctx.ModuleForTests(moduleName, "android_common").Rule("metalava") |
| 1606 | var systemJars []string |
| 1607 | for _, i := range metalavaRule.Implicits { |
| 1608 | systemJars = append(systemJars, i.Base()) |
| 1609 | } |
Ramy Medhat | c7965cd | 2020-04-30 03:08:37 -0400 | [diff] [blame] | 1610 | if len(systemJars) < 1 || systemJars[0] != systemJar { |
Paul Duffin | 83a2d96 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 1611 | t.Errorf("inputs of %q must be []string{%q}, but was %#v.", moduleName, systemJar, systemJars) |
| 1612 | } |
| 1613 | } |
| 1614 | |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 1615 | func TestJarGenrules(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1616 | ctx, _ := testJava(t, ` |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 1617 | java_library { |
| 1618 | name: "foo", |
| 1619 | srcs: ["a.java"], |
| 1620 | } |
| 1621 | |
| 1622 | java_genrule { |
| 1623 | name: "jargen", |
| 1624 | tool_files: ["b.java"], |
| 1625 | cmd: "$(location b.java) $(in) $(out)", |
| 1626 | out: ["jargen.jar"], |
| 1627 | srcs: [":foo"], |
| 1628 | } |
| 1629 | |
| 1630 | java_library { |
| 1631 | name: "bar", |
| 1632 | static_libs: ["jargen"], |
| 1633 | srcs: ["c.java"], |
| 1634 | } |
| 1635 | |
| 1636 | java_library { |
| 1637 | name: "baz", |
| 1638 | libs: ["jargen"], |
| 1639 | srcs: ["c.java"], |
| 1640 | } |
| 1641 | `) |
| 1642 | |
| 1643 | foo := ctx.ModuleForTests("foo", "android_common").Output("javac/foo.jar") |
| 1644 | jargen := ctx.ModuleForTests("jargen", "android_common").Output("jargen.jar") |
| 1645 | bar := ctx.ModuleForTests("bar", "android_common").Output("javac/bar.jar") |
| 1646 | baz := ctx.ModuleForTests("baz", "android_common").Output("javac/baz.jar") |
| 1647 | barCombined := ctx.ModuleForTests("bar", "android_common").Output("combined/bar.jar") |
| 1648 | |
Colin Cross | 3d68051 | 2020-11-13 16:23:53 -0800 | [diff] [blame] | 1649 | if g, w := jargen.Implicits.Strings(), foo.Output.String(); !android.InList(w, g) { |
| 1650 | t.Errorf("expected jargen inputs [%q], got %q", w, g) |
Colin Cross | 5425090 | 2017-12-05 09:28:08 -0800 | [diff] [blame] | 1651 | } |
| 1652 | |
| 1653 | if !strings.Contains(bar.Args["classpath"], jargen.Output.String()) { |
| 1654 | t.Errorf("bar classpath %v does not contain %q", bar.Args["classpath"], jargen.Output.String()) |
| 1655 | } |
| 1656 | |
| 1657 | if !strings.Contains(baz.Args["classpath"], jargen.Output.String()) { |
| 1658 | t.Errorf("baz classpath %v does not contain %q", baz.Args["classpath"], jargen.Output.String()) |
| 1659 | } |
| 1660 | |
| 1661 | if len(barCombined.Inputs) != 2 || |
| 1662 | barCombined.Inputs[0].String() != bar.Output.String() || |
| 1663 | barCombined.Inputs[1].String() != jargen.Output.String() { |
| 1664 | t.Errorf("bar combined jar inputs %v is not [%q, %q]", |
| 1665 | barCombined.Inputs.Strings(), bar.Output.String(), jargen.Output.String()) |
| 1666 | } |
| 1667 | } |
| 1668 | |
Nan Zhang | 27e284d | 2018-02-09 21:03:53 +0000 | [diff] [blame] | 1669 | func TestExcludeFileGroupInSrcs(t *testing.T) { |
Jaewoong Jung | f9a0443 | 2019-07-17 11:15:09 -0700 | [diff] [blame] | 1670 | ctx, _ := testJava(t, ` |
Nan Zhang | 27e284d | 2018-02-09 21:03:53 +0000 | [diff] [blame] | 1671 | java_library { |
| 1672 | name: "foo", |
| 1673 | srcs: ["a.java", ":foo-srcs"], |
| 1674 | exclude_srcs: ["a.java", ":foo-excludes"], |
| 1675 | } |
| 1676 | |
| 1677 | filegroup { |
| 1678 | name: "foo-srcs", |
| 1679 | srcs: ["java-fg/a.java", "java-fg/b.java", "java-fg/c.java"], |
| 1680 | } |
| 1681 | |
| 1682 | filegroup { |
| 1683 | name: "foo-excludes", |
| 1684 | srcs: ["java-fg/a.java", "java-fg/b.java"], |
| 1685 | } |
| 1686 | `) |
| 1687 | |
| 1688 | javac := ctx.ModuleForTests("foo", "android_common").Rule("javac") |
| 1689 | |
| 1690 | if len(javac.Inputs) != 1 || javac.Inputs[0].String() != "java-fg/c.java" { |
| 1691 | t.Errorf(`foo inputs %v != ["java-fg/c.java"]`, javac.Inputs) |
| 1692 | } |
| 1693 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1694 | |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 1695 | func TestJavaLibrary(t *testing.T) { |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1696 | testJavaWithFS(t, "", map[string][]byte{ |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 1697 | "libcore/Android.bp": []byte(` |
| 1698 | java_library { |
| 1699 | name: "core", |
| 1700 | sdk_version: "none", |
| 1701 | system_modules: "none", |
Paul Duffin | aa55f74 | 2020-10-06 17:20:13 +0100 | [diff] [blame] | 1702 | } |
| 1703 | |
| 1704 | filegroup { |
| 1705 | name: "core-jar", |
| 1706 | srcs: [":core{.jar}"], |
| 1707 | } |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1708 | `), |
Paul Duffin | aa55f74 | 2020-10-06 17:20:13 +0100 | [diff] [blame] | 1709 | }) |
Paul Duffin | aa55f74 | 2020-10-06 17:20:13 +0100 | [diff] [blame] | 1710 | } |
| 1711 | |
| 1712 | func TestJavaImport(t *testing.T) { |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1713 | testJavaWithFS(t, "", map[string][]byte{ |
Paul Duffin | aa55f74 | 2020-10-06 17:20:13 +0100 | [diff] [blame] | 1714 | "libcore/Android.bp": []byte(` |
| 1715 | java_import { |
| 1716 | name: "core", |
| 1717 | sdk_version: "none", |
| 1718 | } |
| 1719 | |
| 1720 | filegroup { |
| 1721 | name: "core-jar", |
| 1722 | srcs: [":core{.jar}"], |
| 1723 | } |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 1724 | `), |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 1725 | }) |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 1726 | } |
| 1727 | |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1728 | func TestJavaSdkLibrary(t *testing.T) { |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 1729 | result := android.GroupFixturePreparers( |
| 1730 | prepareForJavaTest, |
Paul Duffin | 163043d | 2021-03-12 19:18:49 +0000 | [diff] [blame] | 1731 | PrepareForTestWithJavaSdkLibraryFiles, |
| 1732 | FixtureWithPrebuiltApis(map[string][]string{ |
| 1733 | "28": {"foo"}, |
| 1734 | "29": {"foo"}, |
| 1735 | "30": {"bar", "barney", "baz", "betty", "foo", "fred", "quuz", "wilma"}, |
| 1736 | }), |
| 1737 | ).RunTestWithBp(t, ` |
Paul Duffin | 884363e | 2019-12-19 10:21:09 +0000 | [diff] [blame] | 1738 | droiddoc_exported_dir { |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1739 | name: "droiddoc-templates-sdk", |
| 1740 | path: ".", |
| 1741 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1742 | java_sdk_library { |
| 1743 | name: "foo", |
| 1744 | srcs: ["a.java", "b.java"], |
| 1745 | api_packages: ["foo"], |
| 1746 | } |
| 1747 | java_sdk_library { |
| 1748 | name: "bar", |
| 1749 | srcs: ["a.java", "b.java"], |
| 1750 | api_packages: ["bar"], |
| 1751 | } |
| 1752 | java_library { |
| 1753 | name: "baz", |
| 1754 | srcs: ["c.java"], |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1755 | libs: ["foo", "bar.stubs"], |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1756 | sdk_version: "system_current", |
| 1757 | } |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1758 | java_sdk_library { |
| 1759 | name: "barney", |
| 1760 | srcs: ["c.java"], |
| 1761 | api_only: true, |
| 1762 | } |
| 1763 | java_sdk_library { |
| 1764 | name: "betty", |
| 1765 | srcs: ["c.java"], |
| 1766 | shared_library: false, |
| 1767 | } |
Paul Duffin | 859fe96 | 2020-05-15 10:20:31 +0100 | [diff] [blame] | 1768 | java_sdk_library_import { |
| 1769 | name: "quuz", |
| 1770 | public: { |
| 1771 | jars: ["c.jar"], |
| 1772 | }, |
| 1773 | } |
| 1774 | java_sdk_library_import { |
| 1775 | name: "fred", |
| 1776 | public: { |
| 1777 | jars: ["b.jar"], |
| 1778 | }, |
| 1779 | } |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1780 | java_sdk_library_import { |
| 1781 | name: "wilma", |
| 1782 | public: { |
| 1783 | jars: ["b.jar"], |
| 1784 | }, |
| 1785 | shared_library: false, |
| 1786 | } |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1787 | java_library { |
| 1788 | name: "qux", |
| 1789 | srcs: ["c.java"], |
Paul Duffin | dfa131e | 2020-05-15 20:37:11 +0100 | [diff] [blame] | 1790 | libs: ["baz", "fred", "quuz.stubs", "wilma", "barney", "betty"], |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1791 | sdk_version: "system_current", |
| 1792 | } |
Paul Duffin | 726d23c | 2020-01-22 16:30:37 +0000 | [diff] [blame] | 1793 | java_library { |
| 1794 | name: "baz-test", |
| 1795 | srcs: ["c.java"], |
| 1796 | libs: ["foo"], |
| 1797 | sdk_version: "test_current", |
| 1798 | } |
Paul Duffin | a2db18f | 2020-01-22 17:11:15 +0000 | [diff] [blame] | 1799 | java_library { |
| 1800 | name: "baz-29", |
| 1801 | srcs: ["c.java"], |
| 1802 | libs: ["foo"], |
| 1803 | sdk_version: "system_29", |
| 1804 | } |
Paul Duffin | fb6ae5b | 2020-09-30 15:17:25 +0100 | [diff] [blame] | 1805 | java_library { |
| 1806 | name: "baz-module-30", |
| 1807 | srcs: ["c.java"], |
| 1808 | libs: ["foo"], |
| 1809 | sdk_version: "module_30", |
| 1810 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1811 | `) |
| 1812 | |
| 1813 | // check the existence of the internal modules |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 1814 | result.ModuleForTests("foo", "android_common") |
| 1815 | result.ModuleForTests(apiScopePublic.stubsLibraryModuleName("foo"), "android_common") |
| 1816 | result.ModuleForTests(apiScopeSystem.stubsLibraryModuleName("foo"), "android_common") |
| 1817 | result.ModuleForTests(apiScopeTest.stubsLibraryModuleName("foo"), "android_common") |
| 1818 | result.ModuleForTests(apiScopePublic.stubsSourceModuleName("foo"), "android_common") |
| 1819 | result.ModuleForTests(apiScopeSystem.stubsSourceModuleName("foo"), "android_common") |
| 1820 | result.ModuleForTests(apiScopeTest.stubsSourceModuleName("foo"), "android_common") |
| 1821 | result.ModuleForTests("foo"+sdkXmlFileSuffix, "android_common") |
| 1822 | result.ModuleForTests("foo.api.public.28", "") |
| 1823 | result.ModuleForTests("foo.api.system.28", "") |
| 1824 | result.ModuleForTests("foo.api.test.28", "") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1825 | |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 1826 | bazJavac := result.ModuleForTests("baz", "android_common").Rule("javac") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1827 | // tests if baz is actually linked to the stubs lib |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 1828 | android.AssertStringDoesContain(t, "baz javac classpath", bazJavac.Args["classpath"], "foo.stubs.system.jar") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1829 | // ... and not to the impl lib |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 1830 | android.AssertStringDoesNotContain(t, "baz javac classpath", bazJavac.Args["classpath"], "foo.jar") |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1831 | // test if baz is not linked to the system variant of foo |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 1832 | android.AssertStringDoesNotContain(t, "baz javac classpath", bazJavac.Args["classpath"], "foo.stubs.jar") |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1833 | |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 1834 | bazTestJavac := result.ModuleForTests("baz-test", "android_common").Rule("javac") |
Paul Duffin | 726d23c | 2020-01-22 16:30:37 +0000 | [diff] [blame] | 1835 | // tests if baz-test is actually linked to the test stubs lib |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 1836 | android.AssertStringDoesContain(t, "baz-test javac classpath", bazTestJavac.Args["classpath"], "foo.stubs.test.jar") |
Paul Duffin | 726d23c | 2020-01-22 16:30:37 +0000 | [diff] [blame] | 1837 | |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 1838 | baz29Javac := result.ModuleForTests("baz-29", "android_common").Rule("javac") |
Paul Duffin | a2db18f | 2020-01-22 17:11:15 +0000 | [diff] [blame] | 1839 | // tests if baz-29 is actually linked to the system 29 stubs lib |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 1840 | android.AssertStringDoesContain(t, "baz-29 javac classpath", baz29Javac.Args["classpath"], "prebuilts/sdk/29/system/foo.jar") |
Paul Duffin | a2db18f | 2020-01-22 17:11:15 +0000 | [diff] [blame] | 1841 | |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 1842 | bazModule30Javac := result.ModuleForTests("baz-module-30", "android_common").Rule("javac") |
Paul Duffin | fb6ae5b | 2020-09-30 15:17:25 +0100 | [diff] [blame] | 1843 | // tests if "baz-module-30" is actually linked to the module 30 stubs lib |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 1844 | android.AssertStringDoesContain(t, "baz-module-30 javac classpath", bazModule30Javac.Args["classpath"], "prebuilts/sdk/30/module-lib/foo.jar") |
Paul Duffin | fb6ae5b | 2020-09-30 15:17:25 +0100 | [diff] [blame] | 1845 | |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1846 | // test if baz has exported SDK lib names foo and bar to qux |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 1847 | qux := result.ModuleForTests("qux", "android_common") |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1848 | if quxLib, ok := qux.Module().(*Library); ok { |
Ulya Trafimovich | b23d28c | 2020-10-08 12:53:58 +0100 | [diff] [blame] | 1849 | sdkLibs := quxLib.ClassLoaderContexts().UsesLibs() |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 1850 | android.AssertDeepEquals(t, "qux exports", []string{"foo", "bar", "fred", "quuz"}, sdkLibs) |
Jiyong Park | 1be9691 | 2018-05-28 18:02:19 +0900 | [diff] [blame] | 1851 | } |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 1852 | } |
Zoran Jovanovic | 8736ce2 | 2018-08-21 17:10:29 +0200 | [diff] [blame] | 1853 | |
Anton Hansson | 7f66efa | 2020-10-08 14:47:23 +0100 | [diff] [blame] | 1854 | func TestJavaSdkLibrary_StubOrImplOnlyLibs(t *testing.T) { |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 1855 | result := android.GroupFixturePreparers( |
| 1856 | prepareForJavaTest, |
Paul Duffin | 163043d | 2021-03-12 19:18:49 +0000 | [diff] [blame] | 1857 | PrepareForTestWithJavaSdkLibraryFiles, |
| 1858 | FixtureWithLastReleaseApis("sdklib"), |
| 1859 | ).RunTestWithBp(t, ` |
Anton Hansson | 7f66efa | 2020-10-08 14:47:23 +0100 | [diff] [blame] | 1860 | java_sdk_library { |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 1861 | name: "sdklib", |
Anton Hansson | 7f66efa | 2020-10-08 14:47:23 +0100 | [diff] [blame] | 1862 | srcs: ["a.java"], |
| 1863 | impl_only_libs: ["foo"], |
| 1864 | stub_only_libs: ["bar"], |
| 1865 | } |
| 1866 | java_library { |
| 1867 | name: "foo", |
| 1868 | srcs: ["a.java"], |
| 1869 | sdk_version: "current", |
| 1870 | } |
| 1871 | java_library { |
| 1872 | name: "bar", |
| 1873 | srcs: ["a.java"], |
| 1874 | sdk_version: "current", |
| 1875 | } |
| 1876 | `) |
| 1877 | |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 1878 | for _, implName := range []string{"sdklib", "sdklib.impl"} { |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 1879 | implJavacCp := result.ModuleForTests(implName, "android_common").Rule("javac").Args["classpath"] |
Anton Hansson | 7f66efa | 2020-10-08 14:47:23 +0100 | [diff] [blame] | 1880 | if !strings.Contains(implJavacCp, "/foo.jar") || strings.Contains(implJavacCp, "/bar.jar") { |
| 1881 | t.Errorf("%v javac classpath %v does not contain foo and not bar", implName, implJavacCp) |
| 1882 | } |
| 1883 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 1884 | stubName := apiScopePublic.stubsLibraryModuleName("sdklib") |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 1885 | stubsJavacCp := result.ModuleForTests(stubName, "android_common").Rule("javac").Args["classpath"] |
Anton Hansson | 7f66efa | 2020-10-08 14:47:23 +0100 | [diff] [blame] | 1886 | if strings.Contains(stubsJavacCp, "/foo.jar") || !strings.Contains(stubsJavacCp, "/bar.jar") { |
| 1887 | t.Errorf("stubs javac classpath %v does not contain bar and not foo", stubsJavacCp) |
| 1888 | } |
| 1889 | } |
| 1890 | |
Paul Duffin | daaa332 | 2020-05-26 18:13:57 +0100 | [diff] [blame] | 1891 | func TestJavaSdkLibrary_DoNotAccessImplWhenItIsNotBuilt(t *testing.T) { |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 1892 | result := android.GroupFixturePreparers( |
| 1893 | prepareForJavaTest, |
Paul Duffin | 163043d | 2021-03-12 19:18:49 +0000 | [diff] [blame] | 1894 | PrepareForTestWithJavaSdkLibraryFiles, |
| 1895 | FixtureWithLastReleaseApis("foo"), |
| 1896 | ).RunTestWithBp(t, ` |
Paul Duffin | daaa332 | 2020-05-26 18:13:57 +0100 | [diff] [blame] | 1897 | java_sdk_library { |
| 1898 | name: "foo", |
| 1899 | srcs: ["a.java"], |
| 1900 | api_only: true, |
| 1901 | public: { |
| 1902 | enabled: true, |
| 1903 | }, |
| 1904 | } |
| 1905 | |
| 1906 | java_library { |
| 1907 | name: "bar", |
| 1908 | srcs: ["b.java"], |
| 1909 | libs: ["foo"], |
| 1910 | } |
| 1911 | `) |
| 1912 | |
| 1913 | // The bar library should depend on the stubs jar. |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 1914 | barLibrary := result.ModuleForTests("bar", "android_common").Rule("javac") |
Paul Duffin | daaa332 | 2020-05-26 18:13:57 +0100 | [diff] [blame] | 1915 | if expected, actual := `^-classpath .*:/[^:]*/turbine-combined/foo\.stubs\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 1916 | t.Errorf("expected %q, found %#q", expected, actual) |
| 1917 | } |
| 1918 | } |
| 1919 | |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1920 | func TestJavaSdkLibrary_UseSourcesFromAnotherSdkLibrary(t *testing.T) { |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 1921 | android.GroupFixturePreparers( |
| 1922 | prepareForJavaTest, |
Paul Duffin | 163043d | 2021-03-12 19:18:49 +0000 | [diff] [blame] | 1923 | PrepareForTestWithJavaSdkLibraryFiles, |
| 1924 | FixtureWithLastReleaseApis("foo"), |
| 1925 | ).RunTestWithBp(t, ` |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1926 | java_sdk_library { |
| 1927 | name: "foo", |
| 1928 | srcs: ["a.java"], |
| 1929 | api_packages: ["foo"], |
| 1930 | public: { |
| 1931 | enabled: true, |
| 1932 | }, |
| 1933 | } |
| 1934 | |
| 1935 | java_library { |
| 1936 | name: "bar", |
| 1937 | srcs: ["b.java", ":foo{.public.stubs.source}"], |
| 1938 | } |
| 1939 | `) |
| 1940 | } |
| 1941 | |
| 1942 | func TestJavaSdkLibrary_AccessOutputFiles_MissingScope(t *testing.T) { |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 1943 | android.GroupFixturePreparers( |
| 1944 | prepareForJavaTest, |
| 1945 | PrepareForTestWithJavaSdkLibraryFiles, |
| 1946 | FixtureWithLastReleaseApis("foo"), |
| 1947 | ). |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 1948 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`"foo" does not provide api scope system`)). |
| 1949 | RunTestWithBp(t, ` |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1950 | java_sdk_library { |
| 1951 | name: "foo", |
| 1952 | srcs: ["a.java"], |
| 1953 | api_packages: ["foo"], |
| 1954 | public: { |
| 1955 | enabled: true, |
| 1956 | }, |
| 1957 | } |
| 1958 | |
| 1959 | java_library { |
| 1960 | name: "bar", |
| 1961 | srcs: ["b.java", ":foo{.system.stubs.source}"], |
| 1962 | } |
| 1963 | `) |
| 1964 | } |
| 1965 | |
Paul Duffin | ca8d9a5 | 2020-06-26 22:20:25 +0100 | [diff] [blame] | 1966 | func TestJavaSdkLibrary_Deps(t *testing.T) { |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 1967 | result := android.GroupFixturePreparers( |
| 1968 | prepareForJavaTest, |
Paul Duffin | 163043d | 2021-03-12 19:18:49 +0000 | [diff] [blame] | 1969 | PrepareForTestWithJavaSdkLibraryFiles, |
| 1970 | FixtureWithLastReleaseApis("sdklib"), |
| 1971 | ).RunTestWithBp(t, ` |
Paul Duffin | ca8d9a5 | 2020-06-26 22:20:25 +0100 | [diff] [blame] | 1972 | java_sdk_library { |
| 1973 | name: "sdklib", |
| 1974 | srcs: ["a.java"], |
| 1975 | sdk_version: "none", |
| 1976 | system_modules: "none", |
| 1977 | public: { |
| 1978 | enabled: true, |
| 1979 | }, |
| 1980 | } |
| 1981 | `) |
| 1982 | |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 1983 | CheckModuleDependencies(t, result.TestContext, "sdklib", "android_common", []string{ |
Paul Duffin | ca8d9a5 | 2020-06-26 22:20:25 +0100 | [diff] [blame] | 1984 | `dex2oatd`, |
| 1985 | `sdklib.impl`, |
| 1986 | `sdklib.stubs`, |
| 1987 | `sdklib.stubs.source`, |
| 1988 | `sdklib.xml`, |
| 1989 | }) |
| 1990 | } |
| 1991 | |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1992 | func TestJavaSdkLibraryImport_AccessOutputFiles(t *testing.T) { |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 1993 | prepareForJavaTest.RunTestWithBp(t, ` |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 1994 | java_sdk_library_import { |
| 1995 | name: "foo", |
| 1996 | public: { |
| 1997 | jars: ["a.jar"], |
| 1998 | stub_srcs: ["a.java"], |
| 1999 | current_api: "api/current.txt", |
| 2000 | removed_api: "api/removed.txt", |
| 2001 | }, |
| 2002 | } |
| 2003 | |
| 2004 | java_library { |
| 2005 | name: "bar", |
| 2006 | srcs: [":foo{.public.stubs.source}"], |
| 2007 | java_resources: [ |
| 2008 | ":foo{.public.api.txt}", |
| 2009 | ":foo{.public.removed-api.txt}", |
| 2010 | ], |
| 2011 | } |
| 2012 | `) |
| 2013 | } |
| 2014 | |
| 2015 | func TestJavaSdkLibraryImport_AccessOutputFiles_Invalid(t *testing.T) { |
| 2016 | bp := ` |
| 2017 | java_sdk_library_import { |
| 2018 | name: "foo", |
| 2019 | public: { |
| 2020 | jars: ["a.jar"], |
| 2021 | }, |
| 2022 | } |
| 2023 | ` |
| 2024 | |
| 2025 | t.Run("stubs.source", func(t *testing.T) { |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 2026 | prepareForJavaTest. |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 2027 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`stubs.source not available for api scope public`)). |
| 2028 | RunTestWithBp(t, bp+` |
| 2029 | java_library { |
| 2030 | name: "bar", |
| 2031 | srcs: [":foo{.public.stubs.source}"], |
| 2032 | java_resources: [ |
| 2033 | ":foo{.public.api.txt}", |
| 2034 | ":foo{.public.removed-api.txt}", |
| 2035 | ], |
| 2036 | } |
| 2037 | `) |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 2038 | }) |
| 2039 | |
| 2040 | t.Run("api.txt", func(t *testing.T) { |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 2041 | prepareForJavaTest. |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 2042 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`api.txt not available for api scope public`)). |
| 2043 | RunTestWithBp(t, bp+` |
| 2044 | java_library { |
| 2045 | name: "bar", |
| 2046 | srcs: ["a.java"], |
| 2047 | java_resources: [ |
| 2048 | ":foo{.public.api.txt}", |
| 2049 | ], |
| 2050 | } |
| 2051 | `) |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 2052 | }) |
| 2053 | |
| 2054 | t.Run("removed-api.txt", func(t *testing.T) { |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 2055 | prepareForJavaTest. |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 2056 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`removed-api.txt not available for api scope public`)). |
| 2057 | RunTestWithBp(t, bp+` |
| 2058 | java_library { |
| 2059 | name: "bar", |
| 2060 | srcs: ["a.java"], |
| 2061 | java_resources: [ |
| 2062 | ":foo{.public.removed-api.txt}", |
| 2063 | ], |
| 2064 | } |
| 2065 | `) |
Paul Duffin | 46dc45a | 2020-05-14 15:39:10 +0100 | [diff] [blame] | 2066 | }) |
| 2067 | } |
| 2068 | |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 2069 | func TestJavaSdkLibrary_InvalidScopes(t *testing.T) { |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 2070 | prepareForJavaTest. |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 2071 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "foo": enabled api scope "system" depends on disabled scope "public"`)). |
| 2072 | RunTestWithBp(t, ` |
| 2073 | java_sdk_library { |
| 2074 | name: "foo", |
| 2075 | srcs: ["a.java", "b.java"], |
| 2076 | api_packages: ["foo"], |
| 2077 | // Explicitly disable public to test the check that ensures the set of enabled |
| 2078 | // scopes is consistent. |
| 2079 | public: { |
| 2080 | enabled: false, |
| 2081 | }, |
| 2082 | system: { |
| 2083 | enabled: true, |
| 2084 | }, |
| 2085 | } |
Paul Duffin | 3375e35 | 2020-04-28 10:44:03 +0100 | [diff] [blame] | 2086 | `) |
| 2087 | } |
| 2088 | |
Paul Duffin | 87a05a3 | 2020-05-12 11:50:28 +0100 | [diff] [blame] | 2089 | func TestJavaSdkLibrary_SdkVersion_ForScope(t *testing.T) { |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 2090 | android.GroupFixturePreparers( |
| 2091 | prepareForJavaTest, |
Paul Duffin | 163043d | 2021-03-12 19:18:49 +0000 | [diff] [blame] | 2092 | PrepareForTestWithJavaSdkLibraryFiles, |
| 2093 | FixtureWithLastReleaseApis("foo"), |
| 2094 | ).RunTestWithBp(t, ` |
Paul Duffin | 87a05a3 | 2020-05-12 11:50:28 +0100 | [diff] [blame] | 2095 | java_sdk_library { |
| 2096 | name: "foo", |
| 2097 | srcs: ["a.java", "b.java"], |
| 2098 | api_packages: ["foo"], |
| 2099 | system: { |
| 2100 | enabled: true, |
| 2101 | sdk_version: "module_current", |
| 2102 | }, |
| 2103 | } |
| 2104 | `) |
| 2105 | } |
| 2106 | |
Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 2107 | func TestJavaSdkLibrary_ModuleLib(t *testing.T) { |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 2108 | android.GroupFixturePreparers( |
| 2109 | prepareForJavaTest, |
Paul Duffin | 163043d | 2021-03-12 19:18:49 +0000 | [diff] [blame] | 2110 | PrepareForTestWithJavaSdkLibraryFiles, |
| 2111 | FixtureWithLastReleaseApis("foo"), |
| 2112 | ).RunTestWithBp(t, ` |
Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 2113 | java_sdk_library { |
| 2114 | name: "foo", |
| 2115 | srcs: ["a.java", "b.java"], |
| 2116 | api_packages: ["foo"], |
| 2117 | system: { |
| 2118 | enabled: true, |
| 2119 | }, |
| 2120 | module_lib: { |
| 2121 | enabled: true, |
| 2122 | }, |
| 2123 | } |
| 2124 | `) |
| 2125 | } |
| 2126 | |
| 2127 | func TestJavaSdkLibrary_SystemServer(t *testing.T) { |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 2128 | android.GroupFixturePreparers( |
| 2129 | prepareForJavaTest, |
Paul Duffin | 163043d | 2021-03-12 19:18:49 +0000 | [diff] [blame] | 2130 | PrepareForTestWithJavaSdkLibraryFiles, |
| 2131 | FixtureWithLastReleaseApis("foo"), |
| 2132 | ).RunTestWithBp(t, ` |
Paul Duffin | 0c5bae5 | 2020-06-02 13:00:08 +0100 | [diff] [blame] | 2133 | java_sdk_library { |
| 2134 | name: "foo", |
| 2135 | srcs: ["a.java", "b.java"], |
| 2136 | api_packages: ["foo"], |
| 2137 | system: { |
| 2138 | enabled: true, |
| 2139 | }, |
| 2140 | system_server: { |
| 2141 | enabled: true, |
| 2142 | }, |
| 2143 | } |
| 2144 | `) |
| 2145 | } |
| 2146 | |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 2147 | func TestJavaSdkLibrary_MissingScope(t *testing.T) { |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 2148 | prepareForJavaTest. |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 2149 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`requires api scope module-lib from foo but it only has \[\] available`)). |
| 2150 | RunTestWithBp(t, ` |
| 2151 | java_sdk_library { |
| 2152 | name: "foo", |
| 2153 | srcs: ["a.java"], |
| 2154 | public: { |
| 2155 | enabled: false, |
| 2156 | }, |
| 2157 | } |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 2158 | |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 2159 | java_library { |
| 2160 | name: "baz", |
| 2161 | srcs: ["a.java"], |
| 2162 | libs: ["foo"], |
| 2163 | sdk_version: "module_current", |
| 2164 | } |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 2165 | `) |
| 2166 | } |
| 2167 | |
| 2168 | func TestJavaSdkLibrary_FallbackScope(t *testing.T) { |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 2169 | android.GroupFixturePreparers( |
| 2170 | prepareForJavaTest, |
Paul Duffin | 163043d | 2021-03-12 19:18:49 +0000 | [diff] [blame] | 2171 | PrepareForTestWithJavaSdkLibraryFiles, |
| 2172 | FixtureWithLastReleaseApis("foo"), |
| 2173 | ).RunTestWithBp(t, ` |
Paul Duffin | 803a956 | 2020-05-20 11:52:25 +0100 | [diff] [blame] | 2174 | java_sdk_library { |
| 2175 | name: "foo", |
| 2176 | srcs: ["a.java"], |
| 2177 | system: { |
| 2178 | enabled: true, |
| 2179 | }, |
| 2180 | } |
| 2181 | |
| 2182 | java_library { |
| 2183 | name: "baz", |
| 2184 | srcs: ["a.java"], |
| 2185 | libs: ["foo"], |
| 2186 | // foo does not have module-lib scope so it should fallback to system |
| 2187 | sdk_version: "module_current", |
| 2188 | } |
| 2189 | `) |
| 2190 | } |
| 2191 | |
Jiyong Park | 932cdfe | 2020-05-28 00:19:53 +0900 | [diff] [blame] | 2192 | func TestJavaSdkLibrary_DefaultToStubs(t *testing.T) { |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame^] | 2193 | result := android.GroupFixturePreparers( |
| 2194 | prepareForJavaTest, |
Paul Duffin | 163043d | 2021-03-12 19:18:49 +0000 | [diff] [blame] | 2195 | PrepareForTestWithJavaSdkLibraryFiles, |
| 2196 | FixtureWithLastReleaseApis("foo"), |
| 2197 | ).RunTestWithBp(t, ` |
Jiyong Park | 932cdfe | 2020-05-28 00:19:53 +0900 | [diff] [blame] | 2198 | java_sdk_library { |
| 2199 | name: "foo", |
| 2200 | srcs: ["a.java"], |
| 2201 | system: { |
| 2202 | enabled: true, |
| 2203 | }, |
| 2204 | default_to_stubs: true, |
| 2205 | } |
| 2206 | |
| 2207 | java_library { |
| 2208 | name: "baz", |
| 2209 | srcs: ["a.java"], |
| 2210 | libs: ["foo"], |
| 2211 | // does not have sdk_version set, should fallback to module, |
| 2212 | // which will then fallback to system because the module scope |
| 2213 | // is not enabled. |
| 2214 | } |
| 2215 | `) |
| 2216 | // The baz library should depend on the system stubs jar. |
Paul Duffin | 22b77cd | 2021-03-12 19:15:01 +0000 | [diff] [blame] | 2217 | bazLibrary := result.ModuleForTests("baz", "android_common").Rule("javac") |
Jiyong Park | 932cdfe | 2020-05-28 00:19:53 +0900 | [diff] [blame] | 2218 | if expected, actual := `^-classpath .*:/[^:]*/turbine-combined/foo\.stubs.system\.jar$`, bazLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
| 2219 | t.Errorf("expected %q, found %#q", expected, actual) |
| 2220 | } |
| 2221 | } |
| 2222 | |
Zoran Jovanovic | 8736ce2 | 2018-08-21 17:10:29 +0200 | [diff] [blame] | 2223 | var compilerFlagsTestCases = []struct { |
| 2224 | in string |
| 2225 | out bool |
| 2226 | }{ |
| 2227 | { |
| 2228 | in: "a", |
| 2229 | out: false, |
| 2230 | }, |
| 2231 | { |
| 2232 | in: "-a", |
| 2233 | out: true, |
| 2234 | }, |
| 2235 | { |
| 2236 | in: "-no-jdk", |
| 2237 | out: false, |
| 2238 | }, |
| 2239 | { |
| 2240 | in: "-no-stdlib", |
| 2241 | out: false, |
| 2242 | }, |
| 2243 | { |
| 2244 | in: "-kotlin-home", |
| 2245 | out: false, |
| 2246 | }, |
| 2247 | { |
| 2248 | in: "-kotlin-home /some/path", |
| 2249 | out: false, |
| 2250 | }, |
| 2251 | { |
| 2252 | in: "-include-runtime", |
| 2253 | out: false, |
| 2254 | }, |
| 2255 | { |
| 2256 | in: "-Xintellij-plugin-root", |
| 2257 | out: false, |
| 2258 | }, |
| 2259 | } |
| 2260 | |
| 2261 | type mockContext struct { |
| 2262 | android.ModuleContext |
| 2263 | result bool |
| 2264 | } |
| 2265 | |
| 2266 | func (ctx *mockContext) PropertyErrorf(property, format string, args ...interface{}) { |
| 2267 | // CheckBadCompilerFlags calls this function when the flag should be rejected |
| 2268 | ctx.result = false |
| 2269 | } |
| 2270 | |
| 2271 | func TestCompilerFlags(t *testing.T) { |
| 2272 | for _, testCase := range compilerFlagsTestCases { |
| 2273 | ctx := &mockContext{result: true} |
| 2274 | CheckKotlincFlags(ctx, []string{testCase.in}) |
| 2275 | if ctx.result != testCase.out { |
| 2276 | t.Errorf("incorrect output:") |
| 2277 | t.Errorf(" input: %#v", testCase.in) |
| 2278 | t.Errorf(" expected: %#v", testCase.out) |
| 2279 | t.Errorf(" got: %#v", ctx.result) |
| 2280 | } |
| 2281 | } |
| 2282 | } |
Jaewoong Jung | 38e4fb2 | 2018-12-12 09:01:34 -0800 | [diff] [blame] | 2283 | |
| 2284 | // TODO(jungjw): Consider making this more robust by ignoring path order. |
| 2285 | func checkPatchModuleFlag(t *testing.T, ctx *android.TestContext, moduleName string, expected string) { |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2286 | variables := ctx.ModuleForTests(moduleName, "android_common").VariablesForTestsRelativeToTop() |
Jaewoong Jung | 38e4fb2 | 2018-12-12 09:01:34 -0800 | [diff] [blame] | 2287 | flags := strings.Split(variables["javacFlags"], " ") |
| 2288 | got := "" |
| 2289 | for _, flag := range flags { |
| 2290 | keyEnd := strings.Index(flag, "=") |
| 2291 | if keyEnd > -1 && flag[:keyEnd] == "--patch-module" { |
| 2292 | got = flag[keyEnd+1:] |
| 2293 | break |
| 2294 | } |
| 2295 | } |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2296 | if expected != android.StringPathRelativeToTop(ctx.Config().BuildDir(), got) { |
Jaewoong Jung | 38e4fb2 | 2018-12-12 09:01:34 -0800 | [diff] [blame] | 2297 | t.Errorf("Unexpected patch-module flag for module %q - expected %q, but got %q", moduleName, expected, got) |
| 2298 | } |
| 2299 | } |
| 2300 | |
| 2301 | func TestPatchModule(t *testing.T) { |
Pete Gillin | 0c2143e | 2019-05-02 15:32:11 +0100 | [diff] [blame] | 2302 | t.Run("Java language level 8", func(t *testing.T) { |
Pete Gillin | 1b3370f | 2019-10-01 13:57:31 +0100 | [diff] [blame] | 2303 | // Test with legacy javac -source 1.8 -target 1.8 |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 2304 | bp := ` |
| 2305 | java_library { |
| 2306 | name: "foo", |
| 2307 | srcs: ["a.java"], |
| 2308 | java_version: "1.8", |
| 2309 | } |
| 2310 | |
| 2311 | java_library { |
| 2312 | name: "bar", |
| 2313 | srcs: ["b.java"], |
| 2314 | sdk_version: "none", |
| 2315 | system_modules: "none", |
| 2316 | patch_module: "java.base", |
| 2317 | java_version: "1.8", |
| 2318 | } |
| 2319 | |
| 2320 | java_library { |
| 2321 | name: "baz", |
| 2322 | srcs: ["c.java"], |
| 2323 | patch_module: "java.base", |
| 2324 | java_version: "1.8", |
| 2325 | } |
| 2326 | ` |
| 2327 | ctx, _ := testJava(t, bp) |
Jaewoong Jung | 38e4fb2 | 2018-12-12 09:01:34 -0800 | [diff] [blame] | 2328 | |
| 2329 | checkPatchModuleFlag(t, ctx, "foo", "") |
| 2330 | checkPatchModuleFlag(t, ctx, "bar", "") |
| 2331 | checkPatchModuleFlag(t, ctx, "baz", "") |
| 2332 | }) |
| 2333 | |
Pete Gillin | 0c2143e | 2019-05-02 15:32:11 +0100 | [diff] [blame] | 2334 | t.Run("Java language level 9", func(t *testing.T) { |
Pete Gillin | 1b3370f | 2019-10-01 13:57:31 +0100 | [diff] [blame] | 2335 | // Test with default javac -source 9 -target 9 |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 2336 | bp := ` |
| 2337 | java_library { |
| 2338 | name: "foo", |
| 2339 | srcs: ["a.java"], |
| 2340 | } |
| 2341 | |
| 2342 | java_library { |
| 2343 | name: "bar", |
| 2344 | srcs: ["b.java"], |
| 2345 | sdk_version: "none", |
| 2346 | system_modules: "none", |
| 2347 | patch_module: "java.base", |
| 2348 | } |
| 2349 | |
| 2350 | java_library { |
| 2351 | name: "baz", |
Jingwen Chen | 5136a6e | 2020-10-30 01:01:35 -0400 | [diff] [blame] | 2352 | srcs: [ |
| 2353 | "c.java", |
| 2354 | // Tests for b/150878007 |
| 2355 | "dir/d.java", |
| 2356 | "dir2/e.java", |
| 2357 | "dir2/f.java", |
| 2358 | "nested/dir/g.java" |
| 2359 | ], |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 2360 | patch_module: "java.base", |
| 2361 | } |
| 2362 | ` |
Pete Gillin | 1b3370f | 2019-10-01 13:57:31 +0100 | [diff] [blame] | 2363 | ctx, _ := testJava(t, bp) |
Jaewoong Jung | 38e4fb2 | 2018-12-12 09:01:34 -0800 | [diff] [blame] | 2364 | |
| 2365 | checkPatchModuleFlag(t, ctx, "foo", "") |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2366 | expected := "java.base=.:out/soong" |
Jaewoong Jung | 38e4fb2 | 2018-12-12 09:01:34 -0800 | [diff] [blame] | 2367 | checkPatchModuleFlag(t, ctx, "bar", expected) |
Jingwen Chen | 5136a6e | 2020-10-30 01:01:35 -0400 | [diff] [blame] | 2368 | expected = "java.base=" + strings.Join([]string{ |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2369 | ".", "out/soong", "dir", "dir2", "nested", defaultModuleToPath("ext"), defaultModuleToPath("framework")}, ":") |
Jaewoong Jung | 38e4fb2 | 2018-12-12 09:01:34 -0800 | [diff] [blame] | 2370 | checkPatchModuleFlag(t, ctx, "baz", expected) |
| 2371 | }) |
| 2372 | } |
Paul Duffin | a7b9f42 | 2020-01-10 17:12:18 +0000 | [diff] [blame] | 2373 | |
Paul Duffin | 83a2d96 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 2374 | func TestJavaLibraryWithSystemModules(t *testing.T) { |
| 2375 | ctx, _ := testJava(t, ` |
| 2376 | java_library { |
| 2377 | name: "lib-with-source-system-modules", |
| 2378 | srcs: [ |
| 2379 | "a.java", |
| 2380 | ], |
| 2381 | sdk_version: "none", |
| 2382 | system_modules: "source-system-modules", |
| 2383 | } |
| 2384 | |
| 2385 | java_library { |
| 2386 | name: "source-jar", |
| 2387 | srcs: [ |
| 2388 | "a.java", |
| 2389 | ], |
| 2390 | } |
| 2391 | |
| 2392 | java_system_modules { |
| 2393 | name: "source-system-modules", |
| 2394 | libs: ["source-jar"], |
| 2395 | } |
| 2396 | |
| 2397 | java_library { |
| 2398 | name: "lib-with-prebuilt-system-modules", |
| 2399 | srcs: [ |
| 2400 | "a.java", |
| 2401 | ], |
| 2402 | sdk_version: "none", |
| 2403 | system_modules: "prebuilt-system-modules", |
| 2404 | } |
| 2405 | |
| 2406 | java_import { |
| 2407 | name: "prebuilt-jar", |
| 2408 | jars: ["a.jar"], |
| 2409 | } |
| 2410 | |
| 2411 | java_system_modules_import { |
| 2412 | name: "prebuilt-system-modules", |
| 2413 | libs: ["prebuilt-jar"], |
| 2414 | } |
| 2415 | `) |
| 2416 | |
| 2417 | checkBootClasspathForSystemModule(t, ctx, "lib-with-source-system-modules", "/source-jar.jar") |
| 2418 | |
| 2419 | checkBootClasspathForSystemModule(t, ctx, "lib-with-prebuilt-system-modules", "/prebuilt-jar.jar") |
| 2420 | } |
| 2421 | |
| 2422 | func checkBootClasspathForSystemModule(t *testing.T, ctx *android.TestContext, moduleName string, expectedSuffix string) { |
| 2423 | javacRule := ctx.ModuleForTests(moduleName, "android_common").Rule("javac") |
| 2424 | bootClasspath := javacRule.Args["bootClasspath"] |
| 2425 | if strings.HasPrefix(bootClasspath, "--system ") && strings.HasSuffix(bootClasspath, expectedSuffix) { |
| 2426 | t.Errorf("bootclasspath of %q must start with --system and end with %q, but was %#v.", moduleName, expectedSuffix, bootClasspath) |
| 2427 | } |
| 2428 | } |
Jiyong Park | 19604de | 2020-03-24 16:44:11 +0900 | [diff] [blame] | 2429 | |
| 2430 | func TestAidlExportIncludeDirsFromImports(t *testing.T) { |
| 2431 | ctx, _ := testJava(t, ` |
| 2432 | java_library { |
| 2433 | name: "foo", |
| 2434 | srcs: ["aidl/foo/IFoo.aidl"], |
| 2435 | libs: ["bar"], |
| 2436 | } |
| 2437 | |
| 2438 | java_import { |
| 2439 | name: "bar", |
| 2440 | jars: ["a.jar"], |
| 2441 | aidl: { |
| 2442 | export_include_dirs: ["aidl/bar"], |
| 2443 | }, |
| 2444 | } |
| 2445 | `) |
| 2446 | |
| 2447 | aidlCommand := ctx.ModuleForTests("foo", "android_common").Rule("aidl").RuleParams.Command |
| 2448 | expectedAidlFlag := "-Iaidl/bar" |
| 2449 | if !strings.Contains(aidlCommand, expectedAidlFlag) { |
| 2450 | t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) |
| 2451 | } |
| 2452 | } |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 2453 | |
Jooyung Han | e197d8b | 2021-01-05 10:33:16 +0900 | [diff] [blame] | 2454 | func TestAidlFlagsArePassedToTheAidlCompiler(t *testing.T) { |
| 2455 | ctx, _ := testJava(t, ` |
| 2456 | java_library { |
| 2457 | name: "foo", |
| 2458 | srcs: ["aidl/foo/IFoo.aidl"], |
| 2459 | aidl: { flags: ["-Werror"], }, |
| 2460 | } |
| 2461 | `) |
| 2462 | |
| 2463 | aidlCommand := ctx.ModuleForTests("foo", "android_common").Rule("aidl").RuleParams.Command |
| 2464 | expectedAidlFlag := "-Werror" |
| 2465 | if !strings.Contains(aidlCommand, expectedAidlFlag) { |
| 2466 | t.Errorf("aidl command %q does not contain %q", aidlCommand, expectedAidlFlag) |
| 2467 | } |
| 2468 | } |
| 2469 | |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 2470 | func TestDataNativeBinaries(t *testing.T) { |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2471 | ctx, _ := testJava(t, ` |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 2472 | java_test_host { |
| 2473 | name: "foo", |
| 2474 | srcs: ["a.java"], |
| 2475 | data_native_bins: ["bin"] |
| 2476 | } |
| 2477 | |
| 2478 | python_binary_host { |
| 2479 | name: "bin", |
| 2480 | srcs: ["bin.py"], |
| 2481 | } |
| 2482 | `) |
| 2483 | |
| 2484 | buildOS := android.BuildOs.String() |
| 2485 | |
| 2486 | test := ctx.ModuleForTests("foo", buildOS+"_common").Module().(*TestHost) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2487 | entries := android.AndroidMkEntriesForTest(t, ctx, test)[0] |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2488 | expected := []string{"out/soong/.intermediates/bin/" + buildOS + "_x86_64_PY3/bin:bin"} |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 2489 | actual := entries.EntryMap["LOCAL_COMPATIBILITY_SUPPORT_FILES"] |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 2490 | android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_COMPATIBILITY_SUPPORT_FILES", ctx.Config(), expected, actual) |
Liz Kammer | dd849a8 | 2020-06-12 16:38:45 -0700 | [diff] [blame] | 2491 | } |
Yuexi Ma | 627263f | 2021-03-04 13:47:56 -0800 | [diff] [blame] | 2492 | |
| 2493 | func TestDefaultInstallable(t *testing.T) { |
| 2494 | ctx, _ := testJava(t, ` |
| 2495 | java_test_host { |
| 2496 | name: "foo" |
| 2497 | } |
| 2498 | `) |
| 2499 | |
| 2500 | buildOS := android.BuildOs.String() |
| 2501 | module := ctx.ModuleForTests("foo", buildOS+"_common").Module().(*TestHost) |
| 2502 | assertDeepEquals(t, "Default installable value should be true.", proptools.BoolPtr(true), |
| 2503 | module.properties.Installable) |
| 2504 | } |