Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1 | // Copyright 2018 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 apex |
| 16 | |
| 17 | import ( |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 18 | "fmt" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 19 | "os" |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 20 | "path" |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 21 | "path/filepath" |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 22 | "reflect" |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 23 | "regexp" |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 24 | "sort" |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 25 | "strconv" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 26 | "strings" |
| 27 | "testing" |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 28 | |
| 29 | "github.com/google/blueprint/proptools" |
| 30 | |
| 31 | "android/soong/android" |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 32 | "android/soong/bpf" |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 33 | "android/soong/cc" |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 34 | "android/soong/dexpreopt" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 35 | prebuilt_etc "android/soong/etc" |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 36 | "android/soong/java" |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 37 | "android/soong/rust" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 38 | "android/soong/sh" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 39 | ) |
| 40 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 41 | // names returns name list from white space separated string |
| 42 | func names(s string) (ns []string) { |
| 43 | for _, n := range strings.Split(s, " ") { |
| 44 | if len(n) > 0 { |
| 45 | ns = append(ns, n) |
| 46 | } |
| 47 | } |
| 48 | return |
| 49 | } |
| 50 | |
Paul Duffin | 40b6257 | 2021-03-20 11:39:01 +0000 | [diff] [blame] | 51 | func testApexError(t *testing.T, pattern, bp string, preparers ...android.FixturePreparer) { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 52 | t.Helper() |
Paul Duffin | 284165a | 2021-03-29 01:50:31 +0100 | [diff] [blame] | 53 | android.GroupFixturePreparers( |
| 54 | prepareForApexTest, |
| 55 | android.GroupFixturePreparers(preparers...), |
| 56 | ). |
Paul Duffin | e05480a | 2021-03-08 15:07:14 +0000 | [diff] [blame] | 57 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)). |
Paul Duffin | 40b6257 | 2021-03-20 11:39:01 +0000 | [diff] [blame] | 58 | RunTestWithBp(t, bp) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 59 | } |
| 60 | |
Paul Duffin | 40b6257 | 2021-03-20 11:39:01 +0000 | [diff] [blame] | 61 | func testApex(t *testing.T, bp string, preparers ...android.FixturePreparer) *android.TestContext { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 62 | t.Helper() |
Paul Duffin | 284165a | 2021-03-29 01:50:31 +0100 | [diff] [blame] | 63 | |
| 64 | optionalBpPreparer := android.NullFixturePreparer |
Paul Duffin | 40b6257 | 2021-03-20 11:39:01 +0000 | [diff] [blame] | 65 | if bp != "" { |
Paul Duffin | 284165a | 2021-03-29 01:50:31 +0100 | [diff] [blame] | 66 | optionalBpPreparer = android.FixtureWithRootAndroidBp(bp) |
Paul Duffin | 40b6257 | 2021-03-20 11:39:01 +0000 | [diff] [blame] | 67 | } |
Paul Duffin | 284165a | 2021-03-29 01:50:31 +0100 | [diff] [blame] | 68 | |
| 69 | result := android.GroupFixturePreparers( |
| 70 | prepareForApexTest, |
| 71 | android.GroupFixturePreparers(preparers...), |
| 72 | optionalBpPreparer, |
| 73 | ).RunTest(t) |
| 74 | |
Paul Duffin | e05480a | 2021-03-08 15:07:14 +0000 | [diff] [blame] | 75 | return result.TestContext |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 76 | } |
| 77 | |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 78 | func withFiles(files android.MockFS) android.FixturePreparer { |
| 79 | return files.AddToFixture() |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 80 | } |
| 81 | |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 82 | func withTargets(targets map[android.OsType][]android.Target) android.FixturePreparer { |
| 83 | return android.FixtureModifyConfig(func(config android.Config) { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 84 | for k, v := range targets { |
| 85 | config.Targets[k] = v |
| 86 | } |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 87 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 88 | } |
| 89 | |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 90 | // withNativeBridgeTargets sets configuration with targets including: |
| 91 | // - X86_64 (primary) |
| 92 | // - X86 (secondary) |
| 93 | // - Arm64 on X86_64 (native bridge) |
| 94 | // - Arm on X86 (native bridge) |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 95 | var withNativeBridgeEnabled = android.FixtureModifyConfig( |
| 96 | func(config android.Config) { |
| 97 | config.Targets[android.Android] = []android.Target{ |
| 98 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, |
| 99 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 100 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, |
| 101 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 102 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, |
| 103 | NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86_64", NativeBridgeRelativePath: "arm64"}, |
| 104 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, |
| 105 | NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86", NativeBridgeRelativePath: "arm"}, |
| 106 | } |
| 107 | }, |
| 108 | ) |
| 109 | |
| 110 | func withManifestPackageNameOverrides(specs []string) android.FixturePreparer { |
| 111 | return android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 112 | variables.ManifestPackageNameOverrides = specs |
| 113 | }) |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 114 | } |
| 115 | |
Albert Martin | 55ccba2 | 2022-03-21 20:11:16 +0000 | [diff] [blame] | 116 | func withApexGlobalMinSdkVersionOverride(minSdkOverride *string) android.FixturePreparer { |
| 117 | return android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 118 | variables.ApexGlobalMinSdkVersionOverride = minSdkOverride |
| 119 | }) |
| 120 | } |
| 121 | |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 122 | var withBinder32bit = android.FixtureModifyProductVariables( |
| 123 | func(variables android.FixtureProductVariables) { |
| 124 | variables.Binder32bit = proptools.BoolPtr(true) |
| 125 | }, |
| 126 | ) |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 127 | |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 128 | var withUnbundledBuild = android.FixtureModifyProductVariables( |
| 129 | func(variables android.FixtureProductVariables) { |
| 130 | variables.Unbundled_build = proptools.BoolPtr(true) |
| 131 | }, |
| 132 | ) |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 133 | |
Paul Duffin | 284165a | 2021-03-29 01:50:31 +0100 | [diff] [blame] | 134 | // Legacy preparer used for running tests within the apex package. |
| 135 | // |
| 136 | // This includes everything that was needed to run any test in the apex package prior to the |
| 137 | // introduction of the test fixtures. Tests that are being converted to use fixtures directly |
| 138 | // rather than through the testApex...() methods should avoid using this and instead use the |
| 139 | // various preparers directly, using android.GroupFixturePreparers(...) to group them when |
| 140 | // necessary. |
| 141 | // |
| 142 | // deprecated |
| 143 | var prepareForApexTest = android.GroupFixturePreparers( |
Paul Duffin | 37aad60 | 2021-03-08 09:47:16 +0000 | [diff] [blame] | 144 | // General preparers in alphabetical order as test infrastructure will enforce correct |
| 145 | // registration order. |
| 146 | android.PrepareForTestWithAndroidBuildComponents, |
| 147 | bpf.PrepareForTestWithBpf, |
| 148 | cc.PrepareForTestWithCcBuildComponents, |
| 149 | java.PrepareForTestWithJavaDefaultModules, |
| 150 | prebuilt_etc.PrepareForTestWithPrebuiltEtc, |
| 151 | rust.PrepareForTestWithRustDefaultModules, |
| 152 | sh.PrepareForTestWithShBuildComponents, |
| 153 | |
| 154 | PrepareForTestWithApexBuildComponents, |
| 155 | |
| 156 | // Additional apex test specific preparers. |
| 157 | android.FixtureAddTextFile("system/sepolicy/Android.bp", ` |
| 158 | filegroup { |
| 159 | name: "myapex-file_contexts", |
| 160 | srcs: [ |
| 161 | "apex/myapex-file_contexts", |
| 162 | ], |
| 163 | } |
| 164 | `), |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 165 | prepareForTestWithMyapex, |
Paul Duffin | 37aad60 | 2021-03-08 09:47:16 +0000 | [diff] [blame] | 166 | android.FixtureMergeMockFs(android.MockFS{ |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 167 | "a.java": nil, |
| 168 | "PrebuiltAppFoo.apk": nil, |
| 169 | "PrebuiltAppFooPriv.apk": nil, |
| 170 | "apex_manifest.json": nil, |
| 171 | "AndroidManifest.xml": nil, |
Paul Duffin | 37aad60 | 2021-03-08 09:47:16 +0000 | [diff] [blame] | 172 | "system/sepolicy/apex/myapex.updatable-file_contexts": nil, |
| 173 | "system/sepolicy/apex/myapex2-file_contexts": nil, |
| 174 | "system/sepolicy/apex/otherapex-file_contexts": nil, |
| 175 | "system/sepolicy/apex/com.android.vndk-file_contexts": nil, |
| 176 | "system/sepolicy/apex/com.android.vndk.current-file_contexts": nil, |
Colin Cross | abc0dab | 2022-04-07 17:39:21 -0700 | [diff] [blame] | 177 | "mylib.cpp": nil, |
| 178 | "mytest.cpp": nil, |
| 179 | "mytest1.cpp": nil, |
| 180 | "mytest2.cpp": nil, |
| 181 | "mytest3.cpp": nil, |
| 182 | "myprebuilt": nil, |
| 183 | "my_include": nil, |
| 184 | "foo/bar/MyClass.java": nil, |
| 185 | "prebuilt.jar": nil, |
| 186 | "prebuilt.so": nil, |
| 187 | "vendor/foo/devkeys/test.x509.pem": nil, |
| 188 | "vendor/foo/devkeys/test.pk8": nil, |
| 189 | "testkey.x509.pem": nil, |
| 190 | "testkey.pk8": nil, |
| 191 | "testkey.override.x509.pem": nil, |
| 192 | "testkey.override.pk8": nil, |
| 193 | "vendor/foo/devkeys/testkey.avbpubkey": nil, |
| 194 | "vendor/foo/devkeys/testkey.pem": nil, |
| 195 | "NOTICE": nil, |
| 196 | "custom_notice": nil, |
| 197 | "custom_notice_for_static_lib": nil, |
| 198 | "testkey2.avbpubkey": nil, |
| 199 | "testkey2.pem": nil, |
| 200 | "myapex-arm64.apex": nil, |
| 201 | "myapex-arm.apex": nil, |
| 202 | "myapex.apks": nil, |
| 203 | "frameworks/base/api/current.txt": nil, |
| 204 | "framework/aidl/a.aidl": nil, |
| 205 | "dummy.txt": nil, |
| 206 | "baz": nil, |
| 207 | "bar/baz": nil, |
| 208 | "testdata/baz": nil, |
| 209 | "AppSet.apks": nil, |
| 210 | "foo.rs": nil, |
| 211 | "libfoo.jar": nil, |
| 212 | "libbar.jar": nil, |
Paul Duffin | 37aad60 | 2021-03-08 09:47:16 +0000 | [diff] [blame] | 213 | }, |
| 214 | ), |
| 215 | |
| 216 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 217 | variables.DeviceVndkVersion = proptools.StringPtr("current") |
| 218 | variables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test") |
| 219 | variables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"} |
| 220 | variables.Platform_sdk_codename = proptools.StringPtr("Q") |
| 221 | variables.Platform_sdk_final = proptools.BoolPtr(false) |
Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 222 | // "Tiramisu" needs to be in the next line for compatibility with soong code, |
| 223 | // not because of these tests specifically (it's not used by the tests) |
| 224 | variables.Platform_version_active_codenames = []string{"Q", "Tiramisu"} |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 225 | variables.Platform_vndk_version = proptools.StringPtr("29") |
Oriol Prieto Gascó | a70425f | 2022-05-20 13:05:34 +0000 | [diff] [blame] | 226 | variables.BuildId = proptools.StringPtr("TEST.BUILD_ID") |
Paul Duffin | 37aad60 | 2021-03-08 09:47:16 +0000 | [diff] [blame] | 227 | }), |
| 228 | ) |
| 229 | |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 230 | var prepareForTestWithMyapex = android.FixtureMergeMockFs(android.MockFS{ |
| 231 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 232 | }) |
| 233 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 234 | // ensure that 'result' equals 'expected' |
| 235 | func ensureEquals(t *testing.T, result string, expected string) { |
| 236 | t.Helper() |
| 237 | if result != expected { |
| 238 | t.Errorf("%q != %q", expected, result) |
| 239 | } |
| 240 | } |
| 241 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 242 | // ensure that 'result' contains 'expected' |
| 243 | func ensureContains(t *testing.T, result string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 244 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 245 | if !strings.Contains(result, expected) { |
| 246 | t.Errorf("%q is not found in %q", expected, result) |
| 247 | } |
| 248 | } |
| 249 | |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 250 | // ensure that 'result' contains 'expected' exactly one time |
| 251 | func ensureContainsOnce(t *testing.T, result string, expected string) { |
| 252 | t.Helper() |
| 253 | count := strings.Count(result, expected) |
| 254 | if count != 1 { |
| 255 | t.Errorf("%q is found %d times (expected 1 time) in %q", expected, count, result) |
| 256 | } |
| 257 | } |
| 258 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 259 | // ensures that 'result' does not contain 'notExpected' |
| 260 | func ensureNotContains(t *testing.T, result string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 261 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 262 | if strings.Contains(result, notExpected) { |
| 263 | t.Errorf("%q is found in %q", notExpected, result) |
| 264 | } |
| 265 | } |
| 266 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 267 | func ensureMatches(t *testing.T, result string, expectedRex string) { |
| 268 | ok, err := regexp.MatchString(expectedRex, result) |
| 269 | if err != nil { |
| 270 | t.Fatalf("regexp failure trying to match %s against `%s` expression: %s", result, expectedRex, err) |
| 271 | return |
| 272 | } |
| 273 | if !ok { |
| 274 | t.Errorf("%s does not match regular expession %s", result, expectedRex) |
| 275 | } |
| 276 | } |
| 277 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 278 | func ensureListContains(t *testing.T, result []string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 279 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 280 | if !android.InList(expected, result) { |
| 281 | t.Errorf("%q is not found in %v", expected, result) |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | func ensureListNotContains(t *testing.T, result []string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 286 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 287 | if android.InList(notExpected, result) { |
| 288 | t.Errorf("%q is found in %v", notExpected, result) |
| 289 | } |
| 290 | } |
| 291 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 292 | func ensureListEmpty(t *testing.T, result []string) { |
| 293 | t.Helper() |
| 294 | if len(result) > 0 { |
| 295 | t.Errorf("%q is expected to be empty", result) |
| 296 | } |
| 297 | } |
| 298 | |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 299 | func ensureListNotEmpty(t *testing.T, result []string) { |
| 300 | t.Helper() |
| 301 | if len(result) == 0 { |
| 302 | t.Errorf("%q is expected to be not empty", result) |
| 303 | } |
| 304 | } |
| 305 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 306 | // Minimal test |
| 307 | func TestBasicApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 308 | ctx := testApex(t, ` |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 309 | apex_defaults { |
| 310 | name: "myapex-defaults", |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 311 | manifest: ":myapex.manifest", |
| 312 | androidManifest: ":myapex.androidmanifest", |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 313 | key: "myapex.key", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 314 | binaries: ["foo.rust"], |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 315 | native_shared_libs: [ |
| 316 | "mylib", |
| 317 | "libfoo.ffi", |
| 318 | ], |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 319 | rust_dyn_libs: ["libfoo.dylib.rust"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 320 | multilib: { |
| 321 | both: { |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 322 | binaries: ["foo"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 323 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 324 | }, |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 325 | java_libs: [ |
| 326 | "myjar", |
| 327 | "myjar_dex", |
| 328 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 329 | updatable: false, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 330 | } |
| 331 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 332 | apex { |
| 333 | name: "myapex", |
| 334 | defaults: ["myapex-defaults"], |
| 335 | } |
| 336 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 337 | apex_key { |
| 338 | name: "myapex.key", |
| 339 | public_key: "testkey.avbpubkey", |
| 340 | private_key: "testkey.pem", |
| 341 | } |
| 342 | |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 343 | filegroup { |
| 344 | name: "myapex.manifest", |
| 345 | srcs: ["apex_manifest.json"], |
| 346 | } |
| 347 | |
| 348 | filegroup { |
| 349 | name: "myapex.androidmanifest", |
| 350 | srcs: ["AndroidManifest.xml"], |
| 351 | } |
| 352 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 353 | cc_library { |
| 354 | name: "mylib", |
| 355 | srcs: ["mylib.cpp"], |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 356 | shared_libs: [ |
| 357 | "mylib2", |
| 358 | "libbar.ffi", |
| 359 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 360 | system_shared_libs: [], |
| 361 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 362 | // TODO: remove //apex_available:platform |
| 363 | apex_available: [ |
| 364 | "//apex_available:platform", |
| 365 | "myapex", |
| 366 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 367 | } |
| 368 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 369 | cc_binary { |
| 370 | name: "foo", |
| 371 | srcs: ["mylib.cpp"], |
| 372 | compile_multilib: "both", |
| 373 | multilib: { |
| 374 | lib32: { |
| 375 | suffix: "32", |
| 376 | }, |
| 377 | lib64: { |
| 378 | suffix: "64", |
| 379 | }, |
| 380 | }, |
| 381 | symlinks: ["foo_link_"], |
| 382 | symlink_preferred_arch: true, |
| 383 | system_shared_libs: [], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 384 | stl: "none", |
Yifan Hong | d22a84a | 2020-07-28 17:37:46 -0700 | [diff] [blame] | 385 | apex_available: [ "myapex", "com.android.gki.*" ], |
| 386 | } |
| 387 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 388 | rust_binary { |
Artur Satayev | 533b98c | 2021-03-11 18:03:42 +0000 | [diff] [blame] | 389 | name: "foo.rust", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 390 | srcs: ["foo.rs"], |
| 391 | rlibs: ["libfoo.rlib.rust"], |
| 392 | dylibs: ["libfoo.dylib.rust"], |
| 393 | apex_available: ["myapex"], |
| 394 | } |
| 395 | |
| 396 | rust_library_rlib { |
Artur Satayev | 533b98c | 2021-03-11 18:03:42 +0000 | [diff] [blame] | 397 | name: "libfoo.rlib.rust", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 398 | srcs: ["foo.rs"], |
| 399 | crate_name: "foo", |
| 400 | apex_available: ["myapex"], |
Jiyong Park | 94e22fd | 2021-04-08 18:19:15 +0900 | [diff] [blame] | 401 | shared_libs: ["libfoo.shared_from_rust"], |
| 402 | } |
| 403 | |
| 404 | cc_library_shared { |
| 405 | name: "libfoo.shared_from_rust", |
| 406 | srcs: ["mylib.cpp"], |
| 407 | system_shared_libs: [], |
| 408 | stl: "none", |
| 409 | apex_available: ["myapex"], |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | rust_library_dylib { |
Artur Satayev | 533b98c | 2021-03-11 18:03:42 +0000 | [diff] [blame] | 413 | name: "libfoo.dylib.rust", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 414 | srcs: ["foo.rs"], |
| 415 | crate_name: "foo", |
| 416 | apex_available: ["myapex"], |
| 417 | } |
| 418 | |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 419 | rust_ffi_shared { |
| 420 | name: "libfoo.ffi", |
| 421 | srcs: ["foo.rs"], |
| 422 | crate_name: "foo", |
| 423 | apex_available: ["myapex"], |
| 424 | } |
| 425 | |
| 426 | rust_ffi_shared { |
| 427 | name: "libbar.ffi", |
| 428 | srcs: ["foo.rs"], |
| 429 | crate_name: "bar", |
| 430 | apex_available: ["myapex"], |
| 431 | } |
| 432 | |
Yifan Hong | d22a84a | 2020-07-28 17:37:46 -0700 | [diff] [blame] | 433 | apex { |
| 434 | name: "com.android.gki.fake", |
| 435 | binaries: ["foo"], |
| 436 | key: "myapex.key", |
| 437 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 438 | updatable: false, |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 439 | } |
| 440 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 441 | cc_library_shared { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 442 | name: "mylib2", |
| 443 | srcs: ["mylib.cpp"], |
| 444 | system_shared_libs: [], |
| 445 | stl: "none", |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 446 | notice: "custom_notice", |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 447 | static_libs: ["libstatic"], |
| 448 | // TODO: remove //apex_available:platform |
| 449 | apex_available: [ |
| 450 | "//apex_available:platform", |
| 451 | "myapex", |
| 452 | ], |
| 453 | } |
| 454 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 455 | cc_prebuilt_library_shared { |
| 456 | name: "mylib2", |
| 457 | srcs: ["prebuilt.so"], |
| 458 | // TODO: remove //apex_available:platform |
| 459 | apex_available: [ |
| 460 | "//apex_available:platform", |
| 461 | "myapex", |
| 462 | ], |
| 463 | } |
| 464 | |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 465 | cc_library_static { |
| 466 | name: "libstatic", |
| 467 | srcs: ["mylib.cpp"], |
| 468 | system_shared_libs: [], |
| 469 | stl: "none", |
| 470 | notice: "custom_notice_for_static_lib", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 471 | // TODO: remove //apex_available:platform |
| 472 | apex_available: [ |
| 473 | "//apex_available:platform", |
| 474 | "myapex", |
| 475 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 476 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 477 | |
| 478 | java_library { |
| 479 | name: "myjar", |
| 480 | srcs: ["foo/bar/MyClass.java"], |
Jiyong Park | a62aa23 | 2020-05-28 23:46:55 +0900 | [diff] [blame] | 481 | stem: "myjar_stem", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 482 | sdk_version: "none", |
| 483 | system_modules: "none", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 484 | static_libs: ["myotherjar"], |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 485 | libs: ["mysharedjar"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 486 | // TODO: remove //apex_available:platform |
| 487 | apex_available: [ |
| 488 | "//apex_available:platform", |
| 489 | "myapex", |
| 490 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 491 | } |
| 492 | |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 493 | dex_import { |
| 494 | name: "myjar_dex", |
| 495 | jars: ["prebuilt.jar"], |
| 496 | apex_available: [ |
| 497 | "//apex_available:platform", |
| 498 | "myapex", |
| 499 | ], |
| 500 | } |
| 501 | |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 502 | java_library { |
| 503 | name: "myotherjar", |
| 504 | srcs: ["foo/bar/MyClass.java"], |
| 505 | sdk_version: "none", |
| 506 | system_modules: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 507 | // TODO: remove //apex_available:platform |
| 508 | apex_available: [ |
| 509 | "//apex_available:platform", |
| 510 | "myapex", |
| 511 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 512 | } |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 513 | |
| 514 | java_library { |
| 515 | name: "mysharedjar", |
| 516 | srcs: ["foo/bar/MyClass.java"], |
| 517 | sdk_version: "none", |
| 518 | system_modules: "none", |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 519 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 520 | `) |
| 521 | |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 522 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 523 | |
Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 524 | // Make sure that Android.mk is created |
| 525 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 526 | data := android.AndroidMkDataForTest(t, ctx, ab) |
Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 527 | var builder strings.Builder |
| 528 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 529 | |
| 530 | androidMk := builder.String() |
| 531 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 532 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
| 533 | |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 534 | optFlags := apexRule.Args["opt_flags"] |
| 535 | ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey") |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 536 | // Ensure that the NOTICE output is being packaged as an asset. |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 537 | ensureContains(t, optFlags, "--assets_dir out/soong/.intermediates/myapex/android_common_myapex_image/NOTICE") |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 538 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 539 | copyCmds := apexRule.Args["copy_commands"] |
| 540 | |
| 541 | // Ensure that main rule creates an output |
| 542 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 543 | |
| 544 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 545 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
| 546 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_apex10000") |
| 547 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar_dex"), "android_common_apex10000") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 548 | ensureListContains(t, ctx.ModuleVariantsForTests("foo.rust"), "android_arm64_armv8-a_apex10000") |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 549 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.ffi"), "android_arm64_armv8-a_shared_apex10000") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 550 | |
| 551 | // Ensure that apex variant is created for the indirect dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 552 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
| 553 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_apex10000") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 554 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.rlib.rust"), "android_arm64_armv8-a_rlib_dylib-std_apex10000") |
| 555 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.dylib.rust"), "android_arm64_armv8-a_dylib_apex10000") |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 556 | ensureListContains(t, ctx.ModuleVariantsForTests("libbar.ffi"), "android_arm64_armv8-a_shared_apex10000") |
Jiyong Park | 94e22fd | 2021-04-08 18:19:15 +0900 | [diff] [blame] | 557 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.shared_from_rust"), "android_arm64_armv8-a_shared_apex10000") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 558 | |
| 559 | // Ensure that both direct and indirect deps are copied into apex |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 560 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 561 | ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | a62aa23 | 2020-05-28 23:46:55 +0900 | [diff] [blame] | 562 | ensureContains(t, copyCmds, "image.apex/javalib/myjar_stem.jar") |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 563 | ensureContains(t, copyCmds, "image.apex/javalib/myjar_dex.jar") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 564 | ensureContains(t, copyCmds, "image.apex/lib64/libfoo.dylib.rust.dylib.so") |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 565 | ensureContains(t, copyCmds, "image.apex/lib64/libfoo.ffi.so") |
| 566 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.ffi.so") |
Jiyong Park | 94e22fd | 2021-04-08 18:19:15 +0900 | [diff] [blame] | 567 | ensureContains(t, copyCmds, "image.apex/lib64/libfoo.shared_from_rust.so") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 568 | // .. but not for java libs |
| 569 | ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 570 | ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar") |
Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 571 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 572 | // Ensure that the platform variant ends with _shared or _common |
| 573 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 574 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 575 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common") |
| 576 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 577 | ensureListContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common") |
| 578 | |
| 579 | // Ensure that dynamic dependency to java libs are not included |
| 580 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common_myapex") |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 581 | |
| 582 | // Ensure that all symlinks are present. |
| 583 | found_foo_link_64 := false |
| 584 | found_foo := false |
| 585 | for _, cmd := range strings.Split(copyCmds, " && ") { |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 586 | if strings.HasPrefix(cmd, "ln -sfn foo64") { |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 587 | if strings.HasSuffix(cmd, "bin/foo") { |
| 588 | found_foo = true |
| 589 | } else if strings.HasSuffix(cmd, "bin/foo_link_64") { |
| 590 | found_foo_link_64 = true |
| 591 | } |
| 592 | } |
| 593 | } |
| 594 | good := found_foo && found_foo_link_64 |
| 595 | if !good { |
| 596 | t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds) |
| 597 | } |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 598 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 599 | fullDepsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("depsinfo/fulllist.txt").Args["content"], "\\n") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 600 | ensureListContains(t, fullDepsInfo, " myjar(minSdkVersion:(no version)) <- myapex") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 601 | ensureListContains(t, fullDepsInfo, " mylib2(minSdkVersion:(no version)) <- mylib") |
| 602 | ensureListContains(t, fullDepsInfo, " myotherjar(minSdkVersion:(no version)) <- myjar") |
| 603 | ensureListContains(t, fullDepsInfo, " mysharedjar(minSdkVersion:(no version)) (external) <- myjar") |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 604 | |
| 605 | flatDepsInfo := strings.Split(ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("depsinfo/flatlist.txt").Args["content"], "\\n") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 606 | ensureListContains(t, flatDepsInfo, "myjar(minSdkVersion:(no version))") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 607 | ensureListContains(t, flatDepsInfo, "mylib2(minSdkVersion:(no version))") |
| 608 | ensureListContains(t, flatDepsInfo, "myotherjar(minSdkVersion:(no version))") |
| 609 | ensureListContains(t, flatDepsInfo, "mysharedjar(minSdkVersion:(no version)) (external)") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 610 | } |
| 611 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 612 | func TestDefaults(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 613 | ctx := testApex(t, ` |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 614 | apex_defaults { |
| 615 | name: "myapex-defaults", |
| 616 | key: "myapex.key", |
| 617 | prebuilts: ["myetc"], |
| 618 | native_shared_libs: ["mylib"], |
| 619 | java_libs: ["myjar"], |
| 620 | apps: ["AppFoo"], |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 621 | rros: ["rro"], |
Ken Chen | fad7f9d | 2021-11-10 22:02:57 +0800 | [diff] [blame] | 622 | bpfs: ["bpf", "netd_test"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 623 | updatable: false, |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | prebuilt_etc { |
| 627 | name: "myetc", |
| 628 | src: "myprebuilt", |
| 629 | } |
| 630 | |
| 631 | apex { |
| 632 | name: "myapex", |
| 633 | defaults: ["myapex-defaults"], |
| 634 | } |
| 635 | |
| 636 | apex_key { |
| 637 | name: "myapex.key", |
| 638 | public_key: "testkey.avbpubkey", |
| 639 | private_key: "testkey.pem", |
| 640 | } |
| 641 | |
| 642 | cc_library { |
| 643 | name: "mylib", |
| 644 | system_shared_libs: [], |
| 645 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 646 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | java_library { |
| 650 | name: "myjar", |
| 651 | srcs: ["foo/bar/MyClass.java"], |
| 652 | sdk_version: "none", |
| 653 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 654 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | android_app { |
| 658 | name: "AppFoo", |
| 659 | srcs: ["foo/bar/MyClass.java"], |
| 660 | sdk_version: "none", |
| 661 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 662 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 663 | } |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 664 | |
| 665 | runtime_resource_overlay { |
| 666 | name: "rro", |
| 667 | theme: "blue", |
| 668 | } |
| 669 | |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 670 | bpf { |
| 671 | name: "bpf", |
| 672 | srcs: ["bpf.c", "bpf2.c"], |
| 673 | } |
| 674 | |
Ken Chen | fad7f9d | 2021-11-10 22:02:57 +0800 | [diff] [blame] | 675 | bpf { |
| 676 | name: "netd_test", |
| 677 | srcs: ["netd_test.c"], |
| 678 | sub_dir: "netd", |
| 679 | } |
| 680 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 681 | `) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 682 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 683 | "etc/myetc", |
| 684 | "javalib/myjar.jar", |
| 685 | "lib64/mylib.so", |
Oriol Prieto Gascó | a70425f | 2022-05-20 13:05:34 +0000 | [diff] [blame] | 686 | "app/AppFoo@TEST.BUILD_ID/AppFoo.apk", |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 687 | "overlay/blue/rro.apk", |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 688 | "etc/bpf/bpf.o", |
| 689 | "etc/bpf/bpf2.o", |
Ken Chen | fad7f9d | 2021-11-10 22:02:57 +0800 | [diff] [blame] | 690 | "etc/bpf/netd/netd_test.o", |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 691 | }) |
| 692 | } |
| 693 | |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 694 | func TestApexManifest(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 695 | ctx := testApex(t, ` |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 696 | apex { |
| 697 | name: "myapex", |
| 698 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 699 | updatable: false, |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | apex_key { |
| 703 | name: "myapex.key", |
| 704 | public_key: "testkey.avbpubkey", |
| 705 | private_key: "testkey.pem", |
| 706 | } |
| 707 | `) |
| 708 | |
| 709 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 710 | args := module.Rule("apexRule").Args |
| 711 | if manifest := args["manifest"]; manifest != module.Output("apex_manifest.pb").Output.String() { |
| 712 | t.Error("manifest should be apex_manifest.pb, but " + manifest) |
| 713 | } |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 714 | } |
| 715 | |
Liz Kammer | 4854a7d | 2021-05-27 14:28:27 -0400 | [diff] [blame] | 716 | func TestApexManifestMinSdkVersion(t *testing.T) { |
| 717 | ctx := testApex(t, ` |
| 718 | apex_defaults { |
| 719 | name: "my_defaults", |
| 720 | key: "myapex.key", |
| 721 | product_specific: true, |
| 722 | file_contexts: ":my-file-contexts", |
| 723 | updatable: false, |
| 724 | } |
| 725 | apex { |
| 726 | name: "myapex_30", |
| 727 | min_sdk_version: "30", |
| 728 | defaults: ["my_defaults"], |
| 729 | } |
| 730 | |
| 731 | apex { |
| 732 | name: "myapex_current", |
| 733 | min_sdk_version: "current", |
| 734 | defaults: ["my_defaults"], |
| 735 | } |
| 736 | |
| 737 | apex { |
| 738 | name: "myapex_none", |
| 739 | defaults: ["my_defaults"], |
| 740 | } |
| 741 | |
| 742 | apex_key { |
| 743 | name: "myapex.key", |
| 744 | public_key: "testkey.avbpubkey", |
| 745 | private_key: "testkey.pem", |
| 746 | } |
| 747 | |
| 748 | filegroup { |
| 749 | name: "my-file-contexts", |
| 750 | srcs: ["product_specific_file_contexts"], |
| 751 | } |
| 752 | `, withFiles(map[string][]byte{ |
| 753 | "product_specific_file_contexts": nil, |
| 754 | }), android.FixtureModifyProductVariables( |
| 755 | func(variables android.FixtureProductVariables) { |
| 756 | variables.Unbundled_build = proptools.BoolPtr(true) |
| 757 | variables.Always_use_prebuilt_sdks = proptools.BoolPtr(false) |
| 758 | }), android.FixtureMergeEnv(map[string]string{ |
| 759 | "UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT": "true", |
| 760 | })) |
| 761 | |
| 762 | testCases := []struct { |
| 763 | module string |
| 764 | minSdkVersion string |
| 765 | }{ |
| 766 | { |
| 767 | module: "myapex_30", |
| 768 | minSdkVersion: "30", |
| 769 | }, |
| 770 | { |
| 771 | module: "myapex_current", |
| 772 | minSdkVersion: "Q.$$(cat out/soong/api_fingerprint.txt)", |
| 773 | }, |
| 774 | { |
| 775 | module: "myapex_none", |
| 776 | minSdkVersion: "Q.$$(cat out/soong/api_fingerprint.txt)", |
| 777 | }, |
| 778 | } |
| 779 | for _, tc := range testCases { |
| 780 | module := ctx.ModuleForTests(tc.module, "android_common_"+tc.module+"_image") |
| 781 | args := module.Rule("apexRule").Args |
| 782 | optFlags := args["opt_flags"] |
| 783 | if !strings.Contains(optFlags, "--min_sdk_version "+tc.minSdkVersion) { |
| 784 | t.Errorf("%s: Expected min_sdk_version=%s, got: %s", tc.module, tc.minSdkVersion, optFlags) |
| 785 | } |
| 786 | } |
| 787 | } |
| 788 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 789 | func TestBasicZipApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 790 | ctx := testApex(t, ` |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 791 | apex { |
| 792 | name: "myapex", |
| 793 | key: "myapex.key", |
| 794 | payload_type: "zip", |
| 795 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 796 | updatable: false, |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | apex_key { |
| 800 | name: "myapex.key", |
| 801 | public_key: "testkey.avbpubkey", |
| 802 | private_key: "testkey.pem", |
| 803 | } |
| 804 | |
| 805 | cc_library { |
| 806 | name: "mylib", |
| 807 | srcs: ["mylib.cpp"], |
| 808 | shared_libs: ["mylib2"], |
| 809 | system_shared_libs: [], |
| 810 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 811 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | cc_library { |
| 815 | name: "mylib2", |
| 816 | srcs: ["mylib.cpp"], |
| 817 | system_shared_libs: [], |
| 818 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 819 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 820 | } |
| 821 | `) |
| 822 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 823 | zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 824 | copyCmds := zipApexRule.Args["copy_commands"] |
| 825 | |
| 826 | // Ensure that main rule creates an output |
| 827 | ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned") |
| 828 | |
| 829 | // Ensure that APEX variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 830 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 831 | |
| 832 | // Ensure that APEX variant is created for the indirect dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 833 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 834 | |
| 835 | // Ensure that both direct and indirect deps are copied into apex |
| 836 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so") |
| 837 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | func TestApexWithStubs(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 841 | ctx := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 842 | apex { |
| 843 | name: "myapex", |
| 844 | key: "myapex.key", |
| 845 | native_shared_libs: ["mylib", "mylib3"], |
Jiyong Park | 105dc32 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 846 | binaries: ["foo.rust"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 847 | updatable: false, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | apex_key { |
| 851 | name: "myapex.key", |
| 852 | public_key: "testkey.avbpubkey", |
| 853 | private_key: "testkey.pem", |
| 854 | } |
| 855 | |
| 856 | cc_library { |
| 857 | name: "mylib", |
| 858 | srcs: ["mylib.cpp"], |
| 859 | shared_libs: ["mylib2", "mylib3"], |
| 860 | system_shared_libs: [], |
| 861 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 862 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | cc_library { |
| 866 | name: "mylib2", |
| 867 | srcs: ["mylib.cpp"], |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 868 | cflags: ["-include mylib.h"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 869 | system_shared_libs: [], |
| 870 | stl: "none", |
| 871 | stubs: { |
| 872 | versions: ["1", "2", "3"], |
| 873 | }, |
| 874 | } |
| 875 | |
| 876 | cc_library { |
| 877 | name: "mylib3", |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 878 | srcs: ["mylib.cpp"], |
| 879 | shared_libs: ["mylib4"], |
| 880 | system_shared_libs: [], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 881 | stl: "none", |
| 882 | stubs: { |
| 883 | versions: ["10", "11", "12"], |
| 884 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 885 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 886 | } |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 887 | |
| 888 | cc_library { |
| 889 | name: "mylib4", |
| 890 | srcs: ["mylib.cpp"], |
| 891 | system_shared_libs: [], |
| 892 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 893 | apex_available: [ "myapex" ], |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 894 | } |
Jiyong Park | 105dc32 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 895 | |
| 896 | rust_binary { |
| 897 | name: "foo.rust", |
| 898 | srcs: ["foo.rs"], |
| 899 | shared_libs: ["libfoo.shared_from_rust"], |
| 900 | prefer_rlib: true, |
| 901 | apex_available: ["myapex"], |
| 902 | } |
| 903 | |
| 904 | cc_library_shared { |
| 905 | name: "libfoo.shared_from_rust", |
| 906 | srcs: ["mylib.cpp"], |
| 907 | system_shared_libs: [], |
| 908 | stl: "none", |
| 909 | stubs: { |
| 910 | versions: ["10", "11", "12"], |
| 911 | }, |
| 912 | } |
| 913 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 914 | `) |
| 915 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 916 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 917 | copyCmds := apexRule.Args["copy_commands"] |
| 918 | |
| 919 | // Ensure that direct non-stubs dep is always included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 920 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 921 | |
| 922 | // Ensure that indirect stubs dep is not included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 923 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 924 | |
| 925 | // Ensure that direct stubs dep is included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 926 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 927 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 928 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 929 | |
| 930 | // Ensure that mylib is linking with the latest version of stubs for mylib2 |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 931 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_current/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 932 | // ... and not linking to the non-stub (impl) variant of mylib2 |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 933 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 934 | |
| 935 | // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex) |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 936 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_apex10000/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 937 | // .. and not linking to the stubs variant of mylib3 |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 938 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12/mylib3.so") |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 939 | |
Chih-Hung Hsieh | b808229 | 2021-09-09 23:20:39 -0700 | [diff] [blame] | 940 | // Comment out this test. Now it fails after the optimization of sharing "cflags" in cc/cc.go |
| 941 | // is replaced by sharing of "cFlags" in cc/builder.go. |
| 942 | // The "cflags" contains "-include mylib.h", but cFlags contained only a reference to the |
| 943 | // module variable representing "cflags". So it was not detected by ensureNotContains. |
| 944 | // Now "cFlags" is a reference to a module variable like $flags1, which includes all previous |
| 945 | // content of "cflags". ModuleForTests...Args["cFlags"] returns the full string of $flags1, |
| 946 | // including the original cflags's "-include mylib.h". |
| 947 | // |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 948 | // Ensure that stubs libs are built without -include flags |
Chih-Hung Hsieh | b808229 | 2021-09-09 23:20:39 -0700 | [diff] [blame] | 949 | // mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 950 | // ensureNotContains(t, mylib2Cflags, "-include ") |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 951 | |
| 952 | // Ensure that genstub is invoked with --apex |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 953 | ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_shared_3").Rule("genStubSrc").Args["flags"]) |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 954 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 955 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 956 | "lib64/mylib.so", |
| 957 | "lib64/mylib3.so", |
| 958 | "lib64/mylib4.so", |
Jiyong Park | 105dc32 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 959 | "bin/foo.rust", |
| 960 | "lib64/libc++.so", // by the implicit dependency from foo.rust |
| 961 | "lib64/liblog.so", // by the implicit dependency from foo.rust |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 962 | }) |
Jiyong Park | 105dc32 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 963 | |
| 964 | // Ensure that stub dependency from a rust module is not included |
| 965 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.shared_from_rust.so") |
| 966 | // The rust module is linked to the stub cc library |
| 967 | rustDeps := ctx.ModuleForTests("foo.rust", "android_arm64_armv8-a_apex10000").Rule("rustc").Args["linkFlags"] |
| 968 | ensureContains(t, rustDeps, "libfoo.shared_from_rust/android_arm64_armv8-a_shared_current/libfoo.shared_from_rust.so") |
| 969 | ensureNotContains(t, rustDeps, "libfoo.shared_from_rust/android_arm64_armv8-a_shared/libfoo.shared_from_rust.so") |
Jiyong Park | 34d5c33 | 2022-02-24 18:02:44 +0900 | [diff] [blame] | 970 | |
| 971 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 972 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.shared_from_rust.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 973 | } |
| 974 | |
Jiyong Park | 1bc8412 | 2021-06-22 20:23:05 +0900 | [diff] [blame] | 975 | func TestApexCanUsePrivateApis(t *testing.T) { |
| 976 | ctx := testApex(t, ` |
| 977 | apex { |
| 978 | name: "myapex", |
| 979 | key: "myapex.key", |
| 980 | native_shared_libs: ["mylib"], |
| 981 | binaries: ["foo.rust"], |
| 982 | updatable: false, |
| 983 | platform_apis: true, |
| 984 | } |
| 985 | |
| 986 | apex_key { |
| 987 | name: "myapex.key", |
| 988 | public_key: "testkey.avbpubkey", |
| 989 | private_key: "testkey.pem", |
| 990 | } |
| 991 | |
| 992 | cc_library { |
| 993 | name: "mylib", |
| 994 | srcs: ["mylib.cpp"], |
| 995 | shared_libs: ["mylib2"], |
| 996 | system_shared_libs: [], |
| 997 | stl: "none", |
| 998 | apex_available: [ "myapex" ], |
| 999 | } |
| 1000 | |
| 1001 | cc_library { |
| 1002 | name: "mylib2", |
| 1003 | srcs: ["mylib.cpp"], |
| 1004 | cflags: ["-include mylib.h"], |
| 1005 | system_shared_libs: [], |
| 1006 | stl: "none", |
| 1007 | stubs: { |
| 1008 | versions: ["1", "2", "3"], |
| 1009 | }, |
| 1010 | } |
| 1011 | |
| 1012 | rust_binary { |
| 1013 | name: "foo.rust", |
| 1014 | srcs: ["foo.rs"], |
| 1015 | shared_libs: ["libfoo.shared_from_rust"], |
| 1016 | prefer_rlib: true, |
| 1017 | apex_available: ["myapex"], |
| 1018 | } |
| 1019 | |
| 1020 | cc_library_shared { |
| 1021 | name: "libfoo.shared_from_rust", |
| 1022 | srcs: ["mylib.cpp"], |
| 1023 | system_shared_libs: [], |
| 1024 | stl: "none", |
| 1025 | stubs: { |
| 1026 | versions: ["10", "11", "12"], |
| 1027 | }, |
| 1028 | } |
| 1029 | `) |
| 1030 | |
| 1031 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 1032 | copyCmds := apexRule.Args["copy_commands"] |
| 1033 | |
| 1034 | // Ensure that indirect stubs dep is not included |
| 1035 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 1036 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.shared_from_rust.so") |
| 1037 | |
| 1038 | // Ensure that we are using non-stub variants of mylib2 and libfoo.shared_from_rust (because |
| 1039 | // of the platform_apis: true) |
Jiyong Park | d4a0063 | 2022-04-12 12:23:20 +0900 | [diff] [blame] | 1040 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
Jiyong Park | 1bc8412 | 2021-06-22 20:23:05 +0900 | [diff] [blame] | 1041 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_current/mylib2.so") |
| 1042 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
Jiyong Park | d4a0063 | 2022-04-12 12:23:20 +0900 | [diff] [blame] | 1043 | rustDeps := ctx.ModuleForTests("foo.rust", "android_arm64_armv8-a_apex10000").Rule("rustc").Args["linkFlags"] |
Jiyong Park | 1bc8412 | 2021-06-22 20:23:05 +0900 | [diff] [blame] | 1044 | ensureNotContains(t, rustDeps, "libfoo.shared_from_rust/android_arm64_armv8-a_shared_current/libfoo.shared_from_rust.so") |
| 1045 | ensureContains(t, rustDeps, "libfoo.shared_from_rust/android_arm64_armv8-a_shared/libfoo.shared_from_rust.so") |
| 1046 | } |
| 1047 | |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 1048 | func TestApexWithStubsWithMinSdkVersion(t *testing.T) { |
| 1049 | t.Parallel() |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1050 | ctx := testApex(t, ` |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 1051 | apex { |
| 1052 | name: "myapex", |
| 1053 | key: "myapex.key", |
| 1054 | native_shared_libs: ["mylib", "mylib3"], |
| 1055 | min_sdk_version: "29", |
| 1056 | } |
| 1057 | |
| 1058 | apex_key { |
| 1059 | name: "myapex.key", |
| 1060 | public_key: "testkey.avbpubkey", |
| 1061 | private_key: "testkey.pem", |
| 1062 | } |
| 1063 | |
| 1064 | cc_library { |
| 1065 | name: "mylib", |
| 1066 | srcs: ["mylib.cpp"], |
| 1067 | shared_libs: ["mylib2", "mylib3"], |
| 1068 | system_shared_libs: [], |
| 1069 | stl: "none", |
| 1070 | apex_available: [ "myapex" ], |
| 1071 | min_sdk_version: "28", |
| 1072 | } |
| 1073 | |
| 1074 | cc_library { |
| 1075 | name: "mylib2", |
| 1076 | srcs: ["mylib.cpp"], |
| 1077 | cflags: ["-include mylib.h"], |
| 1078 | system_shared_libs: [], |
| 1079 | stl: "none", |
| 1080 | stubs: { |
| 1081 | versions: ["28", "29", "30", "current"], |
| 1082 | }, |
| 1083 | min_sdk_version: "28", |
| 1084 | } |
| 1085 | |
| 1086 | cc_library { |
| 1087 | name: "mylib3", |
| 1088 | srcs: ["mylib.cpp"], |
| 1089 | shared_libs: ["mylib4"], |
| 1090 | system_shared_libs: [], |
| 1091 | stl: "none", |
| 1092 | stubs: { |
| 1093 | versions: ["28", "29", "30", "current"], |
| 1094 | }, |
| 1095 | apex_available: [ "myapex" ], |
| 1096 | min_sdk_version: "28", |
| 1097 | } |
| 1098 | |
| 1099 | cc_library { |
| 1100 | name: "mylib4", |
| 1101 | srcs: ["mylib.cpp"], |
| 1102 | system_shared_libs: [], |
| 1103 | stl: "none", |
| 1104 | apex_available: [ "myapex" ], |
| 1105 | min_sdk_version: "28", |
| 1106 | } |
| 1107 | `) |
| 1108 | |
| 1109 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 1110 | copyCmds := apexRule.Args["copy_commands"] |
| 1111 | |
| 1112 | // Ensure that direct non-stubs dep is always included |
| 1113 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1114 | |
| 1115 | // Ensure that indirect stubs dep is not included |
| 1116 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 1117 | |
| 1118 | // Ensure that direct stubs dep is included |
| 1119 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
| 1120 | |
| 1121 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex29").Rule("ld").Args["libFlags"] |
| 1122 | |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1123 | // Ensure that mylib is linking with the latest version of stub for mylib2 |
| 1124 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_current/mylib2.so") |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 1125 | // ... and not linking to the non-stub (impl) variant of mylib2 |
| 1126 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
| 1127 | |
| 1128 | // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex) |
| 1129 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_apex29/mylib3.so") |
| 1130 | // .. and not linking to the stubs variant of mylib3 |
| 1131 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_29/mylib3.so") |
| 1132 | |
| 1133 | // Ensure that stubs libs are built without -include flags |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 1134 | mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_shared_29").Rule("cc").Args["cFlags"] |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 1135 | ensureNotContains(t, mylib2Cflags, "-include ") |
| 1136 | |
| 1137 | // Ensure that genstub is invoked with --apex |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 1138 | ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_shared_29").Rule("genStubSrc").Args["flags"]) |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 1139 | |
| 1140 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 1141 | "lib64/mylib.so", |
| 1142 | "lib64/mylib3.so", |
| 1143 | "lib64/mylib4.so", |
| 1144 | }) |
| 1145 | } |
| 1146 | |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1147 | func TestApex_PlatformUsesLatestStubFromApex(t *testing.T) { |
| 1148 | t.Parallel() |
| 1149 | // myapex (Z) |
| 1150 | // mylib -----------------. |
| 1151 | // | |
| 1152 | // otherapex (29) | |
| 1153 | // libstub's versions: 29 Z current |
| 1154 | // | |
| 1155 | // <platform> | |
| 1156 | // libplatform ----------------' |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1157 | ctx := testApex(t, ` |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1158 | apex { |
| 1159 | name: "myapex", |
| 1160 | key: "myapex.key", |
| 1161 | native_shared_libs: ["mylib"], |
| 1162 | min_sdk_version: "Z", // non-final |
| 1163 | } |
| 1164 | |
| 1165 | cc_library { |
| 1166 | name: "mylib", |
| 1167 | srcs: ["mylib.cpp"], |
| 1168 | shared_libs: ["libstub"], |
| 1169 | apex_available: ["myapex"], |
| 1170 | min_sdk_version: "Z", |
| 1171 | } |
| 1172 | |
| 1173 | apex_key { |
| 1174 | name: "myapex.key", |
| 1175 | public_key: "testkey.avbpubkey", |
| 1176 | private_key: "testkey.pem", |
| 1177 | } |
| 1178 | |
| 1179 | apex { |
| 1180 | name: "otherapex", |
| 1181 | key: "myapex.key", |
| 1182 | native_shared_libs: ["libstub"], |
| 1183 | min_sdk_version: "29", |
| 1184 | } |
| 1185 | |
| 1186 | cc_library { |
| 1187 | name: "libstub", |
| 1188 | srcs: ["mylib.cpp"], |
| 1189 | stubs: { |
| 1190 | versions: ["29", "Z", "current"], |
| 1191 | }, |
| 1192 | apex_available: ["otherapex"], |
| 1193 | min_sdk_version: "29", |
| 1194 | } |
| 1195 | |
| 1196 | // platform module depending on libstub from otherapex should use the latest stub("current") |
| 1197 | cc_library { |
| 1198 | name: "libplatform", |
| 1199 | srcs: ["mylib.cpp"], |
| 1200 | shared_libs: ["libstub"], |
| 1201 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1202 | `, |
| 1203 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1204 | variables.Platform_sdk_codename = proptools.StringPtr("Z") |
| 1205 | variables.Platform_sdk_final = proptools.BoolPtr(false) |
| 1206 | variables.Platform_version_active_codenames = []string{"Z"} |
| 1207 | }), |
| 1208 | ) |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1209 | |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1210 | // Ensure that mylib from myapex is built against the latest stub (current) |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1211 | mylibCflags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex10000").Rule("cc").Args["cFlags"] |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1212 | ensureContains(t, mylibCflags, "-D__LIBSTUB_API__=10000 ") |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1213 | mylibLdflags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1214 | ensureContains(t, mylibLdflags, "libstub/android_arm64_armv8-a_shared_current/libstub.so ") |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1215 | |
| 1216 | // Ensure that libplatform is built against latest stub ("current") of mylib3 from the apex |
| 1217 | libplatformCflags := ctx.ModuleForTests("libplatform", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 1218 | ensureContains(t, libplatformCflags, "-D__LIBSTUB_API__=10000 ") // "current" maps to 10000 |
| 1219 | libplatformLdflags := ctx.ModuleForTests("libplatform", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 1220 | ensureContains(t, libplatformLdflags, "libstub/android_arm64_armv8-a_shared_current/libstub.so ") |
| 1221 | } |
| 1222 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1223 | func TestApexWithExplicitStubsDependency(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1224 | ctx := testApex(t, ` |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1225 | apex { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1226 | name: "myapex2", |
| 1227 | key: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1228 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1229 | updatable: false, |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | apex_key { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1233 | name: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1234 | public_key: "testkey.avbpubkey", |
| 1235 | private_key: "testkey.pem", |
| 1236 | } |
| 1237 | |
| 1238 | cc_library { |
| 1239 | name: "mylib", |
| 1240 | srcs: ["mylib.cpp"], |
| 1241 | shared_libs: ["libfoo#10"], |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1242 | static_libs: ["libbaz"], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1243 | system_shared_libs: [], |
| 1244 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1245 | apex_available: [ "myapex2" ], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | cc_library { |
| 1249 | name: "libfoo", |
| 1250 | srcs: ["mylib.cpp"], |
| 1251 | shared_libs: ["libbar"], |
| 1252 | system_shared_libs: [], |
| 1253 | stl: "none", |
| 1254 | stubs: { |
| 1255 | versions: ["10", "20", "30"], |
| 1256 | }, |
| 1257 | } |
| 1258 | |
| 1259 | cc_library { |
| 1260 | name: "libbar", |
| 1261 | srcs: ["mylib.cpp"], |
| 1262 | system_shared_libs: [], |
| 1263 | stl: "none", |
| 1264 | } |
| 1265 | |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1266 | cc_library_static { |
| 1267 | name: "libbaz", |
| 1268 | srcs: ["mylib.cpp"], |
| 1269 | system_shared_libs: [], |
| 1270 | stl: "none", |
| 1271 | apex_available: [ "myapex2" ], |
| 1272 | } |
| 1273 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1274 | `) |
| 1275 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1276 | apexRule := ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Rule("apexRule") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1277 | copyCmds := apexRule.Args["copy_commands"] |
| 1278 | |
| 1279 | // Ensure that direct non-stubs dep is always included |
| 1280 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1281 | |
| 1282 | // Ensure that indirect stubs dep is not included |
| 1283 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 1284 | |
| 1285 | // Ensure that dependency of stubs is not included |
| 1286 | ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 1287 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1288 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1289 | |
| 1290 | // Ensure that mylib is linking with version 10 of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1291 | ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1292 | // ... and not linking to the non-stub (impl) variant of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1293 | ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1294 | |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1295 | libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared_10").Rule("ld").Args["libFlags"] |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1296 | |
| 1297 | // Ensure that libfoo stubs is not linking to libbar (since it is a stubs) |
| 1298 | ensureNotContains(t, libFooStubsLdFlags, "libbar.so") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1299 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 1300 | fullDepsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("depsinfo/fulllist.txt").Args["content"], "\\n") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 1301 | ensureListContains(t, fullDepsInfo, " libfoo(minSdkVersion:(no version)) (external) <- mylib") |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1302 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 1303 | flatDepsInfo := strings.Split(ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Output("depsinfo/flatlist.txt").Args["content"], "\\n") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 1304 | ensureListContains(t, flatDepsInfo, "libfoo(minSdkVersion:(no version)) (external)") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1305 | } |
| 1306 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1307 | func TestApexWithRuntimeLibsDependency(t *testing.T) { |
| 1308 | /* |
| 1309 | myapex |
| 1310 | | |
| 1311 | v (runtime_libs) |
| 1312 | mylib ------+------> libfoo [provides stub] |
| 1313 | | |
| 1314 | `------> libbar |
| 1315 | */ |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1316 | ctx := testApex(t, ` |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1317 | apex { |
| 1318 | name: "myapex", |
| 1319 | key: "myapex.key", |
| 1320 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1321 | updatable: false, |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | apex_key { |
| 1325 | name: "myapex.key", |
| 1326 | public_key: "testkey.avbpubkey", |
| 1327 | private_key: "testkey.pem", |
| 1328 | } |
| 1329 | |
| 1330 | cc_library { |
| 1331 | name: "mylib", |
| 1332 | srcs: ["mylib.cpp"], |
| 1333 | runtime_libs: ["libfoo", "libbar"], |
| 1334 | system_shared_libs: [], |
| 1335 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1336 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | cc_library { |
| 1340 | name: "libfoo", |
| 1341 | srcs: ["mylib.cpp"], |
| 1342 | system_shared_libs: [], |
| 1343 | stl: "none", |
| 1344 | stubs: { |
| 1345 | versions: ["10", "20", "30"], |
| 1346 | }, |
| 1347 | } |
| 1348 | |
| 1349 | cc_library { |
| 1350 | name: "libbar", |
| 1351 | srcs: ["mylib.cpp"], |
| 1352 | system_shared_libs: [], |
| 1353 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1354 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | `) |
| 1358 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1359 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1360 | copyCmds := apexRule.Args["copy_commands"] |
| 1361 | |
| 1362 | // Ensure that direct non-stubs dep is always included |
| 1363 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1364 | |
| 1365 | // Ensure that indirect stubs dep is not included |
| 1366 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 1367 | |
| 1368 | // Ensure that runtime_libs dep in included |
| 1369 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 1370 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1371 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 1372 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 1373 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1374 | |
| 1375 | } |
| 1376 | |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1377 | var prepareForTestOfRuntimeApexWithHwasan = android.GroupFixturePreparers( |
| 1378 | cc.PrepareForTestWithCcBuildComponents, |
| 1379 | PrepareForTestWithApexBuildComponents, |
| 1380 | android.FixtureAddTextFile("bionic/apex/Android.bp", ` |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1381 | apex { |
| 1382 | name: "com.android.runtime", |
| 1383 | key: "com.android.runtime.key", |
| 1384 | native_shared_libs: ["libc"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1385 | updatable: false, |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | apex_key { |
| 1389 | name: "com.android.runtime.key", |
| 1390 | public_key: "testkey.avbpubkey", |
| 1391 | private_key: "testkey.pem", |
| 1392 | } |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1393 | `), |
| 1394 | android.FixtureAddFile("system/sepolicy/apex/com.android.runtime-file_contexts", nil), |
| 1395 | ) |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1396 | |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1397 | func TestRuntimeApexShouldInstallHwasanIfLibcDependsOnIt(t *testing.T) { |
Paul Duffin | 70d3bee | 2021-03-21 11:26:05 +0000 | [diff] [blame] | 1398 | result := android.GroupFixturePreparers(prepareForTestOfRuntimeApexWithHwasan).RunTestWithBp(t, ` |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1399 | cc_library { |
| 1400 | name: "libc", |
| 1401 | no_libcrt: true, |
| 1402 | nocrt: true, |
| 1403 | stl: "none", |
| 1404 | system_shared_libs: [], |
| 1405 | stubs: { versions: ["1"] }, |
| 1406 | apex_available: ["com.android.runtime"], |
| 1407 | |
| 1408 | sanitize: { |
| 1409 | hwaddress: true, |
| 1410 | } |
| 1411 | } |
| 1412 | |
| 1413 | cc_prebuilt_library_shared { |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 1414 | name: "libclang_rt.hwasan", |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1415 | no_libcrt: true, |
| 1416 | nocrt: true, |
| 1417 | stl: "none", |
| 1418 | system_shared_libs: [], |
| 1419 | srcs: [""], |
| 1420 | stubs: { versions: ["1"] }, |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 1421 | stem: "libclang_rt.hwasan-aarch64-android", |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1422 | |
| 1423 | sanitize: { |
| 1424 | never: true, |
| 1425 | }, |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1426 | } `) |
| 1427 | ctx := result.TestContext |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1428 | |
| 1429 | ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ |
| 1430 | "lib64/bionic/libc.so", |
| 1431 | "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", |
| 1432 | }) |
| 1433 | |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 1434 | hwasan := ctx.ModuleForTests("libclang_rt.hwasan", "android_arm64_armv8-a_shared") |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1435 | |
| 1436 | installed := hwasan.Description("install libclang_rt.hwasan") |
| 1437 | ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") |
| 1438 | |
| 1439 | symlink := hwasan.Description("install symlink libclang_rt.hwasan") |
| 1440 | ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so") |
| 1441 | ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so") |
| 1442 | } |
| 1443 | |
| 1444 | func TestRuntimeApexShouldInstallHwasanIfHwaddressSanitized(t *testing.T) { |
Paul Duffin | 70d3bee | 2021-03-21 11:26:05 +0000 | [diff] [blame] | 1445 | result := android.GroupFixturePreparers( |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1446 | prepareForTestOfRuntimeApexWithHwasan, |
| 1447 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1448 | variables.SanitizeDevice = []string{"hwaddress"} |
| 1449 | }), |
| 1450 | ).RunTestWithBp(t, ` |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1451 | cc_library { |
| 1452 | name: "libc", |
| 1453 | no_libcrt: true, |
| 1454 | nocrt: true, |
| 1455 | stl: "none", |
| 1456 | system_shared_libs: [], |
| 1457 | stubs: { versions: ["1"] }, |
| 1458 | apex_available: ["com.android.runtime"], |
| 1459 | } |
| 1460 | |
| 1461 | cc_prebuilt_library_shared { |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 1462 | name: "libclang_rt.hwasan", |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1463 | no_libcrt: true, |
| 1464 | nocrt: true, |
| 1465 | stl: "none", |
| 1466 | system_shared_libs: [], |
| 1467 | srcs: [""], |
| 1468 | stubs: { versions: ["1"] }, |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 1469 | stem: "libclang_rt.hwasan-aarch64-android", |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1470 | |
| 1471 | sanitize: { |
| 1472 | never: true, |
| 1473 | }, |
| 1474 | } |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1475 | `) |
| 1476 | ctx := result.TestContext |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1477 | |
| 1478 | ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ |
| 1479 | "lib64/bionic/libc.so", |
| 1480 | "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", |
| 1481 | }) |
| 1482 | |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 1483 | hwasan := ctx.ModuleForTests("libclang_rt.hwasan", "android_arm64_armv8-a_shared") |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1484 | |
| 1485 | installed := hwasan.Description("install libclang_rt.hwasan") |
| 1486 | ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") |
| 1487 | |
| 1488 | symlink := hwasan.Description("install symlink libclang_rt.hwasan") |
| 1489 | ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so") |
| 1490 | ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so") |
| 1491 | } |
| 1492 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1493 | func TestApexDependsOnLLNDKTransitively(t *testing.T) { |
| 1494 | testcases := []struct { |
| 1495 | name string |
| 1496 | minSdkVersion string |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1497 | apexVariant string |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1498 | shouldLink string |
| 1499 | shouldNotLink []string |
| 1500 | }{ |
| 1501 | { |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1502 | name: "unspecified version links to the latest", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1503 | minSdkVersion: "", |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1504 | apexVariant: "apex10000", |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1505 | shouldLink: "current", |
| 1506 | shouldNotLink: []string{"29", "30"}, |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1507 | }, |
| 1508 | { |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1509 | name: "always use the latest", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1510 | minSdkVersion: "min_sdk_version: \"29\",", |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1511 | apexVariant: "apex29", |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1512 | shouldLink: "current", |
| 1513 | shouldNotLink: []string{"29", "30"}, |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1514 | }, |
| 1515 | } |
| 1516 | for _, tc := range testcases { |
| 1517 | t.Run(tc.name, func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1518 | ctx := testApex(t, ` |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1519 | apex { |
| 1520 | name: "myapex", |
| 1521 | key: "myapex.key", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1522 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1523 | updatable: false, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1524 | `+tc.minSdkVersion+` |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1525 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1526 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1527 | apex_key { |
| 1528 | name: "myapex.key", |
| 1529 | public_key: "testkey.avbpubkey", |
| 1530 | private_key: "testkey.pem", |
| 1531 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1532 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1533 | cc_library { |
| 1534 | name: "mylib", |
| 1535 | srcs: ["mylib.cpp"], |
| 1536 | vendor_available: true, |
| 1537 | shared_libs: ["libbar"], |
| 1538 | system_shared_libs: [], |
| 1539 | stl: "none", |
| 1540 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1541 | min_sdk_version: "29", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1542 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1543 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1544 | cc_library { |
| 1545 | name: "libbar", |
| 1546 | srcs: ["mylib.cpp"], |
| 1547 | system_shared_libs: [], |
| 1548 | stl: "none", |
| 1549 | stubs: { versions: ["29","30"] }, |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 1550 | llndk: { |
| 1551 | symbol_file: "libbar.map.txt", |
| 1552 | } |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1553 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1554 | `, |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1555 | withUnbundledBuild, |
| 1556 | ) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1557 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1558 | // Ensure that LLNDK dep is not included |
| 1559 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 1560 | "lib64/mylib.so", |
| 1561 | }) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1562 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1563 | // Ensure that LLNDK dep is required |
| 1564 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 1565 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 1566 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so") |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1567 | |
Steven Moreland | 2c4000c | 2021-04-27 02:08:49 +0000 | [diff] [blame] | 1568 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_"+tc.apexVariant).Rule("ld").Args["libFlags"] |
| 1569 | ensureContains(t, mylibLdFlags, "libbar/android_arm64_armv8-a_shared_"+tc.shouldLink+"/libbar.so") |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1570 | for _, ver := range tc.shouldNotLink { |
Steven Moreland | 2c4000c | 2021-04-27 02:08:49 +0000 | [diff] [blame] | 1571 | ensureNotContains(t, mylibLdFlags, "libbar/android_arm64_armv8-a_shared_"+ver+"/libbar.so") |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1572 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1573 | |
Steven Moreland | 2c4000c | 2021-04-27 02:08:49 +0000 | [diff] [blame] | 1574 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_"+tc.apexVariant).Rule("cc").Args["cFlags"] |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1575 | ver := tc.shouldLink |
| 1576 | if tc.shouldLink == "current" { |
| 1577 | ver = strconv.Itoa(android.FutureApiLevelInt) |
| 1578 | } |
| 1579 | ensureContains(t, mylibCFlags, "__LIBBAR_API__="+ver) |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1580 | }) |
| 1581 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1582 | } |
| 1583 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1584 | func TestApexWithSystemLibsStubs(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1585 | ctx := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1586 | apex { |
| 1587 | name: "myapex", |
| 1588 | key: "myapex.key", |
| 1589 | native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1590 | updatable: false, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | apex_key { |
| 1594 | name: "myapex.key", |
| 1595 | public_key: "testkey.avbpubkey", |
| 1596 | private_key: "testkey.pem", |
| 1597 | } |
| 1598 | |
| 1599 | cc_library { |
| 1600 | name: "mylib", |
| 1601 | srcs: ["mylib.cpp"], |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 1602 | system_shared_libs: ["libc", "libm"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1603 | shared_libs: ["libdl#27"], |
| 1604 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1605 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | cc_library_shared { |
| 1609 | name: "mylib_shared", |
| 1610 | srcs: ["mylib.cpp"], |
| 1611 | shared_libs: ["libdl#27"], |
| 1612 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1613 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | cc_library { |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1617 | name: "libBootstrap", |
| 1618 | srcs: ["mylib.cpp"], |
| 1619 | stl: "none", |
| 1620 | bootstrap: true, |
| 1621 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1622 | `) |
| 1623 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1624 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1625 | copyCmds := apexRule.Args["copy_commands"] |
| 1626 | |
| 1627 | // Ensure that mylib, libm, libdl are included. |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1628 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1629 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so") |
| 1630 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1631 | |
| 1632 | // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs) |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1633 | ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1634 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1635 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
| 1636 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex10000").Rule("cc").Args["cFlags"] |
| 1637 | mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_shared_apex10000").Rule("cc").Args["cFlags"] |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1638 | |
| 1639 | // For dependency to libc |
| 1640 | // Ensure that mylib is linking with the latest version of stubs |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1641 | ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_current/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1642 | // ... and not linking to the non-stub (impl) variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1643 | ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1644 | // ... Cflags from stub is correctly exported to mylib |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1645 | ensureContains(t, mylibCFlags, "__LIBC_API__=10000") |
| 1646 | ensureContains(t, mylibSharedCFlags, "__LIBC_API__=10000") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1647 | |
| 1648 | // For dependency to libm |
| 1649 | // Ensure that mylib is linking with the non-stub (impl) variant |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1650 | ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_apex10000/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1651 | // ... and not linking to the stub variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1652 | ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1653 | // ... and is not compiling with the stub |
| 1654 | ensureNotContains(t, mylibCFlags, "__LIBM_API__=29") |
| 1655 | ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29") |
| 1656 | |
| 1657 | // For dependency to libdl |
| 1658 | // Ensure that mylib is linking with the specified version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1659 | ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1660 | // ... and not linking to the other versions of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1661 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28/libdl.so") |
| 1662 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1663 | // ... and not linking to the non-stub (impl) variant |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1664 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_apex10000/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1665 | // ... Cflags from stub is correctly exported to mylib |
| 1666 | ensureContains(t, mylibCFlags, "__LIBDL_API__=27") |
| 1667 | ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1668 | |
| 1669 | // Ensure that libBootstrap is depending on the platform variant of bionic libs |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1670 | libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 1671 | ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
| 1672 | ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so") |
| 1673 | ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1674 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1675 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1676 | func TestApexMinSdkVersion_NativeModulesShouldBeBuiltAgainstStubs(t *testing.T) { |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1677 | // there are three links between liba --> libz. |
| 1678 | // 1) myapex -> libx -> liba -> libz : this should be #30 link |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1679 | // 2) otherapex -> liby -> liba -> libz : this should be #30 link |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1680 | // 3) (platform) -> liba -> libz : this should be non-stub link |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1681 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1682 | apex { |
| 1683 | name: "myapex", |
| 1684 | key: "myapex.key", |
| 1685 | native_shared_libs: ["libx"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1686 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | apex { |
| 1690 | name: "otherapex", |
| 1691 | key: "myapex.key", |
| 1692 | native_shared_libs: ["liby"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1693 | min_sdk_version: "30", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | apex_key { |
| 1697 | name: "myapex.key", |
| 1698 | public_key: "testkey.avbpubkey", |
| 1699 | private_key: "testkey.pem", |
| 1700 | } |
| 1701 | |
| 1702 | cc_library { |
| 1703 | name: "libx", |
| 1704 | shared_libs: ["liba"], |
| 1705 | system_shared_libs: [], |
| 1706 | stl: "none", |
| 1707 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1708 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | cc_library { |
| 1712 | name: "liby", |
| 1713 | shared_libs: ["liba"], |
| 1714 | system_shared_libs: [], |
| 1715 | stl: "none", |
| 1716 | apex_available: [ "otherapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1717 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1718 | } |
| 1719 | |
| 1720 | cc_library { |
| 1721 | name: "liba", |
| 1722 | shared_libs: ["libz"], |
| 1723 | system_shared_libs: [], |
| 1724 | stl: "none", |
| 1725 | apex_available: [ |
| 1726 | "//apex_available:anyapex", |
| 1727 | "//apex_available:platform", |
| 1728 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1729 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | cc_library { |
| 1733 | name: "libz", |
| 1734 | system_shared_libs: [], |
| 1735 | stl: "none", |
| 1736 | stubs: { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1737 | versions: ["28", "30"], |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1738 | }, |
| 1739 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1740 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1741 | |
| 1742 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1743 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1744 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1745 | } |
| 1746 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1747 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1748 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1749 | } |
| 1750 | // platform liba is linked to non-stub version |
| 1751 | expectLink("liba", "shared", "libz", "shared") |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1752 | // liba in myapex is linked to current |
| 1753 | expectLink("liba", "shared_apex29", "libz", "shared_current") |
| 1754 | expectNoLink("liba", "shared_apex29", "libz", "shared_30") |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1755 | expectNoLink("liba", "shared_apex29", "libz", "shared_28") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1756 | expectNoLink("liba", "shared_apex29", "libz", "shared") |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1757 | // liba in otherapex is linked to current |
| 1758 | expectLink("liba", "shared_apex30", "libz", "shared_current") |
| 1759 | expectNoLink("liba", "shared_apex30", "libz", "shared_30") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1760 | expectNoLink("liba", "shared_apex30", "libz", "shared_28") |
| 1761 | expectNoLink("liba", "shared_apex30", "libz", "shared") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1762 | } |
| 1763 | |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1764 | func TestApexMinSdkVersion_SupportsCodeNames(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1765 | ctx := testApex(t, ` |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1766 | apex { |
| 1767 | name: "myapex", |
| 1768 | key: "myapex.key", |
| 1769 | native_shared_libs: ["libx"], |
| 1770 | min_sdk_version: "R", |
| 1771 | } |
| 1772 | |
| 1773 | apex_key { |
| 1774 | name: "myapex.key", |
| 1775 | public_key: "testkey.avbpubkey", |
| 1776 | private_key: "testkey.pem", |
| 1777 | } |
| 1778 | |
| 1779 | cc_library { |
| 1780 | name: "libx", |
| 1781 | shared_libs: ["libz"], |
| 1782 | system_shared_libs: [], |
| 1783 | stl: "none", |
| 1784 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1785 | min_sdk_version: "R", |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | cc_library { |
| 1789 | name: "libz", |
| 1790 | system_shared_libs: [], |
| 1791 | stl: "none", |
| 1792 | stubs: { |
| 1793 | versions: ["29", "R"], |
| 1794 | }, |
| 1795 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1796 | `, |
| 1797 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1798 | variables.Platform_version_active_codenames = []string{"R"} |
| 1799 | }), |
| 1800 | ) |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1801 | |
| 1802 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1803 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1804 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1805 | } |
| 1806 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1807 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1808 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1809 | } |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1810 | expectLink("libx", "shared_apex10000", "libz", "shared_current") |
| 1811 | expectNoLink("libx", "shared_apex10000", "libz", "shared_R") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1812 | expectNoLink("libx", "shared_apex10000", "libz", "shared_29") |
| 1813 | expectNoLink("libx", "shared_apex10000", "libz", "shared") |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1814 | } |
| 1815 | |
Jooyung Han | 4c4da06 | 2021-06-23 10:23:16 +0900 | [diff] [blame] | 1816 | func TestApexMinSdkVersion_SupportsCodeNames_JavaLibs(t *testing.T) { |
| 1817 | testApex(t, ` |
| 1818 | apex { |
| 1819 | name: "myapex", |
| 1820 | key: "myapex.key", |
| 1821 | java_libs: ["libx"], |
| 1822 | min_sdk_version: "S", |
| 1823 | } |
| 1824 | |
| 1825 | apex_key { |
| 1826 | name: "myapex.key", |
| 1827 | public_key: "testkey.avbpubkey", |
| 1828 | private_key: "testkey.pem", |
| 1829 | } |
| 1830 | |
| 1831 | java_library { |
| 1832 | name: "libx", |
| 1833 | srcs: ["a.java"], |
| 1834 | apex_available: [ "myapex" ], |
| 1835 | sdk_version: "current", |
| 1836 | min_sdk_version: "S", // should be okay |
| 1837 | } |
| 1838 | `, |
| 1839 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1840 | variables.Platform_version_active_codenames = []string{"S"} |
| 1841 | variables.Platform_sdk_codename = proptools.StringPtr("S") |
| 1842 | }), |
| 1843 | ) |
| 1844 | } |
| 1845 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1846 | func TestApexMinSdkVersion_DefaultsToLatest(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1847 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1848 | apex { |
| 1849 | name: "myapex", |
| 1850 | key: "myapex.key", |
| 1851 | native_shared_libs: ["libx"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1852 | updatable: false, |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | apex_key { |
| 1856 | name: "myapex.key", |
| 1857 | public_key: "testkey.avbpubkey", |
| 1858 | private_key: "testkey.pem", |
| 1859 | } |
| 1860 | |
| 1861 | cc_library { |
| 1862 | name: "libx", |
| 1863 | shared_libs: ["libz"], |
| 1864 | system_shared_libs: [], |
| 1865 | stl: "none", |
| 1866 | apex_available: [ "myapex" ], |
| 1867 | } |
| 1868 | |
| 1869 | cc_library { |
| 1870 | name: "libz", |
| 1871 | system_shared_libs: [], |
| 1872 | stl: "none", |
| 1873 | stubs: { |
| 1874 | versions: ["1", "2"], |
| 1875 | }, |
| 1876 | } |
| 1877 | `) |
| 1878 | |
| 1879 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1880 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1881 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1882 | } |
| 1883 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1884 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1885 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1886 | } |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1887 | expectLink("libx", "shared_apex10000", "libz", "shared_current") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1888 | expectNoLink("libx", "shared_apex10000", "libz", "shared_1") |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1889 | expectNoLink("libx", "shared_apex10000", "libz", "shared_2") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1890 | expectNoLink("libx", "shared_apex10000", "libz", "shared") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1891 | } |
| 1892 | |
Jiyong Park | 5df7bd3 | 2021-08-25 16:18:46 +0900 | [diff] [blame] | 1893 | func TestApexMinSdkVersion_crtobjectInVendorApex(t *testing.T) { |
| 1894 | ctx := testApex(t, ` |
| 1895 | apex { |
| 1896 | name: "myapex", |
| 1897 | key: "myapex.key", |
| 1898 | native_shared_libs: ["mylib"], |
| 1899 | updatable: false, |
| 1900 | vendor: true, |
| 1901 | min_sdk_version: "29", |
| 1902 | } |
| 1903 | |
| 1904 | apex_key { |
| 1905 | name: "myapex.key", |
| 1906 | public_key: "testkey.avbpubkey", |
| 1907 | private_key: "testkey.pem", |
| 1908 | } |
| 1909 | |
| 1910 | cc_library { |
| 1911 | name: "mylib", |
| 1912 | vendor_available: true, |
| 1913 | system_shared_libs: [], |
| 1914 | stl: "none", |
| 1915 | apex_available: [ "myapex" ], |
| 1916 | min_sdk_version: "29", |
| 1917 | } |
| 1918 | `) |
| 1919 | |
| 1920 | vendorVariant := "android_vendor.29_arm64_armv8-a" |
| 1921 | |
| 1922 | // First check that the correct variant of crtbegin_so is used. |
| 1923 | ldRule := ctx.ModuleForTests("mylib", vendorVariant+"_shared_apex29").Rule("ld") |
| 1924 | crtBegin := names(ldRule.Args["crtBegin"]) |
| 1925 | ensureListContains(t, crtBegin, "out/soong/.intermediates/"+cc.DefaultCcCommonTestModulesDir+"crtbegin_so/"+vendorVariant+"_apex29/crtbegin_so.o") |
| 1926 | |
| 1927 | // Ensure that the crtbegin_so used by the APEX is targeting 29 |
| 1928 | cflags := ctx.ModuleForTests("crtbegin_so", vendorVariant+"_apex29").Rule("cc").Args["cFlags"] |
| 1929 | android.AssertStringDoesContain(t, "cflags", cflags, "-target aarch64-linux-android29") |
| 1930 | } |
| 1931 | |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1932 | func TestPlatformUsesLatestStubsFromApexes(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1933 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1934 | apex { |
| 1935 | name: "myapex", |
| 1936 | key: "myapex.key", |
| 1937 | native_shared_libs: ["libx"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1938 | updatable: false, |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | apex_key { |
| 1942 | name: "myapex.key", |
| 1943 | public_key: "testkey.avbpubkey", |
| 1944 | private_key: "testkey.pem", |
| 1945 | } |
| 1946 | |
| 1947 | cc_library { |
| 1948 | name: "libx", |
| 1949 | system_shared_libs: [], |
| 1950 | stl: "none", |
| 1951 | apex_available: [ "myapex" ], |
| 1952 | stubs: { |
| 1953 | versions: ["1", "2"], |
| 1954 | }, |
| 1955 | } |
| 1956 | |
| 1957 | cc_library { |
| 1958 | name: "libz", |
| 1959 | shared_libs: ["libx"], |
| 1960 | system_shared_libs: [], |
| 1961 | stl: "none", |
| 1962 | } |
| 1963 | `) |
| 1964 | |
| 1965 | expectLink := func(from, from_variant, to, to_variant string) { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1966 | t.Helper() |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1967 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1968 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1969 | } |
| 1970 | expectNoLink := func(from, from_variant, to, to_variant string) { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1971 | t.Helper() |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1972 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1973 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1974 | } |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1975 | expectLink("libz", "shared", "libx", "shared_current") |
| 1976 | expectNoLink("libz", "shared", "libx", "shared_2") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1977 | expectNoLink("libz", "shared", "libz", "shared_1") |
| 1978 | expectNoLink("libz", "shared", "libz", "shared") |
| 1979 | } |
| 1980 | |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1981 | var prepareForTestWithSantitizeHwaddress = android.FixtureModifyProductVariables( |
| 1982 | func(variables android.FixtureProductVariables) { |
| 1983 | variables.SanitizeDevice = []string{"hwaddress"} |
| 1984 | }, |
| 1985 | ) |
| 1986 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1987 | func TestQApexesUseLatestStubsInBundledBuildsAndHWASAN(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1988 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1989 | apex { |
| 1990 | name: "myapex", |
| 1991 | key: "myapex.key", |
| 1992 | native_shared_libs: ["libx"], |
| 1993 | min_sdk_version: "29", |
| 1994 | } |
| 1995 | |
| 1996 | apex_key { |
| 1997 | name: "myapex.key", |
| 1998 | public_key: "testkey.avbpubkey", |
| 1999 | private_key: "testkey.pem", |
| 2000 | } |
| 2001 | |
| 2002 | cc_library { |
| 2003 | name: "libx", |
| 2004 | shared_libs: ["libbar"], |
| 2005 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2006 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | cc_library { |
| 2010 | name: "libbar", |
| 2011 | stubs: { |
| 2012 | versions: ["29", "30"], |
| 2013 | }, |
| 2014 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2015 | `, |
| 2016 | prepareForTestWithSantitizeHwaddress, |
| 2017 | ) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2018 | expectLink := func(from, from_variant, to, to_variant string) { |
| 2019 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 2020 | libFlags := ld.Args["libFlags"] |
| 2021 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 2022 | } |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 2023 | expectLink("libx", "shared_hwasan_apex29", "libbar", "shared_current") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2024 | } |
| 2025 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 2026 | func TestQTargetApexUsesStaticUnwinder(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2027 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2028 | apex { |
| 2029 | name: "myapex", |
| 2030 | key: "myapex.key", |
| 2031 | native_shared_libs: ["libx"], |
| 2032 | min_sdk_version: "29", |
| 2033 | } |
| 2034 | |
| 2035 | apex_key { |
| 2036 | name: "myapex.key", |
| 2037 | public_key: "testkey.avbpubkey", |
| 2038 | private_key: "testkey.pem", |
| 2039 | } |
| 2040 | |
| 2041 | cc_library { |
| 2042 | name: "libx", |
| 2043 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2044 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2045 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 2046 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2047 | |
| 2048 | // ensure apex variant of c++ is linked with static unwinder |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2049 | cm := ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared_apex29").Module().(*cc.Module) |
Ryan Prichard | b35a85e | 2021-01-13 19:18:53 -0800 | [diff] [blame] | 2050 | ensureListContains(t, cm.Properties.AndroidMkStaticLibs, "libunwind") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2051 | // note that platform variant is not. |
| 2052 | cm = ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
Ryan Prichard | b35a85e | 2021-01-13 19:18:53 -0800 | [diff] [blame] | 2053 | ensureListNotContains(t, cm.Properties.AndroidMkStaticLibs, "libunwind") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2054 | } |
| 2055 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2056 | func TestApexMinSdkVersion_ErrorIfIncompatibleVersion(t *testing.T) { |
| 2057 | testApexError(t, `module "mylib".*: should support min_sdk_version\(29\)`, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2058 | apex { |
| 2059 | name: "myapex", |
| 2060 | key: "myapex.key", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2061 | native_shared_libs: ["mylib"], |
| 2062 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2063 | } |
| 2064 | |
| 2065 | apex_key { |
| 2066 | name: "myapex.key", |
| 2067 | public_key: "testkey.avbpubkey", |
| 2068 | private_key: "testkey.pem", |
| 2069 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2070 | |
| 2071 | cc_library { |
| 2072 | name: "mylib", |
| 2073 | srcs: ["mylib.cpp"], |
| 2074 | system_shared_libs: [], |
| 2075 | stl: "none", |
| 2076 | apex_available: [ |
| 2077 | "myapex", |
| 2078 | ], |
| 2079 | min_sdk_version: "30", |
| 2080 | } |
| 2081 | `) |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 2082 | |
| 2083 | testApexError(t, `module "libfoo.ffi".*: should support min_sdk_version\(29\)`, ` |
| 2084 | apex { |
| 2085 | name: "myapex", |
| 2086 | key: "myapex.key", |
| 2087 | native_shared_libs: ["libfoo.ffi"], |
| 2088 | min_sdk_version: "29", |
| 2089 | } |
| 2090 | |
| 2091 | apex_key { |
| 2092 | name: "myapex.key", |
| 2093 | public_key: "testkey.avbpubkey", |
| 2094 | private_key: "testkey.pem", |
| 2095 | } |
| 2096 | |
| 2097 | rust_ffi_shared { |
| 2098 | name: "libfoo.ffi", |
| 2099 | srcs: ["foo.rs"], |
| 2100 | crate_name: "foo", |
| 2101 | apex_available: [ |
| 2102 | "myapex", |
| 2103 | ], |
| 2104 | min_sdk_version: "30", |
| 2105 | } |
| 2106 | `) |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 2107 | |
| 2108 | testApexError(t, `module "libfoo".*: should support min_sdk_version\(29\)`, ` |
| 2109 | apex { |
| 2110 | name: "myapex", |
| 2111 | key: "myapex.key", |
| 2112 | java_libs: ["libfoo"], |
| 2113 | min_sdk_version: "29", |
| 2114 | } |
| 2115 | |
| 2116 | apex_key { |
| 2117 | name: "myapex.key", |
| 2118 | public_key: "testkey.avbpubkey", |
| 2119 | private_key: "testkey.pem", |
| 2120 | } |
| 2121 | |
| 2122 | java_import { |
| 2123 | name: "libfoo", |
| 2124 | jars: ["libfoo.jar"], |
| 2125 | apex_available: [ |
| 2126 | "myapex", |
| 2127 | ], |
| 2128 | min_sdk_version: "30", |
| 2129 | } |
| 2130 | `) |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | func TestApexMinSdkVersion_Okay(t *testing.T) { |
| 2134 | testApex(t, ` |
| 2135 | apex { |
| 2136 | name: "myapex", |
| 2137 | key: "myapex.key", |
| 2138 | native_shared_libs: ["libfoo"], |
| 2139 | java_libs: ["libbar"], |
| 2140 | min_sdk_version: "29", |
| 2141 | } |
| 2142 | |
| 2143 | apex_key { |
| 2144 | name: "myapex.key", |
| 2145 | public_key: "testkey.avbpubkey", |
| 2146 | private_key: "testkey.pem", |
| 2147 | } |
| 2148 | |
| 2149 | cc_library { |
| 2150 | name: "libfoo", |
| 2151 | srcs: ["mylib.cpp"], |
| 2152 | shared_libs: ["libfoo_dep"], |
| 2153 | apex_available: ["myapex"], |
| 2154 | min_sdk_version: "29", |
| 2155 | } |
| 2156 | |
| 2157 | cc_library { |
| 2158 | name: "libfoo_dep", |
| 2159 | srcs: ["mylib.cpp"], |
| 2160 | apex_available: ["myapex"], |
| 2161 | min_sdk_version: "29", |
| 2162 | } |
| 2163 | |
| 2164 | java_library { |
| 2165 | name: "libbar", |
| 2166 | sdk_version: "current", |
| 2167 | srcs: ["a.java"], |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 2168 | static_libs: [ |
| 2169 | "libbar_dep", |
| 2170 | "libbar_import_dep", |
| 2171 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2172 | apex_available: ["myapex"], |
| 2173 | min_sdk_version: "29", |
| 2174 | } |
| 2175 | |
| 2176 | java_library { |
| 2177 | name: "libbar_dep", |
| 2178 | sdk_version: "current", |
| 2179 | srcs: ["a.java"], |
| 2180 | apex_available: ["myapex"], |
| 2181 | min_sdk_version: "29", |
| 2182 | } |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 2183 | |
| 2184 | java_import { |
| 2185 | name: "libbar_import_dep", |
| 2186 | jars: ["libbar.jar"], |
| 2187 | apex_available: ["myapex"], |
| 2188 | min_sdk_version: "29", |
| 2189 | } |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2190 | `) |
| 2191 | } |
| 2192 | |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2193 | func TestJavaStableSdkVersion(t *testing.T) { |
| 2194 | testCases := []struct { |
| 2195 | name string |
| 2196 | expectedError string |
| 2197 | bp string |
Paul Duffin | 1ea7c9f | 2021-03-15 09:39:13 +0000 | [diff] [blame] | 2198 | preparer android.FixturePreparer |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2199 | }{ |
| 2200 | { |
| 2201 | name: "Non-updatable apex with non-stable dep", |
| 2202 | bp: ` |
| 2203 | apex { |
| 2204 | name: "myapex", |
| 2205 | java_libs: ["myjar"], |
| 2206 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2207 | updatable: false, |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2208 | } |
| 2209 | apex_key { |
| 2210 | name: "myapex.key", |
| 2211 | public_key: "testkey.avbpubkey", |
| 2212 | private_key: "testkey.pem", |
| 2213 | } |
| 2214 | java_library { |
| 2215 | name: "myjar", |
| 2216 | srcs: ["foo/bar/MyClass.java"], |
Paul Duffin | 043f5e7 | 2021-03-05 00:00:01 +0000 | [diff] [blame] | 2217 | sdk_version: "test_current", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2218 | apex_available: ["myapex"], |
| 2219 | } |
| 2220 | `, |
| 2221 | }, |
| 2222 | { |
| 2223 | name: "Updatable apex with stable dep", |
| 2224 | bp: ` |
| 2225 | apex { |
| 2226 | name: "myapex", |
| 2227 | java_libs: ["myjar"], |
| 2228 | key: "myapex.key", |
| 2229 | updatable: true, |
| 2230 | min_sdk_version: "29", |
| 2231 | } |
| 2232 | apex_key { |
| 2233 | name: "myapex.key", |
| 2234 | public_key: "testkey.avbpubkey", |
| 2235 | private_key: "testkey.pem", |
| 2236 | } |
| 2237 | java_library { |
| 2238 | name: "myjar", |
| 2239 | srcs: ["foo/bar/MyClass.java"], |
| 2240 | sdk_version: "current", |
| 2241 | apex_available: ["myapex"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2242 | min_sdk_version: "29", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2243 | } |
| 2244 | `, |
| 2245 | }, |
| 2246 | { |
| 2247 | name: "Updatable apex with non-stable dep", |
| 2248 | expectedError: "cannot depend on \"myjar\"", |
| 2249 | bp: ` |
| 2250 | apex { |
| 2251 | name: "myapex", |
| 2252 | java_libs: ["myjar"], |
| 2253 | key: "myapex.key", |
| 2254 | updatable: true, |
| 2255 | } |
| 2256 | apex_key { |
| 2257 | name: "myapex.key", |
| 2258 | public_key: "testkey.avbpubkey", |
| 2259 | private_key: "testkey.pem", |
| 2260 | } |
| 2261 | java_library { |
| 2262 | name: "myjar", |
| 2263 | srcs: ["foo/bar/MyClass.java"], |
Paul Duffin | 043f5e7 | 2021-03-05 00:00:01 +0000 | [diff] [blame] | 2264 | sdk_version: "test_current", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2265 | apex_available: ["myapex"], |
| 2266 | } |
| 2267 | `, |
| 2268 | }, |
| 2269 | { |
Paul Duffin | 1ea7c9f | 2021-03-15 09:39:13 +0000 | [diff] [blame] | 2270 | name: "Updatable apex with non-stable legacy core platform dep", |
| 2271 | expectedError: `\Qcannot depend on "myjar-uses-legacy": non stable SDK core_platform_current - uses legacy core platform\E`, |
| 2272 | bp: ` |
| 2273 | apex { |
| 2274 | name: "myapex", |
| 2275 | java_libs: ["myjar-uses-legacy"], |
| 2276 | key: "myapex.key", |
| 2277 | updatable: true, |
| 2278 | } |
| 2279 | apex_key { |
| 2280 | name: "myapex.key", |
| 2281 | public_key: "testkey.avbpubkey", |
| 2282 | private_key: "testkey.pem", |
| 2283 | } |
| 2284 | java_library { |
| 2285 | name: "myjar-uses-legacy", |
| 2286 | srcs: ["foo/bar/MyClass.java"], |
| 2287 | sdk_version: "core_platform", |
| 2288 | apex_available: ["myapex"], |
| 2289 | } |
| 2290 | `, |
| 2291 | preparer: java.FixtureUseLegacyCorePlatformApi("myjar-uses-legacy"), |
| 2292 | }, |
| 2293 | { |
Paul Duffin | 043f5e7 | 2021-03-05 00:00:01 +0000 | [diff] [blame] | 2294 | name: "Updatable apex with non-stable transitive dep", |
| 2295 | // This is not actually detecting that the transitive dependency is unstable, rather it is |
| 2296 | // detecting that the transitive dependency is building against a wider API surface than the |
| 2297 | // module that depends on it is using. |
Jiyong Park | 670e0f6 | 2021-02-18 13:10:18 +0900 | [diff] [blame] | 2298 | expectedError: "compiles against Android API, but dependency \"transitive-jar\" is compiling against private API.", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2299 | bp: ` |
| 2300 | apex { |
| 2301 | name: "myapex", |
| 2302 | java_libs: ["myjar"], |
| 2303 | key: "myapex.key", |
| 2304 | updatable: true, |
| 2305 | } |
| 2306 | apex_key { |
| 2307 | name: "myapex.key", |
| 2308 | public_key: "testkey.avbpubkey", |
| 2309 | private_key: "testkey.pem", |
| 2310 | } |
| 2311 | java_library { |
| 2312 | name: "myjar", |
| 2313 | srcs: ["foo/bar/MyClass.java"], |
| 2314 | sdk_version: "current", |
| 2315 | apex_available: ["myapex"], |
| 2316 | static_libs: ["transitive-jar"], |
| 2317 | } |
| 2318 | java_library { |
| 2319 | name: "transitive-jar", |
| 2320 | srcs: ["foo/bar/MyClass.java"], |
| 2321 | sdk_version: "core_platform", |
| 2322 | apex_available: ["myapex"], |
| 2323 | } |
| 2324 | `, |
| 2325 | }, |
| 2326 | } |
| 2327 | |
| 2328 | for _, test := range testCases { |
Paul Duffin | 1ea7c9f | 2021-03-15 09:39:13 +0000 | [diff] [blame] | 2329 | if test.name != "Updatable apex with non-stable legacy core platform dep" { |
| 2330 | continue |
| 2331 | } |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2332 | t.Run(test.name, func(t *testing.T) { |
Paul Duffin | 1ea7c9f | 2021-03-15 09:39:13 +0000 | [diff] [blame] | 2333 | errorHandler := android.FixtureExpectsNoErrors |
| 2334 | if test.expectedError != "" { |
| 2335 | errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(test.expectedError) |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2336 | } |
Paul Duffin | 1ea7c9f | 2021-03-15 09:39:13 +0000 | [diff] [blame] | 2337 | android.GroupFixturePreparers( |
| 2338 | java.PrepareForTestWithJavaDefaultModules, |
| 2339 | PrepareForTestWithApexBuildComponents, |
| 2340 | prepareForTestWithMyapex, |
| 2341 | android.OptionalFixturePreparer(test.preparer), |
| 2342 | ). |
| 2343 | ExtendWithErrorHandler(errorHandler). |
| 2344 | RunTestWithBp(t, test.bp) |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2345 | }) |
| 2346 | } |
| 2347 | } |
| 2348 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2349 | func TestApexMinSdkVersion_ErrorIfDepIsNewer(t *testing.T) { |
| 2350 | testApexError(t, `module "mylib2".*: should support min_sdk_version\(29\) for "myapex"`, ` |
| 2351 | apex { |
| 2352 | name: "myapex", |
| 2353 | key: "myapex.key", |
| 2354 | native_shared_libs: ["mylib"], |
| 2355 | min_sdk_version: "29", |
| 2356 | } |
| 2357 | |
| 2358 | apex_key { |
| 2359 | name: "myapex.key", |
| 2360 | public_key: "testkey.avbpubkey", |
| 2361 | private_key: "testkey.pem", |
| 2362 | } |
| 2363 | |
| 2364 | cc_library { |
| 2365 | name: "mylib", |
| 2366 | srcs: ["mylib.cpp"], |
| 2367 | shared_libs: ["mylib2"], |
| 2368 | system_shared_libs: [], |
| 2369 | stl: "none", |
| 2370 | apex_available: [ |
| 2371 | "myapex", |
| 2372 | ], |
| 2373 | min_sdk_version: "29", |
| 2374 | } |
| 2375 | |
| 2376 | // indirect part of the apex |
| 2377 | cc_library { |
| 2378 | name: "mylib2", |
| 2379 | srcs: ["mylib.cpp"], |
| 2380 | system_shared_libs: [], |
| 2381 | stl: "none", |
| 2382 | apex_available: [ |
| 2383 | "myapex", |
| 2384 | ], |
| 2385 | min_sdk_version: "30", |
| 2386 | } |
| 2387 | `) |
| 2388 | } |
| 2389 | |
| 2390 | func TestApexMinSdkVersion_ErrorIfDepIsNewer_Java(t *testing.T) { |
| 2391 | testApexError(t, `module "bar".*: should support min_sdk_version\(29\) for "myapex"`, ` |
| 2392 | apex { |
| 2393 | name: "myapex", |
| 2394 | key: "myapex.key", |
| 2395 | apps: ["AppFoo"], |
| 2396 | min_sdk_version: "29", |
Spandan Das | 91250b1 | 2022-05-06 22:12:55 +0000 | [diff] [blame] | 2397 | updatable: false, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2398 | } |
| 2399 | |
| 2400 | apex_key { |
| 2401 | name: "myapex.key", |
| 2402 | public_key: "testkey.avbpubkey", |
| 2403 | private_key: "testkey.pem", |
| 2404 | } |
| 2405 | |
| 2406 | android_app { |
| 2407 | name: "AppFoo", |
| 2408 | srcs: ["foo/bar/MyClass.java"], |
| 2409 | sdk_version: "current", |
| 2410 | min_sdk_version: "29", |
| 2411 | system_modules: "none", |
| 2412 | stl: "none", |
| 2413 | static_libs: ["bar"], |
| 2414 | apex_available: [ "myapex" ], |
| 2415 | } |
| 2416 | |
| 2417 | java_library { |
| 2418 | name: "bar", |
| 2419 | sdk_version: "current", |
| 2420 | srcs: ["a.java"], |
| 2421 | apex_available: [ "myapex" ], |
| 2422 | } |
| 2423 | `) |
| 2424 | } |
| 2425 | |
| 2426 | func TestApexMinSdkVersion_OkayEvenWhenDepIsNewer_IfItSatisfiesApexMinSdkVersion(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2427 | ctx := testApex(t, ` |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2428 | apex { |
| 2429 | name: "myapex", |
| 2430 | key: "myapex.key", |
| 2431 | native_shared_libs: ["mylib"], |
| 2432 | min_sdk_version: "29", |
| 2433 | } |
| 2434 | |
| 2435 | apex_key { |
| 2436 | name: "myapex.key", |
| 2437 | public_key: "testkey.avbpubkey", |
| 2438 | private_key: "testkey.pem", |
| 2439 | } |
| 2440 | |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 2441 | // mylib in myapex will link to mylib2#current |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2442 | // mylib in otherapex will link to mylib2(non-stub) in otherapex as well |
| 2443 | cc_library { |
| 2444 | name: "mylib", |
| 2445 | srcs: ["mylib.cpp"], |
| 2446 | shared_libs: ["mylib2"], |
| 2447 | system_shared_libs: [], |
| 2448 | stl: "none", |
| 2449 | apex_available: ["myapex", "otherapex"], |
| 2450 | min_sdk_version: "29", |
| 2451 | } |
| 2452 | |
| 2453 | cc_library { |
| 2454 | name: "mylib2", |
| 2455 | srcs: ["mylib.cpp"], |
| 2456 | system_shared_libs: [], |
| 2457 | stl: "none", |
| 2458 | apex_available: ["otherapex"], |
| 2459 | stubs: { versions: ["29", "30"] }, |
| 2460 | min_sdk_version: "30", |
| 2461 | } |
| 2462 | |
| 2463 | apex { |
| 2464 | name: "otherapex", |
| 2465 | key: "myapex.key", |
| 2466 | native_shared_libs: ["mylib", "mylib2"], |
| 2467 | min_sdk_version: "30", |
| 2468 | } |
| 2469 | `) |
| 2470 | expectLink := func(from, from_variant, to, to_variant string) { |
| 2471 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 2472 | libFlags := ld.Args["libFlags"] |
| 2473 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 2474 | } |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 2475 | expectLink("mylib", "shared_apex29", "mylib2", "shared_current") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2476 | expectLink("mylib", "shared_apex30", "mylib2", "shared_apex30") |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2477 | } |
| 2478 | |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2479 | func TestApexMinSdkVersion_WorksWithSdkCodename(t *testing.T) { |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2480 | withSAsActiveCodeNames := android.FixtureModifyProductVariables( |
| 2481 | func(variables android.FixtureProductVariables) { |
| 2482 | variables.Platform_sdk_codename = proptools.StringPtr("S") |
| 2483 | variables.Platform_version_active_codenames = []string{"S"} |
| 2484 | }, |
| 2485 | ) |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2486 | testApexError(t, `libbar.*: should support min_sdk_version\(S\)`, ` |
| 2487 | apex { |
| 2488 | name: "myapex", |
| 2489 | key: "myapex.key", |
| 2490 | native_shared_libs: ["libfoo"], |
| 2491 | min_sdk_version: "S", |
| 2492 | } |
| 2493 | apex_key { |
| 2494 | name: "myapex.key", |
| 2495 | public_key: "testkey.avbpubkey", |
| 2496 | private_key: "testkey.pem", |
| 2497 | } |
| 2498 | cc_library { |
| 2499 | name: "libfoo", |
| 2500 | shared_libs: ["libbar"], |
| 2501 | apex_available: ["myapex"], |
| 2502 | min_sdk_version: "29", |
| 2503 | } |
| 2504 | cc_library { |
| 2505 | name: "libbar", |
| 2506 | apex_available: ["myapex"], |
| 2507 | } |
| 2508 | `, withSAsActiveCodeNames) |
| 2509 | } |
| 2510 | |
| 2511 | func TestApexMinSdkVersion_WorksWithActiveCodenames(t *testing.T) { |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2512 | withSAsActiveCodeNames := android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 2513 | variables.Platform_sdk_codename = proptools.StringPtr("S") |
| 2514 | variables.Platform_version_active_codenames = []string{"S", "T"} |
| 2515 | }) |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2516 | ctx := testApex(t, ` |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2517 | apex { |
| 2518 | name: "myapex", |
| 2519 | key: "myapex.key", |
| 2520 | native_shared_libs: ["libfoo"], |
| 2521 | min_sdk_version: "S", |
| 2522 | } |
| 2523 | apex_key { |
| 2524 | name: "myapex.key", |
| 2525 | public_key: "testkey.avbpubkey", |
| 2526 | private_key: "testkey.pem", |
| 2527 | } |
| 2528 | cc_library { |
| 2529 | name: "libfoo", |
| 2530 | shared_libs: ["libbar"], |
| 2531 | apex_available: ["myapex"], |
| 2532 | min_sdk_version: "S", |
| 2533 | } |
| 2534 | cc_library { |
| 2535 | name: "libbar", |
| 2536 | stubs: { |
| 2537 | symbol_file: "libbar.map.txt", |
| 2538 | versions: ["30", "S", "T"], |
| 2539 | }, |
| 2540 | } |
| 2541 | `, withSAsActiveCodeNames) |
| 2542 | |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 2543 | // ensure libfoo is linked with current version of libbar stub |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2544 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared_apex10000") |
| 2545 | libFlags := libfoo.Rule("ld").Args["libFlags"] |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 2546 | ensureContains(t, libFlags, "android_arm64_armv8-a_shared_current/libbar.so") |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2547 | } |
| 2548 | |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2549 | func TestFilesInSubDir(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2550 | ctx := testApex(t, ` |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2551 | apex { |
| 2552 | name: "myapex", |
| 2553 | key: "myapex.key", |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2554 | native_shared_libs: ["mylib"], |
| 2555 | binaries: ["mybin"], |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2556 | prebuilts: ["myetc"], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2557 | compile_multilib: "both", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2558 | updatable: false, |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2559 | } |
| 2560 | |
| 2561 | apex_key { |
| 2562 | name: "myapex.key", |
| 2563 | public_key: "testkey.avbpubkey", |
| 2564 | private_key: "testkey.pem", |
| 2565 | } |
| 2566 | |
| 2567 | prebuilt_etc { |
| 2568 | name: "myetc", |
| 2569 | src: "myprebuilt", |
| 2570 | sub_dir: "foo/bar", |
| 2571 | } |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2572 | |
| 2573 | cc_library { |
| 2574 | name: "mylib", |
| 2575 | srcs: ["mylib.cpp"], |
| 2576 | relative_install_path: "foo/bar", |
| 2577 | system_shared_libs: [], |
| 2578 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2579 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2580 | } |
| 2581 | |
| 2582 | cc_binary { |
| 2583 | name: "mybin", |
| 2584 | srcs: ["mylib.cpp"], |
| 2585 | relative_install_path: "foo/bar", |
| 2586 | system_shared_libs: [], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2587 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2588 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2589 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2590 | `) |
| 2591 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2592 | generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig") |
Jiyong Park | 1b0893e | 2021-12-13 23:40:17 +0900 | [diff] [blame] | 2593 | cmd := generateFsRule.RuleParams.Command |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2594 | |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2595 | // Ensure that the subdirectories are all listed |
Jiyong Park | 1b0893e | 2021-12-13 23:40:17 +0900 | [diff] [blame] | 2596 | ensureContains(t, cmd, "/etc ") |
| 2597 | ensureContains(t, cmd, "/etc/foo ") |
| 2598 | ensureContains(t, cmd, "/etc/foo/bar ") |
| 2599 | ensureContains(t, cmd, "/lib64 ") |
| 2600 | ensureContains(t, cmd, "/lib64/foo ") |
| 2601 | ensureContains(t, cmd, "/lib64/foo/bar ") |
| 2602 | ensureContains(t, cmd, "/lib ") |
| 2603 | ensureContains(t, cmd, "/lib/foo ") |
| 2604 | ensureContains(t, cmd, "/lib/foo/bar ") |
| 2605 | ensureContains(t, cmd, "/bin ") |
| 2606 | ensureContains(t, cmd, "/bin/foo ") |
| 2607 | ensureContains(t, cmd, "/bin/foo/bar ") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2608 | } |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2609 | |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2610 | func TestFilesInSubDirWhenNativeBridgeEnabled(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2611 | ctx := testApex(t, ` |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2612 | apex { |
| 2613 | name: "myapex", |
| 2614 | key: "myapex.key", |
| 2615 | multilib: { |
| 2616 | both: { |
| 2617 | native_shared_libs: ["mylib"], |
| 2618 | binaries: ["mybin"], |
| 2619 | }, |
| 2620 | }, |
| 2621 | compile_multilib: "both", |
| 2622 | native_bridge_supported: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2623 | updatable: false, |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2624 | } |
| 2625 | |
| 2626 | apex_key { |
| 2627 | name: "myapex.key", |
| 2628 | public_key: "testkey.avbpubkey", |
| 2629 | private_key: "testkey.pem", |
| 2630 | } |
| 2631 | |
| 2632 | cc_library { |
| 2633 | name: "mylib", |
| 2634 | relative_install_path: "foo/bar", |
| 2635 | system_shared_libs: [], |
| 2636 | stl: "none", |
| 2637 | apex_available: [ "myapex" ], |
| 2638 | native_bridge_supported: true, |
| 2639 | } |
| 2640 | |
| 2641 | cc_binary { |
| 2642 | name: "mybin", |
| 2643 | relative_install_path: "foo/bar", |
| 2644 | system_shared_libs: [], |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2645 | stl: "none", |
| 2646 | apex_available: [ "myapex" ], |
| 2647 | native_bridge_supported: true, |
| 2648 | compile_multilib: "both", // default is "first" for binary |
| 2649 | multilib: { |
| 2650 | lib64: { |
| 2651 | suffix: "64", |
| 2652 | }, |
| 2653 | }, |
| 2654 | } |
| 2655 | `, withNativeBridgeEnabled) |
| 2656 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2657 | "bin/foo/bar/mybin", |
| 2658 | "bin/foo/bar/mybin64", |
| 2659 | "bin/arm/foo/bar/mybin", |
| 2660 | "bin/arm64/foo/bar/mybin64", |
| 2661 | "lib/foo/bar/mylib.so", |
| 2662 | "lib/arm/foo/bar/mylib.so", |
| 2663 | "lib64/foo/bar/mylib.so", |
| 2664 | "lib64/arm64/foo/bar/mylib.so", |
| 2665 | }) |
| 2666 | } |
| 2667 | |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2668 | func TestVendorApex(t *testing.T) { |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 2669 | result := android.GroupFixturePreparers( |
| 2670 | prepareForApexTest, |
| 2671 | android.FixtureModifyConfig(android.SetKatiEnabledForTests), |
| 2672 | ).RunTestWithBp(t, ` |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2673 | apex { |
| 2674 | name: "myapex", |
| 2675 | key: "myapex.key", |
| 2676 | binaries: ["mybin"], |
| 2677 | vendor: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2678 | updatable: false, |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2679 | } |
| 2680 | apex_key { |
| 2681 | name: "myapex.key", |
| 2682 | public_key: "testkey.avbpubkey", |
| 2683 | private_key: "testkey.pem", |
| 2684 | } |
| 2685 | cc_binary { |
| 2686 | name: "mybin", |
| 2687 | vendor: true, |
| 2688 | shared_libs: ["libfoo"], |
| 2689 | } |
| 2690 | cc_library { |
| 2691 | name: "libfoo", |
| 2692 | proprietary: true, |
| 2693 | } |
| 2694 | `) |
| 2695 | |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 2696 | ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2697 | "bin/mybin", |
| 2698 | "lib64/libfoo.so", |
| 2699 | // TODO(b/159195575): Add an option to use VNDK libs from VNDK APEX |
| 2700 | "lib64/libc++.so", |
| 2701 | }) |
| 2702 | |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 2703 | apexBundle := result.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 2704 | data := android.AndroidMkDataForTest(t, result.TestContext, apexBundle) |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2705 | name := apexBundle.BaseModuleName() |
| 2706 | prefix := "TARGET_" |
| 2707 | var builder strings.Builder |
| 2708 | data.Custom(&builder, name, prefix, "", data) |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 2709 | androidMk := android.StringRelativeToTop(result.Config, builder.String()) |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 2710 | installPath := "out/target/product/test_device/vendor/apex" |
Lukacs T. Berki | 7690c09 | 2021-02-26 14:27:36 +0100 | [diff] [blame] | 2711 | ensureContains(t, androidMk, "LOCAL_MODULE_PATH := "+installPath) |
Jooyung Han | 6c4cc9c | 2020-07-29 16:00:54 +0900 | [diff] [blame] | 2712 | |
Colin Cross | c68db4b | 2021-11-11 18:59:15 -0800 | [diff] [blame] | 2713 | apexManifestRule := result.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
Jooyung Han | 6c4cc9c | 2020-07-29 16:00:54 +0900 | [diff] [blame] | 2714 | requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"]) |
| 2715 | ensureListNotContains(t, requireNativeLibs, ":vndk") |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2716 | } |
| 2717 | |
Jooyung Han | c5a9676 | 2022-02-04 11:54:50 +0900 | [diff] [blame] | 2718 | func TestVendorApex_use_vndk_as_stable_TryingToIncludeVNDKLib(t *testing.T) { |
| 2719 | testApexError(t, `Trying to include a VNDK library`, ` |
| 2720 | apex { |
| 2721 | name: "myapex", |
| 2722 | key: "myapex.key", |
| 2723 | native_shared_libs: ["libc++"], // libc++ is a VNDK lib |
| 2724 | vendor: true, |
| 2725 | use_vndk_as_stable: true, |
| 2726 | updatable: false, |
| 2727 | } |
| 2728 | apex_key { |
| 2729 | name: "myapex.key", |
| 2730 | public_key: "testkey.avbpubkey", |
| 2731 | private_key: "testkey.pem", |
| 2732 | }`) |
| 2733 | } |
| 2734 | |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2735 | func TestVendorApex_use_vndk_as_stable(t *testing.T) { |
Jooyung Han | 91f9203 | 2022-02-04 12:36:33 +0900 | [diff] [blame] | 2736 | // myapex myapex2 |
| 2737 | // | | |
| 2738 | // mybin ------. mybin2 |
| 2739 | // \ \ / | |
| 2740 | // (stable) .---\--------` | |
| 2741 | // \ / \ | |
| 2742 | // \ / \ / |
| 2743 | // libvndk libvendor |
| 2744 | // (vndk) |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2745 | ctx := testApex(t, ` |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2746 | apex { |
| 2747 | name: "myapex", |
| 2748 | key: "myapex.key", |
| 2749 | binaries: ["mybin"], |
| 2750 | vendor: true, |
| 2751 | use_vndk_as_stable: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2752 | updatable: false, |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2753 | } |
| 2754 | apex_key { |
| 2755 | name: "myapex.key", |
| 2756 | public_key: "testkey.avbpubkey", |
| 2757 | private_key: "testkey.pem", |
| 2758 | } |
| 2759 | cc_binary { |
| 2760 | name: "mybin", |
| 2761 | vendor: true, |
| 2762 | shared_libs: ["libvndk", "libvendor"], |
| 2763 | } |
| 2764 | cc_library { |
| 2765 | name: "libvndk", |
| 2766 | vndk: { |
| 2767 | enabled: true, |
| 2768 | }, |
| 2769 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2770 | product_available: true, |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2771 | } |
| 2772 | cc_library { |
| 2773 | name: "libvendor", |
| 2774 | vendor: true, |
Jooyung Han | 91f9203 | 2022-02-04 12:36:33 +0900 | [diff] [blame] | 2775 | stl: "none", |
| 2776 | } |
| 2777 | apex { |
| 2778 | name: "myapex2", |
| 2779 | key: "myapex.key", |
| 2780 | binaries: ["mybin2"], |
| 2781 | vendor: true, |
| 2782 | use_vndk_as_stable: false, |
| 2783 | updatable: false, |
| 2784 | } |
| 2785 | cc_binary { |
| 2786 | name: "mybin2", |
| 2787 | vendor: true, |
| 2788 | shared_libs: ["libvndk", "libvendor"], |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2789 | } |
| 2790 | `) |
| 2791 | |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 2792 | vendorVariant := "android_vendor.29_arm64_armv8-a" |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2793 | |
Jooyung Han | 91f9203 | 2022-02-04 12:36:33 +0900 | [diff] [blame] | 2794 | for _, tc := range []struct { |
| 2795 | name string |
| 2796 | apexName string |
| 2797 | moduleName string |
| 2798 | moduleVariant string |
| 2799 | libs []string |
| 2800 | contents []string |
| 2801 | requireVndkNamespace bool |
| 2802 | }{ |
| 2803 | { |
| 2804 | name: "use_vndk_as_stable", |
| 2805 | apexName: "myapex", |
| 2806 | moduleName: "mybin", |
| 2807 | moduleVariant: vendorVariant + "_apex10000", |
| 2808 | libs: []string{ |
| 2809 | // should link with vendor variants of VNDK libs(libvndk/libc++) |
| 2810 | "out/soong/.intermediates/libvndk/" + vendorVariant + "_shared/libvndk.so", |
| 2811 | "out/soong/.intermediates/" + cc.DefaultCcCommonTestModulesDir + "libc++/" + vendorVariant + "_shared/libc++.so", |
| 2812 | // unstable Vendor libs as APEX variant |
| 2813 | "out/soong/.intermediates/libvendor/" + vendorVariant + "_shared_apex10000/libvendor.so", |
| 2814 | }, |
| 2815 | contents: []string{ |
| 2816 | "bin/mybin", |
| 2817 | "lib64/libvendor.so", |
| 2818 | // VNDK libs (libvndk/libc++) are not included |
| 2819 | }, |
| 2820 | requireVndkNamespace: true, |
| 2821 | }, |
| 2822 | { |
| 2823 | name: "!use_vndk_as_stable", |
| 2824 | apexName: "myapex2", |
| 2825 | moduleName: "mybin2", |
| 2826 | moduleVariant: vendorVariant + "_myapex2", |
| 2827 | libs: []string{ |
| 2828 | // should link with "unique" APEX(myapex2) variant of VNDK libs(libvndk/libc++) |
| 2829 | "out/soong/.intermediates/libvndk/" + vendorVariant + "_shared_myapex2/libvndk.so", |
| 2830 | "out/soong/.intermediates/" + cc.DefaultCcCommonTestModulesDir + "libc++/" + vendorVariant + "_shared_myapex2/libc++.so", |
| 2831 | // unstable vendor libs have "merged" APEX variants |
| 2832 | "out/soong/.intermediates/libvendor/" + vendorVariant + "_shared_apex10000/libvendor.so", |
| 2833 | }, |
| 2834 | contents: []string{ |
| 2835 | "bin/mybin2", |
| 2836 | "lib64/libvendor.so", |
| 2837 | // VNDK libs are included as well |
| 2838 | "lib64/libvndk.so", |
| 2839 | "lib64/libc++.so", |
| 2840 | }, |
| 2841 | requireVndkNamespace: false, |
| 2842 | }, |
| 2843 | } { |
| 2844 | t.Run(tc.name, func(t *testing.T) { |
| 2845 | // Check linked libs |
| 2846 | ldRule := ctx.ModuleForTests(tc.moduleName, tc.moduleVariant).Rule("ld") |
| 2847 | libs := names(ldRule.Args["libFlags"]) |
| 2848 | for _, lib := range tc.libs { |
| 2849 | ensureListContains(t, libs, lib) |
| 2850 | } |
| 2851 | // Check apex contents |
| 2852 | ensureExactContents(t, ctx, tc.apexName, "android_common_"+tc.apexName+"_image", tc.contents) |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2853 | |
Jooyung Han | 91f9203 | 2022-02-04 12:36:33 +0900 | [diff] [blame] | 2854 | // Check "requireNativeLibs" |
| 2855 | apexManifestRule := ctx.ModuleForTests(tc.apexName, "android_common_"+tc.apexName+"_image").Rule("apexManifestRule") |
| 2856 | requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"]) |
| 2857 | if tc.requireVndkNamespace { |
| 2858 | ensureListContains(t, requireNativeLibs, ":vndk") |
| 2859 | } else { |
| 2860 | ensureListNotContains(t, requireNativeLibs, ":vndk") |
| 2861 | } |
| 2862 | }) |
| 2863 | } |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2864 | } |
| 2865 | |
Justin Yun | 13decfb | 2021-03-08 19:25:55 +0900 | [diff] [blame] | 2866 | func TestProductVariant(t *testing.T) { |
| 2867 | ctx := testApex(t, ` |
| 2868 | apex { |
| 2869 | name: "myapex", |
| 2870 | key: "myapex.key", |
| 2871 | updatable: false, |
| 2872 | product_specific: true, |
| 2873 | binaries: ["foo"], |
| 2874 | } |
| 2875 | |
| 2876 | apex_key { |
| 2877 | name: "myapex.key", |
| 2878 | public_key: "testkey.avbpubkey", |
| 2879 | private_key: "testkey.pem", |
| 2880 | } |
| 2881 | |
| 2882 | cc_binary { |
| 2883 | name: "foo", |
| 2884 | product_available: true, |
| 2885 | apex_available: ["myapex"], |
| 2886 | srcs: ["foo.cpp"], |
| 2887 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2888 | `, android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 2889 | variables.ProductVndkVersion = proptools.StringPtr("current") |
| 2890 | }), |
| 2891 | ) |
Justin Yun | 13decfb | 2021-03-08 19:25:55 +0900 | [diff] [blame] | 2892 | |
| 2893 | cflags := strings.Fields( |
Jooyung Han | 91f9203 | 2022-02-04 12:36:33 +0900 | [diff] [blame] | 2894 | ctx.ModuleForTests("foo", "android_product.29_arm64_armv8-a_myapex").Rule("cc").Args["cFlags"]) |
Justin Yun | 13decfb | 2021-03-08 19:25:55 +0900 | [diff] [blame] | 2895 | ensureListContains(t, cflags, "-D__ANDROID_VNDK__") |
| 2896 | ensureListContains(t, cflags, "-D__ANDROID_APEX__") |
| 2897 | ensureListContains(t, cflags, "-D__ANDROID_PRODUCT__") |
| 2898 | ensureListNotContains(t, cflags, "-D__ANDROID_VENDOR__") |
| 2899 | } |
| 2900 | |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 2901 | func TestApex_withPrebuiltFirmware(t *testing.T) { |
| 2902 | testCases := []struct { |
| 2903 | name string |
| 2904 | additionalProp string |
| 2905 | }{ |
| 2906 | {"system apex with prebuilt_firmware", ""}, |
| 2907 | {"vendor apex with prebuilt_firmware", "vendor: true,"}, |
| 2908 | } |
| 2909 | for _, tc := range testCases { |
| 2910 | t.Run(tc.name, func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2911 | ctx := testApex(t, ` |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 2912 | apex { |
| 2913 | name: "myapex", |
| 2914 | key: "myapex.key", |
| 2915 | prebuilts: ["myfirmware"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2916 | updatable: false, |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 2917 | `+tc.additionalProp+` |
| 2918 | } |
| 2919 | apex_key { |
| 2920 | name: "myapex.key", |
| 2921 | public_key: "testkey.avbpubkey", |
| 2922 | private_key: "testkey.pem", |
| 2923 | } |
| 2924 | prebuilt_firmware { |
| 2925 | name: "myfirmware", |
| 2926 | src: "myfirmware.bin", |
| 2927 | filename_from_src: true, |
| 2928 | `+tc.additionalProp+` |
| 2929 | } |
| 2930 | `) |
| 2931 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2932 | "etc/firmware/myfirmware.bin", |
| 2933 | }) |
| 2934 | }) |
| 2935 | } |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 2936 | } |
| 2937 | |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2938 | func TestAndroidMk_VendorApexRequired(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2939 | ctx := testApex(t, ` |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2940 | apex { |
| 2941 | name: "myapex", |
| 2942 | key: "myapex.key", |
| 2943 | vendor: true, |
| 2944 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2945 | updatable: false, |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2946 | } |
| 2947 | |
| 2948 | apex_key { |
| 2949 | name: "myapex.key", |
| 2950 | public_key: "testkey.avbpubkey", |
| 2951 | private_key: "testkey.pem", |
| 2952 | } |
| 2953 | |
| 2954 | cc_library { |
| 2955 | name: "mylib", |
| 2956 | vendor_available: true, |
| 2957 | } |
| 2958 | `) |
| 2959 | |
| 2960 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2961 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2962 | name := apexBundle.BaseModuleName() |
| 2963 | prefix := "TARGET_" |
| 2964 | var builder strings.Builder |
| 2965 | data.Custom(&builder, name, prefix, "", data) |
| 2966 | androidMk := builder.String() |
| 2967 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += libc.vendor libm.vendor libdl.vendor\n") |
| 2968 | } |
| 2969 | |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2970 | func TestAndroidMkWritesCommonProperties(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2971 | ctx := testApex(t, ` |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2972 | apex { |
| 2973 | name: "myapex", |
| 2974 | key: "myapex.key", |
| 2975 | vintf_fragments: ["fragment.xml"], |
| 2976 | init_rc: ["init.rc"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2977 | updatable: false, |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2978 | } |
| 2979 | apex_key { |
| 2980 | name: "myapex.key", |
| 2981 | public_key: "testkey.avbpubkey", |
| 2982 | private_key: "testkey.pem", |
| 2983 | } |
| 2984 | cc_binary { |
| 2985 | name: "mybin", |
| 2986 | } |
| 2987 | `) |
| 2988 | |
| 2989 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2990 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2991 | name := apexBundle.BaseModuleName() |
| 2992 | prefix := "TARGET_" |
| 2993 | var builder strings.Builder |
| 2994 | data.Custom(&builder, name, prefix, "", data) |
| 2995 | androidMk := builder.String() |
Liz Kammer | 7b3dc8a | 2021-04-16 16:41:59 -0400 | [diff] [blame] | 2996 | ensureContains(t, androidMk, "LOCAL_FULL_VINTF_FRAGMENTS := fragment.xml\n") |
Liz Kammer | 0c4f71c | 2021-04-06 10:35:10 -0400 | [diff] [blame] | 2997 | ensureContains(t, androidMk, "LOCAL_FULL_INIT_RC := init.rc\n") |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2998 | } |
| 2999 | |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 3000 | func TestStaticLinking(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3001 | ctx := testApex(t, ` |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 3002 | apex { |
| 3003 | name: "myapex", |
| 3004 | key: "myapex.key", |
| 3005 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3006 | updatable: false, |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 3007 | } |
| 3008 | |
| 3009 | apex_key { |
| 3010 | name: "myapex.key", |
| 3011 | public_key: "testkey.avbpubkey", |
| 3012 | private_key: "testkey.pem", |
| 3013 | } |
| 3014 | |
| 3015 | cc_library { |
| 3016 | name: "mylib", |
| 3017 | srcs: ["mylib.cpp"], |
| 3018 | system_shared_libs: [], |
| 3019 | stl: "none", |
| 3020 | stubs: { |
| 3021 | versions: ["1", "2", "3"], |
| 3022 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3023 | apex_available: [ |
| 3024 | "//apex_available:platform", |
| 3025 | "myapex", |
| 3026 | ], |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 3027 | } |
| 3028 | |
| 3029 | cc_binary { |
| 3030 | name: "not_in_apex", |
| 3031 | srcs: ["mylib.cpp"], |
| 3032 | static_libs: ["mylib"], |
| 3033 | static_executable: true, |
| 3034 | system_shared_libs: [], |
| 3035 | stl: "none", |
| 3036 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 3037 | `) |
| 3038 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3039 | ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a").Rule("ld").Args["libFlags"] |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 3040 | |
| 3041 | // Ensure that not_in_apex is linking with the static variant of mylib |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3042 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a") |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 3043 | } |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3044 | |
| 3045 | func TestKeys(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3046 | ctx := testApex(t, ` |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3047 | apex { |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 3048 | name: "myapex_keytest", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3049 | key: "myapex.key", |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 3050 | certificate: ":myapex.certificate", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3051 | native_shared_libs: ["mylib"], |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3052 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3053 | updatable: false, |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3054 | } |
| 3055 | |
| 3056 | cc_library { |
| 3057 | name: "mylib", |
| 3058 | srcs: ["mylib.cpp"], |
| 3059 | system_shared_libs: [], |
| 3060 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3061 | apex_available: [ "myapex_keytest" ], |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3062 | } |
| 3063 | |
| 3064 | apex_key { |
| 3065 | name: "myapex.key", |
| 3066 | public_key: "testkey.avbpubkey", |
| 3067 | private_key: "testkey.pem", |
| 3068 | } |
| 3069 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 3070 | android_app_certificate { |
| 3071 | name: "myapex.certificate", |
| 3072 | certificate: "testkey", |
| 3073 | } |
| 3074 | |
| 3075 | android_app_certificate { |
| 3076 | name: "myapex.certificate.override", |
| 3077 | certificate: "testkey.override", |
| 3078 | } |
| 3079 | |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3080 | `) |
| 3081 | |
| 3082 | // check the APEX keys |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 3083 | keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3084 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 3085 | if keys.publicKeyFile.String() != "vendor/foo/devkeys/testkey.avbpubkey" { |
| 3086 | t.Errorf("public key %q is not %q", keys.publicKeyFile.String(), |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3087 | "vendor/foo/devkeys/testkey.avbpubkey") |
| 3088 | } |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 3089 | if keys.privateKeyFile.String() != "vendor/foo/devkeys/testkey.pem" { |
| 3090 | t.Errorf("private key %q is not %q", keys.privateKeyFile.String(), |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3091 | "vendor/foo/devkeys/testkey.pem") |
| 3092 | } |
| 3093 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 3094 | // check the APK certs. It should be overridden to myapex.certificate.override |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3095 | certs := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk").Args["certificates"] |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 3096 | if certs != "testkey.override.x509.pem testkey.override.pk8" { |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3097 | t.Errorf("cert and private key %q are not %q", certs, |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 3098 | "testkey.override.509.pem testkey.override.pk8") |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 3099 | } |
| 3100 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3101 | |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3102 | func TestCertificate(t *testing.T) { |
| 3103 | t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3104 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3105 | apex { |
| 3106 | name: "myapex", |
| 3107 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3108 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3109 | } |
| 3110 | apex_key { |
| 3111 | name: "myapex.key", |
| 3112 | public_key: "testkey.avbpubkey", |
| 3113 | private_key: "testkey.pem", |
| 3114 | }`) |
| 3115 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 3116 | expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8" |
| 3117 | if actual := rule.Args["certificates"]; actual != expected { |
| 3118 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 3119 | } |
| 3120 | }) |
| 3121 | t.Run("override when unspecified", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3122 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3123 | apex { |
| 3124 | name: "myapex_keytest", |
| 3125 | key: "myapex.key", |
| 3126 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3127 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3128 | } |
| 3129 | apex_key { |
| 3130 | name: "myapex.key", |
| 3131 | public_key: "testkey.avbpubkey", |
| 3132 | private_key: "testkey.pem", |
| 3133 | } |
| 3134 | android_app_certificate { |
| 3135 | name: "myapex.certificate.override", |
| 3136 | certificate: "testkey.override", |
| 3137 | }`) |
| 3138 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 3139 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 3140 | if actual := rule.Args["certificates"]; actual != expected { |
| 3141 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 3142 | } |
| 3143 | }) |
| 3144 | t.Run("if specified as :module, it respects the prop", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3145 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3146 | apex { |
| 3147 | name: "myapex", |
| 3148 | key: "myapex.key", |
| 3149 | certificate: ":myapex.certificate", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3150 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3151 | } |
| 3152 | apex_key { |
| 3153 | name: "myapex.key", |
| 3154 | public_key: "testkey.avbpubkey", |
| 3155 | private_key: "testkey.pem", |
| 3156 | } |
| 3157 | android_app_certificate { |
| 3158 | name: "myapex.certificate", |
| 3159 | certificate: "testkey", |
| 3160 | }`) |
| 3161 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 3162 | expected := "testkey.x509.pem testkey.pk8" |
| 3163 | if actual := rule.Args["certificates"]; actual != expected { |
| 3164 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 3165 | } |
| 3166 | }) |
| 3167 | t.Run("override when specifiec as <:module>", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3168 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3169 | apex { |
| 3170 | name: "myapex_keytest", |
| 3171 | key: "myapex.key", |
| 3172 | file_contexts: ":myapex-file_contexts", |
| 3173 | certificate: ":myapex.certificate", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3174 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3175 | } |
| 3176 | apex_key { |
| 3177 | name: "myapex.key", |
| 3178 | public_key: "testkey.avbpubkey", |
| 3179 | private_key: "testkey.pem", |
| 3180 | } |
| 3181 | android_app_certificate { |
| 3182 | name: "myapex.certificate.override", |
| 3183 | certificate: "testkey.override", |
| 3184 | }`) |
| 3185 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 3186 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 3187 | if actual := rule.Args["certificates"]; actual != expected { |
| 3188 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 3189 | } |
| 3190 | }) |
| 3191 | t.Run("if specified as name, finds it from DefaultDevKeyDir", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3192 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3193 | apex { |
| 3194 | name: "myapex", |
| 3195 | key: "myapex.key", |
| 3196 | certificate: "testkey", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3197 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3198 | } |
| 3199 | apex_key { |
| 3200 | name: "myapex.key", |
| 3201 | public_key: "testkey.avbpubkey", |
| 3202 | private_key: "testkey.pem", |
| 3203 | }`) |
| 3204 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 3205 | expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8" |
| 3206 | if actual := rule.Args["certificates"]; actual != expected { |
| 3207 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 3208 | } |
| 3209 | }) |
| 3210 | t.Run("override when specified as <name>", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3211 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3212 | apex { |
| 3213 | name: "myapex_keytest", |
| 3214 | key: "myapex.key", |
| 3215 | file_contexts: ":myapex-file_contexts", |
| 3216 | certificate: "testkey", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3217 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 3218 | } |
| 3219 | apex_key { |
| 3220 | name: "myapex.key", |
| 3221 | public_key: "testkey.avbpubkey", |
| 3222 | private_key: "testkey.pem", |
| 3223 | } |
| 3224 | android_app_certificate { |
| 3225 | name: "myapex.certificate.override", |
| 3226 | certificate: "testkey.override", |
| 3227 | }`) |
| 3228 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 3229 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 3230 | if actual := rule.Args["certificates"]; actual != expected { |
| 3231 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 3232 | } |
| 3233 | }) |
| 3234 | } |
| 3235 | |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3236 | func TestMacro(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3237 | ctx := testApex(t, ` |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3238 | apex { |
| 3239 | name: "myapex", |
| 3240 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3241 | native_shared_libs: ["mylib", "mylib2"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3242 | updatable: false, |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3243 | } |
| 3244 | |
| 3245 | apex { |
| 3246 | name: "otherapex", |
| 3247 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3248 | native_shared_libs: ["mylib", "mylib2"], |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 3249 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3250 | } |
| 3251 | |
| 3252 | apex_key { |
| 3253 | name: "myapex.key", |
| 3254 | public_key: "testkey.avbpubkey", |
| 3255 | private_key: "testkey.pem", |
| 3256 | } |
| 3257 | |
| 3258 | cc_library { |
| 3259 | name: "mylib", |
| 3260 | srcs: ["mylib.cpp"], |
| 3261 | system_shared_libs: [], |
| 3262 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3263 | apex_available: [ |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3264 | "myapex", |
| 3265 | "otherapex", |
| 3266 | ], |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 3267 | recovery_available: true, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 3268 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3269 | } |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3270 | cc_library { |
| 3271 | name: "mylib2", |
| 3272 | srcs: ["mylib.cpp"], |
| 3273 | system_shared_libs: [], |
| 3274 | stl: "none", |
| 3275 | apex_available: [ |
| 3276 | "myapex", |
| 3277 | "otherapex", |
| 3278 | ], |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3279 | static_libs: ["mylib3"], |
| 3280 | recovery_available: true, |
| 3281 | min_sdk_version: "29", |
| 3282 | } |
| 3283 | cc_library { |
| 3284 | name: "mylib3", |
| 3285 | srcs: ["mylib.cpp"], |
| 3286 | system_shared_libs: [], |
| 3287 | stl: "none", |
| 3288 | apex_available: [ |
| 3289 | "myapex", |
| 3290 | "otherapex", |
| 3291 | ], |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3292 | recovery_available: true, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 3293 | min_sdk_version: "29", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3294 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3295 | `) |
| 3296 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3297 | // non-APEX variant does not have __ANDROID_APEX__ defined |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3298 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
Jooyung Han | 6b8459b | 2019-10-30 08:29:25 +0900 | [diff] [blame] | 3299 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3300 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3301 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 3302 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3303 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex10000").Rule("cc").Args["cFlags"] |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3304 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3305 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__=10000") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3306 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 3307 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3308 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex29").Rule("cc").Args["cFlags"] |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3309 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3310 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__=29") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3311 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3312 | // When a cc_library sets use_apex_name_macro: true each apex gets a unique variant and |
| 3313 | // each variant defines additional macros to distinguish which apex variant it is built for |
| 3314 | |
| 3315 | // non-APEX variant does not have __ANDROID_APEX__ defined |
| 3316 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 3317 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3318 | |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3319 | // recovery variant does not set __ANDROID_APEX_MIN_SDK_VERSION__ |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3320 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 3321 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3322 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3323 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3324 | // non-APEX variant does not have __ANDROID_APEX__ defined |
| 3325 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 3326 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3327 | |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3328 | // recovery variant does not set __ANDROID_APEX_MIN_SDK_VERSION__ |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3329 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 3330 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3331 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3332 | } |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3333 | |
| 3334 | func TestHeaderLibsDependency(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3335 | ctx := testApex(t, ` |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3336 | apex { |
| 3337 | name: "myapex", |
| 3338 | key: "myapex.key", |
| 3339 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3340 | updatable: false, |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3341 | } |
| 3342 | |
| 3343 | apex_key { |
| 3344 | name: "myapex.key", |
| 3345 | public_key: "testkey.avbpubkey", |
| 3346 | private_key: "testkey.pem", |
| 3347 | } |
| 3348 | |
| 3349 | cc_library_headers { |
| 3350 | name: "mylib_headers", |
| 3351 | export_include_dirs: ["my_include"], |
| 3352 | system_shared_libs: [], |
| 3353 | stl: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 3354 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3355 | } |
| 3356 | |
| 3357 | cc_library { |
| 3358 | name: "mylib", |
| 3359 | srcs: ["mylib.cpp"], |
| 3360 | system_shared_libs: [], |
| 3361 | stl: "none", |
| 3362 | header_libs: ["mylib_headers"], |
| 3363 | export_header_lib_headers: ["mylib_headers"], |
| 3364 | stubs: { |
| 3365 | versions: ["1", "2", "3"], |
| 3366 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3367 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3368 | } |
| 3369 | |
| 3370 | cc_library { |
| 3371 | name: "otherlib", |
| 3372 | srcs: ["mylib.cpp"], |
| 3373 | system_shared_libs: [], |
| 3374 | stl: "none", |
| 3375 | shared_libs: ["mylib"], |
| 3376 | } |
| 3377 | `) |
| 3378 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3379 | cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3380 | |
| 3381 | // Ensure that the include path of the header lib is exported to 'otherlib' |
| 3382 | ensureContains(t, cFlags, "-Imy_include") |
| 3383 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3384 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3385 | type fileInApex struct { |
| 3386 | path string // path in apex |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3387 | src string // src path |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3388 | isLink bool |
| 3389 | } |
| 3390 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3391 | func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3392 | t.Helper() |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3393 | apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3394 | copyCmds := apexRule.Args["copy_commands"] |
| 3395 | imageApexDir := "/image.apex/" |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3396 | var ret []fileInApex |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3397 | for _, cmd := range strings.Split(copyCmds, "&&") { |
| 3398 | cmd = strings.TrimSpace(cmd) |
| 3399 | if cmd == "" { |
| 3400 | continue |
| 3401 | } |
| 3402 | terms := strings.Split(cmd, " ") |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3403 | var dst, src string |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3404 | var isLink bool |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3405 | switch terms[0] { |
| 3406 | case "mkdir": |
| 3407 | case "cp": |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3408 | if len(terms) != 3 && len(terms) != 4 { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3409 | t.Fatal("copyCmds contains invalid cp command", cmd) |
| 3410 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3411 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3412 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3413 | isLink = false |
| 3414 | case "ln": |
| 3415 | if len(terms) != 3 && len(terms) != 4 { |
| 3416 | // ln LINK TARGET or ln -s LINK TARGET |
| 3417 | t.Fatal("copyCmds contains invalid ln command", cmd) |
| 3418 | } |
| 3419 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3420 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3421 | isLink = true |
| 3422 | default: |
| 3423 | t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd) |
| 3424 | } |
| 3425 | if dst != "" { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3426 | index := strings.Index(dst, imageApexDir) |
| 3427 | if index == -1 { |
| 3428 | t.Fatal("copyCmds should copy a file to image.apex/", cmd) |
| 3429 | } |
| 3430 | dstFile := dst[index+len(imageApexDir):] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3431 | ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink}) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3432 | } |
| 3433 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3434 | return ret |
| 3435 | } |
| 3436 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3437 | func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) { |
| 3438 | t.Helper() |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3439 | var failed bool |
| 3440 | var surplus []string |
| 3441 | filesMatched := make(map[string]bool) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3442 | for _, file := range getFiles(t, ctx, moduleName, variant) { |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3443 | mactchFound := false |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3444 | for _, expected := range files { |
| 3445 | if matched, _ := path.Match(expected, file.path); matched { |
| 3446 | filesMatched[expected] = true |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3447 | mactchFound = true |
| 3448 | break |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3449 | } |
| 3450 | } |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3451 | if !mactchFound { |
| 3452 | surplus = append(surplus, file.path) |
| 3453 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3454 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3455 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3456 | if len(surplus) > 0 { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3457 | sort.Strings(surplus) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3458 | t.Log("surplus files", surplus) |
| 3459 | failed = true |
| 3460 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3461 | |
| 3462 | if len(files) > len(filesMatched) { |
| 3463 | var missing []string |
| 3464 | for _, expected := range files { |
| 3465 | if !filesMatched[expected] { |
| 3466 | missing = append(missing, expected) |
| 3467 | } |
| 3468 | } |
| 3469 | sort.Strings(missing) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3470 | t.Log("missing files", missing) |
| 3471 | failed = true |
| 3472 | } |
| 3473 | if failed { |
| 3474 | t.Fail() |
| 3475 | } |
| 3476 | } |
| 3477 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3478 | func TestVndkApexCurrent(t *testing.T) { |
Jooyung Han | 7d6e79b | 2021-06-24 01:53:43 +0900 | [diff] [blame] | 3479 | commonFiles := []string{ |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3480 | "lib/libc++.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3481 | "lib64/libc++.so", |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 3482 | "etc/llndk.libraries.29.txt", |
| 3483 | "etc/vndkcore.libraries.29.txt", |
| 3484 | "etc/vndksp.libraries.29.txt", |
| 3485 | "etc/vndkprivate.libraries.29.txt", |
| 3486 | "etc/vndkproduct.libraries.29.txt", |
Jooyung Han | 7d6e79b | 2021-06-24 01:53:43 +0900 | [diff] [blame] | 3487 | } |
| 3488 | testCases := []struct { |
| 3489 | vndkVersion string |
| 3490 | expectedFiles []string |
| 3491 | }{ |
| 3492 | { |
| 3493 | vndkVersion: "current", |
| 3494 | expectedFiles: append(commonFiles, |
| 3495 | "lib/libvndk.so", |
| 3496 | "lib/libvndksp.so", |
| 3497 | "lib64/libvndk.so", |
| 3498 | "lib64/libvndksp.so"), |
| 3499 | }, |
| 3500 | { |
| 3501 | vndkVersion: "", |
| 3502 | expectedFiles: append(commonFiles, |
| 3503 | // Legacy VNDK APEX contains only VNDK-SP files (of core variant) |
| 3504 | "lib/libvndksp.so", |
| 3505 | "lib64/libvndksp.so"), |
| 3506 | }, |
| 3507 | } |
| 3508 | for _, tc := range testCases { |
| 3509 | t.Run("VNDK.current with DeviceVndkVersion="+tc.vndkVersion, func(t *testing.T) { |
| 3510 | ctx := testApex(t, ` |
| 3511 | apex_vndk { |
| 3512 | name: "com.android.vndk.current", |
| 3513 | key: "com.android.vndk.current.key", |
| 3514 | updatable: false, |
| 3515 | } |
| 3516 | |
| 3517 | apex_key { |
| 3518 | name: "com.android.vndk.current.key", |
| 3519 | public_key: "testkey.avbpubkey", |
| 3520 | private_key: "testkey.pem", |
| 3521 | } |
| 3522 | |
| 3523 | cc_library { |
| 3524 | name: "libvndk", |
| 3525 | srcs: ["mylib.cpp"], |
| 3526 | vendor_available: true, |
| 3527 | product_available: true, |
| 3528 | vndk: { |
| 3529 | enabled: true, |
| 3530 | }, |
| 3531 | system_shared_libs: [], |
| 3532 | stl: "none", |
| 3533 | apex_available: [ "com.android.vndk.current" ], |
| 3534 | } |
| 3535 | |
| 3536 | cc_library { |
| 3537 | name: "libvndksp", |
| 3538 | srcs: ["mylib.cpp"], |
| 3539 | vendor_available: true, |
| 3540 | product_available: true, |
| 3541 | vndk: { |
| 3542 | enabled: true, |
| 3543 | support_system_process: true, |
| 3544 | }, |
| 3545 | system_shared_libs: [], |
| 3546 | stl: "none", |
| 3547 | apex_available: [ "com.android.vndk.current" ], |
| 3548 | } |
| 3549 | |
| 3550 | // VNDK-Ext should not cause any problems |
| 3551 | |
| 3552 | cc_library { |
| 3553 | name: "libvndk.ext", |
| 3554 | srcs: ["mylib2.cpp"], |
| 3555 | vendor: true, |
| 3556 | vndk: { |
| 3557 | enabled: true, |
| 3558 | extends: "libvndk", |
| 3559 | }, |
| 3560 | system_shared_libs: [], |
| 3561 | stl: "none", |
| 3562 | } |
| 3563 | |
| 3564 | cc_library { |
| 3565 | name: "libvndksp.ext", |
| 3566 | srcs: ["mylib2.cpp"], |
| 3567 | vendor: true, |
| 3568 | vndk: { |
| 3569 | enabled: true, |
| 3570 | support_system_process: true, |
| 3571 | extends: "libvndksp", |
| 3572 | }, |
| 3573 | system_shared_libs: [], |
| 3574 | stl: "none", |
| 3575 | } |
| 3576 | `+vndkLibrariesTxtFiles("current"), android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 3577 | variables.DeviceVndkVersion = proptools.StringPtr(tc.vndkVersion) |
| 3578 | })) |
| 3579 | ensureExactContents(t, ctx, "com.android.vndk.current", "android_common_image", tc.expectedFiles) |
| 3580 | }) |
| 3581 | } |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3582 | } |
| 3583 | |
| 3584 | func TestVndkApexWithPrebuilt(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3585 | ctx := testApex(t, ` |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3586 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3587 | name: "com.android.vndk.current", |
| 3588 | key: "com.android.vndk.current.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3589 | updatable: false, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3590 | } |
| 3591 | |
| 3592 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3593 | name: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3594 | public_key: "testkey.avbpubkey", |
| 3595 | private_key: "testkey.pem", |
| 3596 | } |
| 3597 | |
| 3598 | cc_prebuilt_library_shared { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3599 | name: "libvndk", |
| 3600 | srcs: ["libvndk.so"], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3601 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3602 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3603 | vndk: { |
| 3604 | enabled: true, |
| 3605 | }, |
| 3606 | system_shared_libs: [], |
| 3607 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3608 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3609 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3610 | |
| 3611 | cc_prebuilt_library_shared { |
| 3612 | name: "libvndk.arm", |
| 3613 | srcs: ["libvndk.arm.so"], |
| 3614 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3615 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3616 | vndk: { |
| 3617 | enabled: true, |
| 3618 | }, |
| 3619 | enabled: false, |
| 3620 | arch: { |
| 3621 | arm: { |
| 3622 | enabled: true, |
| 3623 | }, |
| 3624 | }, |
| 3625 | system_shared_libs: [], |
| 3626 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3627 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3628 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3629 | `+vndkLibrariesTxtFiles("current"), |
| 3630 | withFiles(map[string][]byte{ |
| 3631 | "libvndk.so": nil, |
| 3632 | "libvndk.arm.so": nil, |
| 3633 | })) |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3634 | ensureExactContents(t, ctx, "com.android.vndk.current", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3635 | "lib/libvndk.so", |
| 3636 | "lib/libvndk.arm.so", |
| 3637 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3638 | "lib/libc++.so", |
| 3639 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3640 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3641 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3642 | } |
| 3643 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3644 | func vndkLibrariesTxtFiles(vers ...string) (result string) { |
| 3645 | for _, v := range vers { |
| 3646 | if v == "current" { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3647 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate", "vndkproduct"} { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3648 | result += ` |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 3649 | ` + txt + `_libraries_txt { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3650 | name: "` + txt + `.libraries.txt", |
| 3651 | } |
| 3652 | ` |
| 3653 | } |
| 3654 | } else { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3655 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate", "vndkproduct"} { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3656 | result += ` |
| 3657 | prebuilt_etc { |
| 3658 | name: "` + txt + `.libraries.` + v + `.txt", |
| 3659 | src: "dummy.txt", |
| 3660 | } |
| 3661 | ` |
| 3662 | } |
| 3663 | } |
| 3664 | } |
| 3665 | return |
| 3666 | } |
| 3667 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3668 | func TestVndkApexVersion(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3669 | ctx := testApex(t, ` |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3670 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3671 | name: "com.android.vndk.v27", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3672 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3673 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3674 | vndk_version: "27", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3675 | updatable: false, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3676 | } |
| 3677 | |
| 3678 | apex_key { |
| 3679 | name: "myapex.key", |
| 3680 | public_key: "testkey.avbpubkey", |
| 3681 | private_key: "testkey.pem", |
| 3682 | } |
| 3683 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3684 | vndk_prebuilt_shared { |
| 3685 | name: "libvndk27", |
| 3686 | version: "27", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3687 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3688 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3689 | vndk: { |
| 3690 | enabled: true, |
| 3691 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3692 | target_arch: "arm64", |
| 3693 | arch: { |
| 3694 | arm: { |
| 3695 | srcs: ["libvndk27_arm.so"], |
| 3696 | }, |
| 3697 | arm64: { |
| 3698 | srcs: ["libvndk27_arm64.so"], |
| 3699 | }, |
| 3700 | }, |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3701 | apex_available: [ "com.android.vndk.v27" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3702 | } |
| 3703 | |
| 3704 | vndk_prebuilt_shared { |
| 3705 | name: "libvndk27", |
| 3706 | version: "27", |
| 3707 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3708 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3709 | vndk: { |
| 3710 | enabled: true, |
| 3711 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3712 | target_arch: "x86_64", |
| 3713 | arch: { |
| 3714 | x86: { |
| 3715 | srcs: ["libvndk27_x86.so"], |
| 3716 | }, |
| 3717 | x86_64: { |
| 3718 | srcs: ["libvndk27_x86_64.so"], |
| 3719 | }, |
| 3720 | }, |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3721 | } |
| 3722 | `+vndkLibrariesTxtFiles("27"), |
| 3723 | withFiles(map[string][]byte{ |
| 3724 | "libvndk27_arm.so": nil, |
| 3725 | "libvndk27_arm64.so": nil, |
| 3726 | "libvndk27_x86.so": nil, |
| 3727 | "libvndk27_x86_64.so": nil, |
| 3728 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3729 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3730 | ensureExactContents(t, ctx, "com.android.vndk.v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3731 | "lib/libvndk27_arm.so", |
| 3732 | "lib64/libvndk27_arm64.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3733 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3734 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3735 | } |
| 3736 | |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3737 | func TestVndkApexNameRule(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3738 | ctx := testApex(t, ` |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3739 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3740 | name: "com.android.vndk.current", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3741 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3742 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3743 | updatable: false, |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3744 | } |
| 3745 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3746 | name: "com.android.vndk.v28", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3747 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3748 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3749 | vndk_version: "28", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3750 | updatable: false, |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3751 | } |
| 3752 | apex_key { |
| 3753 | name: "myapex.key", |
| 3754 | public_key: "testkey.avbpubkey", |
| 3755 | private_key: "testkey.pem", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3756 | }`+vndkLibrariesTxtFiles("28", "current")) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3757 | |
| 3758 | assertApexName := func(expected, moduleName string) { |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3759 | bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3760 | actual := proptools.String(bundle.properties.Apex_name) |
| 3761 | if !reflect.DeepEqual(actual, expected) { |
| 3762 | t.Errorf("Got '%v', expected '%v'", actual, expected) |
| 3763 | } |
| 3764 | } |
| 3765 | |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 3766 | assertApexName("com.android.vndk.v29", "com.android.vndk.current") |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3767 | assertApexName("com.android.vndk.v28", "com.android.vndk.v28") |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3768 | } |
| 3769 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3770 | func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3771 | ctx := testApex(t, ` |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3772 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3773 | name: "com.android.vndk.current", |
| 3774 | key: "com.android.vndk.current.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3775 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3776 | updatable: false, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3777 | } |
| 3778 | |
| 3779 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3780 | name: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3781 | public_key: "testkey.avbpubkey", |
| 3782 | private_key: "testkey.pem", |
| 3783 | } |
| 3784 | |
| 3785 | cc_library { |
| 3786 | name: "libvndk", |
| 3787 | srcs: ["mylib.cpp"], |
| 3788 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3789 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3790 | native_bridge_supported: true, |
| 3791 | host_supported: true, |
| 3792 | vndk: { |
| 3793 | enabled: true, |
| 3794 | }, |
| 3795 | system_shared_libs: [], |
| 3796 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3797 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3798 | } |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3799 | `+vndkLibrariesTxtFiles("current"), |
| 3800 | withNativeBridgeEnabled) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3801 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3802 | ensureExactContents(t, ctx, "com.android.vndk.current", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3803 | "lib/libvndk.so", |
| 3804 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3805 | "lib/libc++.so", |
| 3806 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3807 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3808 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3809 | } |
| 3810 | |
| 3811 | func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3812 | testApexError(t, `module "com.android.vndk.current" .*: native_bridge_supported: .* doesn't support native bridge binary`, ` |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3813 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3814 | name: "com.android.vndk.current", |
| 3815 | key: "com.android.vndk.current.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3816 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3817 | native_bridge_supported: true, |
| 3818 | } |
| 3819 | |
| 3820 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3821 | name: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3822 | public_key: "testkey.avbpubkey", |
| 3823 | private_key: "testkey.pem", |
| 3824 | } |
| 3825 | |
| 3826 | cc_library { |
| 3827 | name: "libvndk", |
| 3828 | srcs: ["mylib.cpp"], |
| 3829 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3830 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3831 | native_bridge_supported: true, |
| 3832 | host_supported: true, |
| 3833 | vndk: { |
| 3834 | enabled: true, |
| 3835 | }, |
| 3836 | system_shared_libs: [], |
| 3837 | stl: "none", |
| 3838 | } |
| 3839 | `) |
| 3840 | } |
| 3841 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3842 | func TestVndkApexWithBinder32(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3843 | ctx := testApex(t, ` |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3844 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3845 | name: "com.android.vndk.v27", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3846 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3847 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3848 | vndk_version: "27", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3849 | updatable: false, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3850 | } |
| 3851 | |
| 3852 | apex_key { |
| 3853 | name: "myapex.key", |
| 3854 | public_key: "testkey.avbpubkey", |
| 3855 | private_key: "testkey.pem", |
| 3856 | } |
| 3857 | |
| 3858 | vndk_prebuilt_shared { |
| 3859 | name: "libvndk27", |
| 3860 | version: "27", |
| 3861 | target_arch: "arm", |
| 3862 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3863 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3864 | vndk: { |
| 3865 | enabled: true, |
| 3866 | }, |
| 3867 | arch: { |
| 3868 | arm: { |
| 3869 | srcs: ["libvndk27.so"], |
| 3870 | } |
| 3871 | }, |
| 3872 | } |
| 3873 | |
| 3874 | vndk_prebuilt_shared { |
| 3875 | name: "libvndk27", |
| 3876 | version: "27", |
| 3877 | target_arch: "arm", |
| 3878 | binder32bit: true, |
| 3879 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3880 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3881 | vndk: { |
| 3882 | enabled: true, |
| 3883 | }, |
| 3884 | arch: { |
| 3885 | arm: { |
| 3886 | srcs: ["libvndk27binder32.so"], |
| 3887 | } |
| 3888 | }, |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3889 | apex_available: [ "com.android.vndk.v27" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3890 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3891 | `+vndkLibrariesTxtFiles("27"), |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3892 | withFiles(map[string][]byte{ |
| 3893 | "libvndk27.so": nil, |
| 3894 | "libvndk27binder32.so": nil, |
| 3895 | }), |
| 3896 | withBinder32bit, |
| 3897 | withTargets(map[android.OsType][]android.Target{ |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 3898 | android.Android: { |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 3899 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, |
| 3900 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3901 | }, |
| 3902 | }), |
| 3903 | ) |
| 3904 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3905 | ensureExactContents(t, ctx, "com.android.vndk.v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3906 | "lib/libvndk27binder32.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3907 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3908 | }) |
| 3909 | } |
| 3910 | |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3911 | func TestVndkApexShouldNotProvideNativeLibs(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3912 | ctx := testApex(t, ` |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3913 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3914 | name: "com.android.vndk.current", |
| 3915 | key: "com.android.vndk.current.key", |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3916 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3917 | updatable: false, |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3918 | } |
| 3919 | |
| 3920 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3921 | name: "com.android.vndk.current.key", |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3922 | public_key: "testkey.avbpubkey", |
| 3923 | private_key: "testkey.pem", |
| 3924 | } |
| 3925 | |
| 3926 | cc_library { |
| 3927 | name: "libz", |
| 3928 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3929 | product_available: true, |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3930 | vndk: { |
| 3931 | enabled: true, |
| 3932 | }, |
| 3933 | stubs: { |
| 3934 | symbol_file: "libz.map.txt", |
| 3935 | versions: ["30"], |
| 3936 | } |
| 3937 | } |
| 3938 | `+vndkLibrariesTxtFiles("current"), withFiles(map[string][]byte{ |
| 3939 | "libz.map.txt": nil, |
| 3940 | })) |
| 3941 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3942 | apexManifestRule := ctx.ModuleForTests("com.android.vndk.current", "android_common_image").Rule("apexManifestRule") |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3943 | provideNativeLibs := names(apexManifestRule.Args["provideNativeLibs"]) |
| 3944 | ensureListEmpty(t, provideNativeLibs) |
| 3945 | } |
| 3946 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3947 | func TestDependenciesInApexManifest(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3948 | ctx := testApex(t, ` |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3949 | apex { |
| 3950 | name: "myapex_nodep", |
| 3951 | key: "myapex.key", |
| 3952 | native_shared_libs: ["lib_nodep"], |
| 3953 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3954 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3955 | updatable: false, |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3956 | } |
| 3957 | |
| 3958 | apex { |
| 3959 | name: "myapex_dep", |
| 3960 | key: "myapex.key", |
| 3961 | native_shared_libs: ["lib_dep"], |
| 3962 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3963 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3964 | updatable: false, |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3965 | } |
| 3966 | |
| 3967 | apex { |
| 3968 | name: "myapex_provider", |
| 3969 | key: "myapex.key", |
| 3970 | native_shared_libs: ["libfoo"], |
| 3971 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3972 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3973 | updatable: false, |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3974 | } |
| 3975 | |
| 3976 | apex { |
| 3977 | name: "myapex_selfcontained", |
| 3978 | key: "myapex.key", |
| 3979 | native_shared_libs: ["lib_dep", "libfoo"], |
| 3980 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3981 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3982 | updatable: false, |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3983 | } |
| 3984 | |
| 3985 | apex_key { |
| 3986 | name: "myapex.key", |
| 3987 | public_key: "testkey.avbpubkey", |
| 3988 | private_key: "testkey.pem", |
| 3989 | } |
| 3990 | |
| 3991 | cc_library { |
| 3992 | name: "lib_nodep", |
| 3993 | srcs: ["mylib.cpp"], |
| 3994 | system_shared_libs: [], |
| 3995 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3996 | apex_available: [ "myapex_nodep" ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3997 | } |
| 3998 | |
| 3999 | cc_library { |
| 4000 | name: "lib_dep", |
| 4001 | srcs: ["mylib.cpp"], |
| 4002 | shared_libs: ["libfoo"], |
| 4003 | system_shared_libs: [], |
| 4004 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4005 | apex_available: [ |
| 4006 | "myapex_dep", |
| 4007 | "myapex_provider", |
| 4008 | "myapex_selfcontained", |
| 4009 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 4010 | } |
| 4011 | |
| 4012 | cc_library { |
| 4013 | name: "libfoo", |
| 4014 | srcs: ["mytest.cpp"], |
| 4015 | stubs: { |
| 4016 | versions: ["1"], |
| 4017 | }, |
| 4018 | system_shared_libs: [], |
| 4019 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4020 | apex_available: [ |
| 4021 | "myapex_provider", |
| 4022 | "myapex_selfcontained", |
| 4023 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 4024 | } |
| 4025 | `) |
| 4026 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 4027 | var apexManifestRule android.TestingBuildParams |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 4028 | var provideNativeLibs, requireNativeLibs []string |
| 4029 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4030 | apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 4031 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 4032 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 4033 | ensureListEmpty(t, provideNativeLibs) |
| 4034 | ensureListEmpty(t, requireNativeLibs) |
| 4035 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4036 | apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 4037 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 4038 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 4039 | ensureListEmpty(t, provideNativeLibs) |
| 4040 | ensureListContains(t, requireNativeLibs, "libfoo.so") |
| 4041 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4042 | apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 4043 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 4044 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 4045 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 4046 | ensureListEmpty(t, requireNativeLibs) |
| 4047 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4048 | apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 4049 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 4050 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 4051 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 4052 | ensureListEmpty(t, requireNativeLibs) |
| 4053 | } |
| 4054 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 4055 | func TestApexName(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4056 | ctx := testApex(t, ` |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 4057 | apex { |
| 4058 | name: "myapex", |
| 4059 | key: "myapex.key", |
| 4060 | apex_name: "com.android.myapex", |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 4061 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4062 | updatable: false, |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 4063 | } |
| 4064 | |
| 4065 | apex_key { |
| 4066 | name: "myapex.key", |
| 4067 | public_key: "testkey.avbpubkey", |
| 4068 | private_key: "testkey.pem", |
| 4069 | } |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 4070 | |
| 4071 | cc_library { |
| 4072 | name: "mylib", |
| 4073 | srcs: ["mylib.cpp"], |
| 4074 | system_shared_libs: [], |
| 4075 | stl: "none", |
| 4076 | apex_available: [ |
| 4077 | "//apex_available:platform", |
| 4078 | "myapex", |
| 4079 | ], |
| 4080 | } |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 4081 | `) |
| 4082 | |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 4083 | module := ctx.ModuleForTests("myapex", "android_common_com.android.myapex_image") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 4084 | apexManifestRule := module.Rule("apexManifestRule") |
| 4085 | ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex") |
| 4086 | apexRule := module.Rule("apexRule") |
| 4087 | ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname") |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 4088 | |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 4089 | apexBundle := module.Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 4090 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 4091 | name := apexBundle.BaseModuleName() |
| 4092 | prefix := "TARGET_" |
| 4093 | var builder strings.Builder |
| 4094 | data.Custom(&builder, name, prefix, "", data) |
| 4095 | androidMk := builder.String() |
| 4096 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 4097 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 4098 | } |
| 4099 | |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4100 | func TestNonTestApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4101 | ctx := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4102 | apex { |
| 4103 | name: "myapex", |
| 4104 | key: "myapex.key", |
| 4105 | native_shared_libs: ["mylib_common"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4106 | updatable: false, |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4107 | } |
| 4108 | |
| 4109 | apex_key { |
| 4110 | name: "myapex.key", |
| 4111 | public_key: "testkey.avbpubkey", |
| 4112 | private_key: "testkey.pem", |
| 4113 | } |
| 4114 | |
| 4115 | cc_library { |
| 4116 | name: "mylib_common", |
| 4117 | srcs: ["mylib.cpp"], |
| 4118 | system_shared_libs: [], |
| 4119 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4120 | apex_available: [ |
| 4121 | "//apex_available:platform", |
| 4122 | "myapex", |
| 4123 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4124 | } |
| 4125 | `) |
| 4126 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4127 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4128 | apexRule := module.Rule("apexRule") |
| 4129 | copyCmds := apexRule.Args["copy_commands"] |
| 4130 | |
| 4131 | if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex { |
| 4132 | t.Log("Apex was a test apex!") |
| 4133 | t.Fail() |
| 4134 | } |
| 4135 | // Ensure that main rule creates an output |
| 4136 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 4137 | |
| 4138 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 4139 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4140 | |
| 4141 | // Ensure that both direct and indirect deps are copied into apex |
| 4142 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 4143 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4144 | // Ensure that the platform variant ends with _shared |
| 4145 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4146 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 4147 | if !ctx.ModuleForTests("mylib_common", "android_arm64_armv8-a_shared_apex10000").Module().(*cc.Module).InAnyApex() { |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4148 | t.Log("Found mylib_common not in any apex!") |
| 4149 | t.Fail() |
| 4150 | } |
| 4151 | } |
| 4152 | |
| 4153 | func TestTestApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4154 | ctx := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4155 | apex_test { |
| 4156 | name: "myapex", |
| 4157 | key: "myapex.key", |
| 4158 | native_shared_libs: ["mylib_common_test"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4159 | updatable: false, |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4160 | } |
| 4161 | |
| 4162 | apex_key { |
| 4163 | name: "myapex.key", |
| 4164 | public_key: "testkey.avbpubkey", |
| 4165 | private_key: "testkey.pem", |
| 4166 | } |
| 4167 | |
| 4168 | cc_library { |
| 4169 | name: "mylib_common_test", |
| 4170 | srcs: ["mylib.cpp"], |
| 4171 | system_shared_libs: [], |
| 4172 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4173 | // TODO: remove //apex_available:platform |
| 4174 | apex_available: [ |
| 4175 | "//apex_available:platform", |
| 4176 | "myapex", |
| 4177 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4178 | } |
| 4179 | `) |
| 4180 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4181 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4182 | apexRule := module.Rule("apexRule") |
| 4183 | copyCmds := apexRule.Args["copy_commands"] |
| 4184 | |
| 4185 | if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex { |
| 4186 | t.Log("Apex was not a test apex!") |
| 4187 | t.Fail() |
| 4188 | } |
| 4189 | // Ensure that main rule creates an output |
| 4190 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 4191 | |
| 4192 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 4193 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4194 | |
| 4195 | // Ensure that both direct and indirect deps are copied into apex |
| 4196 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so") |
| 4197 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4198 | // Ensure that the platform variant ends with _shared |
| 4199 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 4200 | } |
| 4201 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4202 | func TestApexWithTarget(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4203 | ctx := testApex(t, ` |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4204 | apex { |
| 4205 | name: "myapex", |
| 4206 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4207 | updatable: false, |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4208 | multilib: { |
| 4209 | first: { |
| 4210 | native_shared_libs: ["mylib_common"], |
| 4211 | } |
| 4212 | }, |
| 4213 | target: { |
| 4214 | android: { |
| 4215 | multilib: { |
| 4216 | first: { |
| 4217 | native_shared_libs: ["mylib"], |
| 4218 | } |
| 4219 | } |
| 4220 | }, |
| 4221 | host: { |
| 4222 | multilib: { |
| 4223 | first: { |
| 4224 | native_shared_libs: ["mylib2"], |
| 4225 | } |
| 4226 | } |
| 4227 | } |
| 4228 | } |
| 4229 | } |
| 4230 | |
| 4231 | apex_key { |
| 4232 | name: "myapex.key", |
| 4233 | public_key: "testkey.avbpubkey", |
| 4234 | private_key: "testkey.pem", |
| 4235 | } |
| 4236 | |
| 4237 | cc_library { |
| 4238 | name: "mylib", |
| 4239 | srcs: ["mylib.cpp"], |
| 4240 | system_shared_libs: [], |
| 4241 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4242 | // TODO: remove //apex_available:platform |
| 4243 | apex_available: [ |
| 4244 | "//apex_available:platform", |
| 4245 | "myapex", |
| 4246 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4247 | } |
| 4248 | |
| 4249 | cc_library { |
| 4250 | name: "mylib_common", |
| 4251 | srcs: ["mylib.cpp"], |
| 4252 | system_shared_libs: [], |
| 4253 | stl: "none", |
| 4254 | compile_multilib: "first", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 4255 | // TODO: remove //apex_available:platform |
| 4256 | apex_available: [ |
| 4257 | "//apex_available:platform", |
| 4258 | "myapex", |
| 4259 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4260 | } |
| 4261 | |
| 4262 | cc_library { |
| 4263 | name: "mylib2", |
| 4264 | srcs: ["mylib.cpp"], |
| 4265 | system_shared_libs: [], |
| 4266 | stl: "none", |
| 4267 | compile_multilib: "first", |
| 4268 | } |
| 4269 | `) |
| 4270 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4271 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4272 | copyCmds := apexRule.Args["copy_commands"] |
| 4273 | |
| 4274 | // Ensure that main rule creates an output |
| 4275 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 4276 | |
| 4277 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 4278 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
| 4279 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_apex10000") |
| 4280 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4281 | |
| 4282 | // Ensure that both direct and indirect deps are copied into apex |
| 4283 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 4284 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 4285 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 4286 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 4287 | // Ensure that the platform variant ends with _shared |
| 4288 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 4289 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
| 4290 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 4291 | } |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4292 | |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 4293 | func TestApexWithArch(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4294 | ctx := testApex(t, ` |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 4295 | apex { |
| 4296 | name: "myapex", |
| 4297 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4298 | updatable: false, |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 4299 | arch: { |
| 4300 | arm64: { |
| 4301 | native_shared_libs: ["mylib.arm64"], |
| 4302 | }, |
| 4303 | x86_64: { |
| 4304 | native_shared_libs: ["mylib.x64"], |
| 4305 | }, |
| 4306 | } |
| 4307 | } |
| 4308 | |
| 4309 | apex_key { |
| 4310 | name: "myapex.key", |
| 4311 | public_key: "testkey.avbpubkey", |
| 4312 | private_key: "testkey.pem", |
| 4313 | } |
| 4314 | |
| 4315 | cc_library { |
| 4316 | name: "mylib.arm64", |
| 4317 | srcs: ["mylib.cpp"], |
| 4318 | system_shared_libs: [], |
| 4319 | stl: "none", |
| 4320 | // TODO: remove //apex_available:platform |
| 4321 | apex_available: [ |
| 4322 | "//apex_available:platform", |
| 4323 | "myapex", |
| 4324 | ], |
| 4325 | } |
| 4326 | |
| 4327 | cc_library { |
| 4328 | name: "mylib.x64", |
| 4329 | srcs: ["mylib.cpp"], |
| 4330 | system_shared_libs: [], |
| 4331 | stl: "none", |
| 4332 | // TODO: remove //apex_available:platform |
| 4333 | apex_available: [ |
| 4334 | "//apex_available:platform", |
| 4335 | "myapex", |
| 4336 | ], |
| 4337 | } |
| 4338 | `) |
| 4339 | |
| 4340 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 4341 | copyCmds := apexRule.Args["copy_commands"] |
| 4342 | |
| 4343 | // Ensure that apex variant is created for the direct dep |
| 4344 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib.arm64"), "android_arm64_armv8-a_shared_apex10000") |
| 4345 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib.x64"), "android_arm64_armv8-a_shared_apex10000") |
| 4346 | |
| 4347 | // Ensure that both direct and indirect deps are copied into apex |
| 4348 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.arm64.so") |
| 4349 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib.x64.so") |
| 4350 | } |
| 4351 | |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4352 | func TestApexWithShBinary(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4353 | ctx := testApex(t, ` |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4354 | apex { |
| 4355 | name: "myapex", |
| 4356 | key: "myapex.key", |
Sundong Ahn | 80c0489 | 2021-11-23 00:57:19 +0000 | [diff] [blame] | 4357 | sh_binaries: ["myscript"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4358 | updatable: false, |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4359 | } |
| 4360 | |
| 4361 | apex_key { |
| 4362 | name: "myapex.key", |
| 4363 | public_key: "testkey.avbpubkey", |
| 4364 | private_key: "testkey.pem", |
| 4365 | } |
| 4366 | |
| 4367 | sh_binary { |
| 4368 | name: "myscript", |
| 4369 | src: "mylib.cpp", |
| 4370 | filename: "myscript.sh", |
| 4371 | sub_dir: "script", |
| 4372 | } |
| 4373 | `) |
| 4374 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4375 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4376 | copyCmds := apexRule.Args["copy_commands"] |
| 4377 | |
| 4378 | ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh") |
| 4379 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4380 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4381 | func TestApexInVariousPartition(t *testing.T) { |
| 4382 | testcases := []struct { |
| 4383 | propName, parition, flattenedPartition string |
| 4384 | }{ |
| 4385 | {"", "system", "system_ext"}, |
| 4386 | {"product_specific: true", "product", "product"}, |
| 4387 | {"soc_specific: true", "vendor", "vendor"}, |
| 4388 | {"proprietary: true", "vendor", "vendor"}, |
| 4389 | {"vendor: true", "vendor", "vendor"}, |
| 4390 | {"system_ext_specific: true", "system_ext", "system_ext"}, |
| 4391 | } |
| 4392 | for _, tc := range testcases { |
| 4393 | t.Run(tc.propName+":"+tc.parition, func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4394 | ctx := testApex(t, ` |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4395 | apex { |
| 4396 | name: "myapex", |
| 4397 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4398 | updatable: false, |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4399 | `+tc.propName+` |
| 4400 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4401 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4402 | apex_key { |
| 4403 | name: "myapex.key", |
| 4404 | public_key: "testkey.avbpubkey", |
| 4405 | private_key: "testkey.pem", |
| 4406 | } |
| 4407 | `) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4408 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4409 | apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 4410 | expected := "out/soong/target/product/test_device/" + tc.parition + "/apex" |
| 4411 | actual := apex.installDir.RelativeToTop().String() |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4412 | if actual != expected { |
| 4413 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 4414 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4415 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4416 | flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 4417 | expected = "out/soong/target/product/test_device/" + tc.flattenedPartition + "/apex" |
| 4418 | actual = flattened.installDir.RelativeToTop().String() |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4419 | if actual != expected { |
| 4420 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 4421 | } |
| 4422 | }) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4423 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4424 | } |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4425 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4426 | func TestFileContexts_FindInDefaultLocationIfNotSet(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4427 | ctx := testApex(t, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4428 | apex { |
| 4429 | name: "myapex", |
| 4430 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4431 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4432 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4433 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4434 | apex_key { |
| 4435 | name: "myapex.key", |
| 4436 | public_key: "testkey.avbpubkey", |
| 4437 | private_key: "testkey.pem", |
| 4438 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4439 | `) |
| 4440 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4441 | rule := module.Output("file_contexts") |
| 4442 | ensureContains(t, rule.RuleParams.Command, "cat system/sepolicy/apex/myapex-file_contexts") |
| 4443 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4444 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4445 | func TestFileContexts_ShouldBeUnderSystemSepolicyForSystemApexes(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4446 | testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4447 | apex { |
| 4448 | name: "myapex", |
| 4449 | key: "myapex.key", |
| 4450 | file_contexts: "my_own_file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4451 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4452 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4453 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4454 | apex_key { |
| 4455 | name: "myapex.key", |
| 4456 | public_key: "testkey.avbpubkey", |
| 4457 | private_key: "testkey.pem", |
| 4458 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4459 | `, withFiles(map[string][]byte{ |
| 4460 | "my_own_file_contexts": nil, |
| 4461 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4462 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4463 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4464 | func TestFileContexts_ProductSpecificApexes(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4465 | testApexError(t, `"myapex" .*: file_contexts: cannot find`, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4466 | apex { |
| 4467 | name: "myapex", |
| 4468 | key: "myapex.key", |
| 4469 | product_specific: true, |
| 4470 | file_contexts: "product_specific_file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4471 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4472 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4473 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4474 | apex_key { |
| 4475 | name: "myapex.key", |
| 4476 | public_key: "testkey.avbpubkey", |
| 4477 | private_key: "testkey.pem", |
| 4478 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4479 | `) |
| 4480 | |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4481 | ctx := testApex(t, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4482 | apex { |
| 4483 | name: "myapex", |
| 4484 | key: "myapex.key", |
| 4485 | product_specific: true, |
| 4486 | file_contexts: "product_specific_file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4487 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4488 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4489 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4490 | apex_key { |
| 4491 | name: "myapex.key", |
| 4492 | public_key: "testkey.avbpubkey", |
| 4493 | private_key: "testkey.pem", |
| 4494 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4495 | `, withFiles(map[string][]byte{ |
| 4496 | "product_specific_file_contexts": nil, |
| 4497 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4498 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4499 | rule := module.Output("file_contexts") |
| 4500 | ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") |
| 4501 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4502 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4503 | func TestFileContexts_SetViaFileGroup(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4504 | ctx := testApex(t, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4505 | apex { |
| 4506 | name: "myapex", |
| 4507 | key: "myapex.key", |
| 4508 | product_specific: true, |
| 4509 | file_contexts: ":my-file-contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4510 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4511 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4512 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4513 | apex_key { |
| 4514 | name: "myapex.key", |
| 4515 | public_key: "testkey.avbpubkey", |
| 4516 | private_key: "testkey.pem", |
| 4517 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4518 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4519 | filegroup { |
| 4520 | name: "my-file-contexts", |
| 4521 | srcs: ["product_specific_file_contexts"], |
| 4522 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4523 | `, withFiles(map[string][]byte{ |
| 4524 | "product_specific_file_contexts": nil, |
| 4525 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4526 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4527 | rule := module.Output("file_contexts") |
| 4528 | ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4529 | } |
| 4530 | |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4531 | func TestApexKeyFromOtherModule(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4532 | ctx := testApex(t, ` |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4533 | apex_key { |
| 4534 | name: "myapex.key", |
| 4535 | public_key: ":my.avbpubkey", |
| 4536 | private_key: ":my.pem", |
| 4537 | product_specific: true, |
| 4538 | } |
| 4539 | |
| 4540 | filegroup { |
| 4541 | name: "my.avbpubkey", |
| 4542 | srcs: ["testkey2.avbpubkey"], |
| 4543 | } |
| 4544 | |
| 4545 | filegroup { |
| 4546 | name: "my.pem", |
| 4547 | srcs: ["testkey2.pem"], |
| 4548 | } |
| 4549 | `) |
| 4550 | |
| 4551 | apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
| 4552 | expected_pubkey := "testkey2.avbpubkey" |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 4553 | actual_pubkey := apex_key.publicKeyFile.String() |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4554 | if actual_pubkey != expected_pubkey { |
| 4555 | t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey) |
| 4556 | } |
| 4557 | expected_privkey := "testkey2.pem" |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 4558 | actual_privkey := apex_key.privateKeyFile.String() |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4559 | if actual_privkey != expected_privkey { |
| 4560 | t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey) |
| 4561 | } |
| 4562 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4563 | |
| 4564 | func TestPrebuilt(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4565 | ctx := testApex(t, ` |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4566 | prebuilt_apex { |
| 4567 | name: "myapex", |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 4568 | arch: { |
| 4569 | arm64: { |
| 4570 | src: "myapex-arm64.apex", |
| 4571 | }, |
| 4572 | arm: { |
| 4573 | src: "myapex-arm.apex", |
| 4574 | }, |
| 4575 | }, |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4576 | } |
| 4577 | `) |
| 4578 | |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 4579 | testingModule := ctx.ModuleForTests("myapex", "android_common_myapex") |
| 4580 | prebuilt := testingModule.Module().(*Prebuilt) |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4581 | |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 4582 | expectedInput := "myapex-arm64.apex" |
| 4583 | if prebuilt.inputApex.String() != expectedInput { |
| 4584 | t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String()) |
| 4585 | } |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 4586 | android.AssertStringDoesContain(t, "Invalid provenance metadata file", |
| 4587 | prebuilt.ProvenanceMetaDataFile().String(), "soong/.intermediates/provenance_metadata/myapex/provenance_metadata.textproto") |
| 4588 | rule := testingModule.Rule("genProvenanceMetaData") |
| 4589 | android.AssertStringEquals(t, "Invalid input", "myapex-arm64.apex", rule.Inputs[0].String()) |
| 4590 | android.AssertStringEquals(t, "Invalid output", "out/soong/.intermediates/provenance_metadata/myapex/provenance_metadata.textproto", rule.Output.String()) |
| 4591 | android.AssertStringEquals(t, "Invalid args", "myapex", rule.Args["module_name"]) |
| 4592 | android.AssertStringEquals(t, "Invalid args", "/system/apex/myapex.apex", rule.Args["install_path"]) |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4593 | } |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4594 | |
Paul Duffin | c0609c6 | 2021-03-01 17:27:16 +0000 | [diff] [blame] | 4595 | func TestPrebuiltMissingSrc(t *testing.T) { |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 4596 | testApexError(t, `module "myapex" variant "android_common_myapex".*: prebuilt_apex does not support "arm64_armv8-a"`, ` |
Paul Duffin | c0609c6 | 2021-03-01 17:27:16 +0000 | [diff] [blame] | 4597 | prebuilt_apex { |
| 4598 | name: "myapex", |
| 4599 | } |
| 4600 | `) |
| 4601 | } |
| 4602 | |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4603 | func TestPrebuiltFilenameOverride(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4604 | ctx := testApex(t, ` |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4605 | prebuilt_apex { |
| 4606 | name: "myapex", |
| 4607 | src: "myapex-arm.apex", |
| 4608 | filename: "notmyapex.apex", |
| 4609 | } |
| 4610 | `) |
| 4611 | |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 4612 | testingModule := ctx.ModuleForTests("myapex", "android_common_myapex") |
| 4613 | p := testingModule.Module().(*Prebuilt) |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4614 | |
| 4615 | expected := "notmyapex.apex" |
| 4616 | if p.installFilename != expected { |
| 4617 | t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename) |
| 4618 | } |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 4619 | rule := testingModule.Rule("genProvenanceMetaData") |
| 4620 | android.AssertStringEquals(t, "Invalid input", "myapex-arm.apex", rule.Inputs[0].String()) |
| 4621 | android.AssertStringEquals(t, "Invalid output", "out/soong/.intermediates/provenance_metadata/myapex/provenance_metadata.textproto", rule.Output.String()) |
| 4622 | android.AssertStringEquals(t, "Invalid args", "myapex", rule.Args["module_name"]) |
| 4623 | android.AssertStringEquals(t, "Invalid args", "/system/apex/notmyapex.apex", rule.Args["install_path"]) |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4624 | } |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 4625 | |
Samiul Islam | 7c02e26 | 2021-09-08 17:48:28 +0100 | [diff] [blame] | 4626 | func TestApexSetFilenameOverride(t *testing.T) { |
| 4627 | testApex(t, ` |
| 4628 | apex_set { |
| 4629 | name: "com.company.android.myapex", |
| 4630 | apex_name: "com.android.myapex", |
| 4631 | set: "company-myapex.apks", |
| 4632 | filename: "com.company.android.myapex.apex" |
| 4633 | } |
| 4634 | `).ModuleForTests("com.company.android.myapex", "android_common_com.android.myapex") |
| 4635 | |
| 4636 | testApex(t, ` |
| 4637 | apex_set { |
| 4638 | name: "com.company.android.myapex", |
| 4639 | apex_name: "com.android.myapex", |
| 4640 | set: "company-myapex.apks", |
| 4641 | filename: "com.company.android.myapex.capex" |
| 4642 | } |
| 4643 | `).ModuleForTests("com.company.android.myapex", "android_common_com.android.myapex") |
| 4644 | |
| 4645 | testApexError(t, `filename should end in .apex or .capex for apex_set`, ` |
| 4646 | apex_set { |
| 4647 | name: "com.company.android.myapex", |
| 4648 | apex_name: "com.android.myapex", |
| 4649 | set: "company-myapex.apks", |
| 4650 | filename: "some-random-suffix" |
| 4651 | } |
| 4652 | `) |
| 4653 | } |
| 4654 | |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4655 | func TestPrebuiltOverrides(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4656 | ctx := testApex(t, ` |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4657 | prebuilt_apex { |
| 4658 | name: "myapex.prebuilt", |
| 4659 | src: "myapex-arm.apex", |
| 4660 | overrides: [ |
| 4661 | "myapex", |
| 4662 | ], |
| 4663 | } |
| 4664 | `) |
| 4665 | |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 4666 | testingModule := ctx.ModuleForTests("myapex.prebuilt", "android_common_myapex.prebuilt") |
| 4667 | p := testingModule.Module().(*Prebuilt) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4668 | |
| 4669 | expected := []string{"myapex"} |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 4670 | actual := android.AndroidMkEntriesForTest(t, ctx, p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4671 | if !reflect.DeepEqual(actual, expected) { |
Jiyong Park | b0a012c | 2019-11-14 17:17:03 +0900 | [diff] [blame] | 4672 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4673 | } |
Wei Li | 340ee8e | 2022-03-18 17:33:24 -0700 | [diff] [blame] | 4674 | rule := testingModule.Rule("genProvenanceMetaData") |
| 4675 | android.AssertStringEquals(t, "Invalid input", "myapex-arm.apex", rule.Inputs[0].String()) |
| 4676 | android.AssertStringEquals(t, "Invalid output", "out/soong/.intermediates/provenance_metadata/myapex.prebuilt/provenance_metadata.textproto", rule.Output.String()) |
| 4677 | android.AssertStringEquals(t, "Invalid args", "myapex.prebuilt", rule.Args["module_name"]) |
| 4678 | android.AssertStringEquals(t, "Invalid args", "/system/apex/myapex.prebuilt.apex", rule.Args["install_path"]) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4679 | } |
| 4680 | |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 4681 | func TestPrebuiltApexName(t *testing.T) { |
| 4682 | testApex(t, ` |
| 4683 | prebuilt_apex { |
| 4684 | name: "com.company.android.myapex", |
| 4685 | apex_name: "com.android.myapex", |
| 4686 | src: "company-myapex-arm.apex", |
| 4687 | } |
| 4688 | `).ModuleForTests("com.company.android.myapex", "android_common_com.android.myapex") |
| 4689 | |
| 4690 | testApex(t, ` |
| 4691 | apex_set { |
| 4692 | name: "com.company.android.myapex", |
| 4693 | apex_name: "com.android.myapex", |
| 4694 | set: "company-myapex.apks", |
| 4695 | } |
| 4696 | `).ModuleForTests("com.company.android.myapex", "android_common_com.android.myapex") |
| 4697 | } |
| 4698 | |
| 4699 | func TestPrebuiltApexNameWithPlatformBootclasspath(t *testing.T) { |
| 4700 | _ = android.GroupFixturePreparers( |
| 4701 | java.PrepareForTestWithJavaDefaultModules, |
| 4702 | PrepareForTestWithApexBuildComponents, |
| 4703 | android.FixtureWithRootAndroidBp(` |
| 4704 | platform_bootclasspath { |
| 4705 | name: "platform-bootclasspath", |
| 4706 | fragments: [ |
| 4707 | { |
| 4708 | apex: "com.android.art", |
| 4709 | module: "art-bootclasspath-fragment", |
| 4710 | }, |
| 4711 | ], |
| 4712 | } |
| 4713 | |
| 4714 | prebuilt_apex { |
| 4715 | name: "com.company.android.art", |
| 4716 | apex_name: "com.android.art", |
| 4717 | src: "com.company.android.art-arm.apex", |
| 4718 | exported_bootclasspath_fragments: ["art-bootclasspath-fragment"], |
| 4719 | } |
| 4720 | |
| 4721 | prebuilt_bootclasspath_fragment { |
| 4722 | name: "art-bootclasspath-fragment", |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 4723 | image_name: "art", |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 4724 | contents: ["core-oj"], |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 4725 | hidden_api: { |
| 4726 | annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", |
| 4727 | metadata: "my-bootclasspath-fragment/metadata.csv", |
| 4728 | index: "my-bootclasspath-fragment/index.csv", |
| 4729 | stub_flags: "my-bootclasspath-fragment/stub-flags.csv", |
| 4730 | all_flags: "my-bootclasspath-fragment/all-flags.csv", |
| 4731 | }, |
Martin Stjernholm | bfffae7 | 2021-06-24 14:37:13 +0100 | [diff] [blame] | 4732 | } |
| 4733 | |
| 4734 | java_import { |
| 4735 | name: "core-oj", |
| 4736 | jars: ["prebuilt.jar"], |
| 4737 | } |
| 4738 | `), |
| 4739 | ).RunTest(t) |
| 4740 | } |
| 4741 | |
Paul Duffin | 092153d | 2021-01-26 11:42:39 +0000 | [diff] [blame] | 4742 | // These tests verify that the prebuilt_apex/deapexer to java_import wiring allows for the |
| 4743 | // propagation of paths to dex implementation jars from the former to the latter. |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4744 | func TestPrebuiltExportDexImplementationJars(t *testing.T) { |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 4745 | transform := android.NullFixturePreparer |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4746 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4747 | checkDexJarBuildPath := func(t *testing.T, ctx *android.TestContext, name string) { |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 4748 | t.Helper() |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4749 | // Make sure the import has been given the correct path to the dex jar. |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 4750 | p := ctx.ModuleForTests(name, "android_common_myapex").Module().(java.UsesLibraryDependency) |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 4751 | dexJarBuildPath := p.DexJarBuildPath().PathOrNil() |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4752 | stem := android.RemoveOptionalPrebuiltPrefix(name) |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 4753 | android.AssertStringEquals(t, "DexJarBuildPath should be apex-related path.", |
| 4754 | ".intermediates/myapex.deapexer/android_common/deapexer/javalib/"+stem+".jar", |
| 4755 | android.NormalizePathForTesting(dexJarBuildPath)) |
| 4756 | } |
| 4757 | |
| 4758 | checkDexJarInstallPath := func(t *testing.T, ctx *android.TestContext, name string) { |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 4759 | t.Helper() |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 4760 | // Make sure the import has been given the correct path to the dex jar. |
| 4761 | p := ctx.ModuleForTests(name, "android_common_myapex").Module().(java.UsesLibraryDependency) |
| 4762 | dexJarBuildPath := p.DexJarInstallPath() |
| 4763 | stem := android.RemoveOptionalPrebuiltPrefix(name) |
| 4764 | android.AssertStringEquals(t, "DexJarInstallPath should be apex-related path.", |
| 4765 | "target/product/test_device/apex/myapex/javalib/"+stem+".jar", |
| 4766 | android.NormalizePathForTesting(dexJarBuildPath)) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4767 | } |
| 4768 | |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4769 | ensureNoSourceVariant := func(t *testing.T, ctx *android.TestContext, name string) { |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 4770 | t.Helper() |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4771 | // Make sure that an apex variant is not created for the source module. |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 4772 | android.AssertArrayString(t, "Check if there is no source variant", |
| 4773 | []string{"android_common"}, |
| 4774 | ctx.ModuleVariantsForTests(name)) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4775 | } |
| 4776 | |
| 4777 | t.Run("prebuilt only", func(t *testing.T) { |
| 4778 | bp := ` |
| 4779 | prebuilt_apex { |
| 4780 | name: "myapex", |
| 4781 | arch: { |
| 4782 | arm64: { |
| 4783 | src: "myapex-arm64.apex", |
| 4784 | }, |
| 4785 | arm: { |
| 4786 | src: "myapex-arm.apex", |
| 4787 | }, |
| 4788 | }, |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4789 | exported_java_libs: ["libfoo", "libbar"], |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4790 | } |
| 4791 | |
| 4792 | java_import { |
| 4793 | name: "libfoo", |
| 4794 | jars: ["libfoo.jar"], |
| 4795 | } |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4796 | |
| 4797 | java_sdk_library_import { |
| 4798 | name: "libbar", |
| 4799 | public: { |
| 4800 | jars: ["libbar.jar"], |
| 4801 | }, |
| 4802 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4803 | ` |
| 4804 | |
| 4805 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4806 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4807 | |
Martin Stjernholm | 4482560 | 2021-09-17 01:44:12 +0100 | [diff] [blame] | 4808 | deapexerName := deapexerModuleName("myapex") |
| 4809 | android.AssertStringEquals(t, "APEX module name from deapexer name", "myapex", apexModuleName(deapexerName)) |
| 4810 | |
Paul Duffin | f6932af | 2021-02-26 18:21:56 +0000 | [diff] [blame] | 4811 | // Make sure that the deapexer has the correct input APEX. |
Martin Stjernholm | 4482560 | 2021-09-17 01:44:12 +0100 | [diff] [blame] | 4812 | deapexer := ctx.ModuleForTests(deapexerName, "android_common") |
Paul Duffin | f6932af | 2021-02-26 18:21:56 +0000 | [diff] [blame] | 4813 | rule := deapexer.Rule("deapexer") |
| 4814 | if expected, actual := []string{"myapex-arm64.apex"}, android.NormalizePathsForTesting(rule.Implicits); !reflect.DeepEqual(expected, actual) { |
| 4815 | t.Errorf("expected: %q, found: %q", expected, actual) |
| 4816 | } |
| 4817 | |
Paul Duffin | 0d10c3c | 2021-03-01 17:09:32 +0000 | [diff] [blame] | 4818 | // Make sure that the prebuilt_apex has the correct input APEX. |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 4819 | prebuiltApex := ctx.ModuleForTests("myapex", "android_common_myapex") |
Paul Duffin | 0d10c3c | 2021-03-01 17:09:32 +0000 | [diff] [blame] | 4820 | rule = prebuiltApex.Rule("android/soong/android.Cp") |
| 4821 | if expected, actual := "myapex-arm64.apex", android.NormalizePathForTesting(rule.Input); !reflect.DeepEqual(expected, actual) { |
| 4822 | t.Errorf("expected: %q, found: %q", expected, actual) |
| 4823 | } |
| 4824 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4825 | checkDexJarBuildPath(t, ctx, "libfoo") |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 4826 | checkDexJarInstallPath(t, ctx, "libfoo") |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4827 | |
| 4828 | checkDexJarBuildPath(t, ctx, "libbar") |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 4829 | checkDexJarInstallPath(t, ctx, "libbar") |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4830 | }) |
| 4831 | |
| 4832 | t.Run("prebuilt with source preferred", func(t *testing.T) { |
| 4833 | |
| 4834 | bp := ` |
| 4835 | prebuilt_apex { |
| 4836 | name: "myapex", |
| 4837 | arch: { |
| 4838 | arm64: { |
| 4839 | src: "myapex-arm64.apex", |
| 4840 | }, |
| 4841 | arm: { |
| 4842 | src: "myapex-arm.apex", |
| 4843 | }, |
| 4844 | }, |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4845 | exported_java_libs: ["libfoo", "libbar"], |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4846 | } |
| 4847 | |
| 4848 | java_import { |
| 4849 | name: "libfoo", |
| 4850 | jars: ["libfoo.jar"], |
| 4851 | } |
| 4852 | |
| 4853 | java_library { |
| 4854 | name: "libfoo", |
| 4855 | } |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4856 | |
| 4857 | java_sdk_library_import { |
| 4858 | name: "libbar", |
| 4859 | public: { |
| 4860 | jars: ["libbar.jar"], |
| 4861 | }, |
| 4862 | } |
| 4863 | |
| 4864 | java_sdk_library { |
| 4865 | name: "libbar", |
| 4866 | srcs: ["foo/bar/MyClass.java"], |
| 4867 | unsafe_ignore_missing_latest_api: true, |
| 4868 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4869 | ` |
| 4870 | |
| 4871 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4872 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4873 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4874 | checkDexJarBuildPath(t, ctx, "prebuilt_libfoo") |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 4875 | checkDexJarInstallPath(t, ctx, "prebuilt_libfoo") |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4876 | ensureNoSourceVariant(t, ctx, "libfoo") |
| 4877 | |
| 4878 | checkDexJarBuildPath(t, ctx, "prebuilt_libbar") |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 4879 | checkDexJarInstallPath(t, ctx, "prebuilt_libbar") |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4880 | ensureNoSourceVariant(t, ctx, "libbar") |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4881 | }) |
| 4882 | |
| 4883 | t.Run("prebuilt preferred with source", func(t *testing.T) { |
| 4884 | bp := ` |
| 4885 | prebuilt_apex { |
| 4886 | name: "myapex", |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4887 | arch: { |
| 4888 | arm64: { |
| 4889 | src: "myapex-arm64.apex", |
| 4890 | }, |
| 4891 | arm: { |
| 4892 | src: "myapex-arm.apex", |
| 4893 | }, |
| 4894 | }, |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4895 | exported_java_libs: ["libfoo", "libbar"], |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4896 | } |
| 4897 | |
| 4898 | java_import { |
| 4899 | name: "libfoo", |
Paul Duffin | 092153d | 2021-01-26 11:42:39 +0000 | [diff] [blame] | 4900 | prefer: true, |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4901 | jars: ["libfoo.jar"], |
| 4902 | } |
| 4903 | |
| 4904 | java_library { |
| 4905 | name: "libfoo", |
| 4906 | } |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4907 | |
| 4908 | java_sdk_library_import { |
| 4909 | name: "libbar", |
| 4910 | prefer: true, |
| 4911 | public: { |
| 4912 | jars: ["libbar.jar"], |
| 4913 | }, |
| 4914 | } |
| 4915 | |
| 4916 | java_sdk_library { |
| 4917 | name: "libbar", |
| 4918 | srcs: ["foo/bar/MyClass.java"], |
| 4919 | unsafe_ignore_missing_latest_api: true, |
| 4920 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4921 | ` |
| 4922 | |
| 4923 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4924 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4925 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4926 | checkDexJarBuildPath(t, ctx, "prebuilt_libfoo") |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 4927 | checkDexJarInstallPath(t, ctx, "prebuilt_libfoo") |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4928 | ensureNoSourceVariant(t, ctx, "libfoo") |
| 4929 | |
| 4930 | checkDexJarBuildPath(t, ctx, "prebuilt_libbar") |
Jeongik Cha | d5fe878 | 2021-07-08 01:13:11 +0900 | [diff] [blame] | 4931 | checkDexJarInstallPath(t, ctx, "prebuilt_libbar") |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4932 | ensureNoSourceVariant(t, ctx, "libbar") |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4933 | }) |
| 4934 | } |
| 4935 | |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4936 | func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { |
Paul Duffin | b6f53c0 | 2021-05-14 07:52:42 +0100 | [diff] [blame] | 4937 | preparer := android.GroupFixturePreparers( |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 4938 | java.FixtureConfigureApexBootJars("myapex:libfoo", "myapex:libbar"), |
Paul Duffin | b6f53c0 | 2021-05-14 07:52:42 +0100 | [diff] [blame] | 4939 | // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding |
| 4940 | // is disabled. |
| 4941 | android.FixtureAddTextFile("frameworks/base/Android.bp", ""), |
| 4942 | ) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4943 | |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4944 | checkBootDexJarPath := func(t *testing.T, ctx *android.TestContext, stem string, bootDexJarPath string) { |
| 4945 | t.Helper() |
Paul Duffin | 7ebebfd | 2021-04-27 19:36:57 +0100 | [diff] [blame] | 4946 | s := ctx.ModuleForTests("platform-bootclasspath", "android_common") |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4947 | foundLibfooJar := false |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4948 | base := stem + ".jar" |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4949 | for _, output := range s.AllOutputs() { |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4950 | if filepath.Base(output) == base { |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4951 | foundLibfooJar = true |
| 4952 | buildRule := s.Output(output) |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 4953 | android.AssertStringEquals(t, "boot dex jar path", bootDexJarPath, buildRule.Input.String()) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4954 | } |
| 4955 | } |
| 4956 | if !foundLibfooJar { |
Lukacs T. Berki | 9f6c24a | 2021-08-26 15:07:24 +0200 | [diff] [blame] | 4957 | t.Errorf("Rule for libfoo.jar missing in dex_bootjars singleton outputs %q", android.StringPathsRelativeToTop(ctx.Config().SoongOutDir(), s.AllOutputs())) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4958 | } |
| 4959 | } |
| 4960 | |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 4961 | checkHiddenAPIIndexFromClassesInputs := func(t *testing.T, ctx *android.TestContext, expectedIntermediateInputs string) { |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4962 | t.Helper() |
Paul Duffin | 00b2bfd | 2021-04-12 17:24:36 +0100 | [diff] [blame] | 4963 | platformBootclasspath := ctx.ModuleForTests("platform-bootclasspath", "android_common") |
Paul Duffin | d061d40 | 2021-06-07 21:36:01 +0100 | [diff] [blame] | 4964 | var rule android.TestingBuildParams |
| 4965 | |
| 4966 | rule = platformBootclasspath.Output("hiddenapi-monolithic/index-from-classes.csv") |
| 4967 | java.CheckHiddenAPIRuleInputs(t, "intermediate index", expectedIntermediateInputs, rule) |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4968 | } |
| 4969 | |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 4970 | checkHiddenAPIIndexFromFlagsInputs := func(t *testing.T, ctx *android.TestContext, expectedIntermediateInputs string) { |
| 4971 | t.Helper() |
| 4972 | platformBootclasspath := ctx.ModuleForTests("platform-bootclasspath", "android_common") |
| 4973 | var rule android.TestingBuildParams |
| 4974 | |
| 4975 | rule = platformBootclasspath.Output("hiddenapi-index.csv") |
| 4976 | java.CheckHiddenAPIRuleInputs(t, "monolithic index", expectedIntermediateInputs, rule) |
| 4977 | } |
| 4978 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 4979 | fragment := java.ApexVariantReference{ |
| 4980 | Apex: proptools.StringPtr("myapex"), |
| 4981 | Module: proptools.StringPtr("my-bootclasspath-fragment"), |
| 4982 | } |
| 4983 | |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4984 | t.Run("prebuilt only", func(t *testing.T) { |
| 4985 | bp := ` |
| 4986 | prebuilt_apex { |
| 4987 | name: "myapex", |
| 4988 | arch: { |
| 4989 | arm64: { |
| 4990 | src: "myapex-arm64.apex", |
| 4991 | }, |
| 4992 | arm: { |
| 4993 | src: "myapex-arm.apex", |
| 4994 | }, |
| 4995 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 4996 | exported_bootclasspath_fragments: ["my-bootclasspath-fragment"], |
| 4997 | } |
| 4998 | |
| 4999 | prebuilt_bootclasspath_fragment { |
| 5000 | name: "my-bootclasspath-fragment", |
| 5001 | contents: ["libfoo", "libbar"], |
| 5002 | apex_available: ["myapex"], |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5003 | hidden_api: { |
| 5004 | annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", |
| 5005 | metadata: "my-bootclasspath-fragment/metadata.csv", |
| 5006 | index: "my-bootclasspath-fragment/index.csv", |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 5007 | signature_patterns: "my-bootclasspath-fragment/signature-patterns.csv", |
| 5008 | filtered_stub_flags: "my-bootclasspath-fragment/filtered-stub-flags.csv", |
| 5009 | filtered_flags: "my-bootclasspath-fragment/filtered-flags.csv", |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5010 | }, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5011 | } |
| 5012 | |
| 5013 | java_import { |
| 5014 | name: "libfoo", |
| 5015 | jars: ["libfoo.jar"], |
| 5016 | apex_available: ["myapex"], |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 5017 | permitted_packages: ["foo"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5018 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 5019 | |
| 5020 | java_sdk_library_import { |
| 5021 | name: "libbar", |
| 5022 | public: { |
| 5023 | jars: ["libbar.jar"], |
| 5024 | }, |
| 5025 | apex_available: ["myapex"], |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5026 | shared_library: false, |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 5027 | permitted_packages: ["bar"], |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 5028 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5029 | ` |
| 5030 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5031 | ctx := testDexpreoptWithApexes(t, bp, "", preparer, fragment) |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 5032 | checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
| 5033 | checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 5034 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 5035 | // Verify the correct module jars contribute to the hiddenapi index file. |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5036 | checkHiddenAPIIndexFromClassesInputs(t, ctx, ``) |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 5037 | checkHiddenAPIIndexFromFlagsInputs(t, ctx, ` |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5038 | my-bootclasspath-fragment/index.csv |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 5039 | out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/index-from-classes.csv |
| 5040 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5041 | }) |
| 5042 | |
Paul Duffin | f58fd9a | 2021-04-06 16:00:22 +0100 | [diff] [blame] | 5043 | t.Run("apex_set only", func(t *testing.T) { |
| 5044 | bp := ` |
| 5045 | apex_set { |
| 5046 | name: "myapex", |
| 5047 | set: "myapex.apks", |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5048 | exported_bootclasspath_fragments: ["my-bootclasspath-fragment"], |
| 5049 | } |
| 5050 | |
| 5051 | prebuilt_bootclasspath_fragment { |
| 5052 | name: "my-bootclasspath-fragment", |
| 5053 | contents: ["libfoo", "libbar"], |
| 5054 | apex_available: ["myapex"], |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5055 | hidden_api: { |
| 5056 | annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", |
| 5057 | metadata: "my-bootclasspath-fragment/metadata.csv", |
| 5058 | index: "my-bootclasspath-fragment/index.csv", |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 5059 | signature_patterns: "my-bootclasspath-fragment/signature-patterns.csv", |
| 5060 | filtered_stub_flags: "my-bootclasspath-fragment/filtered-stub-flags.csv", |
| 5061 | filtered_flags: "my-bootclasspath-fragment/filtered-flags.csv", |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5062 | }, |
Paul Duffin | f58fd9a | 2021-04-06 16:00:22 +0100 | [diff] [blame] | 5063 | } |
| 5064 | |
| 5065 | java_import { |
| 5066 | name: "libfoo", |
| 5067 | jars: ["libfoo.jar"], |
| 5068 | apex_available: ["myapex"], |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 5069 | permitted_packages: ["foo"], |
Paul Duffin | f58fd9a | 2021-04-06 16:00:22 +0100 | [diff] [blame] | 5070 | } |
| 5071 | |
| 5072 | java_sdk_library_import { |
| 5073 | name: "libbar", |
| 5074 | public: { |
| 5075 | jars: ["libbar.jar"], |
| 5076 | }, |
| 5077 | apex_available: ["myapex"], |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5078 | shared_library: false, |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 5079 | permitted_packages: ["bar"], |
Paul Duffin | f58fd9a | 2021-04-06 16:00:22 +0100 | [diff] [blame] | 5080 | } |
| 5081 | ` |
| 5082 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5083 | ctx := testDexpreoptWithApexes(t, bp, "", preparer, fragment) |
Paul Duffin | f58fd9a | 2021-04-06 16:00:22 +0100 | [diff] [blame] | 5084 | checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
| 5085 | checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar") |
| 5086 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 5087 | // Verify the correct module jars contribute to the hiddenapi index file. |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5088 | checkHiddenAPIIndexFromClassesInputs(t, ctx, ``) |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 5089 | checkHiddenAPIIndexFromFlagsInputs(t, ctx, ` |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5090 | my-bootclasspath-fragment/index.csv |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 5091 | out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/index-from-classes.csv |
| 5092 | `) |
Paul Duffin | f58fd9a | 2021-04-06 16:00:22 +0100 | [diff] [blame] | 5093 | }) |
| 5094 | |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5095 | t.Run("prebuilt with source library preferred", func(t *testing.T) { |
| 5096 | bp := ` |
| 5097 | prebuilt_apex { |
| 5098 | name: "myapex", |
| 5099 | arch: { |
| 5100 | arm64: { |
| 5101 | src: "myapex-arm64.apex", |
| 5102 | }, |
| 5103 | arm: { |
| 5104 | src: "myapex-arm.apex", |
| 5105 | }, |
| 5106 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5107 | exported_bootclasspath_fragments: ["my-bootclasspath-fragment"], |
| 5108 | } |
| 5109 | |
| 5110 | prebuilt_bootclasspath_fragment { |
| 5111 | name: "my-bootclasspath-fragment", |
| 5112 | contents: ["libfoo", "libbar"], |
| 5113 | apex_available: ["myapex"], |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5114 | hidden_api: { |
| 5115 | annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", |
| 5116 | metadata: "my-bootclasspath-fragment/metadata.csv", |
| 5117 | index: "my-bootclasspath-fragment/index.csv", |
| 5118 | stub_flags: "my-bootclasspath-fragment/stub-flags.csv", |
| 5119 | all_flags: "my-bootclasspath-fragment/all-flags.csv", |
| 5120 | }, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5121 | } |
| 5122 | |
| 5123 | java_import { |
| 5124 | name: "libfoo", |
| 5125 | jars: ["libfoo.jar"], |
| 5126 | apex_available: ["myapex"], |
| 5127 | } |
| 5128 | |
| 5129 | java_library { |
| 5130 | name: "libfoo", |
| 5131 | srcs: ["foo/bar/MyClass.java"], |
| 5132 | apex_available: ["myapex"], |
| 5133 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 5134 | |
| 5135 | java_sdk_library_import { |
| 5136 | name: "libbar", |
| 5137 | public: { |
| 5138 | jars: ["libbar.jar"], |
| 5139 | }, |
| 5140 | apex_available: ["myapex"], |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5141 | shared_library: false, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 5142 | } |
| 5143 | |
| 5144 | java_sdk_library { |
| 5145 | name: "libbar", |
| 5146 | srcs: ["foo/bar/MyClass.java"], |
| 5147 | unsafe_ignore_missing_latest_api: true, |
| 5148 | apex_available: ["myapex"], |
| 5149 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5150 | ` |
| 5151 | |
| 5152 | // In this test the source (java_library) libfoo is active since the |
| 5153 | // prebuilt (java_import) defaults to prefer:false. However the |
| 5154 | // prebuilt_apex module always depends on the prebuilt, and so it doesn't |
| 5155 | // find the dex boot jar in it. We either need to disable the source libfoo |
| 5156 | // or make the prebuilt libfoo preferred. |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5157 | testDexpreoptWithApexes(t, bp, "module libfoo does not provide a dex boot jar", preparer, fragment) |
Spandan Das | 10ea4bf | 2021-08-20 19:18:16 +0000 | [diff] [blame] | 5158 | // dexbootjar check is skipped if AllowMissingDependencies is true |
| 5159 | preparerAllowMissingDeps := android.GroupFixturePreparers( |
| 5160 | preparer, |
| 5161 | android.PrepareForTestWithAllowMissingDependencies, |
| 5162 | ) |
| 5163 | testDexpreoptWithApexes(t, bp, "", preparerAllowMissingDeps, fragment) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5164 | }) |
| 5165 | |
| 5166 | t.Run("prebuilt library preferred with source", func(t *testing.T) { |
| 5167 | bp := ` |
| 5168 | prebuilt_apex { |
| 5169 | name: "myapex", |
| 5170 | arch: { |
| 5171 | arm64: { |
| 5172 | src: "myapex-arm64.apex", |
| 5173 | }, |
| 5174 | arm: { |
| 5175 | src: "myapex-arm.apex", |
| 5176 | }, |
| 5177 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5178 | exported_bootclasspath_fragments: ["my-bootclasspath-fragment"], |
| 5179 | } |
| 5180 | |
| 5181 | prebuilt_bootclasspath_fragment { |
| 5182 | name: "my-bootclasspath-fragment", |
| 5183 | contents: ["libfoo", "libbar"], |
| 5184 | apex_available: ["myapex"], |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5185 | hidden_api: { |
| 5186 | annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", |
| 5187 | metadata: "my-bootclasspath-fragment/metadata.csv", |
| 5188 | index: "my-bootclasspath-fragment/index.csv", |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 5189 | signature_patterns: "my-bootclasspath-fragment/signature-patterns.csv", |
| 5190 | filtered_stub_flags: "my-bootclasspath-fragment/filtered-stub-flags.csv", |
| 5191 | filtered_flags: "my-bootclasspath-fragment/filtered-flags.csv", |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5192 | }, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5193 | } |
| 5194 | |
| 5195 | java_import { |
| 5196 | name: "libfoo", |
| 5197 | prefer: true, |
| 5198 | jars: ["libfoo.jar"], |
| 5199 | apex_available: ["myapex"], |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 5200 | permitted_packages: ["foo"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5201 | } |
| 5202 | |
| 5203 | java_library { |
| 5204 | name: "libfoo", |
| 5205 | srcs: ["foo/bar/MyClass.java"], |
| 5206 | apex_available: ["myapex"], |
| 5207 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 5208 | |
| 5209 | java_sdk_library_import { |
| 5210 | name: "libbar", |
| 5211 | prefer: true, |
| 5212 | public: { |
| 5213 | jars: ["libbar.jar"], |
| 5214 | }, |
| 5215 | apex_available: ["myapex"], |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5216 | shared_library: false, |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 5217 | permitted_packages: ["bar"], |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 5218 | } |
| 5219 | |
| 5220 | java_sdk_library { |
| 5221 | name: "libbar", |
| 5222 | srcs: ["foo/bar/MyClass.java"], |
| 5223 | unsafe_ignore_missing_latest_api: true, |
| 5224 | apex_available: ["myapex"], |
| 5225 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5226 | ` |
| 5227 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5228 | ctx := testDexpreoptWithApexes(t, bp, "", preparer, fragment) |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 5229 | checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
| 5230 | checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 5231 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 5232 | // Verify the correct module jars contribute to the hiddenapi index file. |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5233 | checkHiddenAPIIndexFromClassesInputs(t, ctx, ``) |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 5234 | checkHiddenAPIIndexFromFlagsInputs(t, ctx, ` |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5235 | my-bootclasspath-fragment/index.csv |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 5236 | out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/index-from-classes.csv |
| 5237 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5238 | }) |
| 5239 | |
| 5240 | t.Run("prebuilt with source apex preferred", func(t *testing.T) { |
| 5241 | bp := ` |
| 5242 | apex { |
| 5243 | name: "myapex", |
| 5244 | key: "myapex.key", |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 5245 | java_libs: ["libfoo", "libbar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5246 | updatable: false, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5247 | } |
| 5248 | |
| 5249 | apex_key { |
| 5250 | name: "myapex.key", |
| 5251 | public_key: "testkey.avbpubkey", |
| 5252 | private_key: "testkey.pem", |
| 5253 | } |
| 5254 | |
| 5255 | prebuilt_apex { |
| 5256 | name: "myapex", |
| 5257 | arch: { |
| 5258 | arm64: { |
| 5259 | src: "myapex-arm64.apex", |
| 5260 | }, |
| 5261 | arm: { |
| 5262 | src: "myapex-arm.apex", |
| 5263 | }, |
| 5264 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5265 | exported_bootclasspath_fragments: ["my-bootclasspath-fragment"], |
| 5266 | } |
| 5267 | |
| 5268 | prebuilt_bootclasspath_fragment { |
| 5269 | name: "my-bootclasspath-fragment", |
| 5270 | contents: ["libfoo", "libbar"], |
| 5271 | apex_available: ["myapex"], |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5272 | hidden_api: { |
| 5273 | annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", |
| 5274 | metadata: "my-bootclasspath-fragment/metadata.csv", |
| 5275 | index: "my-bootclasspath-fragment/index.csv", |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 5276 | signature_patterns: "my-bootclasspath-fragment/signature-patterns.csv", |
| 5277 | filtered_stub_flags: "my-bootclasspath-fragment/filtered-stub-flags.csv", |
| 5278 | filtered_flags: "my-bootclasspath-fragment/filtered-flags.csv", |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5279 | }, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5280 | } |
| 5281 | |
| 5282 | java_import { |
| 5283 | name: "libfoo", |
| 5284 | jars: ["libfoo.jar"], |
| 5285 | apex_available: ["myapex"], |
| 5286 | } |
| 5287 | |
| 5288 | java_library { |
| 5289 | name: "libfoo", |
| 5290 | srcs: ["foo/bar/MyClass.java"], |
| 5291 | apex_available: ["myapex"], |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 5292 | permitted_packages: ["foo"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5293 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 5294 | |
| 5295 | java_sdk_library_import { |
| 5296 | name: "libbar", |
| 5297 | public: { |
| 5298 | jars: ["libbar.jar"], |
| 5299 | }, |
| 5300 | apex_available: ["myapex"], |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5301 | shared_library: false, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 5302 | } |
| 5303 | |
| 5304 | java_sdk_library { |
| 5305 | name: "libbar", |
| 5306 | srcs: ["foo/bar/MyClass.java"], |
| 5307 | unsafe_ignore_missing_latest_api: true, |
| 5308 | apex_available: ["myapex"], |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 5309 | permitted_packages: ["bar"], |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 5310 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5311 | ` |
| 5312 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5313 | ctx := testDexpreoptWithApexes(t, bp, "", preparer, fragment) |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 5314 | checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/libfoo/android_common_apex10000/hiddenapi/libfoo.jar") |
| 5315 | checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/libbar/android_common_myapex/hiddenapi/libbar.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 5316 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 5317 | // Verify the correct module jars contribute to the hiddenapi index file. |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5318 | checkHiddenAPIIndexFromClassesInputs(t, ctx, ``) |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 5319 | checkHiddenAPIIndexFromFlagsInputs(t, ctx, ` |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5320 | my-bootclasspath-fragment/index.csv |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 5321 | out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/index-from-classes.csv |
| 5322 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5323 | }) |
| 5324 | |
| 5325 | t.Run("prebuilt preferred with source apex disabled", func(t *testing.T) { |
| 5326 | bp := ` |
| 5327 | apex { |
| 5328 | name: "myapex", |
| 5329 | enabled: false, |
| 5330 | key: "myapex.key", |
Paul Duffin | 8f146b9 | 2021-04-12 17:24:18 +0100 | [diff] [blame] | 5331 | java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5332 | } |
| 5333 | |
| 5334 | apex_key { |
| 5335 | name: "myapex.key", |
| 5336 | public_key: "testkey.avbpubkey", |
| 5337 | private_key: "testkey.pem", |
| 5338 | } |
| 5339 | |
| 5340 | prebuilt_apex { |
| 5341 | name: "myapex", |
| 5342 | arch: { |
| 5343 | arm64: { |
| 5344 | src: "myapex-arm64.apex", |
| 5345 | }, |
| 5346 | arm: { |
| 5347 | src: "myapex-arm.apex", |
| 5348 | }, |
| 5349 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5350 | exported_bootclasspath_fragments: ["my-bootclasspath-fragment"], |
| 5351 | } |
| 5352 | |
| 5353 | prebuilt_bootclasspath_fragment { |
| 5354 | name: "my-bootclasspath-fragment", |
| 5355 | contents: ["libfoo", "libbar"], |
| 5356 | apex_available: ["myapex"], |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5357 | hidden_api: { |
| 5358 | annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", |
| 5359 | metadata: "my-bootclasspath-fragment/metadata.csv", |
| 5360 | index: "my-bootclasspath-fragment/index.csv", |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 5361 | signature_patterns: "my-bootclasspath-fragment/signature-patterns.csv", |
| 5362 | filtered_stub_flags: "my-bootclasspath-fragment/filtered-stub-flags.csv", |
| 5363 | filtered_flags: "my-bootclasspath-fragment/filtered-flags.csv", |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5364 | }, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5365 | } |
| 5366 | |
| 5367 | java_import { |
| 5368 | name: "libfoo", |
| 5369 | prefer: true, |
| 5370 | jars: ["libfoo.jar"], |
| 5371 | apex_available: ["myapex"], |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 5372 | permitted_packages: ["foo"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5373 | } |
| 5374 | |
| 5375 | java_library { |
| 5376 | name: "libfoo", |
| 5377 | srcs: ["foo/bar/MyClass.java"], |
| 5378 | apex_available: ["myapex"], |
| 5379 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 5380 | |
| 5381 | java_sdk_library_import { |
| 5382 | name: "libbar", |
| 5383 | prefer: true, |
| 5384 | public: { |
| 5385 | jars: ["libbar.jar"], |
| 5386 | }, |
| 5387 | apex_available: ["myapex"], |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5388 | shared_library: false, |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 5389 | permitted_packages: ["bar"], |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 5390 | } |
| 5391 | |
| 5392 | java_sdk_library { |
| 5393 | name: "libbar", |
| 5394 | srcs: ["foo/bar/MyClass.java"], |
| 5395 | unsafe_ignore_missing_latest_api: true, |
| 5396 | apex_available: ["myapex"], |
| 5397 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5398 | ` |
| 5399 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 5400 | ctx := testDexpreoptWithApexes(t, bp, "", preparer, fragment) |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 5401 | checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
| 5402 | checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 5403 | |
Paul Duffin | 537ea3d | 2021-05-14 10:38:00 +0100 | [diff] [blame] | 5404 | // Verify the correct module jars contribute to the hiddenapi index file. |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5405 | checkHiddenAPIIndexFromClassesInputs(t, ctx, ``) |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 5406 | checkHiddenAPIIndexFromFlagsInputs(t, ctx, ` |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 5407 | my-bootclasspath-fragment/index.csv |
Paul Duffin | 40a3f65 | 2021-07-19 13:11:24 +0100 | [diff] [blame] | 5408 | out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/index-from-classes.csv |
| 5409 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 5410 | }) |
| 5411 | } |
| 5412 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 5413 | func TestApexWithTests(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5414 | ctx := testApex(t, ` |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 5415 | apex_test { |
| 5416 | name: "myapex", |
| 5417 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5418 | updatable: false, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 5419 | tests: [ |
| 5420 | "mytest", |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 5421 | "mytests", |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 5422 | ], |
| 5423 | } |
| 5424 | |
| 5425 | apex_key { |
| 5426 | name: "myapex.key", |
| 5427 | public_key: "testkey.avbpubkey", |
| 5428 | private_key: "testkey.pem", |
| 5429 | } |
| 5430 | |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 5431 | filegroup { |
| 5432 | name: "fg", |
| 5433 | srcs: [ |
| 5434 | "baz", |
| 5435 | "bar/baz" |
| 5436 | ], |
| 5437 | } |
| 5438 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 5439 | cc_test { |
| 5440 | name: "mytest", |
| 5441 | gtest: false, |
| 5442 | srcs: ["mytest.cpp"], |
| 5443 | relative_install_path: "test", |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 5444 | shared_libs: ["mylib"], |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 5445 | system_shared_libs: [], |
| 5446 | static_executable: true, |
| 5447 | stl: "none", |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 5448 | data: [":fg"], |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 5449 | } |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 5450 | |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 5451 | cc_library { |
| 5452 | name: "mylib", |
| 5453 | srcs: ["mylib.cpp"], |
| 5454 | system_shared_libs: [], |
| 5455 | stl: "none", |
| 5456 | } |
| 5457 | |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 5458 | filegroup { |
| 5459 | name: "fg2", |
| 5460 | srcs: [ |
| 5461 | "testdata/baz" |
| 5462 | ], |
| 5463 | } |
| 5464 | |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 5465 | cc_test { |
| 5466 | name: "mytests", |
| 5467 | gtest: false, |
| 5468 | srcs: [ |
| 5469 | "mytest1.cpp", |
| 5470 | "mytest2.cpp", |
| 5471 | "mytest3.cpp", |
| 5472 | ], |
| 5473 | test_per_src: true, |
| 5474 | relative_install_path: "test", |
| 5475 | system_shared_libs: [], |
| 5476 | static_executable: true, |
| 5477 | stl: "none", |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 5478 | data: [ |
| 5479 | ":fg", |
| 5480 | ":fg2", |
| 5481 | ], |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 5482 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 5483 | `) |
| 5484 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 5485 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 5486 | copyCmds := apexRule.Args["copy_commands"] |
| 5487 | |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 5488 | // Ensure that test dep (and their transitive dependencies) are copied into apex. |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 5489 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest") |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 5490 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 5491 | |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 5492 | //Ensure that test data are copied into apex. |
| 5493 | ensureContains(t, copyCmds, "image.apex/bin/test/baz") |
| 5494 | ensureContains(t, copyCmds, "image.apex/bin/test/bar/baz") |
| 5495 | |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 5496 | // Ensure that test deps built with `test_per_src` are copied into apex. |
| 5497 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest1") |
| 5498 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest2") |
| 5499 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest3") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 5500 | |
| 5501 | // Ensure the module is correctly translated. |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 5502 | bundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 5503 | data := android.AndroidMkDataForTest(t, ctx, bundle) |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 5504 | name := bundle.BaseModuleName() |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 5505 | prefix := "TARGET_" |
| 5506 | var builder strings.Builder |
| 5507 | data.Custom(&builder, name, prefix, "", data) |
| 5508 | androidMk := builder.String() |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 5509 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n") |
| 5510 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n") |
| 5511 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n") |
| 5512 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5513 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 5514 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 5515 | ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n") |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 5516 | |
| 5517 | flatBundle := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 5518 | data = android.AndroidMkDataForTest(t, ctx, flatBundle) |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 5519 | data.Custom(&builder, name, prefix, "", data) |
| 5520 | flatAndroidMk := builder.String() |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 5521 | ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :baz :bar/baz\n") |
| 5522 | ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :testdata/baz\n") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 5523 | } |
| 5524 | |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 5525 | func TestInstallExtraFlattenedApexes(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5526 | ctx := testApex(t, ` |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 5527 | apex { |
| 5528 | name: "myapex", |
| 5529 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5530 | updatable: false, |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 5531 | } |
| 5532 | apex_key { |
| 5533 | name: "myapex.key", |
| 5534 | public_key: "testkey.avbpubkey", |
| 5535 | private_key: "testkey.pem", |
| 5536 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 5537 | `, |
| 5538 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 5539 | variables.InstallExtraFlattenedApexes = proptools.BoolPtr(true) |
| 5540 | }), |
| 5541 | ) |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 5542 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 5543 | ensureListContains(t, ab.requiredDeps, "myapex.flattened") |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 5544 | mk := android.AndroidMkDataForTest(t, ctx, ab) |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 5545 | var builder strings.Builder |
| 5546 | mk.Custom(&builder, ab.Name(), "TARGET_", "", mk) |
| 5547 | androidMk := builder.String() |
| 5548 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened") |
| 5549 | } |
| 5550 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 5551 | func TestErrorsIfDepsAreNotEnabled(t *testing.T) { |
| 5552 | testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, ` |
| 5553 | apex { |
| 5554 | name: "myapex", |
| 5555 | key: "myapex.key", |
| 5556 | native_shared_libs: ["libfoo"], |
| 5557 | } |
| 5558 | |
| 5559 | apex_key { |
| 5560 | name: "myapex.key", |
| 5561 | public_key: "testkey.avbpubkey", |
| 5562 | private_key: "testkey.pem", |
| 5563 | } |
| 5564 | |
| 5565 | cc_library { |
| 5566 | name: "libfoo", |
| 5567 | stl: "none", |
| 5568 | system_shared_libs: [], |
| 5569 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5570 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 5571 | } |
| 5572 | `) |
| 5573 | testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, ` |
| 5574 | apex { |
| 5575 | name: "myapex", |
| 5576 | key: "myapex.key", |
| 5577 | java_libs: ["myjar"], |
| 5578 | } |
| 5579 | |
| 5580 | apex_key { |
| 5581 | name: "myapex.key", |
| 5582 | public_key: "testkey.avbpubkey", |
| 5583 | private_key: "testkey.pem", |
| 5584 | } |
| 5585 | |
| 5586 | java_library { |
| 5587 | name: "myjar", |
| 5588 | srcs: ["foo/bar/MyClass.java"], |
| 5589 | sdk_version: "none", |
| 5590 | system_modules: "none", |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 5591 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5592 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 5593 | } |
| 5594 | `) |
| 5595 | } |
| 5596 | |
Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 5597 | func TestApexWithJavaImport(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5598 | ctx := testApex(t, ` |
Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 5599 | apex { |
| 5600 | name: "myapex", |
| 5601 | key: "myapex.key", |
| 5602 | java_libs: ["myjavaimport"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5603 | updatable: false, |
Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 5604 | } |
| 5605 | |
| 5606 | apex_key { |
| 5607 | name: "myapex.key", |
| 5608 | public_key: "testkey.avbpubkey", |
| 5609 | private_key: "testkey.pem", |
| 5610 | } |
| 5611 | |
| 5612 | java_import { |
| 5613 | name: "myjavaimport", |
| 5614 | apex_available: ["myapex"], |
| 5615 | jars: ["my.jar"], |
| 5616 | compile_dex: true, |
| 5617 | } |
| 5618 | `) |
| 5619 | |
| 5620 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 5621 | apexRule := module.Rule("apexRule") |
| 5622 | copyCmds := apexRule.Args["copy_commands"] |
| 5623 | ensureContains(t, copyCmds, "image.apex/javalib/myjavaimport.jar") |
| 5624 | } |
| 5625 | |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5626 | func TestApexWithApps(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5627 | ctx := testApex(t, ` |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5628 | apex { |
| 5629 | name: "myapex", |
| 5630 | key: "myapex.key", |
| 5631 | apps: [ |
| 5632 | "AppFoo", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5633 | "AppFooPriv", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5634 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5635 | updatable: false, |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5636 | } |
| 5637 | |
| 5638 | apex_key { |
| 5639 | name: "myapex.key", |
| 5640 | public_key: "testkey.avbpubkey", |
| 5641 | private_key: "testkey.pem", |
| 5642 | } |
| 5643 | |
| 5644 | android_app { |
| 5645 | name: "AppFoo", |
| 5646 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5647 | sdk_version: "current", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5648 | system_modules: "none", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 5649 | jni_libs: ["libjni"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5650 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5651 | apex_available: [ "myapex" ], |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5652 | } |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5653 | |
| 5654 | android_app { |
| 5655 | name: "AppFooPriv", |
| 5656 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5657 | sdk_version: "current", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5658 | system_modules: "none", |
| 5659 | privileged: true, |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5660 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5661 | apex_available: [ "myapex" ], |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5662 | } |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 5663 | |
| 5664 | cc_library_shared { |
| 5665 | name: "libjni", |
| 5666 | srcs: ["mylib.cpp"], |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5667 | shared_libs: ["libfoo"], |
| 5668 | stl: "none", |
| 5669 | system_shared_libs: [], |
| 5670 | apex_available: [ "myapex" ], |
| 5671 | sdk_version: "current", |
| 5672 | } |
| 5673 | |
| 5674 | cc_library_shared { |
| 5675 | name: "libfoo", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 5676 | stl: "none", |
| 5677 | system_shared_libs: [], |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 5678 | apex_available: [ "myapex" ], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5679 | sdk_version: "current", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 5680 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5681 | `) |
| 5682 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 5683 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5684 | apexRule := module.Rule("apexRule") |
| 5685 | copyCmds := apexRule.Args["copy_commands"] |
| 5686 | |
Oriol Prieto Gascó | a70425f | 2022-05-20 13:05:34 +0000 | [diff] [blame] | 5687 | ensureContains(t, copyCmds, "image.apex/app/AppFoo@TEST.BUILD_ID/AppFoo.apk") |
| 5688 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv@TEST.BUILD_ID/AppFooPriv.apk") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 5689 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 5690 | appZipRule := ctx.ModuleForTests("AppFoo", "android_common_apex10000").Description("zip jni libs") |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5691 | // JNI libraries are uncompressed |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 5692 | if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") { |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5693 | t.Errorf("jni libs are not uncompressed for AppFoo") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 5694 | } |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5695 | // JNI libraries including transitive deps are |
| 5696 | for _, jni := range []string{"libjni", "libfoo"} { |
Paul Duffin | afdd406 | 2021-03-30 19:44:07 +0100 | [diff] [blame] | 5697 | jniOutput := ctx.ModuleForTests(jni, "android_arm64_armv8-a_sdk_shared_apex10000").Module().(*cc.Module).OutputFile().RelativeToTop() |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5698 | // ... embedded inside APK (jnilibs.zip) |
| 5699 | ensureListContains(t, appZipRule.Implicits.Strings(), jniOutput.String()) |
| 5700 | // ... and not directly inside the APEX |
| 5701 | ensureNotContains(t, copyCmds, "image.apex/lib64/"+jni+".so") |
| 5702 | } |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5703 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5704 | |
Oriol Prieto Gascó | a70425f | 2022-05-20 13:05:34 +0000 | [diff] [blame] | 5705 | func TestApexWithAppImportBuildId(t *testing.T) { |
| 5706 | invalidBuildIds := []string{"../", "a b", "a/b", "a/b/../c", "/a"} |
| 5707 | for _, id := range invalidBuildIds { |
| 5708 | message := fmt.Sprintf("Unable to use build id %s as filename suffix", id) |
| 5709 | fixture := android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 5710 | variables.BuildId = proptools.StringPtr(id) |
| 5711 | }) |
| 5712 | testApexError(t, message, `apex { |
| 5713 | name: "myapex", |
| 5714 | key: "myapex.key", |
| 5715 | apps: ["AppFooPrebuilt"], |
| 5716 | updatable: false, |
| 5717 | } |
| 5718 | |
| 5719 | apex_key { |
| 5720 | name: "myapex.key", |
| 5721 | public_key: "testkey.avbpubkey", |
| 5722 | private_key: "testkey.pem", |
| 5723 | } |
| 5724 | |
| 5725 | android_app_import { |
| 5726 | name: "AppFooPrebuilt", |
| 5727 | apk: "PrebuiltAppFoo.apk", |
| 5728 | presigned: true, |
| 5729 | apex_available: ["myapex"], |
| 5730 | } |
| 5731 | `, fixture) |
| 5732 | } |
| 5733 | } |
| 5734 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5735 | func TestApexWithAppImports(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5736 | ctx := testApex(t, ` |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5737 | apex { |
| 5738 | name: "myapex", |
| 5739 | key: "myapex.key", |
| 5740 | apps: [ |
| 5741 | "AppFooPrebuilt", |
| 5742 | "AppFooPrivPrebuilt", |
| 5743 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5744 | updatable: false, |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5745 | } |
| 5746 | |
| 5747 | apex_key { |
| 5748 | name: "myapex.key", |
| 5749 | public_key: "testkey.avbpubkey", |
| 5750 | private_key: "testkey.pem", |
| 5751 | } |
| 5752 | |
| 5753 | android_app_import { |
| 5754 | name: "AppFooPrebuilt", |
| 5755 | apk: "PrebuiltAppFoo.apk", |
| 5756 | presigned: true, |
| 5757 | dex_preopt: { |
| 5758 | enabled: false, |
| 5759 | }, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5760 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5761 | } |
| 5762 | |
| 5763 | android_app_import { |
| 5764 | name: "AppFooPrivPrebuilt", |
| 5765 | apk: "PrebuiltAppFooPriv.apk", |
| 5766 | privileged: true, |
| 5767 | presigned: true, |
| 5768 | dex_preopt: { |
| 5769 | enabled: false, |
| 5770 | }, |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5771 | filename: "AwesomePrebuiltAppFooPriv.apk", |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5772 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5773 | } |
| 5774 | `) |
| 5775 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 5776 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5777 | apexRule := module.Rule("apexRule") |
| 5778 | copyCmds := apexRule.Args["copy_commands"] |
| 5779 | |
Oriol Prieto Gascó | a70425f | 2022-05-20 13:05:34 +0000 | [diff] [blame] | 5780 | ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt@TEST.BUILD_ID/AppFooPrebuilt.apk") |
| 5781 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt@TEST.BUILD_ID/AwesomePrebuiltAppFooPriv.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5782 | } |
| 5783 | |
| 5784 | func TestApexWithAppImportsPrefer(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5785 | ctx := testApex(t, ` |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5786 | apex { |
| 5787 | name: "myapex", |
| 5788 | key: "myapex.key", |
| 5789 | apps: [ |
| 5790 | "AppFoo", |
| 5791 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5792 | updatable: false, |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5793 | } |
| 5794 | |
| 5795 | apex_key { |
| 5796 | name: "myapex.key", |
| 5797 | public_key: "testkey.avbpubkey", |
| 5798 | private_key: "testkey.pem", |
| 5799 | } |
| 5800 | |
| 5801 | android_app { |
| 5802 | name: "AppFoo", |
| 5803 | srcs: ["foo/bar/MyClass.java"], |
| 5804 | sdk_version: "none", |
| 5805 | system_modules: "none", |
| 5806 | apex_available: [ "myapex" ], |
| 5807 | } |
| 5808 | |
| 5809 | android_app_import { |
| 5810 | name: "AppFoo", |
| 5811 | apk: "AppFooPrebuilt.apk", |
| 5812 | filename: "AppFooPrebuilt.apk", |
| 5813 | presigned: true, |
| 5814 | prefer: true, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5815 | apex_available: ["myapex"], |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5816 | } |
| 5817 | `, withFiles(map[string][]byte{ |
| 5818 | "AppFooPrebuilt.apk": nil, |
| 5819 | })) |
| 5820 | |
| 5821 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Oriol Prieto Gascó | a70425f | 2022-05-20 13:05:34 +0000 | [diff] [blame] | 5822 | "app/AppFoo@TEST.BUILD_ID/AppFooPrebuilt.apk", |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5823 | }) |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5824 | } |
| 5825 | |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5826 | func TestApexWithTestHelperApp(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5827 | ctx := testApex(t, ` |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5828 | apex { |
| 5829 | name: "myapex", |
| 5830 | key: "myapex.key", |
| 5831 | apps: [ |
| 5832 | "TesterHelpAppFoo", |
| 5833 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5834 | updatable: false, |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5835 | } |
| 5836 | |
| 5837 | apex_key { |
| 5838 | name: "myapex.key", |
| 5839 | public_key: "testkey.avbpubkey", |
| 5840 | private_key: "testkey.pem", |
| 5841 | } |
| 5842 | |
| 5843 | android_test_helper_app { |
| 5844 | name: "TesterHelpAppFoo", |
| 5845 | srcs: ["foo/bar/MyClass.java"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5846 | apex_available: [ "myapex" ], |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5847 | } |
| 5848 | |
| 5849 | `) |
| 5850 | |
| 5851 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 5852 | apexRule := module.Rule("apexRule") |
| 5853 | copyCmds := apexRule.Args["copy_commands"] |
| 5854 | |
Oriol Prieto Gascó | a70425f | 2022-05-20 13:05:34 +0000 | [diff] [blame] | 5855 | ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo@TEST.BUILD_ID/TesterHelpAppFoo.apk") |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5856 | } |
| 5857 | |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 5858 | func TestApexPropertiesShouldBeDefaultable(t *testing.T) { |
| 5859 | // libfoo's apex_available comes from cc_defaults |
Steven Moreland | 6e36cd6 | 2020-10-22 01:08:35 +0000 | [diff] [blame] | 5860 | testApexError(t, `requires "libfoo" that doesn't list the APEX under 'apex_available'.`, ` |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 5861 | apex { |
| 5862 | name: "myapex", |
| 5863 | key: "myapex.key", |
| 5864 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5865 | updatable: false, |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 5866 | } |
| 5867 | |
| 5868 | apex_key { |
| 5869 | name: "myapex.key", |
| 5870 | public_key: "testkey.avbpubkey", |
| 5871 | private_key: "testkey.pem", |
| 5872 | } |
| 5873 | |
| 5874 | apex { |
| 5875 | name: "otherapex", |
| 5876 | key: "myapex.key", |
| 5877 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5878 | updatable: false, |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 5879 | } |
| 5880 | |
| 5881 | cc_defaults { |
| 5882 | name: "libfoo-defaults", |
| 5883 | apex_available: ["otherapex"], |
| 5884 | } |
| 5885 | |
| 5886 | cc_library { |
| 5887 | name: "libfoo", |
| 5888 | defaults: ["libfoo-defaults"], |
| 5889 | stl: "none", |
| 5890 | system_shared_libs: [], |
| 5891 | }`) |
| 5892 | } |
| 5893 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5894 | func TestApexAvailable_DirectDep(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5895 | // libfoo is not available to myapex, but only to otherapex |
Steven Moreland | 6e36cd6 | 2020-10-22 01:08:35 +0000 | [diff] [blame] | 5896 | testApexError(t, "requires \"libfoo\" that doesn't list the APEX under 'apex_available'.", ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5897 | apex { |
| 5898 | name: "myapex", |
| 5899 | key: "myapex.key", |
| 5900 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5901 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5902 | } |
| 5903 | |
| 5904 | apex_key { |
| 5905 | name: "myapex.key", |
| 5906 | public_key: "testkey.avbpubkey", |
| 5907 | private_key: "testkey.pem", |
| 5908 | } |
| 5909 | |
| 5910 | apex { |
| 5911 | name: "otherapex", |
| 5912 | key: "otherapex.key", |
| 5913 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5914 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5915 | } |
| 5916 | |
| 5917 | apex_key { |
| 5918 | name: "otherapex.key", |
| 5919 | public_key: "testkey.avbpubkey", |
| 5920 | private_key: "testkey.pem", |
| 5921 | } |
| 5922 | |
| 5923 | cc_library { |
| 5924 | name: "libfoo", |
| 5925 | stl: "none", |
| 5926 | system_shared_libs: [], |
| 5927 | apex_available: ["otherapex"], |
| 5928 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5929 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5930 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5931 | func TestApexAvailable_IndirectDep(t *testing.T) { |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5932 | // libbbaz is an indirect dep |
Jiyong Park | 767dbd9 | 2021-03-04 13:03:10 +0900 | [diff] [blame] | 5933 | testApexError(t, `requires "libbaz" that doesn't list the APEX under 'apex_available'.\n\nDependency path: |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 5934 | .*via tag apex\.dependencyTag.*name:sharedLib.* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 5935 | .*-> libfoo.*link:shared.* |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 5936 | .*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 5937 | .*-> libbar.*link:shared.* |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 5938 | .*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.* |
Paul Duffin | 6534770 | 2020-03-31 15:23:40 +0100 | [diff] [blame] | 5939 | .*-> libbaz.*link:shared.*`, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5940 | apex { |
| 5941 | name: "myapex", |
| 5942 | key: "myapex.key", |
| 5943 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5944 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5945 | } |
| 5946 | |
| 5947 | apex_key { |
| 5948 | name: "myapex.key", |
| 5949 | public_key: "testkey.avbpubkey", |
| 5950 | private_key: "testkey.pem", |
| 5951 | } |
| 5952 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5953 | cc_library { |
| 5954 | name: "libfoo", |
| 5955 | stl: "none", |
| 5956 | shared_libs: ["libbar"], |
| 5957 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5958 | apex_available: ["myapex"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5959 | } |
| 5960 | |
| 5961 | cc_library { |
| 5962 | name: "libbar", |
| 5963 | stl: "none", |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5964 | shared_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5965 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5966 | apex_available: ["myapex"], |
| 5967 | } |
| 5968 | |
| 5969 | cc_library { |
| 5970 | name: "libbaz", |
| 5971 | stl: "none", |
| 5972 | system_shared_libs: [], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5973 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5974 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5975 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5976 | func TestApexAvailable_InvalidApexName(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5977 | testApexError(t, "\"otherapex\" is not a valid module name", ` |
| 5978 | apex { |
| 5979 | name: "myapex", |
| 5980 | key: "myapex.key", |
| 5981 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5982 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5983 | } |
| 5984 | |
| 5985 | apex_key { |
| 5986 | name: "myapex.key", |
| 5987 | public_key: "testkey.avbpubkey", |
| 5988 | private_key: "testkey.pem", |
| 5989 | } |
| 5990 | |
| 5991 | cc_library { |
| 5992 | name: "libfoo", |
| 5993 | stl: "none", |
| 5994 | system_shared_libs: [], |
| 5995 | apex_available: ["otherapex"], |
| 5996 | }`) |
| 5997 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5998 | testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5999 | apex { |
| 6000 | name: "myapex", |
| 6001 | key: "myapex.key", |
| 6002 | native_shared_libs: ["libfoo", "libbar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6003 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 6004 | } |
| 6005 | |
| 6006 | apex_key { |
| 6007 | name: "myapex.key", |
| 6008 | public_key: "testkey.avbpubkey", |
| 6009 | private_key: "testkey.pem", |
| 6010 | } |
| 6011 | |
| 6012 | cc_library { |
| 6013 | name: "libfoo", |
| 6014 | stl: "none", |
| 6015 | system_shared_libs: [], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 6016 | runtime_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 6017 | apex_available: ["myapex"], |
| 6018 | } |
| 6019 | |
| 6020 | cc_library { |
| 6021 | name: "libbar", |
| 6022 | stl: "none", |
| 6023 | system_shared_libs: [], |
| 6024 | apex_available: ["//apex_available:anyapex"], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 6025 | } |
| 6026 | |
| 6027 | cc_library { |
| 6028 | name: "libbaz", |
| 6029 | stl: "none", |
| 6030 | system_shared_libs: [], |
| 6031 | stubs: { |
| 6032 | versions: ["10", "20", "30"], |
| 6033 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 6034 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 6035 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 6036 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 6037 | func TestApexAvailable_CheckForPlatform(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6038 | ctx := testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 6039 | apex { |
| 6040 | name: "myapex", |
| 6041 | key: "myapex.key", |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 6042 | native_shared_libs: ["libbar", "libbaz"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6043 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 6044 | } |
| 6045 | |
| 6046 | apex_key { |
| 6047 | name: "myapex.key", |
| 6048 | public_key: "testkey.avbpubkey", |
| 6049 | private_key: "testkey.pem", |
| 6050 | } |
| 6051 | |
| 6052 | cc_library { |
| 6053 | name: "libfoo", |
| 6054 | stl: "none", |
| 6055 | system_shared_libs: [], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 6056 | shared_libs: ["libbar"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 6057 | apex_available: ["//apex_available:platform"], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 6058 | } |
| 6059 | |
| 6060 | cc_library { |
| 6061 | name: "libfoo2", |
| 6062 | stl: "none", |
| 6063 | system_shared_libs: [], |
| 6064 | shared_libs: ["libbaz"], |
| 6065 | apex_available: ["//apex_available:platform"], |
| 6066 | } |
| 6067 | |
| 6068 | cc_library { |
| 6069 | name: "libbar", |
| 6070 | stl: "none", |
| 6071 | system_shared_libs: [], |
| 6072 | apex_available: ["myapex"], |
| 6073 | } |
| 6074 | |
| 6075 | cc_library { |
| 6076 | name: "libbaz", |
| 6077 | stl: "none", |
| 6078 | system_shared_libs: [], |
| 6079 | apex_available: ["myapex"], |
| 6080 | stubs: { |
| 6081 | versions: ["1"], |
| 6082 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 6083 | }`) |
| 6084 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 6085 | // libfoo shouldn't be available to platform even though it has "//apex_available:platform", |
| 6086 | // because it depends on libbar which isn't available to platform |
| 6087 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 6088 | if libfoo.NotAvailableForPlatform() != true { |
| 6089 | t.Errorf("%q shouldn't be available to platform", libfoo.String()) |
| 6090 | } |
| 6091 | |
| 6092 | // libfoo2 however can be available to platform because it depends on libbaz which provides |
| 6093 | // stubs |
| 6094 | libfoo2 := ctx.ModuleForTests("libfoo2", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 6095 | if libfoo2.NotAvailableForPlatform() == true { |
| 6096 | t.Errorf("%q should be available to platform", libfoo2.String()) |
| 6097 | } |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 6098 | } |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 6099 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 6100 | func TestApexAvailable_CreatedForApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6101 | ctx := testApex(t, ` |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 6102 | apex { |
| 6103 | name: "myapex", |
| 6104 | key: "myapex.key", |
| 6105 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6106 | updatable: false, |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 6107 | } |
| 6108 | |
| 6109 | apex_key { |
| 6110 | name: "myapex.key", |
| 6111 | public_key: "testkey.avbpubkey", |
| 6112 | private_key: "testkey.pem", |
| 6113 | } |
| 6114 | |
| 6115 | cc_library { |
| 6116 | name: "libfoo", |
| 6117 | stl: "none", |
| 6118 | system_shared_libs: [], |
| 6119 | apex_available: ["myapex"], |
| 6120 | static: { |
| 6121 | apex_available: ["//apex_available:platform"], |
| 6122 | }, |
| 6123 | }`) |
| 6124 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 6125 | libfooShared := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 6126 | if libfooShared.NotAvailableForPlatform() != true { |
| 6127 | t.Errorf("%q shouldn't be available to platform", libfooShared.String()) |
| 6128 | } |
| 6129 | libfooStatic := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*cc.Module) |
| 6130 | if libfooStatic.NotAvailableForPlatform() != false { |
| 6131 | t.Errorf("%q should be available to platform", libfooStatic.String()) |
| 6132 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 6133 | } |
| 6134 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6135 | func TestOverrideApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6136 | ctx := testApex(t, ` |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6137 | apex { |
| 6138 | name: "myapex", |
| 6139 | key: "myapex.key", |
| 6140 | apps: ["app"], |
markchien | 7c803b8 | 2021-08-26 22:10:06 +0800 | [diff] [blame] | 6141 | bpfs: ["bpf"], |
Daniel Norman | 5a3ce13 | 2021-08-26 15:44:43 -0700 | [diff] [blame] | 6142 | prebuilts: ["myetc"], |
Remi NGUYEN VAN | be90172 | 2022-03-02 21:00:33 +0900 | [diff] [blame] | 6143 | bootclasspath_fragments: ["mybootclasspath_fragment"], |
| 6144 | systemserverclasspath_fragments: ["mysystemserverclasspath_fragment"], |
| 6145 | java_libs: ["myjava_library"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 6146 | overrides: ["oldapex"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6147 | updatable: false, |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6148 | } |
| 6149 | |
| 6150 | override_apex { |
| 6151 | name: "override_myapex", |
| 6152 | base: "myapex", |
| 6153 | apps: ["override_app"], |
markchien | 7c803b8 | 2021-08-26 22:10:06 +0800 | [diff] [blame] | 6154 | bpfs: ["override_bpf"], |
Daniel Norman | 5a3ce13 | 2021-08-26 15:44:43 -0700 | [diff] [blame] | 6155 | prebuilts: ["override_myetc"], |
Remi NGUYEN VAN | be90172 | 2022-03-02 21:00:33 +0900 | [diff] [blame] | 6156 | bootclasspath_fragments: ["override_bootclasspath_fragment"], |
| 6157 | systemserverclasspath_fragments: ["override_systemserverclasspath_fragment"], |
| 6158 | java_libs: ["override_java_library"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 6159 | overrides: ["unknownapex"], |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 6160 | logging_parent: "com.foo.bar", |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 6161 | package_name: "test.overridden.package", |
Jaewoong Jung | 4cfdf7d | 2021-04-20 16:21:24 -0700 | [diff] [blame] | 6162 | key: "mynewapex.key", |
| 6163 | certificate: ":myapex.certificate", |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6164 | } |
| 6165 | |
| 6166 | apex_key { |
| 6167 | name: "myapex.key", |
| 6168 | public_key: "testkey.avbpubkey", |
| 6169 | private_key: "testkey.pem", |
| 6170 | } |
| 6171 | |
Jaewoong Jung | 4cfdf7d | 2021-04-20 16:21:24 -0700 | [diff] [blame] | 6172 | apex_key { |
| 6173 | name: "mynewapex.key", |
| 6174 | public_key: "testkey2.avbpubkey", |
| 6175 | private_key: "testkey2.pem", |
| 6176 | } |
| 6177 | |
| 6178 | android_app_certificate { |
| 6179 | name: "myapex.certificate", |
| 6180 | certificate: "testkey", |
| 6181 | } |
| 6182 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6183 | android_app { |
| 6184 | name: "app", |
| 6185 | srcs: ["foo/bar/MyClass.java"], |
| 6186 | package_name: "foo", |
| 6187 | sdk_version: "none", |
| 6188 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 6189 | apex_available: [ "myapex" ], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6190 | } |
| 6191 | |
| 6192 | override_android_app { |
| 6193 | name: "override_app", |
| 6194 | base: "app", |
| 6195 | package_name: "bar", |
| 6196 | } |
markchien | 7c803b8 | 2021-08-26 22:10:06 +0800 | [diff] [blame] | 6197 | |
| 6198 | bpf { |
| 6199 | name: "bpf", |
| 6200 | srcs: ["bpf.c"], |
| 6201 | } |
| 6202 | |
| 6203 | bpf { |
| 6204 | name: "override_bpf", |
| 6205 | srcs: ["override_bpf.c"], |
| 6206 | } |
Daniel Norman | 5a3ce13 | 2021-08-26 15:44:43 -0700 | [diff] [blame] | 6207 | |
| 6208 | prebuilt_etc { |
| 6209 | name: "myetc", |
| 6210 | src: "myprebuilt", |
| 6211 | } |
| 6212 | |
| 6213 | prebuilt_etc { |
| 6214 | name: "override_myetc", |
| 6215 | src: "override_myprebuilt", |
| 6216 | } |
Remi NGUYEN VAN | be90172 | 2022-03-02 21:00:33 +0900 | [diff] [blame] | 6217 | |
| 6218 | java_library { |
| 6219 | name: "bcplib", |
| 6220 | srcs: ["a.java"], |
| 6221 | compile_dex: true, |
| 6222 | apex_available: ["myapex"], |
| 6223 | permitted_packages: ["bcp.lib"], |
| 6224 | } |
| 6225 | |
| 6226 | bootclasspath_fragment { |
| 6227 | name: "mybootclasspath_fragment", |
| 6228 | contents: ["bcplib"], |
| 6229 | apex_available: ["myapex"], |
| 6230 | } |
| 6231 | |
| 6232 | java_library { |
| 6233 | name: "override_bcplib", |
| 6234 | srcs: ["a.java"], |
| 6235 | compile_dex: true, |
| 6236 | apex_available: ["myapex"], |
| 6237 | permitted_packages: ["override.bcp.lib"], |
| 6238 | } |
| 6239 | |
| 6240 | bootclasspath_fragment { |
| 6241 | name: "override_bootclasspath_fragment", |
| 6242 | contents: ["override_bcplib"], |
| 6243 | apex_available: ["myapex"], |
| 6244 | } |
| 6245 | |
| 6246 | java_library { |
| 6247 | name: "systemserverlib", |
| 6248 | srcs: ["a.java"], |
| 6249 | apex_available: ["myapex"], |
| 6250 | } |
| 6251 | |
| 6252 | systemserverclasspath_fragment { |
| 6253 | name: "mysystemserverclasspath_fragment", |
| 6254 | standalone_contents: ["systemserverlib"], |
| 6255 | apex_available: ["myapex"], |
| 6256 | } |
| 6257 | |
| 6258 | java_library { |
| 6259 | name: "override_systemserverlib", |
| 6260 | srcs: ["a.java"], |
| 6261 | apex_available: ["myapex"], |
| 6262 | } |
| 6263 | |
| 6264 | systemserverclasspath_fragment { |
| 6265 | name: "override_systemserverclasspath_fragment", |
| 6266 | standalone_contents: ["override_systemserverlib"], |
| 6267 | apex_available: ["myapex"], |
| 6268 | } |
| 6269 | |
| 6270 | java_library { |
| 6271 | name: "myjava_library", |
| 6272 | srcs: ["a.java"], |
| 6273 | compile_dex: true, |
| 6274 | apex_available: ["myapex"], |
| 6275 | } |
| 6276 | |
| 6277 | java_library { |
| 6278 | name: "override_java_library", |
| 6279 | srcs: ["a.java"], |
| 6280 | compile_dex: true, |
| 6281 | apex_available: ["myapex"], |
| 6282 | } |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 6283 | `, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"})) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6284 | |
Jiyong Park | 317645e | 2019-12-05 13:20:58 +0900 | [diff] [blame] | 6285 | originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule) |
| 6286 | overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule) |
| 6287 | if originalVariant.GetOverriddenBy() != "" { |
| 6288 | t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy()) |
| 6289 | } |
| 6290 | if overriddenVariant.GetOverriddenBy() != "override_myapex" { |
| 6291 | t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy()) |
| 6292 | } |
| 6293 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6294 | module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image") |
| 6295 | apexRule := module.Rule("apexRule") |
| 6296 | copyCmds := apexRule.Args["copy_commands"] |
| 6297 | |
Oriol Prieto Gascó | a70425f | 2022-05-20 13:05:34 +0000 | [diff] [blame] | 6298 | ensureNotContains(t, copyCmds, "image.apex/app/app@TEST.BUILD_ID/app.apk") |
| 6299 | ensureContains(t, copyCmds, "image.apex/app/override_app@TEST.BUILD_ID/override_app.apk") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 6300 | |
markchien | 7c803b8 | 2021-08-26 22:10:06 +0800 | [diff] [blame] | 6301 | ensureNotContains(t, copyCmds, "image.apex/etc/bpf/bpf.o") |
| 6302 | ensureContains(t, copyCmds, "image.apex/etc/bpf/override_bpf.o") |
| 6303 | |
Daniel Norman | 5a3ce13 | 2021-08-26 15:44:43 -0700 | [diff] [blame] | 6304 | ensureNotContains(t, copyCmds, "image.apex/etc/myetc") |
| 6305 | ensureContains(t, copyCmds, "image.apex/etc/override_myetc") |
| 6306 | |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 6307 | apexBundle := module.Module().(*apexBundle) |
| 6308 | name := apexBundle.Name() |
| 6309 | if name != "override_myapex" { |
| 6310 | t.Errorf("name should be \"override_myapex\", but was %q", name) |
| 6311 | } |
| 6312 | |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 6313 | if apexBundle.overridableProperties.Logging_parent != "com.foo.bar" { |
| 6314 | t.Errorf("override_myapex should have logging parent (com.foo.bar), but was %q.", apexBundle.overridableProperties.Logging_parent) |
| 6315 | } |
| 6316 | |
Remi NGUYEN VAN | be90172 | 2022-03-02 21:00:33 +0900 | [diff] [blame] | 6317 | android.AssertArrayString(t, "Bootclasspath_fragments does not match", |
| 6318 | []string{"override_bootclasspath_fragment"}, apexBundle.overridableProperties.Bootclasspath_fragments) |
| 6319 | android.AssertArrayString(t, "Systemserverclasspath_fragments does not match", |
| 6320 | []string{"override_systemserverclasspath_fragment"}, apexBundle.overridableProperties.Systemserverclasspath_fragments) |
| 6321 | android.AssertArrayString(t, "Java_libs does not match", |
| 6322 | []string{"override_java_library"}, apexBundle.overridableProperties.Java_libs) |
| 6323 | |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 6324 | optFlags := apexRule.Args["opt_flags"] |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 6325 | ensureContains(t, optFlags, "--override_apk_package_name test.overridden.package") |
Jaewoong Jung | 4cfdf7d | 2021-04-20 16:21:24 -0700 | [diff] [blame] | 6326 | ensureContains(t, optFlags, "--pubkey testkey2.avbpubkey") |
| 6327 | |
| 6328 | signApkRule := module.Rule("signapk") |
| 6329 | ensureEquals(t, signApkRule.Args["certificates"], "testkey.x509.pem testkey.pk8") |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 6330 | |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 6331 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 6332 | var builder strings.Builder |
| 6333 | data.Custom(&builder, name, "TARGET_", "", data) |
| 6334 | androidMk := builder.String() |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 6335 | ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex") |
markchien | 7c803b8 | 2021-08-26 22:10:06 +0800 | [diff] [blame] | 6336 | ensureContains(t, androidMk, "LOCAL_MODULE := override_bpf.o.override_myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 6337 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex") |
Remi NGUYEN VAN | be90172 | 2022-03-02 21:00:33 +0900 | [diff] [blame] | 6338 | ensureContains(t, androidMk, "LOCAL_MODULE := override_bcplib.override_myapex") |
| 6339 | ensureContains(t, androidMk, "LOCAL_MODULE := override_systemserverlib.override_myapex") |
| 6340 | ensureContains(t, androidMk, "LOCAL_MODULE := override_java_library.override_myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 6341 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex") |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 6342 | ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 6343 | ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex") |
markchien | 7c803b8 | 2021-08-26 22:10:06 +0800 | [diff] [blame] | 6344 | ensureNotContains(t, androidMk, "LOCAL_MODULE := bpf.myapex") |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 6345 | ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 6346 | ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex") |
Remi NGUYEN VAN | be90172 | 2022-03-02 21:00:33 +0900 | [diff] [blame] | 6347 | ensureNotContains(t, androidMk, "LOCAL_MODULE := override_bcplib.myapex") |
| 6348 | ensureNotContains(t, androidMk, "LOCAL_MODULE := override_systemserverlib.myapex") |
| 6349 | ensureNotContains(t, androidMk, "LOCAL_MODULE := override_java_library.pb.myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 6350 | ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex") |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6351 | } |
| 6352 | |
Albert Martin | 55ccba2 | 2022-03-21 20:11:16 +0000 | [diff] [blame] | 6353 | func TestMinSdkVersionOverride(t *testing.T) { |
| 6354 | // Override from 29 to 31 |
| 6355 | minSdkOverride31 := "31" |
| 6356 | ctx := testApex(t, ` |
| 6357 | apex { |
| 6358 | name: "myapex", |
| 6359 | key: "myapex.key", |
| 6360 | native_shared_libs: ["mylib"], |
| 6361 | updatable: true, |
| 6362 | min_sdk_version: "29" |
| 6363 | } |
| 6364 | |
| 6365 | override_apex { |
| 6366 | name: "override_myapex", |
| 6367 | base: "myapex", |
| 6368 | logging_parent: "com.foo.bar", |
| 6369 | package_name: "test.overridden.package" |
| 6370 | } |
| 6371 | |
| 6372 | apex_key { |
| 6373 | name: "myapex.key", |
| 6374 | public_key: "testkey.avbpubkey", |
| 6375 | private_key: "testkey.pem", |
| 6376 | } |
| 6377 | |
| 6378 | cc_library { |
| 6379 | name: "mylib", |
| 6380 | srcs: ["mylib.cpp"], |
| 6381 | runtime_libs: ["libbar"], |
| 6382 | system_shared_libs: [], |
| 6383 | stl: "none", |
| 6384 | apex_available: [ "myapex" ], |
| 6385 | min_sdk_version: "apex_inherit" |
| 6386 | } |
| 6387 | |
| 6388 | cc_library { |
| 6389 | name: "libbar", |
| 6390 | srcs: ["mylib.cpp"], |
| 6391 | system_shared_libs: [], |
| 6392 | stl: "none", |
| 6393 | apex_available: [ "myapex" ], |
| 6394 | min_sdk_version: "apex_inherit" |
| 6395 | } |
| 6396 | |
| 6397 | `, withApexGlobalMinSdkVersionOverride(&minSdkOverride31)) |
| 6398 | |
| 6399 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 6400 | copyCmds := apexRule.Args["copy_commands"] |
| 6401 | |
| 6402 | // Ensure that direct non-stubs dep is always included |
| 6403 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 6404 | |
| 6405 | // Ensure that runtime_libs dep in included |
| 6406 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 6407 | |
| 6408 | // Ensure libraries target overridden min_sdk_version value |
| 6409 | ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared_apex31") |
| 6410 | } |
| 6411 | |
| 6412 | func TestMinSdkVersionOverrideToLowerVersionNoOp(t *testing.T) { |
| 6413 | // Attempt to override from 31 to 29, should be a NOOP |
| 6414 | minSdkOverride29 := "29" |
| 6415 | ctx := testApex(t, ` |
| 6416 | apex { |
| 6417 | name: "myapex", |
| 6418 | key: "myapex.key", |
| 6419 | native_shared_libs: ["mylib"], |
| 6420 | updatable: true, |
| 6421 | min_sdk_version: "31" |
| 6422 | } |
| 6423 | |
| 6424 | override_apex { |
| 6425 | name: "override_myapex", |
| 6426 | base: "myapex", |
| 6427 | logging_parent: "com.foo.bar", |
| 6428 | package_name: "test.overridden.package" |
| 6429 | } |
| 6430 | |
| 6431 | apex_key { |
| 6432 | name: "myapex.key", |
| 6433 | public_key: "testkey.avbpubkey", |
| 6434 | private_key: "testkey.pem", |
| 6435 | } |
| 6436 | |
| 6437 | cc_library { |
| 6438 | name: "mylib", |
| 6439 | srcs: ["mylib.cpp"], |
| 6440 | runtime_libs: ["libbar"], |
| 6441 | system_shared_libs: [], |
| 6442 | stl: "none", |
| 6443 | apex_available: [ "myapex" ], |
| 6444 | min_sdk_version: "apex_inherit" |
| 6445 | } |
| 6446 | |
| 6447 | cc_library { |
| 6448 | name: "libbar", |
| 6449 | srcs: ["mylib.cpp"], |
| 6450 | system_shared_libs: [], |
| 6451 | stl: "none", |
| 6452 | apex_available: [ "myapex" ], |
| 6453 | min_sdk_version: "apex_inherit" |
| 6454 | } |
| 6455 | |
| 6456 | `, withApexGlobalMinSdkVersionOverride(&minSdkOverride29)) |
| 6457 | |
| 6458 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 6459 | copyCmds := apexRule.Args["copy_commands"] |
| 6460 | |
| 6461 | // Ensure that direct non-stubs dep is always included |
| 6462 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 6463 | |
| 6464 | // Ensure that runtime_libs dep in included |
| 6465 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 6466 | |
| 6467 | // Ensure libraries target the original min_sdk_version value rather than the overridden |
| 6468 | ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared_apex31") |
| 6469 | } |
| 6470 | |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 6471 | func TestLegacyAndroid10Support(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6472 | ctx := testApex(t, ` |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 6473 | apex { |
| 6474 | name: "myapex", |
| 6475 | key: "myapex.key", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 6476 | native_shared_libs: ["mylib"], |
Jooyung Han | 5417f77 | 2020-03-12 18:37:20 +0900 | [diff] [blame] | 6477 | min_sdk_version: "29", |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 6478 | } |
| 6479 | |
| 6480 | apex_key { |
| 6481 | name: "myapex.key", |
| 6482 | public_key: "testkey.avbpubkey", |
| 6483 | private_key: "testkey.pem", |
| 6484 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 6485 | |
| 6486 | cc_library { |
| 6487 | name: "mylib", |
| 6488 | srcs: ["mylib.cpp"], |
| 6489 | stl: "libc++", |
| 6490 | system_shared_libs: [], |
| 6491 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6492 | min_sdk_version: "29", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 6493 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 6494 | `, withUnbundledBuild) |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 6495 | |
| 6496 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 6497 | args := module.Rule("apexRule").Args |
| 6498 | ensureContains(t, args["opt_flags"], "--manifest_json "+module.Output("apex_manifest.json").Output.String()) |
Dario Freni | e354690 | 2020-01-14 23:50:25 +0000 | [diff] [blame] | 6499 | ensureNotContains(t, args["opt_flags"], "--no_hashtree") |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 6500 | |
| 6501 | // The copies of the libraries in the apex should have one more dependency than |
| 6502 | // the ones outside the apex, namely the unwinder. Ideally we should check |
| 6503 | // the dependency names directly here but for some reason the names are blank in |
| 6504 | // this test. |
| 6505 | for _, lib := range []string{"libc++", "mylib"} { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 6506 | apexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared_apex29").Rule("ld").Implicits |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 6507 | nonApexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld").Implicits |
| 6508 | if len(apexImplicits) != len(nonApexImplicits)+1 { |
| 6509 | t.Errorf("%q missing unwinder dep", lib) |
| 6510 | } |
| 6511 | } |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 6512 | } |
| 6513 | |
Paul Duffin | e05480a | 2021-03-08 15:07:14 +0000 | [diff] [blame] | 6514 | var filesForSdkLibrary = android.MockFS{ |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6515 | "api/current.txt": nil, |
| 6516 | "api/removed.txt": nil, |
| 6517 | "api/system-current.txt": nil, |
| 6518 | "api/system-removed.txt": nil, |
| 6519 | "api/test-current.txt": nil, |
| 6520 | "api/test-removed.txt": nil, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 6521 | |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 6522 | "100/public/api/foo.txt": nil, |
| 6523 | "100/public/api/foo-removed.txt": nil, |
| 6524 | "100/system/api/foo.txt": nil, |
| 6525 | "100/system/api/foo-removed.txt": nil, |
| 6526 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 6527 | // For java_sdk_library_import |
| 6528 | "a.jar": nil, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6529 | } |
| 6530 | |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 6531 | func TestJavaSDKLibrary(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6532 | ctx := testApex(t, ` |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 6533 | apex { |
| 6534 | name: "myapex", |
| 6535 | key: "myapex.key", |
| 6536 | java_libs: ["foo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6537 | updatable: false, |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 6538 | } |
| 6539 | |
| 6540 | apex_key { |
| 6541 | name: "myapex.key", |
| 6542 | public_key: "testkey.avbpubkey", |
| 6543 | private_key: "testkey.pem", |
| 6544 | } |
| 6545 | |
| 6546 | java_sdk_library { |
| 6547 | name: "foo", |
| 6548 | srcs: ["a.java"], |
| 6549 | api_packages: ["foo"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 6550 | apex_available: [ "myapex" ], |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 6551 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 6552 | |
| 6553 | prebuilt_apis { |
| 6554 | name: "sdk", |
| 6555 | api_dirs: ["100"], |
| 6556 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6557 | `, withFiles(filesForSdkLibrary)) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 6558 | |
| 6559 | // java_sdk_library installs both impl jar and permission XML |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 6560 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 6561 | "javalib/foo.jar", |
| 6562 | "etc/permissions/foo.xml", |
| 6563 | }) |
| 6564 | // Permission XML should point to the activated path of impl jar of java_sdk_library |
Jiyong Park | e383388 | 2020-02-17 17:28:10 +0900 | [diff] [blame] | 6565 | sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml") |
Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 6566 | ensureMatches(t, sdkLibrary.RuleParams.Command, `<library\\n\s+name=\\\"foo\\\"\\n\s+file=\\\"/apex/myapex/javalib/foo.jar\\\"`) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 6567 | } |
| 6568 | |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6569 | func TestJavaSDKLibrary_WithinApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6570 | ctx := testApex(t, ` |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6571 | apex { |
| 6572 | name: "myapex", |
| 6573 | key: "myapex.key", |
| 6574 | java_libs: ["foo", "bar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6575 | updatable: false, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6576 | } |
| 6577 | |
| 6578 | apex_key { |
| 6579 | name: "myapex.key", |
| 6580 | public_key: "testkey.avbpubkey", |
| 6581 | private_key: "testkey.pem", |
| 6582 | } |
| 6583 | |
| 6584 | java_sdk_library { |
| 6585 | name: "foo", |
| 6586 | srcs: ["a.java"], |
| 6587 | api_packages: ["foo"], |
| 6588 | apex_available: ["myapex"], |
| 6589 | sdk_version: "none", |
| 6590 | system_modules: "none", |
| 6591 | } |
| 6592 | |
| 6593 | java_library { |
| 6594 | name: "bar", |
| 6595 | srcs: ["a.java"], |
| 6596 | libs: ["foo"], |
| 6597 | apex_available: ["myapex"], |
| 6598 | sdk_version: "none", |
| 6599 | system_modules: "none", |
| 6600 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 6601 | |
| 6602 | prebuilt_apis { |
| 6603 | name: "sdk", |
| 6604 | api_dirs: ["100"], |
| 6605 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6606 | `, withFiles(filesForSdkLibrary)) |
| 6607 | |
| 6608 | // java_sdk_library installs both impl jar and permission XML |
| 6609 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 6610 | "javalib/bar.jar", |
| 6611 | "javalib/foo.jar", |
| 6612 | "etc/permissions/foo.xml", |
| 6613 | }) |
| 6614 | |
| 6615 | // The bar library should depend on the implementation jar. |
| 6616 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
Paul Duffin | cf8d7db | 2021-03-29 00:29:53 +0100 | [diff] [blame] | 6617 | if expected, actual := `^-classpath [^:]*/turbine-combined/foo\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6618 | t.Errorf("expected %q, found %#q", expected, actual) |
| 6619 | } |
| 6620 | } |
| 6621 | |
| 6622 | func TestJavaSDKLibrary_CrossBoundary(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6623 | ctx := testApex(t, ` |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6624 | apex { |
| 6625 | name: "myapex", |
| 6626 | key: "myapex.key", |
| 6627 | java_libs: ["foo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6628 | updatable: false, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6629 | } |
| 6630 | |
| 6631 | apex_key { |
| 6632 | name: "myapex.key", |
| 6633 | public_key: "testkey.avbpubkey", |
| 6634 | private_key: "testkey.pem", |
| 6635 | } |
| 6636 | |
| 6637 | java_sdk_library { |
| 6638 | name: "foo", |
| 6639 | srcs: ["a.java"], |
| 6640 | api_packages: ["foo"], |
| 6641 | apex_available: ["myapex"], |
| 6642 | sdk_version: "none", |
| 6643 | system_modules: "none", |
| 6644 | } |
| 6645 | |
| 6646 | java_library { |
| 6647 | name: "bar", |
| 6648 | srcs: ["a.java"], |
| 6649 | libs: ["foo"], |
| 6650 | sdk_version: "none", |
| 6651 | system_modules: "none", |
| 6652 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 6653 | |
| 6654 | prebuilt_apis { |
| 6655 | name: "sdk", |
| 6656 | api_dirs: ["100"], |
| 6657 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6658 | `, withFiles(filesForSdkLibrary)) |
| 6659 | |
| 6660 | // java_sdk_library installs both impl jar and permission XML |
| 6661 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 6662 | "javalib/foo.jar", |
| 6663 | "etc/permissions/foo.xml", |
| 6664 | }) |
| 6665 | |
| 6666 | // The bar library should depend on the stubs jar. |
| 6667 | barLibrary := ctx.ModuleForTests("bar", "android_common").Rule("javac") |
Paul Duffin | cf8d7db | 2021-03-29 00:29:53 +0100 | [diff] [blame] | 6668 | if expected, actual := `^-classpath [^:]*/turbine-combined/foo\.stubs\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6669 | t.Errorf("expected %q, found %#q", expected, actual) |
| 6670 | } |
| 6671 | } |
| 6672 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 6673 | func TestJavaSDKLibrary_ImportPreferred(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6674 | ctx := testApex(t, ` |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 6675 | prebuilt_apis { |
| 6676 | name: "sdk", |
| 6677 | api_dirs: ["100"], |
| 6678 | }`, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 6679 | withFiles(map[string][]byte{ |
| 6680 | "apex/a.java": nil, |
| 6681 | "apex/apex_manifest.json": nil, |
| 6682 | "apex/Android.bp": []byte(` |
| 6683 | package { |
| 6684 | default_visibility: ["//visibility:private"], |
| 6685 | } |
| 6686 | |
| 6687 | apex { |
| 6688 | name: "myapex", |
| 6689 | key: "myapex.key", |
| 6690 | java_libs: ["foo", "bar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6691 | updatable: false, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 6692 | } |
| 6693 | |
| 6694 | apex_key { |
| 6695 | name: "myapex.key", |
| 6696 | public_key: "testkey.avbpubkey", |
| 6697 | private_key: "testkey.pem", |
| 6698 | } |
| 6699 | |
| 6700 | java_library { |
| 6701 | name: "bar", |
| 6702 | srcs: ["a.java"], |
| 6703 | libs: ["foo"], |
| 6704 | apex_available: ["myapex"], |
| 6705 | sdk_version: "none", |
| 6706 | system_modules: "none", |
| 6707 | } |
| 6708 | `), |
| 6709 | "source/a.java": nil, |
| 6710 | "source/api/current.txt": nil, |
| 6711 | "source/api/removed.txt": nil, |
| 6712 | "source/Android.bp": []byte(` |
| 6713 | package { |
| 6714 | default_visibility: ["//visibility:private"], |
| 6715 | } |
| 6716 | |
| 6717 | java_sdk_library { |
| 6718 | name: "foo", |
| 6719 | visibility: ["//apex"], |
| 6720 | srcs: ["a.java"], |
| 6721 | api_packages: ["foo"], |
| 6722 | apex_available: ["myapex"], |
| 6723 | sdk_version: "none", |
| 6724 | system_modules: "none", |
| 6725 | public: { |
| 6726 | enabled: true, |
| 6727 | }, |
| 6728 | } |
| 6729 | `), |
| 6730 | "prebuilt/a.jar": nil, |
| 6731 | "prebuilt/Android.bp": []byte(` |
| 6732 | package { |
| 6733 | default_visibility: ["//visibility:private"], |
| 6734 | } |
| 6735 | |
| 6736 | java_sdk_library_import { |
| 6737 | name: "foo", |
| 6738 | visibility: ["//apex", "//source"], |
| 6739 | apex_available: ["myapex"], |
| 6740 | prefer: true, |
| 6741 | public: { |
| 6742 | jars: ["a.jar"], |
| 6743 | }, |
| 6744 | } |
| 6745 | `), |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 6746 | }), withFiles(filesForSdkLibrary), |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 6747 | ) |
| 6748 | |
| 6749 | // java_sdk_library installs both impl jar and permission XML |
| 6750 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 6751 | "javalib/bar.jar", |
| 6752 | "javalib/foo.jar", |
| 6753 | "etc/permissions/foo.xml", |
| 6754 | }) |
| 6755 | |
| 6756 | // The bar library should depend on the implementation jar. |
| 6757 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
Paul Duffin | cf8d7db | 2021-03-29 00:29:53 +0100 | [diff] [blame] | 6758 | if expected, actual := `^-classpath [^:]*/turbine-combined/foo\.impl\.jar$`, barLibrary.Args["classpath"]; !regexp.MustCompile(expected).MatchString(actual) { |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 6759 | t.Errorf("expected %q, found %#q", expected, actual) |
| 6760 | } |
| 6761 | } |
| 6762 | |
| 6763 | func TestJavaSDKLibrary_ImportOnly(t *testing.T) { |
| 6764 | testApexError(t, `java_libs: "foo" is not configured to be compiled into dex`, ` |
| 6765 | apex { |
| 6766 | name: "myapex", |
| 6767 | key: "myapex.key", |
| 6768 | java_libs: ["foo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6769 | updatable: false, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 6770 | } |
| 6771 | |
| 6772 | apex_key { |
| 6773 | name: "myapex.key", |
| 6774 | public_key: "testkey.avbpubkey", |
| 6775 | private_key: "testkey.pem", |
| 6776 | } |
| 6777 | |
| 6778 | java_sdk_library_import { |
| 6779 | name: "foo", |
| 6780 | apex_available: ["myapex"], |
| 6781 | prefer: true, |
| 6782 | public: { |
| 6783 | jars: ["a.jar"], |
| 6784 | }, |
| 6785 | } |
| 6786 | |
| 6787 | `, withFiles(filesForSdkLibrary)) |
| 6788 | } |
| 6789 | |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6790 | func TestCompatConfig(t *testing.T) { |
Paul Duffin | 284165a | 2021-03-29 01:50:31 +0100 | [diff] [blame] | 6791 | result := android.GroupFixturePreparers( |
| 6792 | prepareForApexTest, |
| 6793 | java.PrepareForTestWithPlatformCompatConfig, |
| 6794 | ).RunTestWithBp(t, ` |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6795 | apex { |
| 6796 | name: "myapex", |
| 6797 | key: "myapex.key", |
Paul Duffin | 3abc174 | 2021-03-15 19:32:23 +0000 | [diff] [blame] | 6798 | compat_configs: ["myjar-platform-compat-config"], |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6799 | java_libs: ["myjar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6800 | updatable: false, |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6801 | } |
| 6802 | |
| 6803 | apex_key { |
| 6804 | name: "myapex.key", |
| 6805 | public_key: "testkey.avbpubkey", |
| 6806 | private_key: "testkey.pem", |
| 6807 | } |
| 6808 | |
| 6809 | platform_compat_config { |
| 6810 | name: "myjar-platform-compat-config", |
| 6811 | src: ":myjar", |
| 6812 | } |
| 6813 | |
| 6814 | java_library { |
| 6815 | name: "myjar", |
| 6816 | srcs: ["foo/bar/MyClass.java"], |
| 6817 | sdk_version: "none", |
| 6818 | system_modules: "none", |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6819 | apex_available: [ "myapex" ], |
| 6820 | } |
Paul Duffin | 1b29e00 | 2021-03-16 15:06:54 +0000 | [diff] [blame] | 6821 | |
| 6822 | // Make sure that a preferred prebuilt does not affect the apex contents. |
| 6823 | prebuilt_platform_compat_config { |
| 6824 | name: "myjar-platform-compat-config", |
| 6825 | metadata: "compat-config/metadata.xml", |
| 6826 | prefer: true, |
| 6827 | } |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6828 | `) |
Paul Duffin | a369c7b | 2021-03-09 03:08:05 +0000 | [diff] [blame] | 6829 | ctx := result.TestContext |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6830 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 6831 | "etc/compatconfig/myjar-platform-compat-config.xml", |
| 6832 | "javalib/myjar.jar", |
| 6833 | }) |
| 6834 | } |
| 6835 | |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 6836 | func TestRejectNonInstallableJavaLibrary(t *testing.T) { |
| 6837 | testApexError(t, `"myjar" is not configured to be compiled into dex`, ` |
| 6838 | apex { |
| 6839 | name: "myapex", |
| 6840 | key: "myapex.key", |
| 6841 | java_libs: ["myjar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6842 | updatable: false, |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 6843 | } |
| 6844 | |
| 6845 | apex_key { |
| 6846 | name: "myapex.key", |
| 6847 | public_key: "testkey.avbpubkey", |
| 6848 | private_key: "testkey.pem", |
| 6849 | } |
| 6850 | |
| 6851 | java_library { |
| 6852 | name: "myjar", |
| 6853 | srcs: ["foo/bar/MyClass.java"], |
| 6854 | sdk_version: "none", |
| 6855 | system_modules: "none", |
Jiyong Park | 6b21c7d | 2020-02-11 09:16:01 +0900 | [diff] [blame] | 6856 | compile_dex: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 6857 | apex_available: ["myapex"], |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 6858 | } |
| 6859 | `) |
| 6860 | } |
| 6861 | |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 6862 | func TestCarryRequiredModuleNames(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6863 | ctx := testApex(t, ` |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 6864 | apex { |
| 6865 | name: "myapex", |
| 6866 | key: "myapex.key", |
| 6867 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6868 | updatable: false, |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 6869 | } |
| 6870 | |
| 6871 | apex_key { |
| 6872 | name: "myapex.key", |
| 6873 | public_key: "testkey.avbpubkey", |
| 6874 | private_key: "testkey.pem", |
| 6875 | } |
| 6876 | |
| 6877 | cc_library { |
| 6878 | name: "mylib", |
| 6879 | srcs: ["mylib.cpp"], |
| 6880 | system_shared_libs: [], |
| 6881 | stl: "none", |
| 6882 | required: ["a", "b"], |
| 6883 | host_required: ["c", "d"], |
| 6884 | target_required: ["e", "f"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 6885 | apex_available: [ "myapex" ], |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 6886 | } |
| 6887 | `) |
| 6888 | |
| 6889 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 6890 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 6891 | name := apexBundle.BaseModuleName() |
| 6892 | prefix := "TARGET_" |
| 6893 | var builder strings.Builder |
| 6894 | data.Custom(&builder, name, prefix, "", data) |
| 6895 | androidMk := builder.String() |
| 6896 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n") |
| 6897 | ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n") |
| 6898 | ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n") |
| 6899 | } |
| 6900 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6901 | func TestSymlinksFromApexToSystem(t *testing.T) { |
| 6902 | bp := ` |
| 6903 | apex { |
| 6904 | name: "myapex", |
| 6905 | key: "myapex.key", |
| 6906 | native_shared_libs: ["mylib"], |
| 6907 | java_libs: ["myjar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6908 | updatable: false, |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6909 | } |
| 6910 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6911 | apex { |
| 6912 | name: "myapex.updatable", |
| 6913 | key: "myapex.key", |
| 6914 | native_shared_libs: ["mylib"], |
| 6915 | java_libs: ["myjar"], |
| 6916 | updatable: true, |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 6917 | min_sdk_version: "current", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6918 | } |
| 6919 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6920 | apex_key { |
| 6921 | name: "myapex.key", |
| 6922 | public_key: "testkey.avbpubkey", |
| 6923 | private_key: "testkey.pem", |
| 6924 | } |
| 6925 | |
| 6926 | cc_library { |
| 6927 | name: "mylib", |
| 6928 | srcs: ["mylib.cpp"], |
| 6929 | shared_libs: ["myotherlib"], |
| 6930 | system_shared_libs: [], |
| 6931 | stl: "none", |
| 6932 | apex_available: [ |
| 6933 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6934 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6935 | "//apex_available:platform", |
| 6936 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6937 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6938 | } |
| 6939 | |
| 6940 | cc_library { |
| 6941 | name: "myotherlib", |
| 6942 | srcs: ["mylib.cpp"], |
| 6943 | system_shared_libs: [], |
| 6944 | stl: "none", |
| 6945 | apex_available: [ |
| 6946 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6947 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6948 | "//apex_available:platform", |
| 6949 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6950 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6951 | } |
| 6952 | |
| 6953 | java_library { |
| 6954 | name: "myjar", |
| 6955 | srcs: ["foo/bar/MyClass.java"], |
| 6956 | sdk_version: "none", |
| 6957 | system_modules: "none", |
| 6958 | libs: ["myotherjar"], |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6959 | apex_available: [ |
| 6960 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6961 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6962 | "//apex_available:platform", |
| 6963 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6964 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6965 | } |
| 6966 | |
| 6967 | java_library { |
| 6968 | name: "myotherjar", |
| 6969 | srcs: ["foo/bar/MyClass.java"], |
| 6970 | sdk_version: "none", |
| 6971 | system_modules: "none", |
| 6972 | apex_available: [ |
| 6973 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6974 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6975 | "//apex_available:platform", |
| 6976 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6977 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6978 | } |
| 6979 | ` |
| 6980 | |
| 6981 | ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) { |
| 6982 | for _, f := range files { |
| 6983 | if f.path == file { |
| 6984 | if f.isLink { |
| 6985 | t.Errorf("%q is not a real file", file) |
| 6986 | } |
| 6987 | return |
| 6988 | } |
| 6989 | } |
| 6990 | t.Errorf("%q is not found", file) |
| 6991 | } |
| 6992 | |
| 6993 | ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) { |
| 6994 | for _, f := range files { |
| 6995 | if f.path == file { |
| 6996 | if !f.isLink { |
| 6997 | t.Errorf("%q is not a symlink", file) |
| 6998 | } |
| 6999 | return |
| 7000 | } |
| 7001 | } |
| 7002 | t.Errorf("%q is not found", file) |
| 7003 | } |
| 7004 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 7005 | // For unbundled build, symlink shouldn't exist regardless of whether an APEX |
| 7006 | // is updatable or not |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7007 | ctx := testApex(t, bp, withUnbundledBuild) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 7008 | files := getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 7009 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 7010 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 7011 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 7012 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 7013 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 7014 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 7015 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 7016 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 7017 | |
| 7018 | // For bundled build, symlink to the system for the non-updatable APEXes only |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7019 | ctx = testApex(t, bp) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 7020 | files = getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 7021 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 7022 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 7023 | ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 7024 | |
| 7025 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 7026 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 7027 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 7028 | ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 7029 | } |
| 7030 | |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 7031 | func TestSymlinksFromApexToSystemRequiredModuleNames(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7032 | ctx := testApex(t, ` |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 7033 | apex { |
| 7034 | name: "myapex", |
| 7035 | key: "myapex.key", |
| 7036 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7037 | updatable: false, |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 7038 | } |
| 7039 | |
| 7040 | apex_key { |
| 7041 | name: "myapex.key", |
| 7042 | public_key: "testkey.avbpubkey", |
| 7043 | private_key: "testkey.pem", |
| 7044 | } |
| 7045 | |
| 7046 | cc_library_shared { |
| 7047 | name: "mylib", |
| 7048 | srcs: ["mylib.cpp"], |
| 7049 | shared_libs: ["myotherlib"], |
| 7050 | system_shared_libs: [], |
| 7051 | stl: "none", |
| 7052 | apex_available: [ |
| 7053 | "myapex", |
| 7054 | "//apex_available:platform", |
| 7055 | ], |
| 7056 | } |
| 7057 | |
| 7058 | cc_prebuilt_library_shared { |
| 7059 | name: "myotherlib", |
| 7060 | srcs: ["prebuilt.so"], |
| 7061 | system_shared_libs: [], |
| 7062 | stl: "none", |
| 7063 | apex_available: [ |
| 7064 | "myapex", |
| 7065 | "//apex_available:platform", |
| 7066 | ], |
| 7067 | } |
| 7068 | `) |
| 7069 | |
| 7070 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 7071 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 7072 | var builder strings.Builder |
| 7073 | data.Custom(&builder, apexBundle.BaseModuleName(), "TARGET_", "", data) |
| 7074 | androidMk := builder.String() |
| 7075 | // `myotherlib` is added to `myapex` as symlink |
| 7076 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 7077 | ensureNotContains(t, androidMk, "LOCAL_MODULE := prebuilt_myotherlib.myapex\n") |
| 7078 | ensureNotContains(t, androidMk, "LOCAL_MODULE := myotherlib.myapex\n") |
| 7079 | // `myapex` should have `myotherlib` in its required line, not `prebuilt_myotherlib` |
Jiyong Park | 57621b2 | 2021-01-20 20:33:11 +0900 | [diff] [blame] | 7080 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += mylib.myapex:64 myotherlib:64 apex_manifest.pb.myapex apex_pubkey.myapex\n") |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 7081 | } |
| 7082 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 7083 | func TestApexWithJniLibs(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7084 | ctx := testApex(t, ` |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 7085 | apex { |
| 7086 | name: "myapex", |
| 7087 | key: "myapex.key", |
Jiyong Park | 34d5c33 | 2022-02-24 18:02:44 +0900 | [diff] [blame] | 7088 | jni_libs: ["mylib", "libfoo.rust"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7089 | updatable: false, |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 7090 | } |
| 7091 | |
| 7092 | apex_key { |
| 7093 | name: "myapex.key", |
| 7094 | public_key: "testkey.avbpubkey", |
| 7095 | private_key: "testkey.pem", |
| 7096 | } |
| 7097 | |
| 7098 | cc_library { |
| 7099 | name: "mylib", |
| 7100 | srcs: ["mylib.cpp"], |
| 7101 | shared_libs: ["mylib2"], |
| 7102 | system_shared_libs: [], |
| 7103 | stl: "none", |
| 7104 | apex_available: [ "myapex" ], |
| 7105 | } |
| 7106 | |
| 7107 | cc_library { |
| 7108 | name: "mylib2", |
| 7109 | srcs: ["mylib.cpp"], |
| 7110 | system_shared_libs: [], |
| 7111 | stl: "none", |
| 7112 | apex_available: [ "myapex" ], |
| 7113 | } |
Jiyong Park | 34d5c33 | 2022-02-24 18:02:44 +0900 | [diff] [blame] | 7114 | |
| 7115 | rust_ffi_shared { |
| 7116 | name: "libfoo.rust", |
| 7117 | crate_name: "foo", |
| 7118 | srcs: ["foo.rs"], |
| 7119 | shared_libs: ["libfoo.shared_from_rust"], |
| 7120 | prefer_rlib: true, |
| 7121 | apex_available: ["myapex"], |
| 7122 | } |
| 7123 | |
| 7124 | cc_library_shared { |
| 7125 | name: "libfoo.shared_from_rust", |
| 7126 | srcs: ["mylib.cpp"], |
| 7127 | system_shared_libs: [], |
| 7128 | stl: "none", |
| 7129 | stubs: { |
| 7130 | versions: ["10", "11", "12"], |
| 7131 | }, |
| 7132 | } |
| 7133 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 7134 | `) |
| 7135 | |
| 7136 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 7137 | // Notice mylib2.so (transitive dep) is not added as a jni_lib |
Jiyong Park | 34d5c33 | 2022-02-24 18:02:44 +0900 | [diff] [blame] | 7138 | ensureEquals(t, rule.Args["opt"], "-a jniLibs libfoo.rust.so mylib.so") |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 7139 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 7140 | "lib64/mylib.so", |
| 7141 | "lib64/mylib2.so", |
Jiyong Park | 34d5c33 | 2022-02-24 18:02:44 +0900 | [diff] [blame] | 7142 | "lib64/libfoo.rust.so", |
| 7143 | "lib64/libc++.so", // auto-added to libfoo.rust by Soong |
| 7144 | "lib64/liblog.so", // auto-added to libfoo.rust by Soong |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 7145 | }) |
Jiyong Park | 34d5c33 | 2022-02-24 18:02:44 +0900 | [diff] [blame] | 7146 | |
| 7147 | // b/220397949 |
| 7148 | ensureListContains(t, names(rule.Args["requireNativeLibs"]), "libfoo.shared_from_rust.so") |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 7149 | } |
| 7150 | |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 7151 | func TestApexMutatorsDontRunIfDisabled(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7152 | ctx := testApex(t, ` |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 7153 | apex { |
| 7154 | name: "myapex", |
| 7155 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7156 | updatable: false, |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 7157 | } |
| 7158 | apex_key { |
| 7159 | name: "myapex.key", |
| 7160 | public_key: "testkey.avbpubkey", |
| 7161 | private_key: "testkey.pem", |
| 7162 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 7163 | `, |
| 7164 | android.FixtureModifyConfig(func(config android.Config) { |
| 7165 | delete(config.Targets, android.Android) |
| 7166 | config.AndroidCommonTarget = android.Target{} |
| 7167 | }), |
| 7168 | ) |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 7169 | |
| 7170 | if expected, got := []string{""}, ctx.ModuleVariantsForTests("myapex"); !reflect.DeepEqual(expected, got) { |
| 7171 | t.Errorf("Expected variants: %v, but got: %v", expected, got) |
| 7172 | } |
| 7173 | } |
| 7174 | |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 7175 | func TestAppBundle(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7176 | ctx := testApex(t, ` |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 7177 | apex { |
| 7178 | name: "myapex", |
| 7179 | key: "myapex.key", |
| 7180 | apps: ["AppFoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7181 | updatable: false, |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 7182 | } |
| 7183 | |
| 7184 | apex_key { |
| 7185 | name: "myapex.key", |
| 7186 | public_key: "testkey.avbpubkey", |
| 7187 | private_key: "testkey.pem", |
| 7188 | } |
| 7189 | |
| 7190 | android_app { |
| 7191 | name: "AppFoo", |
| 7192 | srcs: ["foo/bar/MyClass.java"], |
| 7193 | sdk_version: "none", |
| 7194 | system_modules: "none", |
| 7195 | apex_available: [ "myapex" ], |
| 7196 | } |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 7197 | `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"})) |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 7198 | |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 7199 | bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("bundle_config.json") |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 7200 | content := bundleConfigRule.Args["content"] |
| 7201 | |
| 7202 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
Oriol Prieto Gascó | a70425f | 2022-05-20 13:05:34 +0000 | [diff] [blame] | 7203 | ensureContains(t, content, `"apex_config":{"apex_embedded_apk_config":[{"package_name":"com.android.foo","path":"app/AppFoo@TEST.BUILD_ID/AppFoo.apk"}]}`) |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 7204 | } |
| 7205 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 7206 | func TestAppSetBundle(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7207 | ctx := testApex(t, ` |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 7208 | apex { |
| 7209 | name: "myapex", |
| 7210 | key: "myapex.key", |
| 7211 | apps: ["AppSet"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7212 | updatable: false, |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 7213 | } |
| 7214 | |
| 7215 | apex_key { |
| 7216 | name: "myapex.key", |
| 7217 | public_key: "testkey.avbpubkey", |
| 7218 | private_key: "testkey.pem", |
| 7219 | } |
| 7220 | |
| 7221 | android_app_set { |
| 7222 | name: "AppSet", |
| 7223 | set: "AppSet.apks", |
| 7224 | }`) |
| 7225 | mod := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 7226 | bundleConfigRule := mod.Output("bundle_config.json") |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 7227 | content := bundleConfigRule.Args["content"] |
| 7228 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
| 7229 | s := mod.Rule("apexRule").Args["copy_commands"] |
| 7230 | copyCmds := regexp.MustCompile(" *&& *").Split(s, -1) |
| 7231 | if len(copyCmds) != 3 { |
| 7232 | t.Fatalf("Expected 3 commands, got %d in:\n%s", len(copyCmds), s) |
| 7233 | } |
Oriol Prieto Gascó | a70425f | 2022-05-20 13:05:34 +0000 | [diff] [blame] | 7234 | ensureMatches(t, copyCmds[0], "^rm -rf .*/app/AppSet@TEST.BUILD_ID$") |
| 7235 | ensureMatches(t, copyCmds[1], "^mkdir -p .*/app/AppSet@TEST.BUILD_ID$") |
| 7236 | ensureMatches(t, copyCmds[2], "^unzip .*-d .*/app/AppSet@TEST.BUILD_ID .*/AppSet.zip$") |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 7237 | } |
| 7238 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 7239 | func TestAppSetBundlePrebuilt(t *testing.T) { |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 7240 | bp := ` |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 7241 | apex_set { |
| 7242 | name: "myapex", |
| 7243 | filename: "foo_v2.apex", |
| 7244 | sanitized: { |
| 7245 | none: { set: "myapex.apks", }, |
| 7246 | hwaddress: { set: "myapex.hwasan.apks", }, |
| 7247 | }, |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 7248 | } |
| 7249 | ` |
| 7250 | ctx := testApex(t, bp, prepareForTestWithSantitizeHwaddress) |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 7251 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 7252 | // Check that the extractor produces the correct output file from the correct input file. |
| 7253 | extractorOutput := "out/soong/.intermediates/myapex.apex.extractor/android_common/extracted/myapex.hwasan.apks" |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 7254 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 7255 | m := ctx.ModuleForTests("myapex.apex.extractor", "android_common") |
| 7256 | extractedApex := m.Output(extractorOutput) |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 7257 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 7258 | android.AssertArrayString(t, "extractor input", []string{"myapex.hwasan.apks"}, extractedApex.Inputs.Strings()) |
| 7259 | |
| 7260 | // Ditto for the apex. |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 7261 | m = ctx.ModuleForTests("myapex", "android_common_myapex") |
| 7262 | copiedApex := m.Output("out/soong/.intermediates/myapex/android_common_myapex/foo_v2.apex") |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 7263 | |
| 7264 | android.AssertStringEquals(t, "myapex input", extractorOutput, copiedApex.Input.String()) |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 7265 | } |
| 7266 | |
Pranav Gupta | 8fa3a2e | 2022-09-27 00:27:08 +0000 | [diff] [blame] | 7267 | func TestApexSetApksModuleAssignment(t *testing.T) { |
| 7268 | ctx := testApex(t, ` |
| 7269 | apex_set { |
| 7270 | name: "myapex", |
| 7271 | set: ":myapex_apks_file", |
| 7272 | } |
| 7273 | |
| 7274 | filegroup { |
| 7275 | name: "myapex_apks_file", |
| 7276 | srcs: ["myapex.apks"], |
| 7277 | } |
| 7278 | `) |
| 7279 | |
| 7280 | m := ctx.ModuleForTests("myapex.apex.extractor", "android_common") |
| 7281 | |
| 7282 | // Check that the extractor produces the correct apks file from the input module |
| 7283 | extractorOutput := "out/soong/.intermediates/myapex.apex.extractor/android_common/extracted/myapex.apks" |
| 7284 | extractedApex := m.Output(extractorOutput) |
| 7285 | |
| 7286 | android.AssertArrayString(t, "extractor input", []string{"myapex.apks"}, extractedApex.Inputs.Strings()) |
| 7287 | } |
| 7288 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7289 | func testNoUpdatableJarsInBootImage(t *testing.T, errmsg string, preparer android.FixturePreparer, fragments ...java.ApexVariantReference) { |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7290 | t.Helper() |
| 7291 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7292 | bp := ` |
| 7293 | java_library { |
| 7294 | name: "some-updatable-apex-lib", |
| 7295 | srcs: ["a.java"], |
| 7296 | sdk_version: "current", |
| 7297 | apex_available: [ |
| 7298 | "some-updatable-apex", |
| 7299 | ], |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7300 | permitted_packages: ["some.updatable.apex.lib"], |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7301 | } |
| 7302 | |
| 7303 | java_library { |
| 7304 | name: "some-non-updatable-apex-lib", |
| 7305 | srcs: ["a.java"], |
| 7306 | apex_available: [ |
| 7307 | "some-non-updatable-apex", |
| 7308 | ], |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7309 | compile_dex: true, |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7310 | permitted_packages: ["some.non.updatable.apex.lib"], |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7311 | } |
| 7312 | |
| 7313 | bootclasspath_fragment { |
| 7314 | name: "some-non-updatable-fragment", |
| 7315 | contents: ["some-non-updatable-apex-lib"], |
| 7316 | apex_available: [ |
| 7317 | "some-non-updatable-apex", |
| 7318 | ], |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7319 | } |
| 7320 | |
| 7321 | java_library { |
| 7322 | name: "some-platform-lib", |
| 7323 | srcs: ["a.java"], |
| 7324 | sdk_version: "current", |
| 7325 | installable: true, |
| 7326 | } |
| 7327 | |
| 7328 | java_library { |
| 7329 | name: "some-art-lib", |
| 7330 | srcs: ["a.java"], |
| 7331 | sdk_version: "current", |
| 7332 | apex_available: [ |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 7333 | "com.android.art.debug", |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7334 | ], |
| 7335 | hostdex: true, |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 7336 | compile_dex: true, |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7337 | } |
| 7338 | |
| 7339 | apex { |
| 7340 | name: "some-updatable-apex", |
| 7341 | key: "some-updatable-apex.key", |
| 7342 | java_libs: ["some-updatable-apex-lib"], |
| 7343 | updatable: true, |
| 7344 | min_sdk_version: "current", |
| 7345 | } |
| 7346 | |
| 7347 | apex { |
| 7348 | name: "some-non-updatable-apex", |
| 7349 | key: "some-non-updatable-apex.key", |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7350 | bootclasspath_fragments: ["some-non-updatable-fragment"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7351 | updatable: false, |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7352 | } |
| 7353 | |
| 7354 | apex_key { |
| 7355 | name: "some-updatable-apex.key", |
| 7356 | } |
| 7357 | |
| 7358 | apex_key { |
| 7359 | name: "some-non-updatable-apex.key", |
| 7360 | } |
| 7361 | |
| 7362 | apex { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 7363 | name: "com.android.art.debug", |
| 7364 | key: "com.android.art.debug.key", |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7365 | bootclasspath_fragments: ["art-bootclasspath-fragment"], |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7366 | updatable: true, |
| 7367 | min_sdk_version: "current", |
| 7368 | } |
| 7369 | |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 7370 | bootclasspath_fragment { |
| 7371 | name: "art-bootclasspath-fragment", |
| 7372 | image_name: "art", |
| 7373 | contents: ["some-art-lib"], |
| 7374 | apex_available: [ |
| 7375 | "com.android.art.debug", |
| 7376 | ], |
| 7377 | } |
| 7378 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7379 | apex_key { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 7380 | name: "com.android.art.debug.key", |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7381 | } |
| 7382 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7383 | filegroup { |
| 7384 | name: "some-updatable-apex-file_contexts", |
| 7385 | srcs: [ |
| 7386 | "system/sepolicy/apex/some-updatable-apex-file_contexts", |
| 7387 | ], |
| 7388 | } |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 7389 | |
| 7390 | filegroup { |
| 7391 | name: "some-non-updatable-apex-file_contexts", |
| 7392 | srcs: [ |
| 7393 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts", |
| 7394 | ], |
| 7395 | } |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7396 | ` |
Paul Duffin | c3bbb96 | 2020-12-10 19:15:49 +0000 | [diff] [blame] | 7397 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7398 | testDexpreoptWithApexes(t, bp, errmsg, preparer, fragments...) |
Paul Duffin | c3bbb96 | 2020-12-10 19:15:49 +0000 | [diff] [blame] | 7399 | } |
| 7400 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7401 | func testDexpreoptWithApexes(t *testing.T, bp, errmsg string, preparer android.FixturePreparer, fragments ...java.ApexVariantReference) *android.TestContext { |
Paul Duffin | c3bbb96 | 2020-12-10 19:15:49 +0000 | [diff] [blame] | 7402 | t.Helper() |
| 7403 | |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 7404 | fs := android.MockFS{ |
| 7405 | "a.java": nil, |
| 7406 | "a.jar": nil, |
| 7407 | "apex_manifest.json": nil, |
| 7408 | "AndroidManifest.xml": nil, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 7409 | "system/sepolicy/apex/myapex-file_contexts": nil, |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 7410 | "system/sepolicy/apex/some-updatable-apex-file_contexts": nil, |
| 7411 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts": nil, |
| 7412 | "system/sepolicy/apex/com.android.art.debug-file_contexts": nil, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 7413 | "framework/aidl/a.aidl": nil, |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7414 | } |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7415 | |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 7416 | errorHandler := android.FixtureExpectsNoErrors |
| 7417 | if errmsg != "" { |
| 7418 | errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(errmsg) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7419 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 7420 | |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 7421 | result := android.GroupFixturePreparers( |
| 7422 | cc.PrepareForTestWithCcDefaultModules, |
| 7423 | java.PrepareForTestWithHiddenApiBuildComponents, |
| 7424 | java.PrepareForTestWithJavaDefaultModules, |
| 7425 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 7426 | PrepareForTestWithApexBuildComponents, |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7427 | preparer, |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 7428 | fs.AddToFixture(), |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7429 | android.FixtureModifyMockFS(func(fs android.MockFS) { |
| 7430 | if _, ok := fs["frameworks/base/boot/Android.bp"]; !ok { |
| 7431 | insert := "" |
| 7432 | for _, fragment := range fragments { |
| 7433 | insert += fmt.Sprintf("{apex: %q, module: %q},\n", *fragment.Apex, *fragment.Module) |
| 7434 | } |
| 7435 | fs["frameworks/base/boot/Android.bp"] = []byte(fmt.Sprintf(` |
| 7436 | platform_bootclasspath { |
| 7437 | name: "platform-bootclasspath", |
| 7438 | fragments: [ |
| 7439 | %s |
| 7440 | ], |
| 7441 | } |
| 7442 | `, insert)) |
Paul Duffin | 8f146b9 | 2021-04-12 17:24:18 +0100 | [diff] [blame] | 7443 | } |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7444 | }), |
Jiakai Zhang | 49b1eb6 | 2021-11-26 18:09:27 +0000 | [diff] [blame] | 7445 | dexpreopt.FixtureSetBootImageProfiles("art/build/boot/boot-image-profile.txt"), |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 7446 | ). |
| 7447 | ExtendWithErrorHandler(errorHandler). |
| 7448 | RunTestWithBp(t, bp) |
| 7449 | |
| 7450 | return result.TestContext |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7451 | } |
| 7452 | |
Paul Duffin | 1aa5056 | 2022-06-09 17:32:21 +0000 | [diff] [blame] | 7453 | func TestDuplicateDeapexersFromPrebuiltApexes(t *testing.T) { |
Martin Stjernholm | 43c44b0 | 2021-06-30 16:35:07 +0100 | [diff] [blame] | 7454 | preparers := android.GroupFixturePreparers( |
| 7455 | java.PrepareForTestWithJavaDefaultModules, |
| 7456 | PrepareForTestWithApexBuildComponents, |
| 7457 | ). |
| 7458 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( |
| 7459 | "Multiple installable prebuilt APEXes provide ambiguous deapexers: com.android.myapex and com.mycompany.android.myapex")) |
| 7460 | |
| 7461 | bpBase := ` |
| 7462 | apex_set { |
| 7463 | name: "com.android.myapex", |
| 7464 | installable: true, |
| 7465 | exported_bootclasspath_fragments: ["my-bootclasspath-fragment"], |
| 7466 | set: "myapex.apks", |
| 7467 | } |
| 7468 | |
| 7469 | apex_set { |
| 7470 | name: "com.mycompany.android.myapex", |
| 7471 | apex_name: "com.android.myapex", |
| 7472 | installable: true, |
| 7473 | exported_bootclasspath_fragments: ["my-bootclasspath-fragment"], |
| 7474 | set: "company-myapex.apks", |
| 7475 | } |
| 7476 | |
| 7477 | prebuilt_bootclasspath_fragment { |
| 7478 | name: "my-bootclasspath-fragment", |
| 7479 | apex_available: ["com.android.myapex"], |
| 7480 | %s |
| 7481 | } |
| 7482 | ` |
| 7483 | |
| 7484 | t.Run("java_import", func(t *testing.T) { |
| 7485 | _ = preparers.RunTestWithBp(t, fmt.Sprintf(bpBase, `contents: ["libfoo"]`)+` |
| 7486 | java_import { |
| 7487 | name: "libfoo", |
| 7488 | jars: ["libfoo.jar"], |
| 7489 | apex_available: ["com.android.myapex"], |
| 7490 | } |
| 7491 | `) |
| 7492 | }) |
| 7493 | |
| 7494 | t.Run("java_sdk_library_import", func(t *testing.T) { |
| 7495 | _ = preparers.RunTestWithBp(t, fmt.Sprintf(bpBase, `contents: ["libfoo"]`)+` |
| 7496 | java_sdk_library_import { |
| 7497 | name: "libfoo", |
| 7498 | public: { |
| 7499 | jars: ["libbar.jar"], |
| 7500 | }, |
| 7501 | apex_available: ["com.android.myapex"], |
| 7502 | } |
| 7503 | `) |
| 7504 | }) |
| 7505 | |
| 7506 | t.Run("prebuilt_bootclasspath_fragment", func(t *testing.T) { |
| 7507 | _ = preparers.RunTestWithBp(t, fmt.Sprintf(bpBase, ` |
| 7508 | image_name: "art", |
| 7509 | contents: ["libfoo"], |
| 7510 | `)+` |
| 7511 | java_sdk_library_import { |
| 7512 | name: "libfoo", |
| 7513 | public: { |
| 7514 | jars: ["libbar.jar"], |
| 7515 | }, |
| 7516 | apex_available: ["com.android.myapex"], |
| 7517 | } |
| 7518 | `) |
| 7519 | }) |
| 7520 | } |
| 7521 | |
Paul Duffin | 1aa5056 | 2022-06-09 17:32:21 +0000 | [diff] [blame] | 7522 | func TestDuplicateButEquivalentDeapexersFromPrebuiltApexes(t *testing.T) { |
| 7523 | preparers := android.GroupFixturePreparers( |
| 7524 | java.PrepareForTestWithJavaDefaultModules, |
| 7525 | PrepareForTestWithApexBuildComponents, |
| 7526 | ) |
| 7527 | |
| 7528 | bpBase := ` |
| 7529 | apex_set { |
| 7530 | name: "com.android.myapex", |
| 7531 | installable: true, |
| 7532 | exported_bootclasspath_fragments: ["my-bootclasspath-fragment"], |
| 7533 | set: "myapex.apks", |
| 7534 | } |
| 7535 | |
| 7536 | apex_set { |
| 7537 | name: "com.android.myapex_compressed", |
| 7538 | apex_name: "com.android.myapex", |
| 7539 | installable: true, |
| 7540 | exported_bootclasspath_fragments: ["my-bootclasspath-fragment"], |
| 7541 | set: "myapex_compressed.apks", |
| 7542 | } |
| 7543 | |
| 7544 | prebuilt_bootclasspath_fragment { |
| 7545 | name: "my-bootclasspath-fragment", |
| 7546 | apex_available: [ |
| 7547 | "com.android.myapex", |
| 7548 | "com.android.myapex_compressed", |
| 7549 | ], |
| 7550 | hidden_api: { |
| 7551 | annotation_flags: "annotation-flags.csv", |
| 7552 | metadata: "metadata.csv", |
| 7553 | index: "index.csv", |
| 7554 | signature_patterns: "signature_patterns.csv", |
| 7555 | }, |
| 7556 | %s |
| 7557 | } |
| 7558 | ` |
| 7559 | |
| 7560 | t.Run("java_import", func(t *testing.T) { |
| 7561 | result := preparers.RunTestWithBp(t, |
| 7562 | fmt.Sprintf(bpBase, `contents: ["libfoo"]`)+` |
| 7563 | java_import { |
| 7564 | name: "libfoo", |
| 7565 | jars: ["libfoo.jar"], |
| 7566 | apex_available: [ |
| 7567 | "com.android.myapex", |
| 7568 | "com.android.myapex_compressed", |
| 7569 | ], |
| 7570 | } |
| 7571 | `) |
| 7572 | |
| 7573 | module := result.Module("libfoo", "android_common_com.android.myapex") |
| 7574 | usesLibraryDep := module.(java.UsesLibraryDependency) |
| 7575 | android.AssertPathRelativeToTopEquals(t, "dex jar path", |
| 7576 | "out/soong/.intermediates/com.android.myapex.deapexer/android_common/deapexer/javalib/libfoo.jar", |
| 7577 | usesLibraryDep.DexJarBuildPath().Path()) |
| 7578 | }) |
| 7579 | |
| 7580 | t.Run("java_sdk_library_import", func(t *testing.T) { |
| 7581 | result := preparers.RunTestWithBp(t, |
| 7582 | fmt.Sprintf(bpBase, `contents: ["libfoo"]`)+` |
| 7583 | java_sdk_library_import { |
| 7584 | name: "libfoo", |
| 7585 | public: { |
| 7586 | jars: ["libbar.jar"], |
| 7587 | }, |
| 7588 | apex_available: [ |
| 7589 | "com.android.myapex", |
| 7590 | "com.android.myapex_compressed", |
| 7591 | ], |
| 7592 | compile_dex: true, |
| 7593 | } |
| 7594 | `) |
| 7595 | |
| 7596 | module := result.Module("libfoo", "android_common_com.android.myapex") |
| 7597 | usesLibraryDep := module.(java.UsesLibraryDependency) |
| 7598 | android.AssertPathRelativeToTopEquals(t, "dex jar path", |
| 7599 | "out/soong/.intermediates/com.android.myapex.deapexer/android_common/deapexer/javalib/libfoo.jar", |
| 7600 | usesLibraryDep.DexJarBuildPath().Path()) |
| 7601 | }) |
| 7602 | |
| 7603 | t.Run("prebuilt_bootclasspath_fragment", func(t *testing.T) { |
| 7604 | _ = preparers.RunTestWithBp(t, fmt.Sprintf(bpBase, ` |
| 7605 | image_name: "art", |
| 7606 | contents: ["libfoo"], |
| 7607 | `)+` |
| 7608 | java_sdk_library_import { |
| 7609 | name: "libfoo", |
| 7610 | public: { |
| 7611 | jars: ["libbar.jar"], |
| 7612 | }, |
| 7613 | apex_available: [ |
| 7614 | "com.android.myapex", |
| 7615 | "com.android.myapex_compressed", |
| 7616 | ], |
| 7617 | compile_dex: true, |
| 7618 | } |
| 7619 | `) |
| 7620 | }) |
| 7621 | } |
| 7622 | |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 7623 | func TestUpdatable_should_set_min_sdk_version(t *testing.T) { |
| 7624 | testApexError(t, `"myapex" .*: updatable: updatable APEXes should set min_sdk_version`, ` |
| 7625 | apex { |
| 7626 | name: "myapex", |
| 7627 | key: "myapex.key", |
| 7628 | updatable: true, |
| 7629 | } |
| 7630 | |
| 7631 | apex_key { |
| 7632 | name: "myapex.key", |
| 7633 | public_key: "testkey.avbpubkey", |
| 7634 | private_key: "testkey.pem", |
| 7635 | } |
| 7636 | `) |
| 7637 | } |
| 7638 | |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7639 | func TestUpdatableDefault_should_set_min_sdk_version(t *testing.T) { |
| 7640 | testApexError(t, `"myapex" .*: updatable: updatable APEXes should set min_sdk_version`, ` |
| 7641 | apex { |
| 7642 | name: "myapex", |
| 7643 | key: "myapex.key", |
| 7644 | } |
| 7645 | |
| 7646 | apex_key { |
| 7647 | name: "myapex.key", |
| 7648 | public_key: "testkey.avbpubkey", |
| 7649 | private_key: "testkey.pem", |
| 7650 | } |
| 7651 | `) |
| 7652 | } |
| 7653 | |
Daniel Norman | 6910911 | 2021-12-02 12:52:42 -0800 | [diff] [blame] | 7654 | func TestUpdatable_cannot_be_vendor_apex(t *testing.T) { |
| 7655 | testApexError(t, `"myapex" .*: updatable: vendor APEXes are not updatable`, ` |
| 7656 | apex { |
| 7657 | name: "myapex", |
| 7658 | key: "myapex.key", |
| 7659 | updatable: true, |
| 7660 | soc_specific: true, |
| 7661 | } |
| 7662 | |
| 7663 | apex_key { |
| 7664 | name: "myapex.key", |
| 7665 | public_key: "testkey.avbpubkey", |
| 7666 | private_key: "testkey.pem", |
| 7667 | } |
| 7668 | `) |
| 7669 | } |
| 7670 | |
satayev | b98371c | 2021-06-15 16:49:50 +0100 | [diff] [blame] | 7671 | func TestUpdatable_should_not_set_generate_classpaths_proto(t *testing.T) { |
| 7672 | testApexError(t, `"mysystemserverclasspathfragment" .* it must not set generate_classpaths_proto to false`, ` |
| 7673 | apex { |
| 7674 | name: "myapex", |
| 7675 | key: "myapex.key", |
| 7676 | systemserverclasspath_fragments: [ |
| 7677 | "mysystemserverclasspathfragment", |
| 7678 | ], |
| 7679 | min_sdk_version: "29", |
| 7680 | updatable: true, |
| 7681 | } |
| 7682 | |
| 7683 | apex_key { |
| 7684 | name: "myapex.key", |
| 7685 | public_key: "testkey.avbpubkey", |
| 7686 | private_key: "testkey.pem", |
| 7687 | } |
| 7688 | |
| 7689 | java_library { |
| 7690 | name: "foo", |
| 7691 | srcs: ["b.java"], |
| 7692 | min_sdk_version: "29", |
| 7693 | installable: true, |
| 7694 | apex_available: [ |
| 7695 | "myapex", |
| 7696 | ], |
| 7697 | } |
| 7698 | |
| 7699 | systemserverclasspath_fragment { |
| 7700 | name: "mysystemserverclasspathfragment", |
| 7701 | generate_classpaths_proto: false, |
| 7702 | contents: [ |
| 7703 | "foo", |
| 7704 | ], |
| 7705 | apex_available: [ |
| 7706 | "myapex", |
| 7707 | ], |
| 7708 | } |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7709 | `, |
| 7710 | dexpreopt.FixtureSetApexSystemServerJars("myapex:foo"), |
| 7711 | ) |
satayev | b98371c | 2021-06-15 16:49:50 +0100 | [diff] [blame] | 7712 | } |
| 7713 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7714 | func TestNoUpdatableJarsInBootImage(t *testing.T) { |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7715 | // Set the BootJars in dexpreopt.GlobalConfig and productVariables to the same value. This can |
| 7716 | // result in an invalid configuration as it does not set the ArtApexJars and allows art apex |
| 7717 | // modules to be included in the BootJars. |
| 7718 | prepareSetBootJars := func(bootJars ...string) android.FixturePreparer { |
| 7719 | return android.GroupFixturePreparers( |
| 7720 | dexpreopt.FixtureSetBootJars(bootJars...), |
| 7721 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 7722 | variables.BootJars = android.CreateTestConfiguredJarList(bootJars) |
| 7723 | }), |
| 7724 | ) |
| 7725 | } |
| 7726 | |
| 7727 | // Set the ArtApexJars and BootJars in dexpreopt.GlobalConfig and productVariables all to the |
| 7728 | // same value. This can result in an invalid configuration as it allows non art apex jars to be |
| 7729 | // specified in the ArtApexJars configuration. |
| 7730 | prepareSetArtJars := func(bootJars ...string) android.FixturePreparer { |
| 7731 | return android.GroupFixturePreparers( |
| 7732 | dexpreopt.FixtureSetArtBootJars(bootJars...), |
| 7733 | dexpreopt.FixtureSetBootJars(bootJars...), |
| 7734 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 7735 | variables.BootJars = android.CreateTestConfiguredJarList(bootJars) |
| 7736 | }), |
| 7737 | ) |
| 7738 | } |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7739 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7740 | t.Run("updatable jar from ART apex in the ART boot image => ok", func(t *testing.T) { |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7741 | preparer := android.GroupFixturePreparers( |
| 7742 | java.FixtureConfigureBootJars("com.android.art.debug:some-art-lib"), |
| 7743 | java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib"), |
| 7744 | ) |
| 7745 | fragments := []java.ApexVariantReference{ |
| 7746 | { |
| 7747 | Apex: proptools.StringPtr("com.android.art.debug"), |
| 7748 | Module: proptools.StringPtr("art-bootclasspath-fragment"), |
| 7749 | }, |
| 7750 | { |
| 7751 | Apex: proptools.StringPtr("some-non-updatable-apex"), |
| 7752 | Module: proptools.StringPtr("some-non-updatable-fragment"), |
| 7753 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7754 | } |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7755 | testNoUpdatableJarsInBootImage(t, "", preparer, fragments...) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7756 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7757 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7758 | t.Run("updatable jar from ART apex in the framework boot image => error", func(t *testing.T) { |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7759 | err := `module "some-art-lib" from updatable apexes \["com.android.art.debug"\] is not allowed in the framework boot image` |
| 7760 | // Update the dexpreopt BootJars directly. |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7761 | preparer := android.GroupFixturePreparers( |
| 7762 | prepareSetBootJars("com.android.art.debug:some-art-lib"), |
| 7763 | java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib"), |
| 7764 | ) |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7765 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7766 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7767 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7768 | t.Run("updatable jar from some other apex in the ART boot image => error", func(t *testing.T) { |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 7769 | err := `ArtApexJars expects this to be in apex "some-updatable-apex" but this is only in apexes.*"com.android.art.debug"` |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7770 | // Update the dexpreopt ArtApexJars directly. |
| 7771 | preparer := prepareSetArtJars("some-updatable-apex:some-updatable-apex-lib") |
| 7772 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7773 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7774 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7775 | t.Run("non-updatable jar from some other apex in the ART boot image => error", func(t *testing.T) { |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 7776 | err := `ArtApexJars expects this to be in apex "some-non-updatable-apex" but this is only in apexes.*"com.android.art.debug"` |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7777 | // Update the dexpreopt ArtApexJars directly. |
| 7778 | preparer := prepareSetArtJars("some-non-updatable-apex:some-non-updatable-apex-lib") |
| 7779 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7780 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 7781 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7782 | t.Run("updatable jar from some other apex in the framework boot image => error", func(t *testing.T) { |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7783 | err := `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the framework boot image` |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7784 | preparer := android.GroupFixturePreparers( |
| 7785 | java.FixtureConfigureBootJars("some-updatable-apex:some-updatable-apex-lib"), |
| 7786 | java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib"), |
| 7787 | ) |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7788 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7789 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7790 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7791 | t.Run("non-updatable jar from some other apex in the framework boot image => ok", func(t *testing.T) { |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7792 | preparer := java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib") |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7793 | fragment := java.ApexVariantReference{ |
| 7794 | Apex: proptools.StringPtr("some-non-updatable-apex"), |
| 7795 | Module: proptools.StringPtr("some-non-updatable-fragment"), |
| 7796 | } |
| 7797 | testNoUpdatableJarsInBootImage(t, "", preparer, fragment) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7798 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 7799 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7800 | t.Run("nonexistent jar in the ART boot image => error", func(t *testing.T) { |
Paul Duffin | 8f146b9 | 2021-04-12 17:24:18 +0100 | [diff] [blame] | 7801 | err := `"platform-bootclasspath" depends on undefined module "nonexistent"` |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7802 | preparer := java.FixtureConfigureBootJars("platform:nonexistent") |
| 7803 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7804 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7805 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7806 | t.Run("nonexistent jar in the framework boot image => error", func(t *testing.T) { |
Paul Duffin | 8f146b9 | 2021-04-12 17:24:18 +0100 | [diff] [blame] | 7807 | err := `"platform-bootclasspath" depends on undefined module "nonexistent"` |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7808 | preparer := java.FixtureConfigureBootJars("platform:nonexistent") |
| 7809 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7810 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7811 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7812 | t.Run("platform jar in the ART boot image => error", func(t *testing.T) { |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 7813 | err := `ArtApexJars is invalid as it requests a platform variant of "some-platform-lib"` |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7814 | // Update the dexpreopt ArtApexJars directly. |
| 7815 | preparer := prepareSetArtJars("platform:some-platform-lib") |
| 7816 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7817 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7818 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7819 | t.Run("platform jar in the framework boot image => ok", func(t *testing.T) { |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7820 | preparer := android.GroupFixturePreparers( |
| 7821 | java.FixtureConfigureBootJars("platform:some-platform-lib"), |
| 7822 | java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib"), |
| 7823 | ) |
| 7824 | fragments := []java.ApexVariantReference{ |
| 7825 | { |
| 7826 | Apex: proptools.StringPtr("some-non-updatable-apex"), |
| 7827 | Module: proptools.StringPtr("some-non-updatable-fragment"), |
| 7828 | }, |
| 7829 | } |
| 7830 | testNoUpdatableJarsInBootImage(t, "", preparer, fragments...) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7831 | }) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 7832 | } |
| 7833 | |
| 7834 | func TestDexpreoptAccessDexFilesFromPrebuiltApex(t *testing.T) { |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7835 | preparer := java.FixtureConfigureApexBootJars("myapex:libfoo") |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 7836 | t.Run("prebuilt no source", func(t *testing.T) { |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7837 | fragment := java.ApexVariantReference{ |
| 7838 | Apex: proptools.StringPtr("myapex"), |
| 7839 | Module: proptools.StringPtr("my-bootclasspath-fragment"), |
| 7840 | } |
| 7841 | |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 7842 | testDexpreoptWithApexes(t, ` |
| 7843 | prebuilt_apex { |
| 7844 | name: "myapex" , |
| 7845 | arch: { |
| 7846 | arm64: { |
| 7847 | src: "myapex-arm64.apex", |
| 7848 | }, |
| 7849 | arm: { |
| 7850 | src: "myapex-arm.apex", |
| 7851 | }, |
| 7852 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7853 | exported_bootclasspath_fragments: ["my-bootclasspath-fragment"], |
| 7854 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 7855 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7856 | prebuilt_bootclasspath_fragment { |
| 7857 | name: "my-bootclasspath-fragment", |
| 7858 | contents: ["libfoo"], |
| 7859 | apex_available: ["myapex"], |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 7860 | hidden_api: { |
| 7861 | annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", |
| 7862 | metadata: "my-bootclasspath-fragment/metadata.csv", |
| 7863 | index: "my-bootclasspath-fragment/index.csv", |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 7864 | signature_patterns: "my-bootclasspath-fragment/signature-patterns.csv", |
| 7865 | filtered_stub_flags: "my-bootclasspath-fragment/filtered-stub-flags.csv", |
| 7866 | filtered_flags: "my-bootclasspath-fragment/filtered-flags.csv", |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 7867 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7868 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 7869 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7870 | java_import { |
| 7871 | name: "libfoo", |
| 7872 | jars: ["libfoo.jar"], |
| 7873 | apex_available: ["myapex"], |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7874 | permitted_packages: ["libfoo"], |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7875 | } |
| 7876 | `, "", preparer, fragment) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 7877 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7878 | } |
| 7879 | |
Spandan Das | 440ff96 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 7880 | func testBootJarPermittedPackagesRules(t *testing.T, errmsg, bp string, bootJars []string, rules []android.Rule) { |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7881 | t.Helper() |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7882 | bp += ` |
| 7883 | apex_key { |
| 7884 | name: "myapex.key", |
| 7885 | public_key: "testkey.avbpubkey", |
| 7886 | private_key: "testkey.pem", |
| 7887 | }` |
Paul Duffin | 45338f0 | 2021-03-30 23:07:52 +0100 | [diff] [blame] | 7888 | fs := android.MockFS{ |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7889 | "lib1/src/A.java": nil, |
| 7890 | "lib2/src/B.java": nil, |
| 7891 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 7892 | } |
| 7893 | |
Paul Duffin | 45338f0 | 2021-03-30 23:07:52 +0100 | [diff] [blame] | 7894 | errorHandler := android.FixtureExpectsNoErrors |
| 7895 | if errmsg != "" { |
| 7896 | errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(errmsg) |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 7897 | } |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 7898 | |
Paul Duffin | 45338f0 | 2021-03-30 23:07:52 +0100 | [diff] [blame] | 7899 | android.GroupFixturePreparers( |
| 7900 | android.PrepareForTestWithAndroidBuildComponents, |
| 7901 | java.PrepareForTestWithJavaBuildComponents, |
| 7902 | PrepareForTestWithApexBuildComponents, |
| 7903 | android.PrepareForTestWithNeverallowRules(rules), |
| 7904 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 7905 | apexBootJars := make([]string, 0, len(bootJars)) |
| 7906 | for _, apexBootJar := range bootJars { |
| 7907 | apexBootJars = append(apexBootJars, "myapex:"+apexBootJar) |
Paul Duffin | 45338f0 | 2021-03-30 23:07:52 +0100 | [diff] [blame] | 7908 | } |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 7909 | variables.ApexBootJars = android.CreateTestConfiguredJarList(apexBootJars) |
Paul Duffin | 45338f0 | 2021-03-30 23:07:52 +0100 | [diff] [blame] | 7910 | }), |
| 7911 | fs.AddToFixture(), |
| 7912 | ). |
| 7913 | ExtendWithErrorHandler(errorHandler). |
| 7914 | RunTestWithBp(t, bp) |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7915 | } |
| 7916 | |
| 7917 | func TestApexPermittedPackagesRules(t *testing.T) { |
| 7918 | testcases := []struct { |
Spandan Das | 440ff96 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 7919 | name string |
| 7920 | expectedError string |
| 7921 | bp string |
| 7922 | bootJars []string |
| 7923 | bcpPermittedPackages map[string][]string |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7924 | }{ |
| 7925 | |
| 7926 | { |
| 7927 | name: "Non-Bootclasspath apex jar not satisfying allowed module packages.", |
| 7928 | expectedError: "", |
| 7929 | bp: ` |
| 7930 | java_library { |
| 7931 | name: "bcp_lib1", |
| 7932 | srcs: ["lib1/src/*.java"], |
| 7933 | permitted_packages: ["foo.bar"], |
| 7934 | apex_available: ["myapex"], |
| 7935 | sdk_version: "none", |
| 7936 | system_modules: "none", |
| 7937 | } |
| 7938 | java_library { |
| 7939 | name: "nonbcp_lib2", |
| 7940 | srcs: ["lib2/src/*.java"], |
| 7941 | apex_available: ["myapex"], |
| 7942 | permitted_packages: ["a.b"], |
| 7943 | sdk_version: "none", |
| 7944 | system_modules: "none", |
| 7945 | } |
| 7946 | apex { |
| 7947 | name: "myapex", |
| 7948 | key: "myapex.key", |
| 7949 | java_libs: ["bcp_lib1", "nonbcp_lib2"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7950 | updatable: false, |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7951 | }`, |
| 7952 | bootJars: []string{"bcp_lib1"}, |
Spandan Das | 440ff96 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 7953 | bcpPermittedPackages: map[string][]string{ |
| 7954 | "bcp_lib1": []string{ |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7955 | "foo.bar", |
| 7956 | }, |
| 7957 | }, |
| 7958 | }, |
| 7959 | { |
Anton Hansson | ddf8c1b | 2021-12-23 15:05:38 +0000 | [diff] [blame] | 7960 | name: "Bootclasspath apex jar not satisfying allowed module packages.", |
Spandan Das | 440ff96 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 7961 | expectedError: `(?s)module "bcp_lib2" .* which is restricted because bcp_lib2 bootjar may only use these package prefixes: foo.bar. Please consider the following alternatives:\n 1. If the offending code is from a statically linked library, consider removing that dependency and using an alternative already in the bootclasspath, or perhaps a shared library. 2. Move the offending code into an allowed package.\n 3. Jarjar the offending code. Please be mindful of the potential system health implications of bundling that code, particularly if the offending jar is part of the bootclasspath.`, |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7962 | bp: ` |
| 7963 | java_library { |
| 7964 | name: "bcp_lib1", |
| 7965 | srcs: ["lib1/src/*.java"], |
| 7966 | apex_available: ["myapex"], |
| 7967 | permitted_packages: ["foo.bar"], |
| 7968 | sdk_version: "none", |
| 7969 | system_modules: "none", |
| 7970 | } |
| 7971 | java_library { |
| 7972 | name: "bcp_lib2", |
| 7973 | srcs: ["lib2/src/*.java"], |
| 7974 | apex_available: ["myapex"], |
| 7975 | permitted_packages: ["foo.bar", "bar.baz"], |
| 7976 | sdk_version: "none", |
| 7977 | system_modules: "none", |
| 7978 | } |
| 7979 | apex { |
| 7980 | name: "myapex", |
Remi NGUYEN VAN | 1fdd6ca | 2021-12-02 19:39:35 +0900 | [diff] [blame] | 7981 | key: "myapex.key", |
| 7982 | java_libs: ["bcp_lib1", "bcp_lib2"], |
| 7983 | updatable: false, |
| 7984 | } |
| 7985 | `, |
| 7986 | bootJars: []string{"bcp_lib1", "bcp_lib2"}, |
Spandan Das | 440ff96 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 7987 | bcpPermittedPackages: map[string][]string{ |
| 7988 | "bcp_lib1": []string{ |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7989 | "foo.bar", |
| 7990 | }, |
Spandan Das | 440ff96 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 7991 | "bcp_lib2": []string{ |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7992 | "foo.bar", |
| 7993 | }, |
| 7994 | }, |
| 7995 | }, |
| 7996 | { |
Spandan Das | 440ff96 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 7997 | name: "Updateable Bootclasspath apex jar not satisfying allowed module packages.", |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 7998 | expectedError: "", |
| 7999 | bp: ` |
| 8000 | java_library { |
Spandan Das | 440ff96 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 8001 | name: "bcp_lib_restricted", |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 8002 | srcs: ["lib1/src/*.java"], |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 8003 | apex_available: ["myapex"], |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 8004 | permitted_packages: ["foo.bar"], |
| 8005 | sdk_version: "none", |
Spandan Das | 440ff96 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 8006 | min_sdk_version: "29", |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 8007 | system_modules: "none", |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 8008 | } |
| 8009 | java_library { |
Spandan Das | 440ff96 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 8010 | name: "bcp_lib_unrestricted", |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 8011 | srcs: ["lib2/src/*.java"], |
| 8012 | apex_available: ["myapex"], |
| 8013 | permitted_packages: ["foo.bar", "bar.baz"], |
| 8014 | sdk_version: "none", |
Spandan Das | 440ff96 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 8015 | min_sdk_version: "29", |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 8016 | system_modules: "none", |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 8017 | } |
| 8018 | apex { |
| 8019 | name: "myapex", |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 8020 | key: "myapex.key", |
Spandan Das | 440ff96 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 8021 | java_libs: ["bcp_lib_restricted", "bcp_lib_unrestricted"], |
| 8022 | updatable: true, |
| 8023 | min_sdk_version: "29", |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 8024 | } |
| 8025 | `, |
| 8026 | bootJars: []string{"bcp_lib1", "bcp_lib2"}, |
Spandan Das | 440ff96 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 8027 | bcpPermittedPackages: map[string][]string{ |
| 8028 | "bcp_lib1_non_updateable": []string{ |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 8029 | "foo.bar", |
| 8030 | }, |
Spandan Das | 440ff96 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 8031 | // bcp_lib2_updateable has no entry here since updateable bcp can contain new packages - tracking via an allowlist is not necessary |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 8032 | }, |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 8033 | }, |
| 8034 | } |
| 8035 | for _, tc := range testcases { |
| 8036 | t.Run(tc.name, func(t *testing.T) { |
Spandan Das | 440ff96 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 8037 | rules := createBcpPermittedPackagesRules(tc.bcpPermittedPackages) |
| 8038 | testBootJarPermittedPackagesRules(t, tc.expectedError, tc.bp, tc.bootJars, rules) |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 8039 | }) |
| 8040 | } |
| 8041 | } |
| 8042 | |
| 8043 | func TestTestFor(t *testing.T) { |
| 8044 | ctx := testApex(t, ` |
| 8045 | apex { |
| 8046 | name: "myapex", |
| 8047 | key: "myapex.key", |
| 8048 | native_shared_libs: ["mylib", "myprivlib"], |
| 8049 | updatable: false, |
| 8050 | } |
| 8051 | |
| 8052 | apex_key { |
| 8053 | name: "myapex.key", |
| 8054 | public_key: "testkey.avbpubkey", |
| 8055 | private_key: "testkey.pem", |
| 8056 | } |
| 8057 | |
| 8058 | cc_library { |
| 8059 | name: "mylib", |
| 8060 | srcs: ["mylib.cpp"], |
| 8061 | system_shared_libs: [], |
| 8062 | stl: "none", |
| 8063 | stubs: { |
| 8064 | versions: ["1"], |
| 8065 | }, |
| 8066 | apex_available: ["myapex"], |
| 8067 | } |
| 8068 | |
| 8069 | cc_library { |
| 8070 | name: "myprivlib", |
| 8071 | srcs: ["mylib.cpp"], |
| 8072 | system_shared_libs: [], |
| 8073 | stl: "none", |
| 8074 | apex_available: ["myapex"], |
| 8075 | } |
| 8076 | |
| 8077 | |
| 8078 | cc_test { |
| 8079 | name: "mytest", |
| 8080 | gtest: false, |
| 8081 | srcs: ["mylib.cpp"], |
| 8082 | system_shared_libs: [], |
| 8083 | stl: "none", |
| 8084 | shared_libs: ["mylib", "myprivlib", "mytestlib"], |
| 8085 | test_for: ["myapex"] |
| 8086 | } |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 8087 | |
| 8088 | cc_library { |
| 8089 | name: "mytestlib", |
| 8090 | srcs: ["mylib.cpp"], |
| 8091 | system_shared_libs: [], |
| 8092 | shared_libs: ["mylib", "myprivlib"], |
| 8093 | stl: "none", |
| 8094 | test_for: ["myapex"], |
| 8095 | } |
| 8096 | |
| 8097 | cc_benchmark { |
| 8098 | name: "mybench", |
| 8099 | srcs: ["mylib.cpp"], |
| 8100 | system_shared_libs: [], |
| 8101 | shared_libs: ["mylib", "myprivlib"], |
| 8102 | stl: "none", |
| 8103 | test_for: ["myapex"], |
| 8104 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 8105 | `) |
| 8106 | |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 8107 | ensureLinkedLibIs := func(mod, variant, linkedLib, expectedVariant string) { |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 8108 | ldFlags := strings.Split(ctx.ModuleForTests(mod, variant).Rule("ld").Args["libFlags"], " ") |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 8109 | mylibLdFlags := android.FilterListPred(ldFlags, func(s string) bool { return strings.HasPrefix(s, linkedLib) }) |
| 8110 | android.AssertArrayString(t, "unexpected "+linkedLib+" link library for "+mod, []string{linkedLib + expectedVariant}, mylibLdFlags) |
| 8111 | } |
| 8112 | |
| 8113 | // These modules are tests for the apex, therefore are linked to the |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 8114 | // actual implementation of mylib instead of its stub. |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 8115 | ensureLinkedLibIs("mytest", "android_arm64_armv8-a", "out/soong/.intermediates/mylib/", "android_arm64_armv8-a_shared/mylib.so") |
| 8116 | ensureLinkedLibIs("mytestlib", "android_arm64_armv8-a_shared", "out/soong/.intermediates/mylib/", "android_arm64_armv8-a_shared/mylib.so") |
| 8117 | ensureLinkedLibIs("mybench", "android_arm64_armv8-a", "out/soong/.intermediates/mylib/", "android_arm64_armv8-a_shared/mylib.so") |
| 8118 | } |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 8119 | |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 8120 | func TestIndirectTestFor(t *testing.T) { |
| 8121 | ctx := testApex(t, ` |
| 8122 | apex { |
| 8123 | name: "myapex", |
| 8124 | key: "myapex.key", |
| 8125 | native_shared_libs: ["mylib", "myprivlib"], |
| 8126 | updatable: false, |
| 8127 | } |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 8128 | |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 8129 | apex_key { |
| 8130 | name: "myapex.key", |
| 8131 | public_key: "testkey.avbpubkey", |
| 8132 | private_key: "testkey.pem", |
| 8133 | } |
| 8134 | |
| 8135 | cc_library { |
| 8136 | name: "mylib", |
| 8137 | srcs: ["mylib.cpp"], |
| 8138 | system_shared_libs: [], |
| 8139 | stl: "none", |
| 8140 | stubs: { |
| 8141 | versions: ["1"], |
| 8142 | }, |
| 8143 | apex_available: ["myapex"], |
| 8144 | } |
| 8145 | |
| 8146 | cc_library { |
| 8147 | name: "myprivlib", |
| 8148 | srcs: ["mylib.cpp"], |
| 8149 | system_shared_libs: [], |
| 8150 | stl: "none", |
| 8151 | shared_libs: ["mylib"], |
| 8152 | apex_available: ["myapex"], |
| 8153 | } |
| 8154 | |
| 8155 | cc_library { |
| 8156 | name: "mytestlib", |
| 8157 | srcs: ["mylib.cpp"], |
| 8158 | system_shared_libs: [], |
| 8159 | shared_libs: ["myprivlib"], |
| 8160 | stl: "none", |
| 8161 | test_for: ["myapex"], |
| 8162 | } |
| 8163 | `) |
| 8164 | |
| 8165 | ensureLinkedLibIs := func(mod, variant, linkedLib, expectedVariant string) { |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 8166 | ldFlags := strings.Split(ctx.ModuleForTests(mod, variant).Rule("ld").Args["libFlags"], " ") |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 8167 | mylibLdFlags := android.FilterListPred(ldFlags, func(s string) bool { return strings.HasPrefix(s, linkedLib) }) |
| 8168 | android.AssertArrayString(t, "unexpected "+linkedLib+" link library for "+mod, []string{linkedLib + expectedVariant}, mylibLdFlags) |
| 8169 | } |
| 8170 | |
| 8171 | // The platform variant of mytestlib links to the platform variant of the |
| 8172 | // internal myprivlib. |
| 8173 | ensureLinkedLibIs("mytestlib", "android_arm64_armv8-a_shared", "out/soong/.intermediates/myprivlib/", "android_arm64_armv8-a_shared/myprivlib.so") |
| 8174 | |
| 8175 | // The platform variant of myprivlib links to the platform variant of mylib |
| 8176 | // and bypasses its stubs. |
| 8177 | ensureLinkedLibIs("myprivlib", "android_arm64_armv8-a_shared", "out/soong/.intermediates/mylib/", "android_arm64_armv8-a_shared/mylib.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 8178 | } |
| 8179 | |
Martin Stjernholm | ec00900 | 2021-03-27 15:18:31 +0000 | [diff] [blame] | 8180 | func TestTestForForLibInOtherApex(t *testing.T) { |
| 8181 | // This case is only allowed for known overlapping APEXes, i.e. the ART APEXes. |
| 8182 | _ = testApex(t, ` |
| 8183 | apex { |
| 8184 | name: "com.android.art", |
| 8185 | key: "myapex.key", |
| 8186 | native_shared_libs: ["mylib"], |
| 8187 | updatable: false, |
| 8188 | } |
| 8189 | |
| 8190 | apex { |
| 8191 | name: "com.android.art.debug", |
| 8192 | key: "myapex.key", |
| 8193 | native_shared_libs: ["mylib", "mytestlib"], |
| 8194 | updatable: false, |
| 8195 | } |
| 8196 | |
| 8197 | apex_key { |
| 8198 | name: "myapex.key", |
| 8199 | public_key: "testkey.avbpubkey", |
| 8200 | private_key: "testkey.pem", |
| 8201 | } |
| 8202 | |
| 8203 | cc_library { |
| 8204 | name: "mylib", |
| 8205 | srcs: ["mylib.cpp"], |
| 8206 | system_shared_libs: [], |
| 8207 | stl: "none", |
| 8208 | stubs: { |
| 8209 | versions: ["1"], |
| 8210 | }, |
| 8211 | apex_available: ["com.android.art", "com.android.art.debug"], |
| 8212 | } |
| 8213 | |
| 8214 | cc_library { |
| 8215 | name: "mytestlib", |
| 8216 | srcs: ["mylib.cpp"], |
| 8217 | system_shared_libs: [], |
| 8218 | shared_libs: ["mylib"], |
| 8219 | stl: "none", |
| 8220 | apex_available: ["com.android.art.debug"], |
| 8221 | test_for: ["com.android.art"], |
| 8222 | } |
| 8223 | `, |
| 8224 | android.MockFS{ |
| 8225 | "system/sepolicy/apex/com.android.art-file_contexts": nil, |
| 8226 | "system/sepolicy/apex/com.android.art.debug-file_contexts": nil, |
| 8227 | }.AddToFixture()) |
| 8228 | } |
| 8229 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 8230 | // TODO(jungjw): Move this to proptools |
| 8231 | func intPtr(i int) *int { |
| 8232 | return &i |
| 8233 | } |
| 8234 | |
| 8235 | func TestApexSet(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 8236 | ctx := testApex(t, ` |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 8237 | apex_set { |
| 8238 | name: "myapex", |
| 8239 | set: "myapex.apks", |
| 8240 | filename: "foo_v2.apex", |
| 8241 | overrides: ["foo"], |
| 8242 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 8243 | `, |
| 8244 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 8245 | variables.Platform_sdk_version = intPtr(30) |
| 8246 | }), |
| 8247 | android.FixtureModifyConfig(func(config android.Config) { |
| 8248 | config.Targets[android.Android] = []android.Target{ |
| 8249 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}}, |
| 8250 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}}, |
| 8251 | } |
| 8252 | }), |
| 8253 | ) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 8254 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 8255 | m := ctx.ModuleForTests("myapex.apex.extractor", "android_common") |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 8256 | |
| 8257 | // Check extract_apks tool parameters. |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 8258 | extractedApex := m.Output("extracted/myapex.apks") |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 8259 | actual := extractedApex.Args["abis"] |
| 8260 | expected := "ARMEABI_V7A,ARM64_V8A" |
| 8261 | if actual != expected { |
| 8262 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 8263 | } |
| 8264 | actual = extractedApex.Args["sdk-version"] |
| 8265 | expected = "30" |
| 8266 | if actual != expected { |
| 8267 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 8268 | } |
| 8269 | |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 8270 | m = ctx.ModuleForTests("myapex", "android_common_myapex") |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 8271 | a := m.Module().(*ApexSet) |
| 8272 | expectedOverrides := []string{"foo"} |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 8273 | actualOverrides := android.AndroidMkEntriesForTest(t, ctx, a)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 8274 | if !reflect.DeepEqual(actualOverrides, expectedOverrides) { |
| 8275 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES - expected %q vs actual %q", expectedOverrides, actualOverrides) |
| 8276 | } |
| 8277 | } |
| 8278 | |
Anton Hansson | 144be1f | 2022-11-25 14:06:46 +0000 | [diff] [blame] | 8279 | func TestApexSet_NativeBridge(t *testing.T) { |
| 8280 | ctx := testApex(t, ` |
| 8281 | apex_set { |
| 8282 | name: "myapex", |
| 8283 | set: "myapex.apks", |
| 8284 | filename: "foo_v2.apex", |
| 8285 | overrides: ["foo"], |
| 8286 | } |
| 8287 | `, |
| 8288 | android.FixtureModifyConfig(func(config android.Config) { |
| 8289 | config.Targets[android.Android] = []android.Target{ |
| 8290 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "", Abi: []string{"x86_64"}}}, |
| 8291 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, NativeBridge: android.NativeBridgeEnabled}, |
| 8292 | } |
| 8293 | }), |
| 8294 | ) |
| 8295 | |
| 8296 | m := ctx.ModuleForTests("myapex.apex.extractor", "android_common") |
| 8297 | |
| 8298 | // Check extract_apks tool parameters. No native bridge arch expected |
| 8299 | extractedApex := m.Output("extracted/myapex.apks") |
| 8300 | android.AssertStringEquals(t, "abis", "X86_64", extractedApex.Args["abis"]) |
| 8301 | } |
| 8302 | |
Jiyong Park | 7d95a51 | 2020-05-10 15:16:24 +0900 | [diff] [blame] | 8303 | func TestNoStaticLinkingToStubsLib(t *testing.T) { |
| 8304 | testApexError(t, `.*required by "mylib" is a native library providing stub.*`, ` |
| 8305 | apex { |
| 8306 | name: "myapex", |
| 8307 | key: "myapex.key", |
| 8308 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 8309 | updatable: false, |
Jiyong Park | 7d95a51 | 2020-05-10 15:16:24 +0900 | [diff] [blame] | 8310 | } |
| 8311 | |
| 8312 | apex_key { |
| 8313 | name: "myapex.key", |
| 8314 | public_key: "testkey.avbpubkey", |
| 8315 | private_key: "testkey.pem", |
| 8316 | } |
| 8317 | |
| 8318 | cc_library { |
| 8319 | name: "mylib", |
| 8320 | srcs: ["mylib.cpp"], |
| 8321 | static_libs: ["otherlib"], |
| 8322 | system_shared_libs: [], |
| 8323 | stl: "none", |
| 8324 | apex_available: [ "myapex" ], |
| 8325 | } |
| 8326 | |
| 8327 | cc_library { |
| 8328 | name: "otherlib", |
| 8329 | srcs: ["mylib.cpp"], |
| 8330 | system_shared_libs: [], |
| 8331 | stl: "none", |
| 8332 | stubs: { |
| 8333 | versions: ["1", "2", "3"], |
| 8334 | }, |
| 8335 | apex_available: [ "myapex" ], |
| 8336 | } |
| 8337 | `) |
| 8338 | } |
| 8339 | |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 8340 | func TestApexKeysTxt(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 8341 | ctx := testApex(t, ` |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 8342 | apex { |
| 8343 | name: "myapex", |
| 8344 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 8345 | updatable: false, |
Jooyung Han | 09c11ad | 2021-10-27 03:45:31 +0900 | [diff] [blame] | 8346 | custom_sign_tool: "sign_myapex", |
| 8347 | } |
| 8348 | |
| 8349 | apex_key { |
| 8350 | name: "myapex.key", |
| 8351 | public_key: "testkey.avbpubkey", |
| 8352 | private_key: "testkey.pem", |
| 8353 | } |
| 8354 | `) |
| 8355 | |
| 8356 | apexKeysText := ctx.SingletonForTests("apex_keys_text") |
| 8357 | content := apexKeysText.MaybeDescription("apexkeys.txt").BuildParams.Args["content"] |
| 8358 | ensureContains(t, content, `name="myapex.apex" public_key="vendor/foo/devkeys/testkey.avbpubkey" private_key="vendor/foo/devkeys/testkey.pem" container_certificate="vendor/foo/devkeys/test.x509.pem" container_private_key="vendor/foo/devkeys/test.pk8" partition="system_ext" sign_tool="sign_myapex"`) |
| 8359 | } |
| 8360 | |
| 8361 | func TestApexKeysTxtOverrides(t *testing.T) { |
| 8362 | ctx := testApex(t, ` |
| 8363 | apex { |
| 8364 | name: "myapex", |
| 8365 | key: "myapex.key", |
| 8366 | updatable: false, |
| 8367 | custom_sign_tool: "sign_myapex", |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 8368 | } |
| 8369 | |
| 8370 | apex_key { |
| 8371 | name: "myapex.key", |
| 8372 | public_key: "testkey.avbpubkey", |
| 8373 | private_key: "testkey.pem", |
| 8374 | } |
| 8375 | |
| 8376 | prebuilt_apex { |
| 8377 | name: "myapex", |
| 8378 | prefer: true, |
| 8379 | arch: { |
| 8380 | arm64: { |
| 8381 | src: "myapex-arm64.apex", |
| 8382 | }, |
| 8383 | arm: { |
| 8384 | src: "myapex-arm.apex", |
| 8385 | }, |
| 8386 | }, |
| 8387 | } |
| 8388 | |
| 8389 | apex_set { |
| 8390 | name: "myapex_set", |
| 8391 | set: "myapex.apks", |
| 8392 | filename: "myapex_set.apex", |
| 8393 | overrides: ["myapex"], |
| 8394 | } |
| 8395 | `) |
| 8396 | |
| 8397 | apexKeysText := ctx.SingletonForTests("apex_keys_text") |
| 8398 | content := apexKeysText.MaybeDescription("apexkeys.txt").BuildParams.Args["content"] |
| 8399 | ensureContains(t, content, `name="myapex_set.apex" public_key="PRESIGNED" private_key="PRESIGNED" container_certificate="PRESIGNED" container_private_key="PRESIGNED" partition="system"`) |
Jiyong Park | 03a7f3e | 2020-06-18 19:34:42 +0900 | [diff] [blame] | 8400 | ensureContains(t, content, `name="myapex.apex" public_key="PRESIGNED" private_key="PRESIGNED" container_certificate="PRESIGNED" container_private_key="PRESIGNED" partition="system"`) |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 8401 | } |
| 8402 | |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 8403 | func TestAllowedFiles(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 8404 | ctx := testApex(t, ` |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 8405 | apex { |
| 8406 | name: "myapex", |
| 8407 | key: "myapex.key", |
| 8408 | apps: ["app"], |
| 8409 | allowed_files: "allowed.txt", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 8410 | updatable: false, |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 8411 | } |
| 8412 | |
| 8413 | apex_key { |
| 8414 | name: "myapex.key", |
| 8415 | public_key: "testkey.avbpubkey", |
| 8416 | private_key: "testkey.pem", |
| 8417 | } |
| 8418 | |
| 8419 | android_app { |
| 8420 | name: "app", |
| 8421 | srcs: ["foo/bar/MyClass.java"], |
| 8422 | package_name: "foo", |
| 8423 | sdk_version: "none", |
| 8424 | system_modules: "none", |
| 8425 | apex_available: [ "myapex" ], |
| 8426 | } |
| 8427 | `, withFiles(map[string][]byte{ |
| 8428 | "sub/Android.bp": []byte(` |
| 8429 | override_apex { |
| 8430 | name: "override_myapex", |
| 8431 | base: "myapex", |
| 8432 | apps: ["override_app"], |
| 8433 | allowed_files: ":allowed", |
| 8434 | } |
| 8435 | // Overridable "path" property should be referenced indirectly |
| 8436 | filegroup { |
| 8437 | name: "allowed", |
| 8438 | srcs: ["allowed.txt"], |
| 8439 | } |
| 8440 | override_android_app { |
| 8441 | name: "override_app", |
| 8442 | base: "app", |
| 8443 | package_name: "bar", |
| 8444 | } |
| 8445 | `), |
| 8446 | })) |
| 8447 | |
| 8448 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("diffApexContentRule") |
| 8449 | if expected, actual := "allowed.txt", rule.Args["allowed_files_file"]; expected != actual { |
| 8450 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 8451 | } |
| 8452 | |
| 8453 | rule2 := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Rule("diffApexContentRule") |
| 8454 | if expected, actual := "sub/allowed.txt", rule2.Args["allowed_files_file"]; expected != actual { |
| 8455 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 8456 | } |
| 8457 | } |
| 8458 | |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 8459 | func TestNonPreferredPrebuiltDependency(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 8460 | testApex(t, ` |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 8461 | apex { |
| 8462 | name: "myapex", |
| 8463 | key: "myapex.key", |
| 8464 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 8465 | updatable: false, |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 8466 | } |
| 8467 | |
| 8468 | apex_key { |
| 8469 | name: "myapex.key", |
| 8470 | public_key: "testkey.avbpubkey", |
| 8471 | private_key: "testkey.pem", |
| 8472 | } |
| 8473 | |
| 8474 | cc_library { |
| 8475 | name: "mylib", |
| 8476 | srcs: ["mylib.cpp"], |
| 8477 | stubs: { |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 8478 | versions: ["current"], |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 8479 | }, |
| 8480 | apex_available: ["myapex"], |
| 8481 | } |
| 8482 | |
| 8483 | cc_prebuilt_library_shared { |
| 8484 | name: "mylib", |
| 8485 | prefer: false, |
| 8486 | srcs: ["prebuilt.so"], |
| 8487 | stubs: { |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 8488 | versions: ["current"], |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 8489 | }, |
| 8490 | apex_available: ["myapex"], |
| 8491 | } |
| 8492 | `) |
| 8493 | } |
| 8494 | |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 8495 | func TestCompressedApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 8496 | ctx := testApex(t, ` |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 8497 | apex { |
| 8498 | name: "myapex", |
| 8499 | key: "myapex.key", |
| 8500 | compressible: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 8501 | updatable: false, |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 8502 | } |
| 8503 | apex_key { |
| 8504 | name: "myapex.key", |
| 8505 | public_key: "testkey.avbpubkey", |
| 8506 | private_key: "testkey.pem", |
| 8507 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 8508 | `, |
| 8509 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 8510 | variables.CompressedApex = proptools.BoolPtr(true) |
| 8511 | }), |
| 8512 | ) |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 8513 | |
| 8514 | compressRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("compressRule") |
| 8515 | ensureContains(t, compressRule.Output.String(), "myapex.capex.unsigned") |
| 8516 | |
| 8517 | signApkRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("sign compressedApex") |
| 8518 | ensureEquals(t, signApkRule.Input.String(), compressRule.Output.String()) |
| 8519 | |
| 8520 | // Make sure output of bundle is .capex |
| 8521 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 8522 | ensureContains(t, ab.outputFile.String(), "myapex.capex") |
| 8523 | |
| 8524 | // Verify android.mk rules |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 8525 | data := android.AndroidMkDataForTest(t, ctx, ab) |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 8526 | var builder strings.Builder |
| 8527 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 8528 | androidMk := builder.String() |
| 8529 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.capex\n") |
| 8530 | } |
| 8531 | |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 8532 | func TestPreferredPrebuiltSharedLibDep(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 8533 | ctx := testApex(t, ` |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 8534 | apex { |
| 8535 | name: "myapex", |
| 8536 | key: "myapex.key", |
| 8537 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 8538 | updatable: false, |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 8539 | } |
| 8540 | |
| 8541 | apex_key { |
| 8542 | name: "myapex.key", |
| 8543 | public_key: "testkey.avbpubkey", |
| 8544 | private_key: "testkey.pem", |
| 8545 | } |
| 8546 | |
| 8547 | cc_library { |
| 8548 | name: "mylib", |
| 8549 | srcs: ["mylib.cpp"], |
| 8550 | apex_available: ["myapex"], |
| 8551 | shared_libs: ["otherlib"], |
| 8552 | system_shared_libs: [], |
| 8553 | } |
| 8554 | |
| 8555 | cc_library { |
| 8556 | name: "otherlib", |
| 8557 | srcs: ["mylib.cpp"], |
| 8558 | stubs: { |
| 8559 | versions: ["current"], |
| 8560 | }, |
| 8561 | } |
| 8562 | |
| 8563 | cc_prebuilt_library_shared { |
| 8564 | name: "otherlib", |
| 8565 | prefer: true, |
| 8566 | srcs: ["prebuilt.so"], |
| 8567 | stubs: { |
| 8568 | versions: ["current"], |
| 8569 | }, |
| 8570 | } |
| 8571 | `) |
| 8572 | |
| 8573 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 8574 | data := android.AndroidMkDataForTest(t, ctx, ab) |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 8575 | var builder strings.Builder |
| 8576 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 8577 | androidMk := builder.String() |
| 8578 | |
| 8579 | // The make level dependency needs to be on otherlib - prebuilt_otherlib isn't |
| 8580 | // a thing there. |
| 8581 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += otherlib\n") |
| 8582 | } |
| 8583 | |
Jiyong Park | e386754 | 2020-12-03 17:28:25 +0900 | [diff] [blame] | 8584 | func TestExcludeDependency(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 8585 | ctx := testApex(t, ` |
Jiyong Park | e386754 | 2020-12-03 17:28:25 +0900 | [diff] [blame] | 8586 | apex { |
| 8587 | name: "myapex", |
| 8588 | key: "myapex.key", |
| 8589 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 8590 | updatable: false, |
Jiyong Park | e386754 | 2020-12-03 17:28:25 +0900 | [diff] [blame] | 8591 | } |
| 8592 | |
| 8593 | apex_key { |
| 8594 | name: "myapex.key", |
| 8595 | public_key: "testkey.avbpubkey", |
| 8596 | private_key: "testkey.pem", |
| 8597 | } |
| 8598 | |
| 8599 | cc_library { |
| 8600 | name: "mylib", |
| 8601 | srcs: ["mylib.cpp"], |
| 8602 | system_shared_libs: [], |
| 8603 | stl: "none", |
| 8604 | apex_available: ["myapex"], |
| 8605 | shared_libs: ["mylib2"], |
| 8606 | target: { |
| 8607 | apex: { |
| 8608 | exclude_shared_libs: ["mylib2"], |
| 8609 | }, |
| 8610 | }, |
| 8611 | } |
| 8612 | |
| 8613 | cc_library { |
| 8614 | name: "mylib2", |
| 8615 | srcs: ["mylib.cpp"], |
| 8616 | system_shared_libs: [], |
| 8617 | stl: "none", |
| 8618 | } |
| 8619 | `) |
| 8620 | |
| 8621 | // Check if mylib is linked to mylib2 for the non-apex target |
| 8622 | ldFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 8623 | ensureContains(t, ldFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
| 8624 | |
| 8625 | // Make sure that the link doesn't occur for the apex target |
| 8626 | ldFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
| 8627 | ensureNotContains(t, ldFlags, "mylib2/android_arm64_armv8-a_shared_apex10000/mylib2.so") |
| 8628 | |
| 8629 | // It shouldn't appear in the copy cmd as well. |
| 8630 | copyCmds := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule").Args["copy_commands"] |
| 8631 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 8632 | } |
| 8633 | |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 8634 | func TestPrebuiltStubLibDep(t *testing.T) { |
| 8635 | bpBase := ` |
| 8636 | apex { |
| 8637 | name: "myapex", |
| 8638 | key: "myapex.key", |
| 8639 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 8640 | updatable: false, |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 8641 | } |
| 8642 | apex_key { |
| 8643 | name: "myapex.key", |
| 8644 | public_key: "testkey.avbpubkey", |
| 8645 | private_key: "testkey.pem", |
| 8646 | } |
| 8647 | cc_library { |
| 8648 | name: "mylib", |
| 8649 | srcs: ["mylib.cpp"], |
| 8650 | apex_available: ["myapex"], |
| 8651 | shared_libs: ["stublib"], |
| 8652 | system_shared_libs: [], |
| 8653 | } |
| 8654 | apex { |
| 8655 | name: "otherapex", |
| 8656 | enabled: %s, |
| 8657 | key: "myapex.key", |
| 8658 | native_shared_libs: ["stublib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 8659 | updatable: false, |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 8660 | } |
| 8661 | ` |
| 8662 | |
| 8663 | stublibSourceBp := ` |
| 8664 | cc_library { |
| 8665 | name: "stublib", |
| 8666 | srcs: ["mylib.cpp"], |
| 8667 | apex_available: ["otherapex"], |
| 8668 | system_shared_libs: [], |
| 8669 | stl: "none", |
| 8670 | stubs: { |
| 8671 | versions: ["1"], |
| 8672 | }, |
| 8673 | } |
| 8674 | ` |
| 8675 | |
| 8676 | stublibPrebuiltBp := ` |
| 8677 | cc_prebuilt_library_shared { |
| 8678 | name: "stublib", |
| 8679 | srcs: ["prebuilt.so"], |
| 8680 | apex_available: ["otherapex"], |
| 8681 | stubs: { |
| 8682 | versions: ["1"], |
| 8683 | }, |
| 8684 | %s |
| 8685 | } |
| 8686 | ` |
| 8687 | |
| 8688 | tests := []struct { |
| 8689 | name string |
| 8690 | stublibBp string |
| 8691 | usePrebuilt bool |
| 8692 | modNames []string // Modules to collect AndroidMkEntries for |
| 8693 | otherApexEnabled []string |
| 8694 | }{ |
| 8695 | { |
| 8696 | name: "only_source", |
| 8697 | stublibBp: stublibSourceBp, |
| 8698 | usePrebuilt: false, |
| 8699 | modNames: []string{"stublib"}, |
| 8700 | otherApexEnabled: []string{"true", "false"}, |
| 8701 | }, |
| 8702 | { |
| 8703 | name: "source_preferred", |
| 8704 | stublibBp: stublibSourceBp + fmt.Sprintf(stublibPrebuiltBp, ""), |
| 8705 | usePrebuilt: false, |
| 8706 | modNames: []string{"stublib", "prebuilt_stublib"}, |
| 8707 | otherApexEnabled: []string{"true", "false"}, |
| 8708 | }, |
| 8709 | { |
| 8710 | name: "prebuilt_preferred", |
| 8711 | stublibBp: stublibSourceBp + fmt.Sprintf(stublibPrebuiltBp, "prefer: true,"), |
| 8712 | usePrebuilt: true, |
| 8713 | modNames: []string{"stublib", "prebuilt_stublib"}, |
| 8714 | otherApexEnabled: []string{"false"}, // No "true" since APEX cannot depend on prebuilt. |
| 8715 | }, |
| 8716 | { |
| 8717 | name: "only_prebuilt", |
| 8718 | stublibBp: fmt.Sprintf(stublibPrebuiltBp, ""), |
| 8719 | usePrebuilt: true, |
| 8720 | modNames: []string{"stublib"}, |
| 8721 | otherApexEnabled: []string{"false"}, // No "true" since APEX cannot depend on prebuilt. |
| 8722 | }, |
| 8723 | } |
| 8724 | |
| 8725 | for _, test := range tests { |
| 8726 | t.Run(test.name, func(t *testing.T) { |
| 8727 | for _, otherApexEnabled := range test.otherApexEnabled { |
| 8728 | t.Run("otherapex_enabled_"+otherApexEnabled, func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 8729 | ctx := testApex(t, fmt.Sprintf(bpBase, otherApexEnabled)+test.stublibBp) |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 8730 | |
| 8731 | type modAndMkEntries struct { |
| 8732 | mod *cc.Module |
| 8733 | mkEntries android.AndroidMkEntries |
| 8734 | } |
| 8735 | entries := []*modAndMkEntries{} |
| 8736 | |
| 8737 | // Gather shared lib modules that are installable |
| 8738 | for _, modName := range test.modNames { |
| 8739 | for _, variant := range ctx.ModuleVariantsForTests(modName) { |
| 8740 | if !strings.HasPrefix(variant, "android_arm64_armv8-a_shared") { |
| 8741 | continue |
| 8742 | } |
| 8743 | mod := ctx.ModuleForTests(modName, variant).Module().(*cc.Module) |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 8744 | if !mod.Enabled() || mod.IsHideFromMake() { |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 8745 | continue |
| 8746 | } |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 8747 | for _, ent := range android.AndroidMkEntriesForTest(t, ctx, mod) { |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 8748 | if ent.Disabled { |
| 8749 | continue |
| 8750 | } |
| 8751 | entries = append(entries, &modAndMkEntries{ |
| 8752 | mod: mod, |
| 8753 | mkEntries: ent, |
| 8754 | }) |
| 8755 | } |
| 8756 | } |
| 8757 | } |
| 8758 | |
| 8759 | var entry *modAndMkEntries = nil |
| 8760 | for _, ent := range entries { |
| 8761 | if strings.Join(ent.mkEntries.EntryMap["LOCAL_MODULE"], ",") == "stublib" { |
| 8762 | if entry != nil { |
| 8763 | t.Errorf("More than one AndroidMk entry for \"stublib\": %s and %s", entry.mod, ent.mod) |
| 8764 | } else { |
| 8765 | entry = ent |
| 8766 | } |
| 8767 | } |
| 8768 | } |
| 8769 | |
| 8770 | if entry == nil { |
| 8771 | t.Errorf("AndroidMk entry for \"stublib\" missing") |
| 8772 | } else { |
| 8773 | isPrebuilt := entry.mod.Prebuilt() != nil |
| 8774 | if isPrebuilt != test.usePrebuilt { |
| 8775 | t.Errorf("Wrong module for \"stublib\" AndroidMk entry: got prebuilt %t, want prebuilt %t", isPrebuilt, test.usePrebuilt) |
| 8776 | } |
| 8777 | if !entry.mod.IsStubs() { |
| 8778 | t.Errorf("Module for \"stublib\" AndroidMk entry isn't a stub: %s", entry.mod) |
| 8779 | } |
| 8780 | if entry.mkEntries.EntryMap["LOCAL_NOT_AVAILABLE_FOR_PLATFORM"] != nil { |
| 8781 | t.Errorf("AndroidMk entry for \"stublib\" has LOCAL_NOT_AVAILABLE_FOR_PLATFORM set: %+v", entry.mkEntries) |
| 8782 | } |
Jiyong Park | 892a98f | 2020-12-14 09:20:00 +0900 | [diff] [blame] | 8783 | cflags := entry.mkEntries.EntryMap["LOCAL_EXPORT_CFLAGS"] |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 8784 | expected := "-D__STUBLIB_API__=10000" |
Jiyong Park | 892a98f | 2020-12-14 09:20:00 +0900 | [diff] [blame] | 8785 | if !android.InList(expected, cflags) { |
| 8786 | t.Errorf("LOCAL_EXPORT_CFLAGS expected to have %q, but got %q", expected, cflags) |
| 8787 | } |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 8788 | } |
| 8789 | }) |
| 8790 | } |
| 8791 | }) |
| 8792 | } |
| 8793 | } |
| 8794 | |
Martin Stjernholm | df298b3 | 2021-05-21 20:57:29 +0100 | [diff] [blame] | 8795 | func TestHostApexInHostOnlyBuild(t *testing.T) { |
| 8796 | testApex(t, ` |
| 8797 | apex { |
| 8798 | name: "myapex", |
| 8799 | host_supported: true, |
| 8800 | key: "myapex.key", |
| 8801 | updatable: false, |
| 8802 | payload_type: "zip", |
| 8803 | } |
| 8804 | apex_key { |
| 8805 | name: "myapex.key", |
| 8806 | public_key: "testkey.avbpubkey", |
| 8807 | private_key: "testkey.pem", |
| 8808 | } |
| 8809 | `, |
| 8810 | android.FixtureModifyConfig(func(config android.Config) { |
| 8811 | // We may not have device targets in all builds, e.g. in |
| 8812 | // prebuilts/build-tools/build-prebuilts.sh |
| 8813 | config.Targets[android.Android] = []android.Target{} |
| 8814 | })) |
| 8815 | } |
| 8816 | |
Colin Cross | c33e521 | 2021-05-25 18:16:02 -0700 | [diff] [blame] | 8817 | func TestApexJavaCoverage(t *testing.T) { |
| 8818 | bp := ` |
| 8819 | apex { |
| 8820 | name: "myapex", |
| 8821 | key: "myapex.key", |
| 8822 | java_libs: ["mylib"], |
| 8823 | bootclasspath_fragments: ["mybootclasspathfragment"], |
| 8824 | systemserverclasspath_fragments: ["mysystemserverclasspathfragment"], |
| 8825 | updatable: false, |
| 8826 | } |
| 8827 | |
| 8828 | apex_key { |
| 8829 | name: "myapex.key", |
| 8830 | public_key: "testkey.avbpubkey", |
| 8831 | private_key: "testkey.pem", |
| 8832 | } |
| 8833 | |
| 8834 | java_library { |
| 8835 | name: "mylib", |
| 8836 | srcs: ["mylib.java"], |
| 8837 | apex_available: ["myapex"], |
| 8838 | compile_dex: true, |
| 8839 | } |
| 8840 | |
| 8841 | bootclasspath_fragment { |
| 8842 | name: "mybootclasspathfragment", |
| 8843 | contents: ["mybootclasspathlib"], |
| 8844 | apex_available: ["myapex"], |
| 8845 | } |
| 8846 | |
| 8847 | java_library { |
| 8848 | name: "mybootclasspathlib", |
| 8849 | srcs: ["mybootclasspathlib.java"], |
| 8850 | apex_available: ["myapex"], |
| 8851 | compile_dex: true, |
| 8852 | } |
| 8853 | |
| 8854 | systemserverclasspath_fragment { |
| 8855 | name: "mysystemserverclasspathfragment", |
| 8856 | contents: ["mysystemserverclasspathlib"], |
| 8857 | apex_available: ["myapex"], |
| 8858 | } |
| 8859 | |
| 8860 | java_library { |
| 8861 | name: "mysystemserverclasspathlib", |
| 8862 | srcs: ["mysystemserverclasspathlib.java"], |
| 8863 | apex_available: ["myapex"], |
| 8864 | compile_dex: true, |
| 8865 | } |
| 8866 | ` |
| 8867 | |
| 8868 | result := android.GroupFixturePreparers( |
| 8869 | PrepareForTestWithApexBuildComponents, |
| 8870 | prepareForTestWithMyapex, |
| 8871 | java.PrepareForTestWithJavaDefaultModules, |
| 8872 | android.PrepareForTestWithAndroidBuildComponents, |
| 8873 | android.FixtureWithRootAndroidBp(bp), |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 8874 | dexpreopt.FixtureSetApexBootJars("myapex:mybootclasspathlib"), |
| 8875 | dexpreopt.FixtureSetApexSystemServerJars("myapex:mysystemserverclasspathlib"), |
Colin Cross | c33e521 | 2021-05-25 18:16:02 -0700 | [diff] [blame] | 8876 | android.FixtureMergeEnv(map[string]string{ |
| 8877 | "EMMA_INSTRUMENT": "true", |
| 8878 | }), |
| 8879 | ).RunTest(t) |
| 8880 | |
| 8881 | // Make sure jacoco ran on both mylib and mybootclasspathlib |
| 8882 | if result.ModuleForTests("mylib", "android_common_apex10000").MaybeRule("jacoco").Rule == nil { |
| 8883 | t.Errorf("Failed to find jacoco rule for mylib") |
| 8884 | } |
| 8885 | if result.ModuleForTests("mybootclasspathlib", "android_common_apex10000").MaybeRule("jacoco").Rule == nil { |
| 8886 | t.Errorf("Failed to find jacoco rule for mybootclasspathlib") |
| 8887 | } |
| 8888 | if result.ModuleForTests("mysystemserverclasspathlib", "android_common_apex10000").MaybeRule("jacoco").Rule == nil { |
| 8889 | t.Errorf("Failed to find jacoco rule for mysystemserverclasspathlib") |
| 8890 | } |
| 8891 | } |
| 8892 | |
Jiyong Park | 192600a | 2021-08-03 07:52:17 +0000 | [diff] [blame] | 8893 | func TestProhibitStaticExecutable(t *testing.T) { |
| 8894 | testApexError(t, `executable mybin is static`, ` |
| 8895 | apex { |
| 8896 | name: "myapex", |
| 8897 | key: "myapex.key", |
| 8898 | binaries: ["mybin"], |
| 8899 | min_sdk_version: "29", |
| 8900 | } |
| 8901 | |
| 8902 | apex_key { |
| 8903 | name: "myapex.key", |
| 8904 | public_key: "testkey.avbpubkey", |
| 8905 | private_key: "testkey.pem", |
| 8906 | } |
| 8907 | |
| 8908 | cc_binary { |
| 8909 | name: "mybin", |
| 8910 | srcs: ["mylib.cpp"], |
| 8911 | relative_install_path: "foo/bar", |
| 8912 | static_executable: true, |
| 8913 | system_shared_libs: [], |
| 8914 | stl: "none", |
| 8915 | apex_available: [ "myapex" ], |
Jiyong Park | d12979d | 2021-08-03 13:36:09 +0900 | [diff] [blame] | 8916 | min_sdk_version: "29", |
| 8917 | } |
| 8918 | `) |
| 8919 | |
| 8920 | testApexError(t, `executable mybin.rust is static`, ` |
| 8921 | apex { |
| 8922 | name: "myapex", |
| 8923 | key: "myapex.key", |
| 8924 | binaries: ["mybin.rust"], |
| 8925 | min_sdk_version: "29", |
| 8926 | } |
| 8927 | |
| 8928 | apex_key { |
| 8929 | name: "myapex.key", |
| 8930 | public_key: "testkey.avbpubkey", |
| 8931 | private_key: "testkey.pem", |
| 8932 | } |
| 8933 | |
| 8934 | rust_binary { |
| 8935 | name: "mybin.rust", |
| 8936 | srcs: ["foo.rs"], |
| 8937 | static_executable: true, |
| 8938 | apex_available: ["myapex"], |
| 8939 | min_sdk_version: "29", |
Jiyong Park | 192600a | 2021-08-03 07:52:17 +0000 | [diff] [blame] | 8940 | } |
| 8941 | `) |
| 8942 | } |
| 8943 | |
Jiakai Zhang | 470b7e2 | 2021-09-30 09:34:26 +0000 | [diff] [blame] | 8944 | func TestAndroidMk_DexpreoptBuiltInstalledForApex(t *testing.T) { |
| 8945 | ctx := testApex(t, ` |
| 8946 | apex { |
| 8947 | name: "myapex", |
| 8948 | key: "myapex.key", |
| 8949 | updatable: false, |
| 8950 | java_libs: ["foo"], |
| 8951 | } |
| 8952 | |
| 8953 | apex_key { |
| 8954 | name: "myapex.key", |
| 8955 | public_key: "testkey.avbpubkey", |
| 8956 | private_key: "testkey.pem", |
| 8957 | } |
| 8958 | |
| 8959 | java_library { |
| 8960 | name: "foo", |
| 8961 | srcs: ["foo.java"], |
| 8962 | apex_available: ["myapex"], |
| 8963 | installable: true, |
| 8964 | } |
| 8965 | `, |
| 8966 | dexpreopt.FixtureSetApexSystemServerJars("myapex:foo"), |
| 8967 | ) |
| 8968 | |
| 8969 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 8970 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
| 8971 | var builder strings.Builder |
| 8972 | data.Custom(&builder, apexBundle.BaseModuleName(), "TARGET_", "", data) |
| 8973 | androidMk := builder.String() |
| 8974 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += foo-dexpreopt-arm64-apex@myapex@javalib@foo.jar@classes.odex foo-dexpreopt-arm64-apex@myapex@javalib@foo.jar@classes.vdex") |
| 8975 | } |
| 8976 | |
| 8977 | func TestAndroidMk_DexpreoptBuiltInstalledForApex_Prebuilt(t *testing.T) { |
| 8978 | ctx := testApex(t, ` |
| 8979 | prebuilt_apex { |
| 8980 | name: "myapex", |
| 8981 | arch: { |
| 8982 | arm64: { |
| 8983 | src: "myapex-arm64.apex", |
| 8984 | }, |
| 8985 | arm: { |
| 8986 | src: "myapex-arm.apex", |
| 8987 | }, |
| 8988 | }, |
| 8989 | exported_java_libs: ["foo"], |
| 8990 | } |
| 8991 | |
| 8992 | java_import { |
| 8993 | name: "foo", |
| 8994 | jars: ["foo.jar"], |
Jiakai Zhang | 28bc9a8 | 2021-12-20 15:08:57 +0000 | [diff] [blame] | 8995 | apex_available: ["myapex"], |
Jiakai Zhang | 470b7e2 | 2021-09-30 09:34:26 +0000 | [diff] [blame] | 8996 | } |
| 8997 | `, |
| 8998 | dexpreopt.FixtureSetApexSystemServerJars("myapex:foo"), |
| 8999 | ) |
| 9000 | |
| 9001 | prebuilt := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*Prebuilt) |
| 9002 | entriesList := android.AndroidMkEntriesForTest(t, ctx, prebuilt) |
| 9003 | mainModuleEntries := entriesList[0] |
| 9004 | android.AssertArrayString(t, |
| 9005 | "LOCAL_REQUIRED_MODULES", |
| 9006 | mainModuleEntries.EntryMap["LOCAL_REQUIRED_MODULES"], |
| 9007 | []string{ |
| 9008 | "foo-dexpreopt-arm64-apex@myapex@javalib@foo.jar@classes.odex", |
| 9009 | "foo-dexpreopt-arm64-apex@myapex@javalib@foo.jar@classes.vdex", |
| 9010 | }) |
| 9011 | } |
| 9012 | |
Jiyong Park | cacc4f3 | 2021-10-28 14:26:03 +0900 | [diff] [blame] | 9013 | func TestAndroidMk_RequiredModules(t *testing.T) { |
| 9014 | ctx := testApex(t, ` |
| 9015 | apex { |
| 9016 | name: "myapex", |
| 9017 | key: "myapex.key", |
| 9018 | updatable: false, |
| 9019 | java_libs: ["foo"], |
| 9020 | required: ["otherapex"], |
| 9021 | } |
| 9022 | |
| 9023 | apex { |
| 9024 | name: "otherapex", |
| 9025 | key: "myapex.key", |
| 9026 | updatable: false, |
| 9027 | java_libs: ["foo"], |
| 9028 | required: ["otherapex"], |
| 9029 | } |
| 9030 | |
| 9031 | apex_key { |
| 9032 | name: "myapex.key", |
| 9033 | public_key: "testkey.avbpubkey", |
| 9034 | private_key: "testkey.pem", |
| 9035 | } |
| 9036 | |
| 9037 | java_library { |
| 9038 | name: "foo", |
| 9039 | srcs: ["foo.java"], |
| 9040 | apex_available: ["myapex", "otherapex"], |
| 9041 | installable: true, |
| 9042 | } |
| 9043 | `) |
| 9044 | |
| 9045 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 9046 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
| 9047 | var builder strings.Builder |
| 9048 | data.Custom(&builder, apexBundle.BaseModuleName(), "TARGET_", "", data) |
| 9049 | androidMk := builder.String() |
| 9050 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += otherapex") |
| 9051 | } |
| 9052 | |
Jiakai Zhang | d70dff7 | 2022-02-24 15:06:05 +0000 | [diff] [blame] | 9053 | func TestAndroidMk_RequiredDeps(t *testing.T) { |
| 9054 | ctx := testApex(t, ` |
| 9055 | apex { |
| 9056 | name: "myapex", |
| 9057 | key: "myapex.key", |
| 9058 | updatable: false, |
| 9059 | } |
| 9060 | |
| 9061 | apex_key { |
| 9062 | name: "myapex.key", |
| 9063 | public_key: "testkey.avbpubkey", |
| 9064 | private_key: "testkey.pem", |
| 9065 | } |
| 9066 | `) |
| 9067 | |
| 9068 | bundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 9069 | bundle.requiredDeps = append(bundle.requiredDeps, "foo") |
| 9070 | data := android.AndroidMkDataForTest(t, ctx, bundle) |
| 9071 | var builder strings.Builder |
| 9072 | data.Custom(&builder, bundle.BaseModuleName(), "TARGET_", "", data) |
| 9073 | androidMk := builder.String() |
| 9074 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += foo") |
| 9075 | |
| 9076 | flattenedBundle := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
| 9077 | flattenedBundle.requiredDeps = append(flattenedBundle.requiredDeps, "foo") |
| 9078 | flattenedData := android.AndroidMkDataForTest(t, ctx, flattenedBundle) |
| 9079 | var flattenedBuilder strings.Builder |
| 9080 | flattenedData.Custom(&flattenedBuilder, flattenedBundle.BaseModuleName(), "TARGET_", "", flattenedData) |
| 9081 | flattenedAndroidMk := flattenedBuilder.String() |
| 9082 | ensureContains(t, flattenedAndroidMk, "LOCAL_REQUIRED_MODULES += foo") |
| 9083 | } |
| 9084 | |
Jooyung Han | a6d3667 | 2022-02-24 13:58:07 +0900 | [diff] [blame] | 9085 | func TestApexOutputFileProducer(t *testing.T) { |
| 9086 | for _, tc := range []struct { |
| 9087 | name string |
| 9088 | ref string |
| 9089 | expected_data []string |
| 9090 | }{ |
| 9091 | { |
| 9092 | name: "test_using_output", |
| 9093 | ref: ":myapex", |
| 9094 | expected_data: []string{"out/soong/.intermediates/myapex/android_common_myapex_image/myapex.capex:myapex.capex"}, |
| 9095 | }, |
| 9096 | { |
| 9097 | name: "test_using_apex", |
| 9098 | ref: ":myapex{.apex}", |
| 9099 | expected_data: []string{"out/soong/.intermediates/myapex/android_common_myapex_image/myapex.apex:myapex.apex"}, |
| 9100 | }, |
| 9101 | } { |
| 9102 | t.Run(tc.name, func(t *testing.T) { |
| 9103 | ctx := testApex(t, ` |
| 9104 | apex { |
| 9105 | name: "myapex", |
| 9106 | key: "myapex.key", |
| 9107 | compressible: true, |
| 9108 | updatable: false, |
| 9109 | } |
| 9110 | |
| 9111 | apex_key { |
| 9112 | name: "myapex.key", |
| 9113 | public_key: "testkey.avbpubkey", |
| 9114 | private_key: "testkey.pem", |
| 9115 | } |
| 9116 | |
| 9117 | java_test { |
| 9118 | name: "`+tc.name+`", |
| 9119 | srcs: ["a.java"], |
| 9120 | data: ["`+tc.ref+`"], |
| 9121 | } |
| 9122 | `, |
| 9123 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 9124 | variables.CompressedApex = proptools.BoolPtr(true) |
| 9125 | })) |
| 9126 | javaTest := ctx.ModuleForTests(tc.name, "android_common").Module().(*java.Test) |
| 9127 | data := android.AndroidMkEntriesForTest(t, ctx, javaTest)[0].EntryMap["LOCAL_COMPATIBILITY_SUPPORT_FILES"] |
| 9128 | android.AssertStringPathsRelativeToTopEquals(t, "data", ctx.Config(), tc.expected_data, data) |
| 9129 | }) |
| 9130 | } |
| 9131 | } |
| 9132 | |
satayev | 758968a | 2021-12-06 11:42:40 +0000 | [diff] [blame] | 9133 | func TestSdkLibraryCanHaveHigherMinSdkVersion(t *testing.T) { |
| 9134 | preparer := android.GroupFixturePreparers( |
| 9135 | PrepareForTestWithApexBuildComponents, |
| 9136 | prepareForTestWithMyapex, |
| 9137 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 9138 | java.PrepareForTestWithJavaDefaultModules, |
| 9139 | android.PrepareForTestWithAndroidBuildComponents, |
| 9140 | dexpreopt.FixtureSetApexBootJars("myapex:mybootclasspathlib"), |
| 9141 | dexpreopt.FixtureSetApexSystemServerJars("myapex:mysystemserverclasspathlib"), |
| 9142 | ) |
| 9143 | |
| 9144 | // Test java_sdk_library in bootclasspath_fragment may define higher min_sdk_version than the apex |
| 9145 | t.Run("bootclasspath_fragment jar has higher min_sdk_version than apex", func(t *testing.T) { |
| 9146 | preparer.RunTestWithBp(t, ` |
| 9147 | apex { |
| 9148 | name: "myapex", |
| 9149 | key: "myapex.key", |
| 9150 | bootclasspath_fragments: ["mybootclasspathfragment"], |
| 9151 | min_sdk_version: "30", |
| 9152 | updatable: false, |
| 9153 | } |
| 9154 | |
| 9155 | apex_key { |
| 9156 | name: "myapex.key", |
| 9157 | public_key: "testkey.avbpubkey", |
| 9158 | private_key: "testkey.pem", |
| 9159 | } |
| 9160 | |
| 9161 | bootclasspath_fragment { |
| 9162 | name: "mybootclasspathfragment", |
| 9163 | contents: ["mybootclasspathlib"], |
| 9164 | apex_available: ["myapex"], |
| 9165 | } |
| 9166 | |
| 9167 | java_sdk_library { |
| 9168 | name: "mybootclasspathlib", |
| 9169 | srcs: ["mybootclasspathlib.java"], |
| 9170 | apex_available: ["myapex"], |
| 9171 | compile_dex: true, |
| 9172 | unsafe_ignore_missing_latest_api: true, |
| 9173 | min_sdk_version: "31", |
| 9174 | static_libs: ["util"], |
| 9175 | } |
| 9176 | |
| 9177 | java_library { |
| 9178 | name: "util", |
| 9179 | srcs: ["a.java"], |
| 9180 | apex_available: ["myapex"], |
| 9181 | min_sdk_version: "31", |
| 9182 | static_libs: ["another_util"], |
| 9183 | } |
| 9184 | |
| 9185 | java_library { |
| 9186 | name: "another_util", |
| 9187 | srcs: ["a.java"], |
| 9188 | min_sdk_version: "31", |
| 9189 | apex_available: ["myapex"], |
| 9190 | } |
| 9191 | `) |
| 9192 | }) |
| 9193 | |
| 9194 | // Test java_sdk_library in systemserverclasspath_fragment may define higher min_sdk_version than the apex |
| 9195 | t.Run("systemserverclasspath_fragment jar has higher min_sdk_version than apex", func(t *testing.T) { |
| 9196 | preparer.RunTestWithBp(t, ` |
| 9197 | apex { |
| 9198 | name: "myapex", |
| 9199 | key: "myapex.key", |
| 9200 | systemserverclasspath_fragments: ["mysystemserverclasspathfragment"], |
| 9201 | min_sdk_version: "30", |
| 9202 | updatable: false, |
| 9203 | } |
| 9204 | |
| 9205 | apex_key { |
| 9206 | name: "myapex.key", |
| 9207 | public_key: "testkey.avbpubkey", |
| 9208 | private_key: "testkey.pem", |
| 9209 | } |
| 9210 | |
| 9211 | systemserverclasspath_fragment { |
| 9212 | name: "mysystemserverclasspathfragment", |
| 9213 | contents: ["mysystemserverclasspathlib"], |
| 9214 | apex_available: ["myapex"], |
| 9215 | } |
| 9216 | |
| 9217 | java_sdk_library { |
| 9218 | name: "mysystemserverclasspathlib", |
| 9219 | srcs: ["mysystemserverclasspathlib.java"], |
| 9220 | apex_available: ["myapex"], |
| 9221 | compile_dex: true, |
| 9222 | min_sdk_version: "32", |
| 9223 | unsafe_ignore_missing_latest_api: true, |
| 9224 | static_libs: ["util"], |
| 9225 | } |
| 9226 | |
| 9227 | java_library { |
| 9228 | name: "util", |
| 9229 | srcs: ["a.java"], |
| 9230 | apex_available: ["myapex"], |
| 9231 | min_sdk_version: "31", |
| 9232 | static_libs: ["another_util"], |
| 9233 | } |
| 9234 | |
| 9235 | java_library { |
| 9236 | name: "another_util", |
| 9237 | srcs: ["a.java"], |
| 9238 | min_sdk_version: "31", |
| 9239 | apex_available: ["myapex"], |
| 9240 | } |
| 9241 | `) |
| 9242 | }) |
| 9243 | |
| 9244 | t.Run("bootclasspath_fragment jar must set min_sdk_version", func(t *testing.T) { |
| 9245 | preparer.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "mybootclasspathlib".*must set min_sdk_version`)). |
| 9246 | RunTestWithBp(t, ` |
| 9247 | apex { |
| 9248 | name: "myapex", |
| 9249 | key: "myapex.key", |
| 9250 | bootclasspath_fragments: ["mybootclasspathfragment"], |
| 9251 | min_sdk_version: "30", |
| 9252 | updatable: false, |
| 9253 | } |
| 9254 | |
| 9255 | apex_key { |
| 9256 | name: "myapex.key", |
| 9257 | public_key: "testkey.avbpubkey", |
| 9258 | private_key: "testkey.pem", |
| 9259 | } |
| 9260 | |
| 9261 | bootclasspath_fragment { |
| 9262 | name: "mybootclasspathfragment", |
| 9263 | contents: ["mybootclasspathlib"], |
| 9264 | apex_available: ["myapex"], |
| 9265 | } |
| 9266 | |
| 9267 | java_sdk_library { |
| 9268 | name: "mybootclasspathlib", |
| 9269 | srcs: ["mybootclasspathlib.java"], |
| 9270 | apex_available: ["myapex"], |
| 9271 | compile_dex: true, |
| 9272 | unsafe_ignore_missing_latest_api: true, |
| 9273 | } |
| 9274 | `) |
| 9275 | }) |
| 9276 | |
| 9277 | t.Run("systemserverclasspath_fragment jar must set min_sdk_version", func(t *testing.T) { |
| 9278 | preparer.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "mysystemserverclasspathlib".*must set min_sdk_version`)). |
| 9279 | RunTestWithBp(t, ` |
| 9280 | apex { |
| 9281 | name: "myapex", |
| 9282 | key: "myapex.key", |
| 9283 | systemserverclasspath_fragments: ["mysystemserverclasspathfragment"], |
| 9284 | min_sdk_version: "30", |
| 9285 | updatable: false, |
| 9286 | } |
| 9287 | |
| 9288 | apex_key { |
| 9289 | name: "myapex.key", |
| 9290 | public_key: "testkey.avbpubkey", |
| 9291 | private_key: "testkey.pem", |
| 9292 | } |
| 9293 | |
| 9294 | systemserverclasspath_fragment { |
| 9295 | name: "mysystemserverclasspathfragment", |
| 9296 | contents: ["mysystemserverclasspathlib"], |
| 9297 | apex_available: ["myapex"], |
| 9298 | } |
| 9299 | |
| 9300 | java_sdk_library { |
| 9301 | name: "mysystemserverclasspathlib", |
| 9302 | srcs: ["mysystemserverclasspathlib.java"], |
| 9303 | apex_available: ["myapex"], |
| 9304 | compile_dex: true, |
| 9305 | unsafe_ignore_missing_latest_api: true, |
| 9306 | } |
| 9307 | `) |
| 9308 | }) |
| 9309 | } |
| 9310 | |
Jiakai Zhang | 6decef9 | 2022-01-12 17:56:19 +0000 | [diff] [blame] | 9311 | // Verifies that the APEX depends on all the Make modules in the list. |
| 9312 | func ensureContainsRequiredDeps(t *testing.T, ctx *android.TestContext, moduleName, variant string, deps []string) { |
| 9313 | a := ctx.ModuleForTests(moduleName, variant).Module().(*apexBundle) |
| 9314 | for _, dep := range deps { |
| 9315 | android.AssertStringListContains(t, "", a.requiredDeps, dep) |
| 9316 | } |
| 9317 | } |
| 9318 | |
| 9319 | // Verifies that the APEX does not depend on any of the Make modules in the list. |
| 9320 | func ensureDoesNotContainRequiredDeps(t *testing.T, ctx *android.TestContext, moduleName, variant string, deps []string) { |
| 9321 | a := ctx.ModuleForTests(moduleName, variant).Module().(*apexBundle) |
| 9322 | for _, dep := range deps { |
| 9323 | android.AssertStringListDoesNotContain(t, "", a.requiredDeps, dep) |
| 9324 | } |
| 9325 | } |
| 9326 | |
Spandan Das | 6677325 | 2022-01-15 00:23:18 +0000 | [diff] [blame] | 9327 | func TestApexStrictUpdtabilityLint(t *testing.T) { |
| 9328 | bpTemplate := ` |
| 9329 | apex { |
| 9330 | name: "myapex", |
| 9331 | key: "myapex.key", |
| 9332 | java_libs: ["myjavalib"], |
| 9333 | updatable: %v, |
| 9334 | min_sdk_version: "29", |
| 9335 | } |
| 9336 | apex_key { |
| 9337 | name: "myapex.key", |
| 9338 | } |
| 9339 | java_library { |
| 9340 | name: "myjavalib", |
| 9341 | srcs: ["MyClass.java"], |
| 9342 | apex_available: [ "myapex" ], |
| 9343 | lint: { |
| 9344 | strict_updatability_linting: %v, |
| 9345 | }, |
| 9346 | sdk_version: "current", |
| 9347 | min_sdk_version: "29", |
| 9348 | } |
| 9349 | ` |
| 9350 | fs := android.MockFS{ |
| 9351 | "lint-baseline.xml": nil, |
| 9352 | } |
| 9353 | |
| 9354 | testCases := []struct { |
| 9355 | testCaseName string |
| 9356 | apexUpdatable bool |
| 9357 | javaStrictUpdtabilityLint bool |
| 9358 | lintFileExists bool |
| 9359 | disallowedFlagExpected bool |
| 9360 | }{ |
| 9361 | { |
| 9362 | testCaseName: "lint-baseline.xml does not exist, no disallowed flag necessary in lint cmd", |
| 9363 | apexUpdatable: true, |
| 9364 | javaStrictUpdtabilityLint: true, |
| 9365 | lintFileExists: false, |
| 9366 | disallowedFlagExpected: false, |
| 9367 | }, |
| 9368 | { |
| 9369 | testCaseName: "non-updatable apex respects strict_updatability of javalib", |
| 9370 | apexUpdatable: false, |
| 9371 | javaStrictUpdtabilityLint: false, |
| 9372 | lintFileExists: true, |
| 9373 | disallowedFlagExpected: false, |
| 9374 | }, |
| 9375 | { |
| 9376 | testCaseName: "non-updatable apex respects strict updatability of javalib", |
| 9377 | apexUpdatable: false, |
| 9378 | javaStrictUpdtabilityLint: true, |
| 9379 | lintFileExists: true, |
| 9380 | disallowedFlagExpected: true, |
| 9381 | }, |
| 9382 | { |
| 9383 | testCaseName: "updatable apex sets strict updatability of javalib to true", |
| 9384 | apexUpdatable: true, |
| 9385 | javaStrictUpdtabilityLint: false, // will be set to true by mutator |
| 9386 | lintFileExists: true, |
| 9387 | disallowedFlagExpected: true, |
| 9388 | }, |
| 9389 | } |
| 9390 | |
| 9391 | for _, testCase := range testCases { |
| 9392 | bp := fmt.Sprintf(bpTemplate, testCase.apexUpdatable, testCase.javaStrictUpdtabilityLint) |
| 9393 | fixtures := []android.FixturePreparer{} |
| 9394 | if testCase.lintFileExists { |
| 9395 | fixtures = append(fixtures, fs.AddToFixture()) |
| 9396 | } |
| 9397 | |
| 9398 | result := testApex(t, bp, fixtures...) |
| 9399 | myjavalib := result.ModuleForTests("myjavalib", "android_common_apex29") |
| 9400 | sboxProto := android.RuleBuilderSboxProtoForTests(t, myjavalib.Output("lint.sbox.textproto")) |
| 9401 | disallowedFlagActual := strings.Contains(*sboxProto.Commands[0].Command, "--baseline lint-baseline.xml --disallowed_issues NewApi") |
| 9402 | |
| 9403 | if disallowedFlagActual != testCase.disallowedFlagExpected { |
| 9404 | t.Errorf("Failed testcase: %v \nActual lint cmd: %v", testCase.testCaseName, *sboxProto.Commands[0].Command) |
| 9405 | } |
| 9406 | } |
| 9407 | } |
| 9408 | |
Spandan Das | d9c23ab | 2022-02-10 02:34:13 +0000 | [diff] [blame] | 9409 | func TestUpdatabilityLintSkipLibcore(t *testing.T) { |
| 9410 | bp := ` |
| 9411 | apex { |
| 9412 | name: "myapex", |
| 9413 | key: "myapex.key", |
| 9414 | java_libs: ["myjavalib"], |
| 9415 | updatable: true, |
| 9416 | min_sdk_version: "29", |
| 9417 | } |
| 9418 | apex_key { |
| 9419 | name: "myapex.key", |
| 9420 | } |
| 9421 | java_library { |
| 9422 | name: "myjavalib", |
| 9423 | srcs: ["MyClass.java"], |
| 9424 | apex_available: [ "myapex" ], |
| 9425 | sdk_version: "current", |
| 9426 | min_sdk_version: "29", |
| 9427 | } |
| 9428 | ` |
| 9429 | |
| 9430 | testCases := []struct { |
| 9431 | testCaseName string |
| 9432 | moduleDirectory string |
| 9433 | disallowedFlagExpected bool |
| 9434 | }{ |
| 9435 | { |
| 9436 | testCaseName: "lintable module defined outside libcore", |
| 9437 | moduleDirectory: "", |
| 9438 | disallowedFlagExpected: true, |
| 9439 | }, |
| 9440 | { |
| 9441 | testCaseName: "lintable module defined in libcore root directory", |
| 9442 | moduleDirectory: "libcore/", |
| 9443 | disallowedFlagExpected: false, |
| 9444 | }, |
| 9445 | { |
| 9446 | testCaseName: "lintable module defined in libcore child directory", |
| 9447 | moduleDirectory: "libcore/childdir/", |
| 9448 | disallowedFlagExpected: true, |
| 9449 | }, |
| 9450 | } |
| 9451 | |
| 9452 | for _, testCase := range testCases { |
| 9453 | lintFileCreator := android.FixtureAddTextFile(testCase.moduleDirectory+"lint-baseline.xml", "") |
| 9454 | bpFileCreator := android.FixtureAddTextFile(testCase.moduleDirectory+"Android.bp", bp) |
| 9455 | result := testApex(t, "", lintFileCreator, bpFileCreator) |
| 9456 | myjavalib := result.ModuleForTests("myjavalib", "android_common_apex29") |
| 9457 | sboxProto := android.RuleBuilderSboxProtoForTests(t, myjavalib.Output("lint.sbox.textproto")) |
| 9458 | cmdFlags := fmt.Sprintf("--baseline %vlint-baseline.xml --disallowed_issues NewApi", testCase.moduleDirectory) |
| 9459 | disallowedFlagActual := strings.Contains(*sboxProto.Commands[0].Command, cmdFlags) |
| 9460 | |
| 9461 | if disallowedFlagActual != testCase.disallowedFlagExpected { |
| 9462 | t.Errorf("Failed testcase: %v \nActual lint cmd: %v", testCase.testCaseName, *sboxProto.Commands[0].Command) |
| 9463 | } |
| 9464 | } |
| 9465 | } |
| 9466 | |
Spandan Das | 6677325 | 2022-01-15 00:23:18 +0000 | [diff] [blame] | 9467 | // checks transtive deps of an apex coming from bootclasspath_fragment |
| 9468 | func TestApexStrictUpdtabilityLintBcpFragmentDeps(t *testing.T) { |
| 9469 | bp := ` |
| 9470 | apex { |
| 9471 | name: "myapex", |
| 9472 | key: "myapex.key", |
| 9473 | bootclasspath_fragments: ["mybootclasspathfragment"], |
| 9474 | updatable: true, |
| 9475 | min_sdk_version: "29", |
| 9476 | } |
| 9477 | apex_key { |
| 9478 | name: "myapex.key", |
| 9479 | } |
| 9480 | bootclasspath_fragment { |
| 9481 | name: "mybootclasspathfragment", |
| 9482 | contents: ["myjavalib"], |
| 9483 | apex_available: ["myapex"], |
| 9484 | } |
| 9485 | java_library { |
| 9486 | name: "myjavalib", |
| 9487 | srcs: ["MyClass.java"], |
| 9488 | apex_available: [ "myapex" ], |
| 9489 | sdk_version: "current", |
| 9490 | min_sdk_version: "29", |
| 9491 | compile_dex: true, |
| 9492 | } |
| 9493 | ` |
| 9494 | fs := android.MockFS{ |
| 9495 | "lint-baseline.xml": nil, |
| 9496 | } |
| 9497 | |
| 9498 | result := testApex(t, bp, dexpreopt.FixtureSetApexBootJars("myapex:myjavalib"), fs.AddToFixture()) |
| 9499 | myjavalib := result.ModuleForTests("myjavalib", "android_common_apex29") |
| 9500 | sboxProto := android.RuleBuilderSboxProtoForTests(t, myjavalib.Output("lint.sbox.textproto")) |
| 9501 | if !strings.Contains(*sboxProto.Commands[0].Command, "--baseline lint-baseline.xml --disallowed_issues NewApi") { |
| 9502 | t.Errorf("Strict updabality lint missing in myjavalib coming from bootclasspath_fragment mybootclasspath-fragment\nActual lint cmd: %v", *sboxProto.Commands[0].Command) |
| 9503 | } |
| 9504 | } |
| 9505 | |
Spandan Das | 91250b1 | 2022-05-06 22:12:55 +0000 | [diff] [blame] | 9506 | // updatable apexes should propagate updatable=true to its apps |
| 9507 | func TestUpdatableApexEnforcesAppUpdatability(t *testing.T) { |
| 9508 | bp := ` |
| 9509 | apex { |
| 9510 | name: "myapex", |
| 9511 | key: "myapex.key", |
| 9512 | updatable: %v, |
| 9513 | apps: [ |
| 9514 | "myapp", |
| 9515 | ], |
| 9516 | min_sdk_version: "30", |
| 9517 | } |
| 9518 | apex_key { |
| 9519 | name: "myapex.key", |
| 9520 | } |
| 9521 | android_app { |
| 9522 | name: "myapp", |
| 9523 | updatable: %v, |
| 9524 | apex_available: [ |
| 9525 | "myapex", |
| 9526 | ], |
| 9527 | sdk_version: "current", |
| 9528 | min_sdk_version: "30", |
| 9529 | } |
| 9530 | ` |
| 9531 | testCases := []struct { |
| 9532 | name string |
| 9533 | apex_is_updatable_bp bool |
| 9534 | app_is_updatable_bp bool |
| 9535 | app_is_updatable_expected bool |
| 9536 | }{ |
| 9537 | { |
| 9538 | name: "Non-updatable apex respects updatable property of non-updatable app", |
| 9539 | apex_is_updatable_bp: false, |
| 9540 | app_is_updatable_bp: false, |
| 9541 | app_is_updatable_expected: false, |
| 9542 | }, |
| 9543 | { |
| 9544 | name: "Non-updatable apex respects updatable property of updatable app", |
| 9545 | apex_is_updatable_bp: false, |
| 9546 | app_is_updatable_bp: true, |
| 9547 | app_is_updatable_expected: true, |
| 9548 | }, |
| 9549 | { |
| 9550 | name: "Updatable apex respects updatable property of updatable app", |
| 9551 | apex_is_updatable_bp: true, |
| 9552 | app_is_updatable_bp: true, |
| 9553 | app_is_updatable_expected: true, |
| 9554 | }, |
| 9555 | { |
| 9556 | name: "Updatable apex sets updatable=true on non-updatable app", |
| 9557 | apex_is_updatable_bp: true, |
| 9558 | app_is_updatable_bp: false, |
| 9559 | app_is_updatable_expected: true, |
| 9560 | }, |
| 9561 | } |
| 9562 | for _, testCase := range testCases { |
| 9563 | result := testApex(t, fmt.Sprintf(bp, testCase.apex_is_updatable_bp, testCase.app_is_updatable_bp)) |
| 9564 | myapp := result.ModuleForTests("myapp", "android_common").Module().(*java.AndroidApp) |
| 9565 | android.AssertBoolEquals(t, testCase.name, testCase.app_is_updatable_expected, myapp.Updatable()) |
| 9566 | } |
| 9567 | } |
| 9568 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 9569 | func TestMain(m *testing.M) { |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 9570 | os.Exit(m.Run()) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 9571 | } |