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