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