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 | eefabcf | 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, |
| 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 | "build/make/core/proguard.flags": nil, |
| 206 | "build/make/core/proguard_basic_keeps.flags": nil, |
| 207 | "dummy.txt": nil, |
| 208 | "baz": nil, |
| 209 | "bar/baz": nil, |
| 210 | "testdata/baz": nil, |
| 211 | "AppSet.apks": nil, |
| 212 | "foo.rs": nil, |
| 213 | "libfoo.jar": nil, |
| 214 | "libbar.jar": nil, |
| 215 | }, |
| 216 | ), |
| 217 | |
| 218 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 219 | variables.DeviceVndkVersion = proptools.StringPtr("current") |
| 220 | variables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test") |
| 221 | variables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"} |
| 222 | variables.Platform_sdk_codename = proptools.StringPtr("Q") |
| 223 | variables.Platform_sdk_final = proptools.BoolPtr(false) |
Pedro Loureiro | c362142 | 2021-09-28 15:40:23 +0000 | [diff] [blame] | 224 | // "Tiramisu" needs to be in the next line for compatibility with soong code, |
| 225 | // not because of these tests specifically (it's not used by the tests) |
| 226 | variables.Platform_version_active_codenames = []string{"Q", "Tiramisu"} |
Jiyong Park | f58c46e | 2021-04-01 21:35:20 +0900 | [diff] [blame] | 227 | variables.Platform_vndk_version = proptools.StringPtr("29") |
Paul Duffin | 37aad60 | 2021-03-08 09:47:16 +0000 | [diff] [blame] | 228 | }), |
| 229 | ) |
| 230 | |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 231 | var prepareForTestWithMyapex = android.FixtureMergeMockFs(android.MockFS{ |
| 232 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 233 | }) |
| 234 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 235 | // ensure that 'result' equals 'expected' |
| 236 | func ensureEquals(t *testing.T, result string, expected string) { |
| 237 | t.Helper() |
| 238 | if result != expected { |
| 239 | t.Errorf("%q != %q", expected, result) |
| 240 | } |
| 241 | } |
| 242 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 243 | // ensure that 'result' contains 'expected' |
| 244 | func ensureContains(t *testing.T, result string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 245 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 246 | if !strings.Contains(result, expected) { |
| 247 | t.Errorf("%q is not found in %q", expected, result) |
| 248 | } |
| 249 | } |
| 250 | |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 251 | // ensure that 'result' contains 'expected' exactly one time |
| 252 | func ensureContainsOnce(t *testing.T, result string, expected string) { |
| 253 | t.Helper() |
| 254 | count := strings.Count(result, expected) |
| 255 | if count != 1 { |
| 256 | t.Errorf("%q is found %d times (expected 1 time) in %q", expected, count, result) |
| 257 | } |
| 258 | } |
| 259 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 260 | // ensures that 'result' does not contain 'notExpected' |
| 261 | func ensureNotContains(t *testing.T, result string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 262 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 263 | if strings.Contains(result, notExpected) { |
| 264 | t.Errorf("%q is found in %q", notExpected, result) |
| 265 | } |
| 266 | } |
| 267 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 268 | func ensureMatches(t *testing.T, result string, expectedRex string) { |
| 269 | ok, err := regexp.MatchString(expectedRex, result) |
| 270 | if err != nil { |
| 271 | t.Fatalf("regexp failure trying to match %s against `%s` expression: %s", result, expectedRex, err) |
| 272 | return |
| 273 | } |
| 274 | if !ok { |
| 275 | t.Errorf("%s does not match regular expession %s", result, expectedRex) |
| 276 | } |
| 277 | } |
| 278 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 279 | func ensureListContains(t *testing.T, result []string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 280 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 281 | if !android.InList(expected, result) { |
| 282 | t.Errorf("%q is not found in %v", expected, result) |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | func ensureListNotContains(t *testing.T, result []string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 287 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 288 | if android.InList(notExpected, result) { |
| 289 | t.Errorf("%q is found in %v", notExpected, result) |
| 290 | } |
| 291 | } |
| 292 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 293 | func ensureListEmpty(t *testing.T, result []string) { |
| 294 | t.Helper() |
| 295 | if len(result) > 0 { |
| 296 | t.Errorf("%q is expected to be empty", result) |
| 297 | } |
| 298 | } |
| 299 | |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 300 | func ensureListNotEmpty(t *testing.T, result []string) { |
| 301 | t.Helper() |
| 302 | if len(result) == 0 { |
| 303 | t.Errorf("%q is expected to be not empty", result) |
| 304 | } |
| 305 | } |
| 306 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 307 | // Minimal test |
| 308 | func TestBasicApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 309 | ctx := testApex(t, ` |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 310 | apex_defaults { |
| 311 | name: "myapex-defaults", |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 312 | manifest: ":myapex.manifest", |
| 313 | androidManifest: ":myapex.androidmanifest", |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 314 | key: "myapex.key", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 315 | binaries: ["foo.rust"], |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 316 | native_shared_libs: [ |
| 317 | "mylib", |
| 318 | "libfoo.ffi", |
| 319 | ], |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 320 | rust_dyn_libs: ["libfoo.dylib.rust"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 321 | multilib: { |
| 322 | both: { |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 323 | binaries: ["foo"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 324 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 325 | }, |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 326 | java_libs: [ |
| 327 | "myjar", |
| 328 | "myjar_dex", |
| 329 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 330 | updatable: false, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 331 | } |
| 332 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 333 | apex { |
| 334 | name: "myapex", |
| 335 | defaults: ["myapex-defaults"], |
| 336 | } |
| 337 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 338 | apex_key { |
| 339 | name: "myapex.key", |
| 340 | public_key: "testkey.avbpubkey", |
| 341 | private_key: "testkey.pem", |
| 342 | } |
| 343 | |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 344 | filegroup { |
| 345 | name: "myapex.manifest", |
| 346 | srcs: ["apex_manifest.json"], |
| 347 | } |
| 348 | |
| 349 | filegroup { |
| 350 | name: "myapex.androidmanifest", |
| 351 | srcs: ["AndroidManifest.xml"], |
| 352 | } |
| 353 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 354 | cc_library { |
| 355 | name: "mylib", |
| 356 | srcs: ["mylib.cpp"], |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 357 | shared_libs: [ |
| 358 | "mylib2", |
| 359 | "libbar.ffi", |
| 360 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 361 | system_shared_libs: [], |
| 362 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 363 | // TODO: remove //apex_available:platform |
| 364 | apex_available: [ |
| 365 | "//apex_available:platform", |
| 366 | "myapex", |
| 367 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 368 | } |
| 369 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 370 | cc_binary { |
| 371 | name: "foo", |
| 372 | srcs: ["mylib.cpp"], |
| 373 | compile_multilib: "both", |
| 374 | multilib: { |
| 375 | lib32: { |
| 376 | suffix: "32", |
| 377 | }, |
| 378 | lib64: { |
| 379 | suffix: "64", |
| 380 | }, |
| 381 | }, |
| 382 | symlinks: ["foo_link_"], |
| 383 | symlink_preferred_arch: true, |
| 384 | system_shared_libs: [], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 385 | stl: "none", |
Yifan Hong | d22a84a | 2020-07-28 17:37:46 -0700 | [diff] [blame] | 386 | apex_available: [ "myapex", "com.android.gki.*" ], |
| 387 | } |
| 388 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 389 | rust_binary { |
Artur Satayev | 533b98c | 2021-03-11 18:03:42 +0000 | [diff] [blame] | 390 | name: "foo.rust", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 391 | srcs: ["foo.rs"], |
| 392 | rlibs: ["libfoo.rlib.rust"], |
| 393 | dylibs: ["libfoo.dylib.rust"], |
| 394 | apex_available: ["myapex"], |
| 395 | } |
| 396 | |
| 397 | rust_library_rlib { |
Artur Satayev | 533b98c | 2021-03-11 18:03:42 +0000 | [diff] [blame] | 398 | name: "libfoo.rlib.rust", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 399 | srcs: ["foo.rs"], |
| 400 | crate_name: "foo", |
| 401 | apex_available: ["myapex"], |
Jiyong Park | 94e22fd | 2021-04-08 18:19:15 +0900 | [diff] [blame] | 402 | shared_libs: ["libfoo.shared_from_rust"], |
| 403 | } |
| 404 | |
| 405 | cc_library_shared { |
| 406 | name: "libfoo.shared_from_rust", |
| 407 | srcs: ["mylib.cpp"], |
| 408 | system_shared_libs: [], |
| 409 | stl: "none", |
| 410 | apex_available: ["myapex"], |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | rust_library_dylib { |
Artur Satayev | 533b98c | 2021-03-11 18:03:42 +0000 | [diff] [blame] | 414 | name: "libfoo.dylib.rust", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 415 | srcs: ["foo.rs"], |
| 416 | crate_name: "foo", |
| 417 | apex_available: ["myapex"], |
| 418 | } |
| 419 | |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 420 | rust_ffi_shared { |
| 421 | name: "libfoo.ffi", |
| 422 | srcs: ["foo.rs"], |
| 423 | crate_name: "foo", |
| 424 | apex_available: ["myapex"], |
| 425 | } |
| 426 | |
| 427 | rust_ffi_shared { |
| 428 | name: "libbar.ffi", |
| 429 | srcs: ["foo.rs"], |
| 430 | crate_name: "bar", |
| 431 | apex_available: ["myapex"], |
| 432 | } |
| 433 | |
Yifan Hong | d22a84a | 2020-07-28 17:37:46 -0700 | [diff] [blame] | 434 | apex { |
| 435 | name: "com.android.gki.fake", |
| 436 | binaries: ["foo"], |
| 437 | key: "myapex.key", |
| 438 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 439 | updatable: false, |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 440 | } |
| 441 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 442 | cc_library_shared { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 443 | name: "mylib2", |
| 444 | srcs: ["mylib.cpp"], |
| 445 | system_shared_libs: [], |
| 446 | stl: "none", |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 447 | notice: "custom_notice", |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 448 | static_libs: ["libstatic"], |
| 449 | // TODO: remove //apex_available:platform |
| 450 | apex_available: [ |
| 451 | "//apex_available:platform", |
| 452 | "myapex", |
| 453 | ], |
| 454 | } |
| 455 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 456 | cc_prebuilt_library_shared { |
| 457 | name: "mylib2", |
| 458 | srcs: ["prebuilt.so"], |
| 459 | // TODO: remove //apex_available:platform |
| 460 | apex_available: [ |
| 461 | "//apex_available:platform", |
| 462 | "myapex", |
| 463 | ], |
| 464 | } |
| 465 | |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 466 | cc_library_static { |
| 467 | name: "libstatic", |
| 468 | srcs: ["mylib.cpp"], |
| 469 | system_shared_libs: [], |
| 470 | stl: "none", |
| 471 | notice: "custom_notice_for_static_lib", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 472 | // TODO: remove //apex_available:platform |
| 473 | apex_available: [ |
| 474 | "//apex_available:platform", |
| 475 | "myapex", |
| 476 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 477 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 478 | |
| 479 | java_library { |
| 480 | name: "myjar", |
| 481 | srcs: ["foo/bar/MyClass.java"], |
Jiyong Park | a62aa23 | 2020-05-28 23:46:55 +0900 | [diff] [blame] | 482 | stem: "myjar_stem", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 483 | sdk_version: "none", |
| 484 | system_modules: "none", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 485 | static_libs: ["myotherjar"], |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 486 | libs: ["mysharedjar"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 487 | // TODO: remove //apex_available:platform |
| 488 | apex_available: [ |
| 489 | "//apex_available:platform", |
| 490 | "myapex", |
| 491 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 492 | } |
| 493 | |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 494 | dex_import { |
| 495 | name: "myjar_dex", |
| 496 | jars: ["prebuilt.jar"], |
| 497 | apex_available: [ |
| 498 | "//apex_available:platform", |
| 499 | "myapex", |
| 500 | ], |
| 501 | } |
| 502 | |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 503 | java_library { |
| 504 | name: "myotherjar", |
| 505 | srcs: ["foo/bar/MyClass.java"], |
| 506 | sdk_version: "none", |
| 507 | system_modules: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 508 | // TODO: remove //apex_available:platform |
| 509 | apex_available: [ |
| 510 | "//apex_available:platform", |
| 511 | "myapex", |
| 512 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 513 | } |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 514 | |
| 515 | java_library { |
| 516 | name: "mysharedjar", |
| 517 | srcs: ["foo/bar/MyClass.java"], |
| 518 | sdk_version: "none", |
| 519 | system_modules: "none", |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 520 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 521 | `) |
| 522 | |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 523 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 524 | |
Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 525 | // Make sure that Android.mk is created |
| 526 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 527 | data := android.AndroidMkDataForTest(t, ctx, ab) |
Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 528 | var builder strings.Builder |
| 529 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 530 | |
| 531 | androidMk := builder.String() |
| 532 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 533 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
| 534 | |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 535 | optFlags := apexRule.Args["opt_flags"] |
| 536 | ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey") |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 537 | // Ensure that the NOTICE output is being packaged as an asset. |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 538 | 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] | 539 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 540 | copyCmds := apexRule.Args["copy_commands"] |
| 541 | |
| 542 | // Ensure that main rule creates an output |
| 543 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 544 | |
| 545 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 546 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
| 547 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_apex10000") |
| 548 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar_dex"), "android_common_apex10000") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 549 | ensureListContains(t, ctx.ModuleVariantsForTests("foo.rust"), "android_arm64_armv8-a_apex10000") |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 550 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.ffi"), "android_arm64_armv8-a_shared_apex10000") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 551 | |
| 552 | // Ensure that apex variant is created for the indirect dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 553 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
| 554 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_apex10000") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 555 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.rlib.rust"), "android_arm64_armv8-a_rlib_dylib-std_apex10000") |
| 556 | 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] | 557 | ensureListContains(t, ctx.ModuleVariantsForTests("libbar.ffi"), "android_arm64_armv8-a_shared_apex10000") |
Jiyong Park | 94e22fd | 2021-04-08 18:19:15 +0900 | [diff] [blame] | 558 | 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] | 559 | |
| 560 | // Ensure that both direct and indirect deps are copied into apex |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 561 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 562 | ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | a62aa23 | 2020-05-28 23:46:55 +0900 | [diff] [blame] | 563 | ensureContains(t, copyCmds, "image.apex/javalib/myjar_stem.jar") |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 564 | ensureContains(t, copyCmds, "image.apex/javalib/myjar_dex.jar") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 565 | ensureContains(t, copyCmds, "image.apex/lib64/libfoo.dylib.rust.dylib.so") |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 566 | ensureContains(t, copyCmds, "image.apex/lib64/libfoo.ffi.so") |
| 567 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.ffi.so") |
Jiyong Park | 94e22fd | 2021-04-08 18:19:15 +0900 | [diff] [blame] | 568 | ensureContains(t, copyCmds, "image.apex/lib64/libfoo.shared_from_rust.so") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 569 | // .. but not for java libs |
| 570 | ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 571 | ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar") |
Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 572 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 573 | // Ensure that the platform variant ends with _shared or _common |
| 574 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 575 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 576 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common") |
| 577 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 578 | ensureListContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common") |
| 579 | |
| 580 | // Ensure that dynamic dependency to java libs are not included |
| 581 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common_myapex") |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 582 | |
| 583 | // Ensure that all symlinks are present. |
| 584 | found_foo_link_64 := false |
| 585 | found_foo := false |
| 586 | for _, cmd := range strings.Split(copyCmds, " && ") { |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 587 | if strings.HasPrefix(cmd, "ln -sfn foo64") { |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 588 | if strings.HasSuffix(cmd, "bin/foo") { |
| 589 | found_foo = true |
| 590 | } else if strings.HasSuffix(cmd, "bin/foo_link_64") { |
| 591 | found_foo_link_64 = true |
| 592 | } |
| 593 | } |
| 594 | } |
| 595 | good := found_foo && found_foo_link_64 |
| 596 | if !good { |
| 597 | t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds) |
| 598 | } |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 599 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 600 | 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] | 601 | ensureListContains(t, fullDepsInfo, " myjar(minSdkVersion:(no version)) <- myapex") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 602 | ensureListContains(t, fullDepsInfo, " mylib2(minSdkVersion:(no version)) <- mylib") |
| 603 | ensureListContains(t, fullDepsInfo, " myotherjar(minSdkVersion:(no version)) <- myjar") |
| 604 | ensureListContains(t, fullDepsInfo, " mysharedjar(minSdkVersion:(no version)) (external) <- myjar") |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 605 | |
| 606 | 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] | 607 | ensureListContains(t, flatDepsInfo, "myjar(minSdkVersion:(no version))") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 608 | ensureListContains(t, flatDepsInfo, "mylib2(minSdkVersion:(no version))") |
| 609 | ensureListContains(t, flatDepsInfo, "myotherjar(minSdkVersion:(no version))") |
| 610 | ensureListContains(t, flatDepsInfo, "mysharedjar(minSdkVersion:(no version)) (external)") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 611 | } |
| 612 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 613 | func TestDefaults(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 614 | ctx := testApex(t, ` |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 615 | apex_defaults { |
| 616 | name: "myapex-defaults", |
| 617 | key: "myapex.key", |
| 618 | prebuilts: ["myetc"], |
| 619 | native_shared_libs: ["mylib"], |
| 620 | java_libs: ["myjar"], |
| 621 | apps: ["AppFoo"], |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 622 | rros: ["rro"], |
Ken Chen | fad7f9d | 2021-11-10 22:02:57 +0800 | [diff] [blame] | 623 | bpfs: ["bpf", "netd_test"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 624 | updatable: false, |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | prebuilt_etc { |
| 628 | name: "myetc", |
| 629 | src: "myprebuilt", |
| 630 | } |
| 631 | |
| 632 | apex { |
| 633 | name: "myapex", |
| 634 | defaults: ["myapex-defaults"], |
| 635 | } |
| 636 | |
| 637 | apex_key { |
| 638 | name: "myapex.key", |
| 639 | public_key: "testkey.avbpubkey", |
| 640 | private_key: "testkey.pem", |
| 641 | } |
| 642 | |
| 643 | cc_library { |
| 644 | name: "mylib", |
| 645 | system_shared_libs: [], |
| 646 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 647 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | java_library { |
| 651 | name: "myjar", |
| 652 | srcs: ["foo/bar/MyClass.java"], |
| 653 | sdk_version: "none", |
| 654 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 655 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | android_app { |
| 659 | name: "AppFoo", |
| 660 | srcs: ["foo/bar/MyClass.java"], |
| 661 | sdk_version: "none", |
| 662 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 663 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 664 | } |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 665 | |
| 666 | runtime_resource_overlay { |
| 667 | name: "rro", |
| 668 | theme: "blue", |
| 669 | } |
| 670 | |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 671 | bpf { |
| 672 | name: "bpf", |
| 673 | srcs: ["bpf.c", "bpf2.c"], |
| 674 | } |
| 675 | |
Ken Chen | fad7f9d | 2021-11-10 22:02:57 +0800 | [diff] [blame] | 676 | bpf { |
| 677 | name: "netd_test", |
| 678 | srcs: ["netd_test.c"], |
| 679 | sub_dir: "netd", |
| 680 | } |
| 681 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 682 | `) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 683 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 684 | "etc/myetc", |
| 685 | "javalib/myjar.jar", |
| 686 | "lib64/mylib.so", |
| 687 | "app/AppFoo/AppFoo.apk", |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 688 | "overlay/blue/rro.apk", |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 689 | "etc/bpf/bpf.o", |
| 690 | "etc/bpf/bpf2.o", |
Ken Chen | fad7f9d | 2021-11-10 22:02:57 +0800 | [diff] [blame] | 691 | "etc/bpf/netd/netd_test.o", |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 692 | }) |
| 693 | } |
| 694 | |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 695 | func TestApexManifest(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 696 | ctx := testApex(t, ` |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 697 | apex { |
| 698 | name: "myapex", |
| 699 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 700 | updatable: false, |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | apex_key { |
| 704 | name: "myapex.key", |
| 705 | public_key: "testkey.avbpubkey", |
| 706 | private_key: "testkey.pem", |
| 707 | } |
| 708 | `) |
| 709 | |
| 710 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 711 | args := module.Rule("apexRule").Args |
| 712 | if manifest := args["manifest"]; manifest != module.Output("apex_manifest.pb").Output.String() { |
| 713 | t.Error("manifest should be apex_manifest.pb, but " + manifest) |
| 714 | } |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 715 | } |
| 716 | |
Liz Kammer | 4854a7d | 2021-05-27 14:28:27 -0400 | [diff] [blame] | 717 | func TestApexManifestMinSdkVersion(t *testing.T) { |
| 718 | ctx := testApex(t, ` |
| 719 | apex_defaults { |
| 720 | name: "my_defaults", |
| 721 | key: "myapex.key", |
| 722 | product_specific: true, |
| 723 | file_contexts: ":my-file-contexts", |
| 724 | updatable: false, |
| 725 | } |
| 726 | apex { |
| 727 | name: "myapex_30", |
| 728 | min_sdk_version: "30", |
| 729 | defaults: ["my_defaults"], |
| 730 | } |
| 731 | |
| 732 | apex { |
| 733 | name: "myapex_current", |
| 734 | min_sdk_version: "current", |
| 735 | defaults: ["my_defaults"], |
| 736 | } |
| 737 | |
| 738 | apex { |
| 739 | name: "myapex_none", |
| 740 | defaults: ["my_defaults"], |
| 741 | } |
| 742 | |
| 743 | apex_key { |
| 744 | name: "myapex.key", |
| 745 | public_key: "testkey.avbpubkey", |
| 746 | private_key: "testkey.pem", |
| 747 | } |
| 748 | |
| 749 | filegroup { |
| 750 | name: "my-file-contexts", |
| 751 | srcs: ["product_specific_file_contexts"], |
| 752 | } |
| 753 | `, withFiles(map[string][]byte{ |
| 754 | "product_specific_file_contexts": nil, |
| 755 | }), android.FixtureModifyProductVariables( |
| 756 | func(variables android.FixtureProductVariables) { |
| 757 | variables.Unbundled_build = proptools.BoolPtr(true) |
| 758 | variables.Always_use_prebuilt_sdks = proptools.BoolPtr(false) |
| 759 | }), android.FixtureMergeEnv(map[string]string{ |
| 760 | "UNBUNDLED_BUILD_TARGET_SDK_WITH_API_FINGERPRINT": "true", |
| 761 | })) |
| 762 | |
| 763 | testCases := []struct { |
| 764 | module string |
| 765 | minSdkVersion string |
| 766 | }{ |
| 767 | { |
| 768 | module: "myapex_30", |
| 769 | minSdkVersion: "30", |
| 770 | }, |
| 771 | { |
| 772 | module: "myapex_current", |
| 773 | minSdkVersion: "Q.$$(cat out/soong/api_fingerprint.txt)", |
| 774 | }, |
| 775 | { |
| 776 | module: "myapex_none", |
| 777 | minSdkVersion: "Q.$$(cat out/soong/api_fingerprint.txt)", |
| 778 | }, |
| 779 | } |
| 780 | for _, tc := range testCases { |
| 781 | module := ctx.ModuleForTests(tc.module, "android_common_"+tc.module+"_image") |
| 782 | args := module.Rule("apexRule").Args |
| 783 | optFlags := args["opt_flags"] |
| 784 | if !strings.Contains(optFlags, "--min_sdk_version "+tc.minSdkVersion) { |
| 785 | t.Errorf("%s: Expected min_sdk_version=%s, got: %s", tc.module, tc.minSdkVersion, optFlags) |
| 786 | } |
| 787 | } |
| 788 | } |
| 789 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 790 | func TestBasicZipApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 791 | ctx := testApex(t, ` |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 792 | apex { |
| 793 | name: "myapex", |
| 794 | key: "myapex.key", |
| 795 | payload_type: "zip", |
| 796 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 797 | updatable: false, |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | apex_key { |
| 801 | name: "myapex.key", |
| 802 | public_key: "testkey.avbpubkey", |
| 803 | private_key: "testkey.pem", |
| 804 | } |
| 805 | |
| 806 | cc_library { |
| 807 | name: "mylib", |
| 808 | srcs: ["mylib.cpp"], |
| 809 | shared_libs: ["mylib2"], |
| 810 | system_shared_libs: [], |
| 811 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 812 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | cc_library { |
| 816 | name: "mylib2", |
| 817 | srcs: ["mylib.cpp"], |
| 818 | system_shared_libs: [], |
| 819 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 820 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 821 | } |
| 822 | `) |
| 823 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 824 | zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 825 | copyCmds := zipApexRule.Args["copy_commands"] |
| 826 | |
| 827 | // Ensure that main rule creates an output |
| 828 | ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned") |
| 829 | |
| 830 | // Ensure that APEX variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 831 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 832 | |
| 833 | // Ensure that APEX variant is created for the indirect dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 834 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 835 | |
| 836 | // Ensure that both direct and indirect deps are copied into apex |
| 837 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so") |
| 838 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | func TestApexWithStubs(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 842 | ctx := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 843 | apex { |
| 844 | name: "myapex", |
| 845 | key: "myapex.key", |
| 846 | native_shared_libs: ["mylib", "mylib3"], |
Jiyong Park | 105dc32 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 847 | binaries: ["foo.rust"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 848 | updatable: false, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | apex_key { |
| 852 | name: "myapex.key", |
| 853 | public_key: "testkey.avbpubkey", |
| 854 | private_key: "testkey.pem", |
| 855 | } |
| 856 | |
| 857 | cc_library { |
| 858 | name: "mylib", |
| 859 | srcs: ["mylib.cpp"], |
| 860 | shared_libs: ["mylib2", "mylib3"], |
| 861 | system_shared_libs: [], |
| 862 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 863 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | cc_library { |
| 867 | name: "mylib2", |
| 868 | srcs: ["mylib.cpp"], |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 869 | cflags: ["-include mylib.h"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 870 | system_shared_libs: [], |
| 871 | stl: "none", |
| 872 | stubs: { |
| 873 | versions: ["1", "2", "3"], |
| 874 | }, |
| 875 | } |
| 876 | |
| 877 | cc_library { |
| 878 | name: "mylib3", |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 879 | srcs: ["mylib.cpp"], |
| 880 | shared_libs: ["mylib4"], |
| 881 | system_shared_libs: [], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 882 | stl: "none", |
| 883 | stubs: { |
| 884 | versions: ["10", "11", "12"], |
| 885 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 886 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 887 | } |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 888 | |
| 889 | cc_library { |
| 890 | name: "mylib4", |
| 891 | srcs: ["mylib.cpp"], |
| 892 | system_shared_libs: [], |
| 893 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 894 | apex_available: [ "myapex" ], |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 895 | } |
Jiyong Park | 105dc32 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 896 | |
| 897 | rust_binary { |
| 898 | name: "foo.rust", |
| 899 | srcs: ["foo.rs"], |
| 900 | shared_libs: ["libfoo.shared_from_rust"], |
| 901 | prefer_rlib: true, |
| 902 | apex_available: ["myapex"], |
| 903 | } |
| 904 | |
| 905 | cc_library_shared { |
| 906 | name: "libfoo.shared_from_rust", |
| 907 | srcs: ["mylib.cpp"], |
| 908 | system_shared_libs: [], |
| 909 | stl: "none", |
| 910 | stubs: { |
| 911 | versions: ["10", "11", "12"], |
| 912 | }, |
| 913 | } |
| 914 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 915 | `) |
| 916 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 917 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 918 | copyCmds := apexRule.Args["copy_commands"] |
| 919 | |
| 920 | // Ensure that direct non-stubs dep is always included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 921 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 922 | |
| 923 | // Ensure that indirect stubs dep is not included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 924 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 925 | |
| 926 | // Ensure that direct stubs dep is included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 927 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 928 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 929 | 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] | 930 | |
| 931 | // 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] | 932 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_current/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 933 | // ... and not linking to the non-stub (impl) variant of mylib2 |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 934 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 935 | |
| 936 | // 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] | 937 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_apex10000/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 938 | // .. and not linking to the stubs variant of mylib3 |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 939 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12/mylib3.so") |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 940 | |
Chih-Hung Hsieh | b808229 | 2021-09-09 23:20:39 -0700 | [diff] [blame] | 941 | // Comment out this test. Now it fails after the optimization of sharing "cflags" in cc/cc.go |
| 942 | // is replaced by sharing of "cFlags" in cc/builder.go. |
| 943 | // The "cflags" contains "-include mylib.h", but cFlags contained only a reference to the |
| 944 | // module variable representing "cflags". So it was not detected by ensureNotContains. |
| 945 | // Now "cFlags" is a reference to a module variable like $flags1, which includes all previous |
| 946 | // content of "cflags". ModuleForTests...Args["cFlags"] returns the full string of $flags1, |
| 947 | // including the original cflags's "-include mylib.h". |
| 948 | // |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 949 | // Ensure that stubs libs are built without -include flags |
Chih-Hung Hsieh | b808229 | 2021-09-09 23:20:39 -0700 | [diff] [blame] | 950 | // mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 951 | // ensureNotContains(t, mylib2Cflags, "-include ") |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 952 | |
| 953 | // Ensure that genstub is invoked with --apex |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 954 | 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] | 955 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 956 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 957 | "lib64/mylib.so", |
| 958 | "lib64/mylib3.so", |
| 959 | "lib64/mylib4.so", |
Jiyong Park | 105dc32 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 960 | "bin/foo.rust", |
| 961 | "lib64/libc++.so", // by the implicit dependency from foo.rust |
| 962 | "lib64/liblog.so", // by the implicit dependency from foo.rust |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 963 | }) |
Jiyong Park | 105dc32 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 964 | |
| 965 | // Ensure that stub dependency from a rust module is not included |
| 966 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.shared_from_rust.so") |
| 967 | // The rust module is linked to the stub cc library |
| 968 | rustDeps := ctx.ModuleForTests("foo.rust", "android_arm64_armv8-a_apex10000").Rule("rustc").Args["linkFlags"] |
| 969 | ensureContains(t, rustDeps, "libfoo.shared_from_rust/android_arm64_armv8-a_shared_current/libfoo.shared_from_rust.so") |
| 970 | 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] | 971 | |
| 972 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 973 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.shared_from_rust.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 974 | } |
| 975 | |
Jiyong Park | 1bc8412 | 2021-06-22 20:23:05 +0900 | [diff] [blame] | 976 | func TestApexCanUsePrivateApis(t *testing.T) { |
| 977 | ctx := testApex(t, ` |
| 978 | apex { |
| 979 | name: "myapex", |
| 980 | key: "myapex.key", |
| 981 | native_shared_libs: ["mylib"], |
| 982 | binaries: ["foo.rust"], |
| 983 | updatable: false, |
| 984 | platform_apis: true, |
| 985 | } |
| 986 | |
| 987 | apex_key { |
| 988 | name: "myapex.key", |
| 989 | public_key: "testkey.avbpubkey", |
| 990 | private_key: "testkey.pem", |
| 991 | } |
| 992 | |
| 993 | cc_library { |
| 994 | name: "mylib", |
| 995 | srcs: ["mylib.cpp"], |
| 996 | shared_libs: ["mylib2"], |
| 997 | system_shared_libs: [], |
| 998 | stl: "none", |
| 999 | apex_available: [ "myapex" ], |
| 1000 | } |
| 1001 | |
| 1002 | cc_library { |
| 1003 | name: "mylib2", |
| 1004 | srcs: ["mylib.cpp"], |
| 1005 | cflags: ["-include mylib.h"], |
| 1006 | system_shared_libs: [], |
| 1007 | stl: "none", |
| 1008 | stubs: { |
| 1009 | versions: ["1", "2", "3"], |
| 1010 | }, |
| 1011 | } |
| 1012 | |
| 1013 | rust_binary { |
| 1014 | name: "foo.rust", |
| 1015 | srcs: ["foo.rs"], |
| 1016 | shared_libs: ["libfoo.shared_from_rust"], |
| 1017 | prefer_rlib: true, |
| 1018 | apex_available: ["myapex"], |
| 1019 | } |
| 1020 | |
| 1021 | cc_library_shared { |
| 1022 | name: "libfoo.shared_from_rust", |
| 1023 | srcs: ["mylib.cpp"], |
| 1024 | system_shared_libs: [], |
| 1025 | stl: "none", |
| 1026 | stubs: { |
| 1027 | versions: ["10", "11", "12"], |
| 1028 | }, |
| 1029 | } |
| 1030 | `) |
| 1031 | |
| 1032 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 1033 | copyCmds := apexRule.Args["copy_commands"] |
| 1034 | |
| 1035 | // Ensure that indirect stubs dep is not included |
| 1036 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 1037 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.shared_from_rust.so") |
| 1038 | |
| 1039 | // Ensure that we are using non-stub variants of mylib2 and libfoo.shared_from_rust (because |
| 1040 | // of the platform_apis: true) |
Jiyong Park | d4a0063 | 2022-04-12 12:23:20 +0900 | [diff] [blame^] | 1041 | 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] | 1042 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_current/mylib2.so") |
| 1043 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
Jiyong Park | d4a0063 | 2022-04-12 12:23:20 +0900 | [diff] [blame^] | 1044 | 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] | 1045 | ensureNotContains(t, rustDeps, "libfoo.shared_from_rust/android_arm64_armv8-a_shared_current/libfoo.shared_from_rust.so") |
| 1046 | ensureContains(t, rustDeps, "libfoo.shared_from_rust/android_arm64_armv8-a_shared/libfoo.shared_from_rust.so") |
| 1047 | } |
| 1048 | |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 1049 | func TestApexWithStubsWithMinSdkVersion(t *testing.T) { |
| 1050 | t.Parallel() |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1051 | ctx := testApex(t, ` |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 1052 | apex { |
| 1053 | name: "myapex", |
| 1054 | key: "myapex.key", |
| 1055 | native_shared_libs: ["mylib", "mylib3"], |
| 1056 | min_sdk_version: "29", |
| 1057 | } |
| 1058 | |
| 1059 | apex_key { |
| 1060 | name: "myapex.key", |
| 1061 | public_key: "testkey.avbpubkey", |
| 1062 | private_key: "testkey.pem", |
| 1063 | } |
| 1064 | |
| 1065 | cc_library { |
| 1066 | name: "mylib", |
| 1067 | srcs: ["mylib.cpp"], |
| 1068 | shared_libs: ["mylib2", "mylib3"], |
| 1069 | system_shared_libs: [], |
| 1070 | stl: "none", |
| 1071 | apex_available: [ "myapex" ], |
| 1072 | min_sdk_version: "28", |
| 1073 | } |
| 1074 | |
| 1075 | cc_library { |
| 1076 | name: "mylib2", |
| 1077 | srcs: ["mylib.cpp"], |
| 1078 | cflags: ["-include mylib.h"], |
| 1079 | system_shared_libs: [], |
| 1080 | stl: "none", |
| 1081 | stubs: { |
| 1082 | versions: ["28", "29", "30", "current"], |
| 1083 | }, |
| 1084 | min_sdk_version: "28", |
| 1085 | } |
| 1086 | |
| 1087 | cc_library { |
| 1088 | name: "mylib3", |
| 1089 | srcs: ["mylib.cpp"], |
| 1090 | shared_libs: ["mylib4"], |
| 1091 | system_shared_libs: [], |
| 1092 | stl: "none", |
| 1093 | stubs: { |
| 1094 | versions: ["28", "29", "30", "current"], |
| 1095 | }, |
| 1096 | apex_available: [ "myapex" ], |
| 1097 | min_sdk_version: "28", |
| 1098 | } |
| 1099 | |
| 1100 | cc_library { |
| 1101 | name: "mylib4", |
| 1102 | srcs: ["mylib.cpp"], |
| 1103 | system_shared_libs: [], |
| 1104 | stl: "none", |
| 1105 | apex_available: [ "myapex" ], |
| 1106 | min_sdk_version: "28", |
| 1107 | } |
| 1108 | `) |
| 1109 | |
| 1110 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 1111 | copyCmds := apexRule.Args["copy_commands"] |
| 1112 | |
| 1113 | // Ensure that direct non-stubs dep is always included |
| 1114 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1115 | |
| 1116 | // Ensure that indirect stubs dep is not included |
| 1117 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 1118 | |
| 1119 | // Ensure that direct stubs dep is included |
| 1120 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
| 1121 | |
| 1122 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex29").Rule("ld").Args["libFlags"] |
| 1123 | |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1124 | // Ensure that mylib is linking with the latest version of stub for mylib2 |
| 1125 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_current/mylib2.so") |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 1126 | // ... and not linking to the non-stub (impl) variant of mylib2 |
| 1127 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
| 1128 | |
| 1129 | // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex) |
| 1130 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_apex29/mylib3.so") |
| 1131 | // .. and not linking to the stubs variant of mylib3 |
| 1132 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_29/mylib3.so") |
| 1133 | |
| 1134 | // Ensure that stubs libs are built without -include flags |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 1135 | 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] | 1136 | ensureNotContains(t, mylib2Cflags, "-include ") |
| 1137 | |
| 1138 | // Ensure that genstub is invoked with --apex |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 1139 | 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] | 1140 | |
| 1141 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 1142 | "lib64/mylib.so", |
| 1143 | "lib64/mylib3.so", |
| 1144 | "lib64/mylib4.so", |
| 1145 | }) |
| 1146 | } |
| 1147 | |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1148 | func TestApex_PlatformUsesLatestStubFromApex(t *testing.T) { |
| 1149 | t.Parallel() |
| 1150 | // myapex (Z) |
| 1151 | // mylib -----------------. |
| 1152 | // | |
| 1153 | // otherapex (29) | |
| 1154 | // libstub's versions: 29 Z current |
| 1155 | // | |
| 1156 | // <platform> | |
| 1157 | // libplatform ----------------' |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1158 | ctx := testApex(t, ` |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1159 | apex { |
| 1160 | name: "myapex", |
| 1161 | key: "myapex.key", |
| 1162 | native_shared_libs: ["mylib"], |
| 1163 | min_sdk_version: "Z", // non-final |
| 1164 | } |
| 1165 | |
| 1166 | cc_library { |
| 1167 | name: "mylib", |
| 1168 | srcs: ["mylib.cpp"], |
| 1169 | shared_libs: ["libstub"], |
| 1170 | apex_available: ["myapex"], |
| 1171 | min_sdk_version: "Z", |
| 1172 | } |
| 1173 | |
| 1174 | apex_key { |
| 1175 | name: "myapex.key", |
| 1176 | public_key: "testkey.avbpubkey", |
| 1177 | private_key: "testkey.pem", |
| 1178 | } |
| 1179 | |
| 1180 | apex { |
| 1181 | name: "otherapex", |
| 1182 | key: "myapex.key", |
| 1183 | native_shared_libs: ["libstub"], |
| 1184 | min_sdk_version: "29", |
| 1185 | } |
| 1186 | |
| 1187 | cc_library { |
| 1188 | name: "libstub", |
| 1189 | srcs: ["mylib.cpp"], |
| 1190 | stubs: { |
| 1191 | versions: ["29", "Z", "current"], |
| 1192 | }, |
| 1193 | apex_available: ["otherapex"], |
| 1194 | min_sdk_version: "29", |
| 1195 | } |
| 1196 | |
| 1197 | // platform module depending on libstub from otherapex should use the latest stub("current") |
| 1198 | cc_library { |
| 1199 | name: "libplatform", |
| 1200 | srcs: ["mylib.cpp"], |
| 1201 | shared_libs: ["libstub"], |
| 1202 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1203 | `, |
| 1204 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1205 | variables.Platform_sdk_codename = proptools.StringPtr("Z") |
| 1206 | variables.Platform_sdk_final = proptools.BoolPtr(false) |
| 1207 | variables.Platform_version_active_codenames = []string{"Z"} |
| 1208 | }), |
| 1209 | ) |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1210 | |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1211 | // Ensure that mylib from myapex is built against the latest stub (current) |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1212 | 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] | 1213 | ensureContains(t, mylibCflags, "-D__LIBSTUB_API__=10000 ") |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1214 | 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] | 1215 | ensureContains(t, mylibLdflags, "libstub/android_arm64_armv8-a_shared_current/libstub.so ") |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 1216 | |
| 1217 | // Ensure that libplatform is built against latest stub ("current") of mylib3 from the apex |
| 1218 | libplatformCflags := ctx.ModuleForTests("libplatform", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 1219 | ensureContains(t, libplatformCflags, "-D__LIBSTUB_API__=10000 ") // "current" maps to 10000 |
| 1220 | libplatformLdflags := ctx.ModuleForTests("libplatform", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 1221 | ensureContains(t, libplatformLdflags, "libstub/android_arm64_armv8-a_shared_current/libstub.so ") |
| 1222 | } |
| 1223 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1224 | func TestApexWithExplicitStubsDependency(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1225 | ctx := testApex(t, ` |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1226 | apex { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1227 | name: "myapex2", |
| 1228 | key: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1229 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1230 | updatable: false, |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1231 | } |
| 1232 | |
| 1233 | apex_key { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1234 | name: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1235 | public_key: "testkey.avbpubkey", |
| 1236 | private_key: "testkey.pem", |
| 1237 | } |
| 1238 | |
| 1239 | cc_library { |
| 1240 | name: "mylib", |
| 1241 | srcs: ["mylib.cpp"], |
| 1242 | shared_libs: ["libfoo#10"], |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1243 | static_libs: ["libbaz"], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1244 | system_shared_libs: [], |
| 1245 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1246 | apex_available: [ "myapex2" ], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | cc_library { |
| 1250 | name: "libfoo", |
| 1251 | srcs: ["mylib.cpp"], |
| 1252 | shared_libs: ["libbar"], |
| 1253 | system_shared_libs: [], |
| 1254 | stl: "none", |
| 1255 | stubs: { |
| 1256 | versions: ["10", "20", "30"], |
| 1257 | }, |
| 1258 | } |
| 1259 | |
| 1260 | cc_library { |
| 1261 | name: "libbar", |
| 1262 | srcs: ["mylib.cpp"], |
| 1263 | system_shared_libs: [], |
| 1264 | stl: "none", |
| 1265 | } |
| 1266 | |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1267 | cc_library_static { |
| 1268 | name: "libbaz", |
| 1269 | srcs: ["mylib.cpp"], |
| 1270 | system_shared_libs: [], |
| 1271 | stl: "none", |
| 1272 | apex_available: [ "myapex2" ], |
| 1273 | } |
| 1274 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1275 | `) |
| 1276 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1277 | apexRule := ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Rule("apexRule") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1278 | copyCmds := apexRule.Args["copy_commands"] |
| 1279 | |
| 1280 | // Ensure that direct non-stubs dep is always included |
| 1281 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1282 | |
| 1283 | // Ensure that indirect stubs dep is not included |
| 1284 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 1285 | |
| 1286 | // Ensure that dependency of stubs is not included |
| 1287 | ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 1288 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1289 | 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] | 1290 | |
| 1291 | // Ensure that mylib is linking with version 10 of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1292 | ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1293 | // ... and not linking to the non-stub (impl) variant of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1294 | ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1295 | |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1296 | 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] | 1297 | |
| 1298 | // Ensure that libfoo stubs is not linking to libbar (since it is a stubs) |
| 1299 | ensureNotContains(t, libFooStubsLdFlags, "libbar.so") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1300 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 1301 | 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] | 1302 | ensureListContains(t, fullDepsInfo, " libfoo(minSdkVersion:(no version)) (external) <- mylib") |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1303 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 1304 | 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] | 1305 | ensureListContains(t, flatDepsInfo, "libfoo(minSdkVersion:(no version)) (external)") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1306 | } |
| 1307 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1308 | func TestApexWithRuntimeLibsDependency(t *testing.T) { |
| 1309 | /* |
| 1310 | myapex |
| 1311 | | |
| 1312 | v (runtime_libs) |
| 1313 | mylib ------+------> libfoo [provides stub] |
| 1314 | | |
| 1315 | `------> libbar |
| 1316 | */ |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1317 | ctx := testApex(t, ` |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1318 | apex { |
| 1319 | name: "myapex", |
| 1320 | key: "myapex.key", |
| 1321 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1322 | updatable: false, |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | apex_key { |
| 1326 | name: "myapex.key", |
| 1327 | public_key: "testkey.avbpubkey", |
| 1328 | private_key: "testkey.pem", |
| 1329 | } |
| 1330 | |
| 1331 | cc_library { |
| 1332 | name: "mylib", |
| 1333 | srcs: ["mylib.cpp"], |
| 1334 | runtime_libs: ["libfoo", "libbar"], |
| 1335 | system_shared_libs: [], |
| 1336 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1337 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | cc_library { |
| 1341 | name: "libfoo", |
| 1342 | srcs: ["mylib.cpp"], |
| 1343 | system_shared_libs: [], |
| 1344 | stl: "none", |
| 1345 | stubs: { |
| 1346 | versions: ["10", "20", "30"], |
| 1347 | }, |
| 1348 | } |
| 1349 | |
| 1350 | cc_library { |
| 1351 | name: "libbar", |
| 1352 | srcs: ["mylib.cpp"], |
| 1353 | system_shared_libs: [], |
| 1354 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1355 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1356 | } |
| 1357 | |
| 1358 | `) |
| 1359 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1360 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1361 | copyCmds := apexRule.Args["copy_commands"] |
| 1362 | |
| 1363 | // Ensure that direct non-stubs dep is always included |
| 1364 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1365 | |
| 1366 | // Ensure that indirect stubs dep is not included |
| 1367 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 1368 | |
| 1369 | // Ensure that runtime_libs dep in included |
| 1370 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 1371 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1372 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 1373 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 1374 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1375 | |
| 1376 | } |
| 1377 | |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1378 | var prepareForTestOfRuntimeApexWithHwasan = android.GroupFixturePreparers( |
| 1379 | cc.PrepareForTestWithCcBuildComponents, |
| 1380 | PrepareForTestWithApexBuildComponents, |
| 1381 | android.FixtureAddTextFile("bionic/apex/Android.bp", ` |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1382 | apex { |
| 1383 | name: "com.android.runtime", |
| 1384 | key: "com.android.runtime.key", |
| 1385 | native_shared_libs: ["libc"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1386 | updatable: false, |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | apex_key { |
| 1390 | name: "com.android.runtime.key", |
| 1391 | public_key: "testkey.avbpubkey", |
| 1392 | private_key: "testkey.pem", |
| 1393 | } |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1394 | `), |
| 1395 | android.FixtureAddFile("system/sepolicy/apex/com.android.runtime-file_contexts", nil), |
| 1396 | ) |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1397 | |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1398 | func TestRuntimeApexShouldInstallHwasanIfLibcDependsOnIt(t *testing.T) { |
Paul Duffin | 70d3bee | 2021-03-21 11:26:05 +0000 | [diff] [blame] | 1399 | result := android.GroupFixturePreparers(prepareForTestOfRuntimeApexWithHwasan).RunTestWithBp(t, ` |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1400 | cc_library { |
| 1401 | name: "libc", |
| 1402 | no_libcrt: true, |
| 1403 | nocrt: true, |
| 1404 | stl: "none", |
| 1405 | system_shared_libs: [], |
| 1406 | stubs: { versions: ["1"] }, |
| 1407 | apex_available: ["com.android.runtime"], |
| 1408 | |
| 1409 | sanitize: { |
| 1410 | hwaddress: true, |
| 1411 | } |
| 1412 | } |
| 1413 | |
| 1414 | cc_prebuilt_library_shared { |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 1415 | name: "libclang_rt.hwasan", |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1416 | no_libcrt: true, |
| 1417 | nocrt: true, |
| 1418 | stl: "none", |
| 1419 | system_shared_libs: [], |
| 1420 | srcs: [""], |
| 1421 | stubs: { versions: ["1"] }, |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 1422 | stem: "libclang_rt.hwasan-aarch64-android", |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1423 | |
| 1424 | sanitize: { |
| 1425 | never: true, |
| 1426 | }, |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1427 | } `) |
| 1428 | ctx := result.TestContext |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1429 | |
| 1430 | ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ |
| 1431 | "lib64/bionic/libc.so", |
| 1432 | "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", |
| 1433 | }) |
| 1434 | |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 1435 | hwasan := ctx.ModuleForTests("libclang_rt.hwasan", "android_arm64_armv8-a_shared") |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1436 | |
| 1437 | installed := hwasan.Description("install libclang_rt.hwasan") |
| 1438 | ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") |
| 1439 | |
| 1440 | symlink := hwasan.Description("install symlink libclang_rt.hwasan") |
| 1441 | ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so") |
| 1442 | ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so") |
| 1443 | } |
| 1444 | |
| 1445 | func TestRuntimeApexShouldInstallHwasanIfHwaddressSanitized(t *testing.T) { |
Paul Duffin | 70d3bee | 2021-03-21 11:26:05 +0000 | [diff] [blame] | 1446 | result := android.GroupFixturePreparers( |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1447 | prepareForTestOfRuntimeApexWithHwasan, |
| 1448 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1449 | variables.SanitizeDevice = []string{"hwaddress"} |
| 1450 | }), |
| 1451 | ).RunTestWithBp(t, ` |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1452 | cc_library { |
| 1453 | name: "libc", |
| 1454 | no_libcrt: true, |
| 1455 | nocrt: true, |
| 1456 | stl: "none", |
| 1457 | system_shared_libs: [], |
| 1458 | stubs: { versions: ["1"] }, |
| 1459 | apex_available: ["com.android.runtime"], |
| 1460 | } |
| 1461 | |
| 1462 | cc_prebuilt_library_shared { |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 1463 | name: "libclang_rt.hwasan", |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1464 | no_libcrt: true, |
| 1465 | nocrt: true, |
| 1466 | stl: "none", |
| 1467 | system_shared_libs: [], |
| 1468 | srcs: [""], |
| 1469 | stubs: { versions: ["1"] }, |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 1470 | stem: "libclang_rt.hwasan-aarch64-android", |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1471 | |
| 1472 | sanitize: { |
| 1473 | never: true, |
| 1474 | }, |
| 1475 | } |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1476 | `) |
| 1477 | ctx := result.TestContext |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1478 | |
| 1479 | ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ |
| 1480 | "lib64/bionic/libc.so", |
| 1481 | "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", |
| 1482 | }) |
| 1483 | |
Colin Cross | 4c4c1be | 2022-02-10 11:41:18 -0800 | [diff] [blame] | 1484 | hwasan := ctx.ModuleForTests("libclang_rt.hwasan", "android_arm64_armv8-a_shared") |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1485 | |
| 1486 | installed := hwasan.Description("install libclang_rt.hwasan") |
| 1487 | ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") |
| 1488 | |
| 1489 | symlink := hwasan.Description("install symlink libclang_rt.hwasan") |
| 1490 | ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so") |
| 1491 | ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so") |
| 1492 | } |
| 1493 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1494 | func TestApexDependsOnLLNDKTransitively(t *testing.T) { |
| 1495 | testcases := []struct { |
| 1496 | name string |
| 1497 | minSdkVersion string |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1498 | apexVariant string |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1499 | shouldLink string |
| 1500 | shouldNotLink []string |
| 1501 | }{ |
| 1502 | { |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1503 | name: "unspecified version links to the latest", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1504 | minSdkVersion: "", |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1505 | apexVariant: "apex10000", |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1506 | shouldLink: "current", |
| 1507 | shouldNotLink: []string{"29", "30"}, |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1508 | }, |
| 1509 | { |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1510 | name: "always use the latest", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1511 | minSdkVersion: "min_sdk_version: \"29\",", |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1512 | apexVariant: "apex29", |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1513 | shouldLink: "current", |
| 1514 | shouldNotLink: []string{"29", "30"}, |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1515 | }, |
| 1516 | } |
| 1517 | for _, tc := range testcases { |
| 1518 | t.Run(tc.name, func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1519 | ctx := testApex(t, ` |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1520 | apex { |
| 1521 | name: "myapex", |
| 1522 | key: "myapex.key", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1523 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1524 | updatable: false, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1525 | `+tc.minSdkVersion+` |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1526 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1527 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1528 | apex_key { |
| 1529 | name: "myapex.key", |
| 1530 | public_key: "testkey.avbpubkey", |
| 1531 | private_key: "testkey.pem", |
| 1532 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1533 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1534 | cc_library { |
| 1535 | name: "mylib", |
| 1536 | srcs: ["mylib.cpp"], |
| 1537 | vendor_available: true, |
| 1538 | shared_libs: ["libbar"], |
| 1539 | system_shared_libs: [], |
| 1540 | stl: "none", |
| 1541 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1542 | min_sdk_version: "29", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1543 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1544 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1545 | cc_library { |
| 1546 | name: "libbar", |
| 1547 | srcs: ["mylib.cpp"], |
| 1548 | system_shared_libs: [], |
| 1549 | stl: "none", |
| 1550 | stubs: { versions: ["29","30"] }, |
Colin Cross | 203b421 | 2021-04-26 17:19:41 -0700 | [diff] [blame] | 1551 | llndk: { |
| 1552 | symbol_file: "libbar.map.txt", |
| 1553 | } |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1554 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1555 | `, |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1556 | withUnbundledBuild, |
| 1557 | ) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1558 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1559 | // Ensure that LLNDK dep is not included |
| 1560 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 1561 | "lib64/mylib.so", |
| 1562 | }) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1563 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1564 | // Ensure that LLNDK dep is required |
| 1565 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 1566 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 1567 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so") |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1568 | |
Steven Moreland | 2c4000c | 2021-04-27 02:08:49 +0000 | [diff] [blame] | 1569 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_"+tc.apexVariant).Rule("ld").Args["libFlags"] |
| 1570 | 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] | 1571 | for _, ver := range tc.shouldNotLink { |
Steven Moreland | 2c4000c | 2021-04-27 02:08:49 +0000 | [diff] [blame] | 1572 | ensureNotContains(t, mylibLdFlags, "libbar/android_arm64_armv8-a_shared_"+ver+"/libbar.so") |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1573 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1574 | |
Steven Moreland | 2c4000c | 2021-04-27 02:08:49 +0000 | [diff] [blame] | 1575 | 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] | 1576 | ver := tc.shouldLink |
| 1577 | if tc.shouldLink == "current" { |
| 1578 | ver = strconv.Itoa(android.FutureApiLevelInt) |
| 1579 | } |
| 1580 | ensureContains(t, mylibCFlags, "__LIBBAR_API__="+ver) |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1581 | }) |
| 1582 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1583 | } |
| 1584 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1585 | func TestApexWithSystemLibsStubs(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1586 | ctx := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1587 | apex { |
| 1588 | name: "myapex", |
| 1589 | key: "myapex.key", |
| 1590 | native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1591 | updatable: false, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | apex_key { |
| 1595 | name: "myapex.key", |
| 1596 | public_key: "testkey.avbpubkey", |
| 1597 | private_key: "testkey.pem", |
| 1598 | } |
| 1599 | |
| 1600 | cc_library { |
| 1601 | name: "mylib", |
| 1602 | srcs: ["mylib.cpp"], |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 1603 | system_shared_libs: ["libc", "libm"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1604 | shared_libs: ["libdl#27"], |
| 1605 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1606 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1607 | } |
| 1608 | |
| 1609 | cc_library_shared { |
| 1610 | name: "mylib_shared", |
| 1611 | srcs: ["mylib.cpp"], |
| 1612 | shared_libs: ["libdl#27"], |
| 1613 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1614 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | cc_library { |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1618 | name: "libBootstrap", |
| 1619 | srcs: ["mylib.cpp"], |
| 1620 | stl: "none", |
| 1621 | bootstrap: true, |
| 1622 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1623 | `) |
| 1624 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1625 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1626 | copyCmds := apexRule.Args["copy_commands"] |
| 1627 | |
| 1628 | // Ensure that mylib, libm, libdl are included. |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1629 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1630 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so") |
| 1631 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1632 | |
| 1633 | // 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] | 1634 | ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1635 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1636 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
| 1637 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex10000").Rule("cc").Args["cFlags"] |
| 1638 | 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] | 1639 | |
| 1640 | // For dependency to libc |
| 1641 | // Ensure that mylib is linking with the latest version of stubs |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1642 | ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_current/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1643 | // ... and not linking to the non-stub (impl) variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1644 | ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1645 | // ... Cflags from stub is correctly exported to mylib |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1646 | ensureContains(t, mylibCFlags, "__LIBC_API__=10000") |
| 1647 | ensureContains(t, mylibSharedCFlags, "__LIBC_API__=10000") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1648 | |
| 1649 | // For dependency to libm |
| 1650 | // Ensure that mylib is linking with the non-stub (impl) variant |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1651 | ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_apex10000/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1652 | // ... and not linking to the stub variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1653 | ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1654 | // ... and is not compiling with the stub |
| 1655 | ensureNotContains(t, mylibCFlags, "__LIBM_API__=29") |
| 1656 | ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29") |
| 1657 | |
| 1658 | // For dependency to libdl |
| 1659 | // Ensure that mylib is linking with the specified version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1660 | ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1661 | // ... and not linking to the other versions of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1662 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28/libdl.so") |
| 1663 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1664 | // ... and not linking to the non-stub (impl) variant |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1665 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_apex10000/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1666 | // ... Cflags from stub is correctly exported to mylib |
| 1667 | ensureContains(t, mylibCFlags, "__LIBDL_API__=27") |
| 1668 | ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1669 | |
| 1670 | // Ensure that libBootstrap is depending on the platform variant of bionic libs |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1671 | libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 1672 | ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
| 1673 | ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so") |
| 1674 | ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1675 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1676 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1677 | func TestApexMinSdkVersion_NativeModulesShouldBeBuiltAgainstStubs(t *testing.T) { |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1678 | // there are three links between liba --> libz. |
| 1679 | // 1) myapex -> libx -> liba -> libz : this should be #30 link |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1680 | // 2) otherapex -> liby -> liba -> libz : this should be #30 link |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1681 | // 3) (platform) -> liba -> libz : this should be non-stub link |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1682 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1683 | apex { |
| 1684 | name: "myapex", |
| 1685 | key: "myapex.key", |
| 1686 | native_shared_libs: ["libx"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1687 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1688 | } |
| 1689 | |
| 1690 | apex { |
| 1691 | name: "otherapex", |
| 1692 | key: "myapex.key", |
| 1693 | native_shared_libs: ["liby"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1694 | min_sdk_version: "30", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1695 | } |
| 1696 | |
| 1697 | apex_key { |
| 1698 | name: "myapex.key", |
| 1699 | public_key: "testkey.avbpubkey", |
| 1700 | private_key: "testkey.pem", |
| 1701 | } |
| 1702 | |
| 1703 | cc_library { |
| 1704 | name: "libx", |
| 1705 | shared_libs: ["liba"], |
| 1706 | system_shared_libs: [], |
| 1707 | stl: "none", |
| 1708 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1709 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1710 | } |
| 1711 | |
| 1712 | cc_library { |
| 1713 | name: "liby", |
| 1714 | shared_libs: ["liba"], |
| 1715 | system_shared_libs: [], |
| 1716 | stl: "none", |
| 1717 | apex_available: [ "otherapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1718 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | cc_library { |
| 1722 | name: "liba", |
| 1723 | shared_libs: ["libz"], |
| 1724 | system_shared_libs: [], |
| 1725 | stl: "none", |
| 1726 | apex_available: [ |
| 1727 | "//apex_available:anyapex", |
| 1728 | "//apex_available:platform", |
| 1729 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1730 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | cc_library { |
| 1734 | name: "libz", |
| 1735 | system_shared_libs: [], |
| 1736 | stl: "none", |
| 1737 | stubs: { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1738 | versions: ["28", "30"], |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1739 | }, |
| 1740 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1741 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1742 | |
| 1743 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1744 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1745 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1746 | } |
| 1747 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1748 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1749 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1750 | } |
| 1751 | // platform liba is linked to non-stub version |
| 1752 | expectLink("liba", "shared", "libz", "shared") |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1753 | // liba in myapex is linked to current |
| 1754 | expectLink("liba", "shared_apex29", "libz", "shared_current") |
| 1755 | expectNoLink("liba", "shared_apex29", "libz", "shared_30") |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1756 | expectNoLink("liba", "shared_apex29", "libz", "shared_28") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1757 | expectNoLink("liba", "shared_apex29", "libz", "shared") |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1758 | // liba in otherapex is linked to current |
| 1759 | expectLink("liba", "shared_apex30", "libz", "shared_current") |
| 1760 | expectNoLink("liba", "shared_apex30", "libz", "shared_30") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1761 | expectNoLink("liba", "shared_apex30", "libz", "shared_28") |
| 1762 | expectNoLink("liba", "shared_apex30", "libz", "shared") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1763 | } |
| 1764 | |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1765 | func TestApexMinSdkVersion_SupportsCodeNames(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1766 | ctx := testApex(t, ` |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1767 | apex { |
| 1768 | name: "myapex", |
| 1769 | key: "myapex.key", |
| 1770 | native_shared_libs: ["libx"], |
| 1771 | min_sdk_version: "R", |
| 1772 | } |
| 1773 | |
| 1774 | apex_key { |
| 1775 | name: "myapex.key", |
| 1776 | public_key: "testkey.avbpubkey", |
| 1777 | private_key: "testkey.pem", |
| 1778 | } |
| 1779 | |
| 1780 | cc_library { |
| 1781 | name: "libx", |
| 1782 | shared_libs: ["libz"], |
| 1783 | system_shared_libs: [], |
| 1784 | stl: "none", |
| 1785 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1786 | min_sdk_version: "R", |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | cc_library { |
| 1790 | name: "libz", |
| 1791 | system_shared_libs: [], |
| 1792 | stl: "none", |
| 1793 | stubs: { |
| 1794 | versions: ["29", "R"], |
| 1795 | }, |
| 1796 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1797 | `, |
| 1798 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1799 | variables.Platform_version_active_codenames = []string{"R"} |
| 1800 | }), |
| 1801 | ) |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1802 | |
| 1803 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1804 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1805 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1806 | } |
| 1807 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1808 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1809 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1810 | } |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1811 | expectLink("libx", "shared_apex10000", "libz", "shared_current") |
| 1812 | expectNoLink("libx", "shared_apex10000", "libz", "shared_R") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1813 | expectNoLink("libx", "shared_apex10000", "libz", "shared_29") |
| 1814 | expectNoLink("libx", "shared_apex10000", "libz", "shared") |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1815 | } |
| 1816 | |
Jooyung Han | 4c4da06 | 2021-06-23 10:23:16 +0900 | [diff] [blame] | 1817 | func TestApexMinSdkVersion_SupportsCodeNames_JavaLibs(t *testing.T) { |
| 1818 | testApex(t, ` |
| 1819 | apex { |
| 1820 | name: "myapex", |
| 1821 | key: "myapex.key", |
| 1822 | java_libs: ["libx"], |
| 1823 | min_sdk_version: "S", |
| 1824 | } |
| 1825 | |
| 1826 | apex_key { |
| 1827 | name: "myapex.key", |
| 1828 | public_key: "testkey.avbpubkey", |
| 1829 | private_key: "testkey.pem", |
| 1830 | } |
| 1831 | |
| 1832 | java_library { |
| 1833 | name: "libx", |
| 1834 | srcs: ["a.java"], |
| 1835 | apex_available: [ "myapex" ], |
| 1836 | sdk_version: "current", |
| 1837 | min_sdk_version: "S", // should be okay |
| 1838 | } |
| 1839 | `, |
| 1840 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1841 | variables.Platform_version_active_codenames = []string{"S"} |
| 1842 | variables.Platform_sdk_codename = proptools.StringPtr("S") |
| 1843 | }), |
| 1844 | ) |
| 1845 | } |
| 1846 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1847 | func TestApexMinSdkVersion_DefaultsToLatest(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1848 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1849 | apex { |
| 1850 | name: "myapex", |
| 1851 | key: "myapex.key", |
| 1852 | native_shared_libs: ["libx"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1853 | updatable: false, |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1854 | } |
| 1855 | |
| 1856 | apex_key { |
| 1857 | name: "myapex.key", |
| 1858 | public_key: "testkey.avbpubkey", |
| 1859 | private_key: "testkey.pem", |
| 1860 | } |
| 1861 | |
| 1862 | cc_library { |
| 1863 | name: "libx", |
| 1864 | shared_libs: ["libz"], |
| 1865 | system_shared_libs: [], |
| 1866 | stl: "none", |
| 1867 | apex_available: [ "myapex" ], |
| 1868 | } |
| 1869 | |
| 1870 | cc_library { |
| 1871 | name: "libz", |
| 1872 | system_shared_libs: [], |
| 1873 | stl: "none", |
| 1874 | stubs: { |
| 1875 | versions: ["1", "2"], |
| 1876 | }, |
| 1877 | } |
| 1878 | `) |
| 1879 | |
| 1880 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1881 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1882 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1883 | } |
| 1884 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1885 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1886 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1887 | } |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1888 | expectLink("libx", "shared_apex10000", "libz", "shared_current") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1889 | expectNoLink("libx", "shared_apex10000", "libz", "shared_1") |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1890 | expectNoLink("libx", "shared_apex10000", "libz", "shared_2") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1891 | expectNoLink("libx", "shared_apex10000", "libz", "shared") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1892 | } |
| 1893 | |
Jiyong Park | 5df7bd3 | 2021-08-25 16:18:46 +0900 | [diff] [blame] | 1894 | func TestApexMinSdkVersion_crtobjectInVendorApex(t *testing.T) { |
| 1895 | ctx := testApex(t, ` |
| 1896 | apex { |
| 1897 | name: "myapex", |
| 1898 | key: "myapex.key", |
| 1899 | native_shared_libs: ["mylib"], |
| 1900 | updatable: false, |
| 1901 | vendor: true, |
| 1902 | min_sdk_version: "29", |
| 1903 | } |
| 1904 | |
| 1905 | apex_key { |
| 1906 | name: "myapex.key", |
| 1907 | public_key: "testkey.avbpubkey", |
| 1908 | private_key: "testkey.pem", |
| 1909 | } |
| 1910 | |
| 1911 | cc_library { |
| 1912 | name: "mylib", |
| 1913 | vendor_available: true, |
| 1914 | system_shared_libs: [], |
| 1915 | stl: "none", |
| 1916 | apex_available: [ "myapex" ], |
| 1917 | min_sdk_version: "29", |
| 1918 | } |
| 1919 | `) |
| 1920 | |
| 1921 | vendorVariant := "android_vendor.29_arm64_armv8-a" |
| 1922 | |
| 1923 | // First check that the correct variant of crtbegin_so is used. |
| 1924 | ldRule := ctx.ModuleForTests("mylib", vendorVariant+"_shared_apex29").Rule("ld") |
| 1925 | crtBegin := names(ldRule.Args["crtBegin"]) |
| 1926 | ensureListContains(t, crtBegin, "out/soong/.intermediates/"+cc.DefaultCcCommonTestModulesDir+"crtbegin_so/"+vendorVariant+"_apex29/crtbegin_so.o") |
| 1927 | |
| 1928 | // Ensure that the crtbegin_so used by the APEX is targeting 29 |
| 1929 | cflags := ctx.ModuleForTests("crtbegin_so", vendorVariant+"_apex29").Rule("cc").Args["cFlags"] |
| 1930 | android.AssertStringDoesContain(t, "cflags", cflags, "-target aarch64-linux-android29") |
| 1931 | } |
| 1932 | |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1933 | func TestPlatformUsesLatestStubsFromApexes(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1934 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1935 | apex { |
| 1936 | name: "myapex", |
| 1937 | key: "myapex.key", |
| 1938 | native_shared_libs: ["libx"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1939 | updatable: false, |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | apex_key { |
| 1943 | name: "myapex.key", |
| 1944 | public_key: "testkey.avbpubkey", |
| 1945 | private_key: "testkey.pem", |
| 1946 | } |
| 1947 | |
| 1948 | cc_library { |
| 1949 | name: "libx", |
| 1950 | system_shared_libs: [], |
| 1951 | stl: "none", |
| 1952 | apex_available: [ "myapex" ], |
| 1953 | stubs: { |
| 1954 | versions: ["1", "2"], |
| 1955 | }, |
| 1956 | } |
| 1957 | |
| 1958 | cc_library { |
| 1959 | name: "libz", |
| 1960 | shared_libs: ["libx"], |
| 1961 | system_shared_libs: [], |
| 1962 | stl: "none", |
| 1963 | } |
| 1964 | `) |
| 1965 | |
| 1966 | expectLink := func(from, from_variant, to, to_variant string) { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1967 | t.Helper() |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1968 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1969 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1970 | } |
| 1971 | expectNoLink := func(from, from_variant, to, to_variant string) { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1972 | t.Helper() |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1973 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1974 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1975 | } |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 1976 | expectLink("libz", "shared", "libx", "shared_current") |
| 1977 | expectNoLink("libz", "shared", "libx", "shared_2") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1978 | expectNoLink("libz", "shared", "libz", "shared_1") |
| 1979 | expectNoLink("libz", "shared", "libz", "shared") |
| 1980 | } |
| 1981 | |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1982 | var prepareForTestWithSantitizeHwaddress = android.FixtureModifyProductVariables( |
| 1983 | func(variables android.FixtureProductVariables) { |
| 1984 | variables.SanitizeDevice = []string{"hwaddress"} |
| 1985 | }, |
| 1986 | ) |
| 1987 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1988 | func TestQApexesUseLatestStubsInBundledBuildsAndHWASAN(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1989 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1990 | apex { |
| 1991 | name: "myapex", |
| 1992 | key: "myapex.key", |
| 1993 | native_shared_libs: ["libx"], |
| 1994 | min_sdk_version: "29", |
| 1995 | } |
| 1996 | |
| 1997 | apex_key { |
| 1998 | name: "myapex.key", |
| 1999 | public_key: "testkey.avbpubkey", |
| 2000 | private_key: "testkey.pem", |
| 2001 | } |
| 2002 | |
| 2003 | cc_library { |
| 2004 | name: "libx", |
| 2005 | shared_libs: ["libbar"], |
| 2006 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2007 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | cc_library { |
| 2011 | name: "libbar", |
| 2012 | stubs: { |
| 2013 | versions: ["29", "30"], |
| 2014 | }, |
| 2015 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2016 | `, |
| 2017 | prepareForTestWithSantitizeHwaddress, |
| 2018 | ) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2019 | expectLink := func(from, from_variant, to, to_variant string) { |
| 2020 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 2021 | libFlags := ld.Args["libFlags"] |
| 2022 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 2023 | } |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 2024 | expectLink("libx", "shared_hwasan_apex29", "libbar", "shared_current") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2025 | } |
| 2026 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 2027 | func TestQTargetApexUsesStaticUnwinder(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2028 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2029 | apex { |
| 2030 | name: "myapex", |
| 2031 | key: "myapex.key", |
| 2032 | native_shared_libs: ["libx"], |
| 2033 | min_sdk_version: "29", |
| 2034 | } |
| 2035 | |
| 2036 | apex_key { |
| 2037 | name: "myapex.key", |
| 2038 | public_key: "testkey.avbpubkey", |
| 2039 | private_key: "testkey.pem", |
| 2040 | } |
| 2041 | |
| 2042 | cc_library { |
| 2043 | name: "libx", |
| 2044 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2045 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2046 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 2047 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2048 | |
| 2049 | // ensure apex variant of c++ is linked with static unwinder |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2050 | 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] | 2051 | ensureListContains(t, cm.Properties.AndroidMkStaticLibs, "libunwind") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2052 | // note that platform variant is not. |
| 2053 | cm = ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
Ryan Prichard | b35a85e | 2021-01-13 19:18:53 -0800 | [diff] [blame] | 2054 | ensureListNotContains(t, cm.Properties.AndroidMkStaticLibs, "libunwind") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2055 | } |
| 2056 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2057 | func TestApexMinSdkVersion_ErrorIfIncompatibleVersion(t *testing.T) { |
| 2058 | testApexError(t, `module "mylib".*: should support min_sdk_version\(29\)`, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2059 | apex { |
| 2060 | name: "myapex", |
| 2061 | key: "myapex.key", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2062 | native_shared_libs: ["mylib"], |
| 2063 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | apex_key { |
| 2067 | name: "myapex.key", |
| 2068 | public_key: "testkey.avbpubkey", |
| 2069 | private_key: "testkey.pem", |
| 2070 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2071 | |
| 2072 | cc_library { |
| 2073 | name: "mylib", |
| 2074 | srcs: ["mylib.cpp"], |
| 2075 | system_shared_libs: [], |
| 2076 | stl: "none", |
| 2077 | apex_available: [ |
| 2078 | "myapex", |
| 2079 | ], |
| 2080 | min_sdk_version: "30", |
| 2081 | } |
| 2082 | `) |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 2083 | |
| 2084 | testApexError(t, `module "libfoo.ffi".*: should support min_sdk_version\(29\)`, ` |
| 2085 | apex { |
| 2086 | name: "myapex", |
| 2087 | key: "myapex.key", |
| 2088 | native_shared_libs: ["libfoo.ffi"], |
| 2089 | min_sdk_version: "29", |
| 2090 | } |
| 2091 | |
| 2092 | apex_key { |
| 2093 | name: "myapex.key", |
| 2094 | public_key: "testkey.avbpubkey", |
| 2095 | private_key: "testkey.pem", |
| 2096 | } |
| 2097 | |
| 2098 | rust_ffi_shared { |
| 2099 | name: "libfoo.ffi", |
| 2100 | srcs: ["foo.rs"], |
| 2101 | crate_name: "foo", |
| 2102 | apex_available: [ |
| 2103 | "myapex", |
| 2104 | ], |
| 2105 | min_sdk_version: "30", |
| 2106 | } |
| 2107 | `) |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 2108 | |
| 2109 | testApexError(t, `module "libfoo".*: should support min_sdk_version\(29\)`, ` |
| 2110 | apex { |
| 2111 | name: "myapex", |
| 2112 | key: "myapex.key", |
| 2113 | java_libs: ["libfoo"], |
| 2114 | min_sdk_version: "29", |
| 2115 | } |
| 2116 | |
| 2117 | apex_key { |
| 2118 | name: "myapex.key", |
| 2119 | public_key: "testkey.avbpubkey", |
| 2120 | private_key: "testkey.pem", |
| 2121 | } |
| 2122 | |
| 2123 | java_import { |
| 2124 | name: "libfoo", |
| 2125 | jars: ["libfoo.jar"], |
| 2126 | apex_available: [ |
| 2127 | "myapex", |
| 2128 | ], |
| 2129 | min_sdk_version: "30", |
| 2130 | } |
| 2131 | `) |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2132 | } |
| 2133 | |
| 2134 | func TestApexMinSdkVersion_Okay(t *testing.T) { |
| 2135 | testApex(t, ` |
| 2136 | apex { |
| 2137 | name: "myapex", |
| 2138 | key: "myapex.key", |
| 2139 | native_shared_libs: ["libfoo"], |
| 2140 | java_libs: ["libbar"], |
| 2141 | min_sdk_version: "29", |
| 2142 | } |
| 2143 | |
| 2144 | apex_key { |
| 2145 | name: "myapex.key", |
| 2146 | public_key: "testkey.avbpubkey", |
| 2147 | private_key: "testkey.pem", |
| 2148 | } |
| 2149 | |
| 2150 | cc_library { |
| 2151 | name: "libfoo", |
| 2152 | srcs: ["mylib.cpp"], |
| 2153 | shared_libs: ["libfoo_dep"], |
| 2154 | apex_available: ["myapex"], |
| 2155 | min_sdk_version: "29", |
| 2156 | } |
| 2157 | |
| 2158 | cc_library { |
| 2159 | name: "libfoo_dep", |
| 2160 | srcs: ["mylib.cpp"], |
| 2161 | apex_available: ["myapex"], |
| 2162 | min_sdk_version: "29", |
| 2163 | } |
| 2164 | |
| 2165 | java_library { |
| 2166 | name: "libbar", |
| 2167 | sdk_version: "current", |
| 2168 | srcs: ["a.java"], |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 2169 | static_libs: [ |
| 2170 | "libbar_dep", |
| 2171 | "libbar_import_dep", |
| 2172 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2173 | apex_available: ["myapex"], |
| 2174 | min_sdk_version: "29", |
| 2175 | } |
| 2176 | |
| 2177 | java_library { |
| 2178 | name: "libbar_dep", |
| 2179 | sdk_version: "current", |
| 2180 | srcs: ["a.java"], |
| 2181 | apex_available: ["myapex"], |
| 2182 | min_sdk_version: "29", |
| 2183 | } |
Jaewoong Jung | 56e12db | 2021-04-02 00:38:25 +0000 | [diff] [blame] | 2184 | |
| 2185 | java_import { |
| 2186 | name: "libbar_import_dep", |
| 2187 | jars: ["libbar.jar"], |
| 2188 | apex_available: ["myapex"], |
| 2189 | min_sdk_version: "29", |
| 2190 | } |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2191 | `) |
| 2192 | } |
| 2193 | |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2194 | func TestJavaStableSdkVersion(t *testing.T) { |
| 2195 | testCases := []struct { |
| 2196 | name string |
| 2197 | expectedError string |
| 2198 | bp string |
Paul Duffin | 1ea7c9f | 2021-03-15 09:39:13 +0000 | [diff] [blame] | 2199 | preparer android.FixturePreparer |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2200 | }{ |
| 2201 | { |
| 2202 | name: "Non-updatable apex with non-stable dep", |
| 2203 | bp: ` |
| 2204 | apex { |
| 2205 | name: "myapex", |
| 2206 | java_libs: ["myjar"], |
| 2207 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2208 | updatable: false, |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2209 | } |
| 2210 | apex_key { |
| 2211 | name: "myapex.key", |
| 2212 | public_key: "testkey.avbpubkey", |
| 2213 | private_key: "testkey.pem", |
| 2214 | } |
| 2215 | java_library { |
| 2216 | name: "myjar", |
| 2217 | srcs: ["foo/bar/MyClass.java"], |
Paul Duffin | 043f5e7 | 2021-03-05 00:00:01 +0000 | [diff] [blame] | 2218 | sdk_version: "test_current", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2219 | apex_available: ["myapex"], |
| 2220 | } |
| 2221 | `, |
| 2222 | }, |
| 2223 | { |
| 2224 | name: "Updatable apex with stable dep", |
| 2225 | bp: ` |
| 2226 | apex { |
| 2227 | name: "myapex", |
| 2228 | java_libs: ["myjar"], |
| 2229 | key: "myapex.key", |
| 2230 | updatable: true, |
| 2231 | min_sdk_version: "29", |
| 2232 | } |
| 2233 | apex_key { |
| 2234 | name: "myapex.key", |
| 2235 | public_key: "testkey.avbpubkey", |
| 2236 | private_key: "testkey.pem", |
| 2237 | } |
| 2238 | java_library { |
| 2239 | name: "myjar", |
| 2240 | srcs: ["foo/bar/MyClass.java"], |
| 2241 | sdk_version: "current", |
| 2242 | apex_available: ["myapex"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2243 | min_sdk_version: "29", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2244 | } |
| 2245 | `, |
| 2246 | }, |
| 2247 | { |
| 2248 | name: "Updatable apex with non-stable dep", |
| 2249 | expectedError: "cannot depend on \"myjar\"", |
| 2250 | bp: ` |
| 2251 | apex { |
| 2252 | name: "myapex", |
| 2253 | java_libs: ["myjar"], |
| 2254 | key: "myapex.key", |
| 2255 | updatable: true, |
| 2256 | } |
| 2257 | apex_key { |
| 2258 | name: "myapex.key", |
| 2259 | public_key: "testkey.avbpubkey", |
| 2260 | private_key: "testkey.pem", |
| 2261 | } |
| 2262 | java_library { |
| 2263 | name: "myjar", |
| 2264 | srcs: ["foo/bar/MyClass.java"], |
Paul Duffin | 043f5e7 | 2021-03-05 00:00:01 +0000 | [diff] [blame] | 2265 | sdk_version: "test_current", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2266 | apex_available: ["myapex"], |
| 2267 | } |
| 2268 | `, |
| 2269 | }, |
| 2270 | { |
Paul Duffin | 1ea7c9f | 2021-03-15 09:39:13 +0000 | [diff] [blame] | 2271 | name: "Updatable apex with non-stable legacy core platform dep", |
| 2272 | expectedError: `\Qcannot depend on "myjar-uses-legacy": non stable SDK core_platform_current - uses legacy core platform\E`, |
| 2273 | bp: ` |
| 2274 | apex { |
| 2275 | name: "myapex", |
| 2276 | java_libs: ["myjar-uses-legacy"], |
| 2277 | key: "myapex.key", |
| 2278 | updatable: true, |
| 2279 | } |
| 2280 | apex_key { |
| 2281 | name: "myapex.key", |
| 2282 | public_key: "testkey.avbpubkey", |
| 2283 | private_key: "testkey.pem", |
| 2284 | } |
| 2285 | java_library { |
| 2286 | name: "myjar-uses-legacy", |
| 2287 | srcs: ["foo/bar/MyClass.java"], |
| 2288 | sdk_version: "core_platform", |
| 2289 | apex_available: ["myapex"], |
| 2290 | } |
| 2291 | `, |
| 2292 | preparer: java.FixtureUseLegacyCorePlatformApi("myjar-uses-legacy"), |
| 2293 | }, |
| 2294 | { |
Paul Duffin | 043f5e7 | 2021-03-05 00:00:01 +0000 | [diff] [blame] | 2295 | name: "Updatable apex with non-stable transitive dep", |
| 2296 | // This is not actually detecting that the transitive dependency is unstable, rather it is |
| 2297 | // detecting that the transitive dependency is building against a wider API surface than the |
| 2298 | // module that depends on it is using. |
Jiyong Park | 670e0f6 | 2021-02-18 13:10:18 +0900 | [diff] [blame] | 2299 | 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] | 2300 | bp: ` |
| 2301 | apex { |
| 2302 | name: "myapex", |
| 2303 | java_libs: ["myjar"], |
| 2304 | key: "myapex.key", |
| 2305 | updatable: true, |
| 2306 | } |
| 2307 | apex_key { |
| 2308 | name: "myapex.key", |
| 2309 | public_key: "testkey.avbpubkey", |
| 2310 | private_key: "testkey.pem", |
| 2311 | } |
| 2312 | java_library { |
| 2313 | name: "myjar", |
| 2314 | srcs: ["foo/bar/MyClass.java"], |
| 2315 | sdk_version: "current", |
| 2316 | apex_available: ["myapex"], |
| 2317 | static_libs: ["transitive-jar"], |
| 2318 | } |
| 2319 | java_library { |
| 2320 | name: "transitive-jar", |
| 2321 | srcs: ["foo/bar/MyClass.java"], |
| 2322 | sdk_version: "core_platform", |
| 2323 | apex_available: ["myapex"], |
| 2324 | } |
| 2325 | `, |
| 2326 | }, |
| 2327 | } |
| 2328 | |
| 2329 | for _, test := range testCases { |
Paul Duffin | 1ea7c9f | 2021-03-15 09:39:13 +0000 | [diff] [blame] | 2330 | if test.name != "Updatable apex with non-stable legacy core platform dep" { |
| 2331 | continue |
| 2332 | } |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2333 | t.Run(test.name, func(t *testing.T) { |
Paul Duffin | 1ea7c9f | 2021-03-15 09:39:13 +0000 | [diff] [blame] | 2334 | errorHandler := android.FixtureExpectsNoErrors |
| 2335 | if test.expectedError != "" { |
| 2336 | errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(test.expectedError) |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2337 | } |
Paul Duffin | 1ea7c9f | 2021-03-15 09:39:13 +0000 | [diff] [blame] | 2338 | android.GroupFixturePreparers( |
| 2339 | java.PrepareForTestWithJavaDefaultModules, |
| 2340 | PrepareForTestWithApexBuildComponents, |
| 2341 | prepareForTestWithMyapex, |
| 2342 | android.OptionalFixturePreparer(test.preparer), |
| 2343 | ). |
| 2344 | ExtendWithErrorHandler(errorHandler). |
| 2345 | RunTestWithBp(t, test.bp) |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 2346 | }) |
| 2347 | } |
| 2348 | } |
| 2349 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2350 | func TestApexMinSdkVersion_ErrorIfDepIsNewer(t *testing.T) { |
| 2351 | testApexError(t, `module "mylib2".*: should support min_sdk_version\(29\) for "myapex"`, ` |
| 2352 | apex { |
| 2353 | name: "myapex", |
| 2354 | key: "myapex.key", |
| 2355 | native_shared_libs: ["mylib"], |
| 2356 | min_sdk_version: "29", |
| 2357 | } |
| 2358 | |
| 2359 | apex_key { |
| 2360 | name: "myapex.key", |
| 2361 | public_key: "testkey.avbpubkey", |
| 2362 | private_key: "testkey.pem", |
| 2363 | } |
| 2364 | |
| 2365 | cc_library { |
| 2366 | name: "mylib", |
| 2367 | srcs: ["mylib.cpp"], |
| 2368 | shared_libs: ["mylib2"], |
| 2369 | system_shared_libs: [], |
| 2370 | stl: "none", |
| 2371 | apex_available: [ |
| 2372 | "myapex", |
| 2373 | ], |
| 2374 | min_sdk_version: "29", |
| 2375 | } |
| 2376 | |
| 2377 | // indirect part of the apex |
| 2378 | cc_library { |
| 2379 | name: "mylib2", |
| 2380 | srcs: ["mylib.cpp"], |
| 2381 | system_shared_libs: [], |
| 2382 | stl: "none", |
| 2383 | apex_available: [ |
| 2384 | "myapex", |
| 2385 | ], |
| 2386 | min_sdk_version: "30", |
| 2387 | } |
| 2388 | `) |
| 2389 | } |
| 2390 | |
| 2391 | func TestApexMinSdkVersion_ErrorIfDepIsNewer_Java(t *testing.T) { |
| 2392 | testApexError(t, `module "bar".*: should support min_sdk_version\(29\) for "myapex"`, ` |
| 2393 | apex { |
| 2394 | name: "myapex", |
| 2395 | key: "myapex.key", |
| 2396 | apps: ["AppFoo"], |
| 2397 | min_sdk_version: "29", |
| 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 | |
| 5687 | ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk") |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5688 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/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 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5705 | func TestApexWithAppImports(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5706 | ctx := testApex(t, ` |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5707 | apex { |
| 5708 | name: "myapex", |
| 5709 | key: "myapex.key", |
| 5710 | apps: [ |
| 5711 | "AppFooPrebuilt", |
| 5712 | "AppFooPrivPrebuilt", |
| 5713 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5714 | updatable: false, |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5715 | } |
| 5716 | |
| 5717 | apex_key { |
| 5718 | name: "myapex.key", |
| 5719 | public_key: "testkey.avbpubkey", |
| 5720 | private_key: "testkey.pem", |
| 5721 | } |
| 5722 | |
| 5723 | android_app_import { |
| 5724 | name: "AppFooPrebuilt", |
| 5725 | apk: "PrebuiltAppFoo.apk", |
| 5726 | presigned: true, |
| 5727 | dex_preopt: { |
| 5728 | enabled: false, |
| 5729 | }, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5730 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5731 | } |
| 5732 | |
| 5733 | android_app_import { |
| 5734 | name: "AppFooPrivPrebuilt", |
| 5735 | apk: "PrebuiltAppFooPriv.apk", |
| 5736 | privileged: true, |
| 5737 | presigned: true, |
| 5738 | dex_preopt: { |
| 5739 | enabled: false, |
| 5740 | }, |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5741 | filename: "AwesomePrebuiltAppFooPriv.apk", |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5742 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5743 | } |
| 5744 | `) |
| 5745 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 5746 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5747 | apexRule := module.Rule("apexRule") |
| 5748 | copyCmds := apexRule.Args["copy_commands"] |
| 5749 | |
| 5750 | ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5751 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AwesomePrebuiltAppFooPriv.apk") |
| 5752 | } |
| 5753 | |
| 5754 | func TestApexWithAppImportsPrefer(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5755 | ctx := testApex(t, ` |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5756 | apex { |
| 5757 | name: "myapex", |
| 5758 | key: "myapex.key", |
| 5759 | apps: [ |
| 5760 | "AppFoo", |
| 5761 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5762 | updatable: false, |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5763 | } |
| 5764 | |
| 5765 | apex_key { |
| 5766 | name: "myapex.key", |
| 5767 | public_key: "testkey.avbpubkey", |
| 5768 | private_key: "testkey.pem", |
| 5769 | } |
| 5770 | |
| 5771 | android_app { |
| 5772 | name: "AppFoo", |
| 5773 | srcs: ["foo/bar/MyClass.java"], |
| 5774 | sdk_version: "none", |
| 5775 | system_modules: "none", |
| 5776 | apex_available: [ "myapex" ], |
| 5777 | } |
| 5778 | |
| 5779 | android_app_import { |
| 5780 | name: "AppFoo", |
| 5781 | apk: "AppFooPrebuilt.apk", |
| 5782 | filename: "AppFooPrebuilt.apk", |
| 5783 | presigned: true, |
| 5784 | prefer: true, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5785 | apex_available: ["myapex"], |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5786 | } |
| 5787 | `, withFiles(map[string][]byte{ |
| 5788 | "AppFooPrebuilt.apk": nil, |
| 5789 | })) |
| 5790 | |
| 5791 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 86feead | 2021-03-08 13:11:48 +0900 | [diff] [blame] | 5792 | "app/AppFoo/AppFooPrebuilt.apk", |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5793 | }) |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5794 | } |
| 5795 | |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5796 | func TestApexWithTestHelperApp(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5797 | ctx := testApex(t, ` |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5798 | apex { |
| 5799 | name: "myapex", |
| 5800 | key: "myapex.key", |
| 5801 | apps: [ |
| 5802 | "TesterHelpAppFoo", |
| 5803 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5804 | updatable: false, |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5805 | } |
| 5806 | |
| 5807 | apex_key { |
| 5808 | name: "myapex.key", |
| 5809 | public_key: "testkey.avbpubkey", |
| 5810 | private_key: "testkey.pem", |
| 5811 | } |
| 5812 | |
| 5813 | android_test_helper_app { |
| 5814 | name: "TesterHelpAppFoo", |
| 5815 | srcs: ["foo/bar/MyClass.java"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5816 | apex_available: [ "myapex" ], |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5817 | } |
| 5818 | |
| 5819 | `) |
| 5820 | |
| 5821 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 5822 | apexRule := module.Rule("apexRule") |
| 5823 | copyCmds := apexRule.Args["copy_commands"] |
| 5824 | |
| 5825 | ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk") |
| 5826 | } |
| 5827 | |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 5828 | func TestApexPropertiesShouldBeDefaultable(t *testing.T) { |
| 5829 | // libfoo's apex_available comes from cc_defaults |
Steven Moreland | 6e36cd6 | 2020-10-22 01:08:35 +0000 | [diff] [blame] | 5830 | 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] | 5831 | apex { |
| 5832 | name: "myapex", |
| 5833 | key: "myapex.key", |
| 5834 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5835 | updatable: false, |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 5836 | } |
| 5837 | |
| 5838 | apex_key { |
| 5839 | name: "myapex.key", |
| 5840 | public_key: "testkey.avbpubkey", |
| 5841 | private_key: "testkey.pem", |
| 5842 | } |
| 5843 | |
| 5844 | apex { |
| 5845 | name: "otherapex", |
| 5846 | key: "myapex.key", |
| 5847 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5848 | updatable: false, |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 5849 | } |
| 5850 | |
| 5851 | cc_defaults { |
| 5852 | name: "libfoo-defaults", |
| 5853 | apex_available: ["otherapex"], |
| 5854 | } |
| 5855 | |
| 5856 | cc_library { |
| 5857 | name: "libfoo", |
| 5858 | defaults: ["libfoo-defaults"], |
| 5859 | stl: "none", |
| 5860 | system_shared_libs: [], |
| 5861 | }`) |
| 5862 | } |
| 5863 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5864 | func TestApexAvailable_DirectDep(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5865 | // libfoo is not available to myapex, but only to otherapex |
Steven Moreland | 6e36cd6 | 2020-10-22 01:08:35 +0000 | [diff] [blame] | 5866 | 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] | 5867 | apex { |
| 5868 | name: "myapex", |
| 5869 | key: "myapex.key", |
| 5870 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5871 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5872 | } |
| 5873 | |
| 5874 | apex_key { |
| 5875 | name: "myapex.key", |
| 5876 | public_key: "testkey.avbpubkey", |
| 5877 | private_key: "testkey.pem", |
| 5878 | } |
| 5879 | |
| 5880 | apex { |
| 5881 | name: "otherapex", |
| 5882 | key: "otherapex.key", |
| 5883 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5884 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5885 | } |
| 5886 | |
| 5887 | apex_key { |
| 5888 | name: "otherapex.key", |
| 5889 | public_key: "testkey.avbpubkey", |
| 5890 | private_key: "testkey.pem", |
| 5891 | } |
| 5892 | |
| 5893 | cc_library { |
| 5894 | name: "libfoo", |
| 5895 | stl: "none", |
| 5896 | system_shared_libs: [], |
| 5897 | apex_available: ["otherapex"], |
| 5898 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5899 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5900 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5901 | func TestApexAvailable_IndirectDep(t *testing.T) { |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5902 | // libbbaz is an indirect dep |
Jiyong Park | 767dbd9 | 2021-03-04 13:03:10 +0900 | [diff] [blame] | 5903 | 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] | 5904 | .*via tag apex\.dependencyTag.*name:sharedLib.* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 5905 | .*-> libfoo.*link:shared.* |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 5906 | .*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 5907 | .*-> libbar.*link:shared.* |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 5908 | .*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.* |
Paul Duffin | 6534770 | 2020-03-31 15:23:40 +0100 | [diff] [blame] | 5909 | .*-> libbaz.*link:shared.*`, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5910 | apex { |
| 5911 | name: "myapex", |
| 5912 | key: "myapex.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: "myapex.key", |
| 5919 | public_key: "testkey.avbpubkey", |
| 5920 | private_key: "testkey.pem", |
| 5921 | } |
| 5922 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5923 | cc_library { |
| 5924 | name: "libfoo", |
| 5925 | stl: "none", |
| 5926 | shared_libs: ["libbar"], |
| 5927 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5928 | apex_available: ["myapex"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5929 | } |
| 5930 | |
| 5931 | cc_library { |
| 5932 | name: "libbar", |
| 5933 | stl: "none", |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5934 | shared_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5935 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5936 | apex_available: ["myapex"], |
| 5937 | } |
| 5938 | |
| 5939 | cc_library { |
| 5940 | name: "libbaz", |
| 5941 | stl: "none", |
| 5942 | system_shared_libs: [], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5943 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5944 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5945 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5946 | func TestApexAvailable_InvalidApexName(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5947 | testApexError(t, "\"otherapex\" is not a valid module name", ` |
| 5948 | apex { |
| 5949 | name: "myapex", |
| 5950 | key: "myapex.key", |
| 5951 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5952 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5953 | } |
| 5954 | |
| 5955 | apex_key { |
| 5956 | name: "myapex.key", |
| 5957 | public_key: "testkey.avbpubkey", |
| 5958 | private_key: "testkey.pem", |
| 5959 | } |
| 5960 | |
| 5961 | cc_library { |
| 5962 | name: "libfoo", |
| 5963 | stl: "none", |
| 5964 | system_shared_libs: [], |
| 5965 | apex_available: ["otherapex"], |
| 5966 | }`) |
| 5967 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5968 | testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5969 | apex { |
| 5970 | name: "myapex", |
| 5971 | key: "myapex.key", |
| 5972 | native_shared_libs: ["libfoo", "libbar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5973 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5974 | } |
| 5975 | |
| 5976 | apex_key { |
| 5977 | name: "myapex.key", |
| 5978 | public_key: "testkey.avbpubkey", |
| 5979 | private_key: "testkey.pem", |
| 5980 | } |
| 5981 | |
| 5982 | cc_library { |
| 5983 | name: "libfoo", |
| 5984 | stl: "none", |
| 5985 | system_shared_libs: [], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 5986 | runtime_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5987 | apex_available: ["myapex"], |
| 5988 | } |
| 5989 | |
| 5990 | cc_library { |
| 5991 | name: "libbar", |
| 5992 | stl: "none", |
| 5993 | system_shared_libs: [], |
| 5994 | apex_available: ["//apex_available:anyapex"], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 5995 | } |
| 5996 | |
| 5997 | cc_library { |
| 5998 | name: "libbaz", |
| 5999 | stl: "none", |
| 6000 | system_shared_libs: [], |
| 6001 | stubs: { |
| 6002 | versions: ["10", "20", "30"], |
| 6003 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 6004 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 6005 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 6006 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 6007 | func TestApexAvailable_CheckForPlatform(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6008 | ctx := testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 6009 | apex { |
| 6010 | name: "myapex", |
| 6011 | key: "myapex.key", |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 6012 | native_shared_libs: ["libbar", "libbaz"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6013 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 6014 | } |
| 6015 | |
| 6016 | apex_key { |
| 6017 | name: "myapex.key", |
| 6018 | public_key: "testkey.avbpubkey", |
| 6019 | private_key: "testkey.pem", |
| 6020 | } |
| 6021 | |
| 6022 | cc_library { |
| 6023 | name: "libfoo", |
| 6024 | stl: "none", |
| 6025 | system_shared_libs: [], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 6026 | shared_libs: ["libbar"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 6027 | apex_available: ["//apex_available:platform"], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 6028 | } |
| 6029 | |
| 6030 | cc_library { |
| 6031 | name: "libfoo2", |
| 6032 | stl: "none", |
| 6033 | system_shared_libs: [], |
| 6034 | shared_libs: ["libbaz"], |
| 6035 | apex_available: ["//apex_available:platform"], |
| 6036 | } |
| 6037 | |
| 6038 | cc_library { |
| 6039 | name: "libbar", |
| 6040 | stl: "none", |
| 6041 | system_shared_libs: [], |
| 6042 | apex_available: ["myapex"], |
| 6043 | } |
| 6044 | |
| 6045 | cc_library { |
| 6046 | name: "libbaz", |
| 6047 | stl: "none", |
| 6048 | system_shared_libs: [], |
| 6049 | apex_available: ["myapex"], |
| 6050 | stubs: { |
| 6051 | versions: ["1"], |
| 6052 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 6053 | }`) |
| 6054 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 6055 | // libfoo shouldn't be available to platform even though it has "//apex_available:platform", |
| 6056 | // because it depends on libbar which isn't available to platform |
| 6057 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 6058 | if libfoo.NotAvailableForPlatform() != true { |
| 6059 | t.Errorf("%q shouldn't be available to platform", libfoo.String()) |
| 6060 | } |
| 6061 | |
| 6062 | // libfoo2 however can be available to platform because it depends on libbaz which provides |
| 6063 | // stubs |
| 6064 | libfoo2 := ctx.ModuleForTests("libfoo2", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 6065 | if libfoo2.NotAvailableForPlatform() == true { |
| 6066 | t.Errorf("%q should be available to platform", libfoo2.String()) |
| 6067 | } |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 6068 | } |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 6069 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 6070 | func TestApexAvailable_CreatedForApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6071 | ctx := testApex(t, ` |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 6072 | apex { |
| 6073 | name: "myapex", |
| 6074 | key: "myapex.key", |
| 6075 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6076 | updatable: false, |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 6077 | } |
| 6078 | |
| 6079 | apex_key { |
| 6080 | name: "myapex.key", |
| 6081 | public_key: "testkey.avbpubkey", |
| 6082 | private_key: "testkey.pem", |
| 6083 | } |
| 6084 | |
| 6085 | cc_library { |
| 6086 | name: "libfoo", |
| 6087 | stl: "none", |
| 6088 | system_shared_libs: [], |
| 6089 | apex_available: ["myapex"], |
| 6090 | static: { |
| 6091 | apex_available: ["//apex_available:platform"], |
| 6092 | }, |
| 6093 | }`) |
| 6094 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 6095 | libfooShared := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 6096 | if libfooShared.NotAvailableForPlatform() != true { |
| 6097 | t.Errorf("%q shouldn't be available to platform", libfooShared.String()) |
| 6098 | } |
| 6099 | libfooStatic := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*cc.Module) |
| 6100 | if libfooStatic.NotAvailableForPlatform() != false { |
| 6101 | t.Errorf("%q should be available to platform", libfooStatic.String()) |
| 6102 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 6103 | } |
| 6104 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6105 | func TestOverrideApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6106 | ctx := testApex(t, ` |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6107 | apex { |
| 6108 | name: "myapex", |
| 6109 | key: "myapex.key", |
| 6110 | apps: ["app"], |
markchien | 7c803b8 | 2021-08-26 22:10:06 +0800 | [diff] [blame] | 6111 | bpfs: ["bpf"], |
Daniel Norman | 5a3ce13 | 2021-08-26 15:44:43 -0700 | [diff] [blame] | 6112 | prebuilts: ["myetc"], |
Remi NGUYEN VAN | be90172 | 2022-03-02 21:00:33 +0900 | [diff] [blame] | 6113 | bootclasspath_fragments: ["mybootclasspath_fragment"], |
| 6114 | systemserverclasspath_fragments: ["mysystemserverclasspath_fragment"], |
| 6115 | java_libs: ["myjava_library"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 6116 | overrides: ["oldapex"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6117 | updatable: false, |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6118 | } |
| 6119 | |
| 6120 | override_apex { |
| 6121 | name: "override_myapex", |
| 6122 | base: "myapex", |
| 6123 | apps: ["override_app"], |
markchien | 7c803b8 | 2021-08-26 22:10:06 +0800 | [diff] [blame] | 6124 | bpfs: ["override_bpf"], |
Daniel Norman | 5a3ce13 | 2021-08-26 15:44:43 -0700 | [diff] [blame] | 6125 | prebuilts: ["override_myetc"], |
Remi NGUYEN VAN | be90172 | 2022-03-02 21:00:33 +0900 | [diff] [blame] | 6126 | bootclasspath_fragments: ["override_bootclasspath_fragment"], |
| 6127 | systemserverclasspath_fragments: ["override_systemserverclasspath_fragment"], |
| 6128 | java_libs: ["override_java_library"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 6129 | overrides: ["unknownapex"], |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 6130 | logging_parent: "com.foo.bar", |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 6131 | package_name: "test.overridden.package", |
Jaewoong Jung | 4cfdf7d | 2021-04-20 16:21:24 -0700 | [diff] [blame] | 6132 | key: "mynewapex.key", |
| 6133 | certificate: ":myapex.certificate", |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6134 | } |
| 6135 | |
| 6136 | apex_key { |
| 6137 | name: "myapex.key", |
| 6138 | public_key: "testkey.avbpubkey", |
| 6139 | private_key: "testkey.pem", |
| 6140 | } |
| 6141 | |
Jaewoong Jung | 4cfdf7d | 2021-04-20 16:21:24 -0700 | [diff] [blame] | 6142 | apex_key { |
| 6143 | name: "mynewapex.key", |
| 6144 | public_key: "testkey2.avbpubkey", |
| 6145 | private_key: "testkey2.pem", |
| 6146 | } |
| 6147 | |
| 6148 | android_app_certificate { |
| 6149 | name: "myapex.certificate", |
| 6150 | certificate: "testkey", |
| 6151 | } |
| 6152 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6153 | android_app { |
| 6154 | name: "app", |
| 6155 | srcs: ["foo/bar/MyClass.java"], |
| 6156 | package_name: "foo", |
| 6157 | sdk_version: "none", |
| 6158 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 6159 | apex_available: [ "myapex" ], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6160 | } |
| 6161 | |
| 6162 | override_android_app { |
| 6163 | name: "override_app", |
| 6164 | base: "app", |
| 6165 | package_name: "bar", |
| 6166 | } |
markchien | 7c803b8 | 2021-08-26 22:10:06 +0800 | [diff] [blame] | 6167 | |
| 6168 | bpf { |
| 6169 | name: "bpf", |
| 6170 | srcs: ["bpf.c"], |
| 6171 | } |
| 6172 | |
| 6173 | bpf { |
| 6174 | name: "override_bpf", |
| 6175 | srcs: ["override_bpf.c"], |
| 6176 | } |
Daniel Norman | 5a3ce13 | 2021-08-26 15:44:43 -0700 | [diff] [blame] | 6177 | |
| 6178 | prebuilt_etc { |
| 6179 | name: "myetc", |
| 6180 | src: "myprebuilt", |
| 6181 | } |
| 6182 | |
| 6183 | prebuilt_etc { |
| 6184 | name: "override_myetc", |
| 6185 | src: "override_myprebuilt", |
| 6186 | } |
Remi NGUYEN VAN | be90172 | 2022-03-02 21:00:33 +0900 | [diff] [blame] | 6187 | |
| 6188 | java_library { |
| 6189 | name: "bcplib", |
| 6190 | srcs: ["a.java"], |
| 6191 | compile_dex: true, |
| 6192 | apex_available: ["myapex"], |
| 6193 | permitted_packages: ["bcp.lib"], |
| 6194 | } |
| 6195 | |
| 6196 | bootclasspath_fragment { |
| 6197 | name: "mybootclasspath_fragment", |
| 6198 | contents: ["bcplib"], |
| 6199 | apex_available: ["myapex"], |
| 6200 | } |
| 6201 | |
| 6202 | java_library { |
| 6203 | name: "override_bcplib", |
| 6204 | srcs: ["a.java"], |
| 6205 | compile_dex: true, |
| 6206 | apex_available: ["myapex"], |
| 6207 | permitted_packages: ["override.bcp.lib"], |
| 6208 | } |
| 6209 | |
| 6210 | bootclasspath_fragment { |
| 6211 | name: "override_bootclasspath_fragment", |
| 6212 | contents: ["override_bcplib"], |
| 6213 | apex_available: ["myapex"], |
| 6214 | } |
| 6215 | |
| 6216 | java_library { |
| 6217 | name: "systemserverlib", |
| 6218 | srcs: ["a.java"], |
| 6219 | apex_available: ["myapex"], |
| 6220 | } |
| 6221 | |
| 6222 | systemserverclasspath_fragment { |
| 6223 | name: "mysystemserverclasspath_fragment", |
| 6224 | standalone_contents: ["systemserverlib"], |
| 6225 | apex_available: ["myapex"], |
| 6226 | } |
| 6227 | |
| 6228 | java_library { |
| 6229 | name: "override_systemserverlib", |
| 6230 | srcs: ["a.java"], |
| 6231 | apex_available: ["myapex"], |
| 6232 | } |
| 6233 | |
| 6234 | systemserverclasspath_fragment { |
| 6235 | name: "override_systemserverclasspath_fragment", |
| 6236 | standalone_contents: ["override_systemserverlib"], |
| 6237 | apex_available: ["myapex"], |
| 6238 | } |
| 6239 | |
| 6240 | java_library { |
| 6241 | name: "myjava_library", |
| 6242 | srcs: ["a.java"], |
| 6243 | compile_dex: true, |
| 6244 | apex_available: ["myapex"], |
| 6245 | } |
| 6246 | |
| 6247 | java_library { |
| 6248 | name: "override_java_library", |
| 6249 | srcs: ["a.java"], |
| 6250 | compile_dex: true, |
| 6251 | apex_available: ["myapex"], |
| 6252 | } |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 6253 | `, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"})) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6254 | |
Jiyong Park | 317645e | 2019-12-05 13:20:58 +0900 | [diff] [blame] | 6255 | originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule) |
| 6256 | overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule) |
| 6257 | if originalVariant.GetOverriddenBy() != "" { |
| 6258 | t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy()) |
| 6259 | } |
| 6260 | if overriddenVariant.GetOverriddenBy() != "override_myapex" { |
| 6261 | t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy()) |
| 6262 | } |
| 6263 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6264 | module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image") |
| 6265 | apexRule := module.Rule("apexRule") |
| 6266 | copyCmds := apexRule.Args["copy_commands"] |
| 6267 | |
| 6268 | ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 6269 | ensureContains(t, copyCmds, "image.apex/app/override_app/override_app.apk") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 6270 | |
markchien | 7c803b8 | 2021-08-26 22:10:06 +0800 | [diff] [blame] | 6271 | ensureNotContains(t, copyCmds, "image.apex/etc/bpf/bpf.o") |
| 6272 | ensureContains(t, copyCmds, "image.apex/etc/bpf/override_bpf.o") |
| 6273 | |
Daniel Norman | 5a3ce13 | 2021-08-26 15:44:43 -0700 | [diff] [blame] | 6274 | ensureNotContains(t, copyCmds, "image.apex/etc/myetc") |
| 6275 | ensureContains(t, copyCmds, "image.apex/etc/override_myetc") |
| 6276 | |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 6277 | apexBundle := module.Module().(*apexBundle) |
| 6278 | name := apexBundle.Name() |
| 6279 | if name != "override_myapex" { |
| 6280 | t.Errorf("name should be \"override_myapex\", but was %q", name) |
| 6281 | } |
| 6282 | |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 6283 | if apexBundle.overridableProperties.Logging_parent != "com.foo.bar" { |
| 6284 | t.Errorf("override_myapex should have logging parent (com.foo.bar), but was %q.", apexBundle.overridableProperties.Logging_parent) |
| 6285 | } |
| 6286 | |
Remi NGUYEN VAN | be90172 | 2022-03-02 21:00:33 +0900 | [diff] [blame] | 6287 | android.AssertArrayString(t, "Bootclasspath_fragments does not match", |
| 6288 | []string{"override_bootclasspath_fragment"}, apexBundle.overridableProperties.Bootclasspath_fragments) |
| 6289 | android.AssertArrayString(t, "Systemserverclasspath_fragments does not match", |
| 6290 | []string{"override_systemserverclasspath_fragment"}, apexBundle.overridableProperties.Systemserverclasspath_fragments) |
| 6291 | android.AssertArrayString(t, "Java_libs does not match", |
| 6292 | []string{"override_java_library"}, apexBundle.overridableProperties.Java_libs) |
| 6293 | |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 6294 | optFlags := apexRule.Args["opt_flags"] |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 6295 | ensureContains(t, optFlags, "--override_apk_package_name test.overridden.package") |
Jaewoong Jung | 4cfdf7d | 2021-04-20 16:21:24 -0700 | [diff] [blame] | 6296 | ensureContains(t, optFlags, "--pubkey testkey2.avbpubkey") |
| 6297 | |
| 6298 | signApkRule := module.Rule("signapk") |
| 6299 | ensureEquals(t, signApkRule.Args["certificates"], "testkey.x509.pem testkey.pk8") |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 6300 | |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 6301 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 6302 | var builder strings.Builder |
| 6303 | data.Custom(&builder, name, "TARGET_", "", data) |
| 6304 | androidMk := builder.String() |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 6305 | ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex") |
markchien | 7c803b8 | 2021-08-26 22:10:06 +0800 | [diff] [blame] | 6306 | ensureContains(t, androidMk, "LOCAL_MODULE := override_bpf.o.override_myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 6307 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex") |
Remi NGUYEN VAN | be90172 | 2022-03-02 21:00:33 +0900 | [diff] [blame] | 6308 | ensureContains(t, androidMk, "LOCAL_MODULE := override_bcplib.override_myapex") |
| 6309 | ensureContains(t, androidMk, "LOCAL_MODULE := override_systemserverlib.override_myapex") |
| 6310 | ensureContains(t, androidMk, "LOCAL_MODULE := override_java_library.override_myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 6311 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex") |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 6312 | ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 6313 | ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex") |
markchien | 7c803b8 | 2021-08-26 22:10:06 +0800 | [diff] [blame] | 6314 | ensureNotContains(t, androidMk, "LOCAL_MODULE := bpf.myapex") |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 6315 | ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 6316 | ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex") |
Remi NGUYEN VAN | be90172 | 2022-03-02 21:00:33 +0900 | [diff] [blame] | 6317 | ensureNotContains(t, androidMk, "LOCAL_MODULE := override_bcplib.myapex") |
| 6318 | ensureNotContains(t, androidMk, "LOCAL_MODULE := override_systemserverlib.myapex") |
| 6319 | ensureNotContains(t, androidMk, "LOCAL_MODULE := override_java_library.pb.myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 6320 | ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex") |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 6321 | } |
| 6322 | |
Albert Martin | eefabcf | 2022-03-21 20:11:16 +0000 | [diff] [blame] | 6323 | func TestMinSdkVersionOverride(t *testing.T) { |
| 6324 | // Override from 29 to 31 |
| 6325 | minSdkOverride31 := "31" |
| 6326 | ctx := testApex(t, ` |
| 6327 | apex { |
| 6328 | name: "myapex", |
| 6329 | key: "myapex.key", |
| 6330 | native_shared_libs: ["mylib"], |
| 6331 | updatable: true, |
| 6332 | min_sdk_version: "29" |
| 6333 | } |
| 6334 | |
| 6335 | override_apex { |
| 6336 | name: "override_myapex", |
| 6337 | base: "myapex", |
| 6338 | logging_parent: "com.foo.bar", |
| 6339 | package_name: "test.overridden.package" |
| 6340 | } |
| 6341 | |
| 6342 | apex_key { |
| 6343 | name: "myapex.key", |
| 6344 | public_key: "testkey.avbpubkey", |
| 6345 | private_key: "testkey.pem", |
| 6346 | } |
| 6347 | |
| 6348 | cc_library { |
| 6349 | name: "mylib", |
| 6350 | srcs: ["mylib.cpp"], |
| 6351 | runtime_libs: ["libbar"], |
| 6352 | system_shared_libs: [], |
| 6353 | stl: "none", |
| 6354 | apex_available: [ "myapex" ], |
| 6355 | min_sdk_version: "apex_inherit" |
| 6356 | } |
| 6357 | |
| 6358 | cc_library { |
| 6359 | name: "libbar", |
| 6360 | srcs: ["mylib.cpp"], |
| 6361 | system_shared_libs: [], |
| 6362 | stl: "none", |
| 6363 | apex_available: [ "myapex" ], |
| 6364 | min_sdk_version: "apex_inherit" |
| 6365 | } |
| 6366 | |
| 6367 | `, withApexGlobalMinSdkVersionOverride(&minSdkOverride31)) |
| 6368 | |
| 6369 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 6370 | copyCmds := apexRule.Args["copy_commands"] |
| 6371 | |
| 6372 | // Ensure that direct non-stubs dep is always included |
| 6373 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 6374 | |
| 6375 | // Ensure that runtime_libs dep in included |
| 6376 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 6377 | |
| 6378 | // Ensure libraries target overridden min_sdk_version value |
| 6379 | ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared_apex31") |
| 6380 | } |
| 6381 | |
| 6382 | func TestMinSdkVersionOverrideToLowerVersionNoOp(t *testing.T) { |
| 6383 | // Attempt to override from 31 to 29, should be a NOOP |
| 6384 | minSdkOverride29 := "29" |
| 6385 | ctx := testApex(t, ` |
| 6386 | apex { |
| 6387 | name: "myapex", |
| 6388 | key: "myapex.key", |
| 6389 | native_shared_libs: ["mylib"], |
| 6390 | updatable: true, |
| 6391 | min_sdk_version: "31" |
| 6392 | } |
| 6393 | |
| 6394 | override_apex { |
| 6395 | name: "override_myapex", |
| 6396 | base: "myapex", |
| 6397 | logging_parent: "com.foo.bar", |
| 6398 | package_name: "test.overridden.package" |
| 6399 | } |
| 6400 | |
| 6401 | apex_key { |
| 6402 | name: "myapex.key", |
| 6403 | public_key: "testkey.avbpubkey", |
| 6404 | private_key: "testkey.pem", |
| 6405 | } |
| 6406 | |
| 6407 | cc_library { |
| 6408 | name: "mylib", |
| 6409 | srcs: ["mylib.cpp"], |
| 6410 | runtime_libs: ["libbar"], |
| 6411 | system_shared_libs: [], |
| 6412 | stl: "none", |
| 6413 | apex_available: [ "myapex" ], |
| 6414 | min_sdk_version: "apex_inherit" |
| 6415 | } |
| 6416 | |
| 6417 | cc_library { |
| 6418 | name: "libbar", |
| 6419 | srcs: ["mylib.cpp"], |
| 6420 | system_shared_libs: [], |
| 6421 | stl: "none", |
| 6422 | apex_available: [ "myapex" ], |
| 6423 | min_sdk_version: "apex_inherit" |
| 6424 | } |
| 6425 | |
| 6426 | `, withApexGlobalMinSdkVersionOverride(&minSdkOverride29)) |
| 6427 | |
| 6428 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 6429 | copyCmds := apexRule.Args["copy_commands"] |
| 6430 | |
| 6431 | // Ensure that direct non-stubs dep is always included |
| 6432 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 6433 | |
| 6434 | // Ensure that runtime_libs dep in included |
| 6435 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 6436 | |
| 6437 | // Ensure libraries target the original min_sdk_version value rather than the overridden |
| 6438 | ensureListContains(t, ctx.ModuleVariantsForTests("libbar"), "android_arm64_armv8-a_shared_apex31") |
| 6439 | } |
| 6440 | |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 6441 | func TestLegacyAndroid10Support(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6442 | ctx := testApex(t, ` |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 6443 | apex { |
| 6444 | name: "myapex", |
| 6445 | key: "myapex.key", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 6446 | native_shared_libs: ["mylib"], |
Jooyung Han | 5417f77 | 2020-03-12 18:37:20 +0900 | [diff] [blame] | 6447 | min_sdk_version: "29", |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 6448 | } |
| 6449 | |
| 6450 | apex_key { |
| 6451 | name: "myapex.key", |
| 6452 | public_key: "testkey.avbpubkey", |
| 6453 | private_key: "testkey.pem", |
| 6454 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 6455 | |
| 6456 | cc_library { |
| 6457 | name: "mylib", |
| 6458 | srcs: ["mylib.cpp"], |
| 6459 | stl: "libc++", |
| 6460 | system_shared_libs: [], |
| 6461 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6462 | min_sdk_version: "29", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 6463 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 6464 | `, withUnbundledBuild) |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 6465 | |
| 6466 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 6467 | args := module.Rule("apexRule").Args |
| 6468 | 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] | 6469 | ensureNotContains(t, args["opt_flags"], "--no_hashtree") |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 6470 | |
| 6471 | // The copies of the libraries in the apex should have one more dependency than |
| 6472 | // the ones outside the apex, namely the unwinder. Ideally we should check |
| 6473 | // the dependency names directly here but for some reason the names are blank in |
| 6474 | // this test. |
| 6475 | for _, lib := range []string{"libc++", "mylib"} { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 6476 | 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] | 6477 | nonApexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld").Implicits |
| 6478 | if len(apexImplicits) != len(nonApexImplicits)+1 { |
| 6479 | t.Errorf("%q missing unwinder dep", lib) |
| 6480 | } |
| 6481 | } |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 6482 | } |
| 6483 | |
Paul Duffin | e05480a | 2021-03-08 15:07:14 +0000 | [diff] [blame] | 6484 | var filesForSdkLibrary = android.MockFS{ |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6485 | "api/current.txt": nil, |
| 6486 | "api/removed.txt": nil, |
| 6487 | "api/system-current.txt": nil, |
| 6488 | "api/system-removed.txt": nil, |
| 6489 | "api/test-current.txt": nil, |
| 6490 | "api/test-removed.txt": nil, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 6491 | |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 6492 | "100/public/api/foo.txt": nil, |
| 6493 | "100/public/api/foo-removed.txt": nil, |
| 6494 | "100/system/api/foo.txt": nil, |
| 6495 | "100/system/api/foo-removed.txt": nil, |
| 6496 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 6497 | // For java_sdk_library_import |
| 6498 | "a.jar": nil, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6499 | } |
| 6500 | |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 6501 | func TestJavaSDKLibrary(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6502 | ctx := testApex(t, ` |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 6503 | apex { |
| 6504 | name: "myapex", |
| 6505 | key: "myapex.key", |
| 6506 | java_libs: ["foo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6507 | updatable: false, |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 6508 | } |
| 6509 | |
| 6510 | apex_key { |
| 6511 | name: "myapex.key", |
| 6512 | public_key: "testkey.avbpubkey", |
| 6513 | private_key: "testkey.pem", |
| 6514 | } |
| 6515 | |
| 6516 | java_sdk_library { |
| 6517 | name: "foo", |
| 6518 | srcs: ["a.java"], |
| 6519 | api_packages: ["foo"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 6520 | apex_available: [ "myapex" ], |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 6521 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 6522 | |
| 6523 | prebuilt_apis { |
| 6524 | name: "sdk", |
| 6525 | api_dirs: ["100"], |
| 6526 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6527 | `, withFiles(filesForSdkLibrary)) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 6528 | |
| 6529 | // java_sdk_library installs both impl jar and permission XML |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 6530 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 6531 | "javalib/foo.jar", |
| 6532 | "etc/permissions/foo.xml", |
| 6533 | }) |
| 6534 | // 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] | 6535 | sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml") |
Pedro Loureiro | 9956e5e | 2021-09-07 17:21:59 +0000 | [diff] [blame] | 6536 | 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] | 6537 | } |
| 6538 | |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6539 | func TestJavaSDKLibrary_WithinApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6540 | ctx := testApex(t, ` |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6541 | apex { |
| 6542 | name: "myapex", |
| 6543 | key: "myapex.key", |
| 6544 | java_libs: ["foo", "bar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6545 | updatable: false, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6546 | } |
| 6547 | |
| 6548 | apex_key { |
| 6549 | name: "myapex.key", |
| 6550 | public_key: "testkey.avbpubkey", |
| 6551 | private_key: "testkey.pem", |
| 6552 | } |
| 6553 | |
| 6554 | java_sdk_library { |
| 6555 | name: "foo", |
| 6556 | srcs: ["a.java"], |
| 6557 | api_packages: ["foo"], |
| 6558 | apex_available: ["myapex"], |
| 6559 | sdk_version: "none", |
| 6560 | system_modules: "none", |
| 6561 | } |
| 6562 | |
| 6563 | java_library { |
| 6564 | name: "bar", |
| 6565 | srcs: ["a.java"], |
| 6566 | libs: ["foo"], |
| 6567 | apex_available: ["myapex"], |
| 6568 | sdk_version: "none", |
| 6569 | system_modules: "none", |
| 6570 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 6571 | |
| 6572 | prebuilt_apis { |
| 6573 | name: "sdk", |
| 6574 | api_dirs: ["100"], |
| 6575 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6576 | `, withFiles(filesForSdkLibrary)) |
| 6577 | |
| 6578 | // java_sdk_library installs both impl jar and permission XML |
| 6579 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 6580 | "javalib/bar.jar", |
| 6581 | "javalib/foo.jar", |
| 6582 | "etc/permissions/foo.xml", |
| 6583 | }) |
| 6584 | |
| 6585 | // The bar library should depend on the implementation jar. |
| 6586 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
Paul Duffin | cf8d7db | 2021-03-29 00:29:53 +0100 | [diff] [blame] | 6587 | 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] | 6588 | t.Errorf("expected %q, found %#q", expected, actual) |
| 6589 | } |
| 6590 | } |
| 6591 | |
| 6592 | func TestJavaSDKLibrary_CrossBoundary(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6593 | ctx := testApex(t, ` |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6594 | apex { |
| 6595 | name: "myapex", |
| 6596 | key: "myapex.key", |
| 6597 | java_libs: ["foo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6598 | updatable: false, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6599 | } |
| 6600 | |
| 6601 | apex_key { |
| 6602 | name: "myapex.key", |
| 6603 | public_key: "testkey.avbpubkey", |
| 6604 | private_key: "testkey.pem", |
| 6605 | } |
| 6606 | |
| 6607 | java_sdk_library { |
| 6608 | name: "foo", |
| 6609 | srcs: ["a.java"], |
| 6610 | api_packages: ["foo"], |
| 6611 | apex_available: ["myapex"], |
| 6612 | sdk_version: "none", |
| 6613 | system_modules: "none", |
| 6614 | } |
| 6615 | |
| 6616 | java_library { |
| 6617 | name: "bar", |
| 6618 | srcs: ["a.java"], |
| 6619 | libs: ["foo"], |
| 6620 | sdk_version: "none", |
| 6621 | system_modules: "none", |
| 6622 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 6623 | |
| 6624 | prebuilt_apis { |
| 6625 | name: "sdk", |
| 6626 | api_dirs: ["100"], |
| 6627 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 6628 | `, withFiles(filesForSdkLibrary)) |
| 6629 | |
| 6630 | // java_sdk_library installs both impl jar and permission XML |
| 6631 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 6632 | "javalib/foo.jar", |
| 6633 | "etc/permissions/foo.xml", |
| 6634 | }) |
| 6635 | |
| 6636 | // The bar library should depend on the stubs jar. |
| 6637 | barLibrary := ctx.ModuleForTests("bar", "android_common").Rule("javac") |
Paul Duffin | cf8d7db | 2021-03-29 00:29:53 +0100 | [diff] [blame] | 6638 | 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] | 6639 | t.Errorf("expected %q, found %#q", expected, actual) |
| 6640 | } |
| 6641 | } |
| 6642 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 6643 | func TestJavaSDKLibrary_ImportPreferred(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6644 | ctx := testApex(t, ` |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 6645 | prebuilt_apis { |
| 6646 | name: "sdk", |
| 6647 | api_dirs: ["100"], |
| 6648 | }`, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 6649 | withFiles(map[string][]byte{ |
| 6650 | "apex/a.java": nil, |
| 6651 | "apex/apex_manifest.json": nil, |
| 6652 | "apex/Android.bp": []byte(` |
| 6653 | package { |
| 6654 | default_visibility: ["//visibility:private"], |
| 6655 | } |
| 6656 | |
| 6657 | apex { |
| 6658 | name: "myapex", |
| 6659 | key: "myapex.key", |
| 6660 | java_libs: ["foo", "bar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6661 | updatable: false, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 6662 | } |
| 6663 | |
| 6664 | apex_key { |
| 6665 | name: "myapex.key", |
| 6666 | public_key: "testkey.avbpubkey", |
| 6667 | private_key: "testkey.pem", |
| 6668 | } |
| 6669 | |
| 6670 | java_library { |
| 6671 | name: "bar", |
| 6672 | srcs: ["a.java"], |
| 6673 | libs: ["foo"], |
| 6674 | apex_available: ["myapex"], |
| 6675 | sdk_version: "none", |
| 6676 | system_modules: "none", |
| 6677 | } |
| 6678 | `), |
| 6679 | "source/a.java": nil, |
| 6680 | "source/api/current.txt": nil, |
| 6681 | "source/api/removed.txt": nil, |
| 6682 | "source/Android.bp": []byte(` |
| 6683 | package { |
| 6684 | default_visibility: ["//visibility:private"], |
| 6685 | } |
| 6686 | |
| 6687 | java_sdk_library { |
| 6688 | name: "foo", |
| 6689 | visibility: ["//apex"], |
| 6690 | srcs: ["a.java"], |
| 6691 | api_packages: ["foo"], |
| 6692 | apex_available: ["myapex"], |
| 6693 | sdk_version: "none", |
| 6694 | system_modules: "none", |
| 6695 | public: { |
| 6696 | enabled: true, |
| 6697 | }, |
| 6698 | } |
| 6699 | `), |
| 6700 | "prebuilt/a.jar": nil, |
| 6701 | "prebuilt/Android.bp": []byte(` |
| 6702 | package { |
| 6703 | default_visibility: ["//visibility:private"], |
| 6704 | } |
| 6705 | |
| 6706 | java_sdk_library_import { |
| 6707 | name: "foo", |
| 6708 | visibility: ["//apex", "//source"], |
| 6709 | apex_available: ["myapex"], |
| 6710 | prefer: true, |
| 6711 | public: { |
| 6712 | jars: ["a.jar"], |
| 6713 | }, |
| 6714 | } |
| 6715 | `), |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 6716 | }), withFiles(filesForSdkLibrary), |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 6717 | ) |
| 6718 | |
| 6719 | // java_sdk_library installs both impl jar and permission XML |
| 6720 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 6721 | "javalib/bar.jar", |
| 6722 | "javalib/foo.jar", |
| 6723 | "etc/permissions/foo.xml", |
| 6724 | }) |
| 6725 | |
| 6726 | // The bar library should depend on the implementation jar. |
| 6727 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
Paul Duffin | cf8d7db | 2021-03-29 00:29:53 +0100 | [diff] [blame] | 6728 | 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] | 6729 | t.Errorf("expected %q, found %#q", expected, actual) |
| 6730 | } |
| 6731 | } |
| 6732 | |
| 6733 | func TestJavaSDKLibrary_ImportOnly(t *testing.T) { |
| 6734 | testApexError(t, `java_libs: "foo" is not configured to be compiled into dex`, ` |
| 6735 | apex { |
| 6736 | name: "myapex", |
| 6737 | key: "myapex.key", |
| 6738 | java_libs: ["foo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6739 | updatable: false, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 6740 | } |
| 6741 | |
| 6742 | apex_key { |
| 6743 | name: "myapex.key", |
| 6744 | public_key: "testkey.avbpubkey", |
| 6745 | private_key: "testkey.pem", |
| 6746 | } |
| 6747 | |
| 6748 | java_sdk_library_import { |
| 6749 | name: "foo", |
| 6750 | apex_available: ["myapex"], |
| 6751 | prefer: true, |
| 6752 | public: { |
| 6753 | jars: ["a.jar"], |
| 6754 | }, |
| 6755 | } |
| 6756 | |
| 6757 | `, withFiles(filesForSdkLibrary)) |
| 6758 | } |
| 6759 | |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6760 | func TestCompatConfig(t *testing.T) { |
Paul Duffin | 284165a | 2021-03-29 01:50:31 +0100 | [diff] [blame] | 6761 | result := android.GroupFixturePreparers( |
| 6762 | prepareForApexTest, |
| 6763 | java.PrepareForTestWithPlatformCompatConfig, |
| 6764 | ).RunTestWithBp(t, ` |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6765 | apex { |
| 6766 | name: "myapex", |
| 6767 | key: "myapex.key", |
Paul Duffin | 3abc174 | 2021-03-15 19:32:23 +0000 | [diff] [blame] | 6768 | compat_configs: ["myjar-platform-compat-config"], |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6769 | java_libs: ["myjar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6770 | updatable: false, |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6771 | } |
| 6772 | |
| 6773 | apex_key { |
| 6774 | name: "myapex.key", |
| 6775 | public_key: "testkey.avbpubkey", |
| 6776 | private_key: "testkey.pem", |
| 6777 | } |
| 6778 | |
| 6779 | platform_compat_config { |
| 6780 | name: "myjar-platform-compat-config", |
| 6781 | src: ":myjar", |
| 6782 | } |
| 6783 | |
| 6784 | java_library { |
| 6785 | name: "myjar", |
| 6786 | srcs: ["foo/bar/MyClass.java"], |
| 6787 | sdk_version: "none", |
| 6788 | system_modules: "none", |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6789 | apex_available: [ "myapex" ], |
| 6790 | } |
Paul Duffin | 1b29e00 | 2021-03-16 15:06:54 +0000 | [diff] [blame] | 6791 | |
| 6792 | // Make sure that a preferred prebuilt does not affect the apex contents. |
| 6793 | prebuilt_platform_compat_config { |
| 6794 | name: "myjar-platform-compat-config", |
| 6795 | metadata: "compat-config/metadata.xml", |
| 6796 | prefer: true, |
| 6797 | } |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6798 | `) |
Paul Duffin | a369c7b | 2021-03-09 03:08:05 +0000 | [diff] [blame] | 6799 | ctx := result.TestContext |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 6800 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 6801 | "etc/compatconfig/myjar-platform-compat-config.xml", |
| 6802 | "javalib/myjar.jar", |
| 6803 | }) |
| 6804 | } |
| 6805 | |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 6806 | func TestRejectNonInstallableJavaLibrary(t *testing.T) { |
| 6807 | testApexError(t, `"myjar" is not configured to be compiled into dex`, ` |
| 6808 | apex { |
| 6809 | name: "myapex", |
| 6810 | key: "myapex.key", |
| 6811 | java_libs: ["myjar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6812 | updatable: false, |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 6813 | } |
| 6814 | |
| 6815 | apex_key { |
| 6816 | name: "myapex.key", |
| 6817 | public_key: "testkey.avbpubkey", |
| 6818 | private_key: "testkey.pem", |
| 6819 | } |
| 6820 | |
| 6821 | java_library { |
| 6822 | name: "myjar", |
| 6823 | srcs: ["foo/bar/MyClass.java"], |
| 6824 | sdk_version: "none", |
| 6825 | system_modules: "none", |
Jiyong Park | 6b21c7d | 2020-02-11 09:16:01 +0900 | [diff] [blame] | 6826 | compile_dex: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 6827 | apex_available: ["myapex"], |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 6828 | } |
| 6829 | `) |
| 6830 | } |
| 6831 | |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 6832 | func TestCarryRequiredModuleNames(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6833 | ctx := testApex(t, ` |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 6834 | apex { |
| 6835 | name: "myapex", |
| 6836 | key: "myapex.key", |
| 6837 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6838 | updatable: false, |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 6839 | } |
| 6840 | |
| 6841 | apex_key { |
| 6842 | name: "myapex.key", |
| 6843 | public_key: "testkey.avbpubkey", |
| 6844 | private_key: "testkey.pem", |
| 6845 | } |
| 6846 | |
| 6847 | cc_library { |
| 6848 | name: "mylib", |
| 6849 | srcs: ["mylib.cpp"], |
| 6850 | system_shared_libs: [], |
| 6851 | stl: "none", |
| 6852 | required: ["a", "b"], |
| 6853 | host_required: ["c", "d"], |
| 6854 | target_required: ["e", "f"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 6855 | apex_available: [ "myapex" ], |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 6856 | } |
| 6857 | `) |
| 6858 | |
| 6859 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 6860 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 6861 | name := apexBundle.BaseModuleName() |
| 6862 | prefix := "TARGET_" |
| 6863 | var builder strings.Builder |
| 6864 | data.Custom(&builder, name, prefix, "", data) |
| 6865 | androidMk := builder.String() |
| 6866 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n") |
| 6867 | ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n") |
| 6868 | ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n") |
| 6869 | } |
| 6870 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6871 | func TestSymlinksFromApexToSystem(t *testing.T) { |
| 6872 | bp := ` |
| 6873 | apex { |
| 6874 | name: "myapex", |
| 6875 | key: "myapex.key", |
| 6876 | native_shared_libs: ["mylib"], |
| 6877 | java_libs: ["myjar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6878 | updatable: false, |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6879 | } |
| 6880 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6881 | apex { |
| 6882 | name: "myapex.updatable", |
| 6883 | key: "myapex.key", |
| 6884 | native_shared_libs: ["mylib"], |
| 6885 | java_libs: ["myjar"], |
| 6886 | updatable: true, |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 6887 | min_sdk_version: "current", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6888 | } |
| 6889 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6890 | apex_key { |
| 6891 | name: "myapex.key", |
| 6892 | public_key: "testkey.avbpubkey", |
| 6893 | private_key: "testkey.pem", |
| 6894 | } |
| 6895 | |
| 6896 | cc_library { |
| 6897 | name: "mylib", |
| 6898 | srcs: ["mylib.cpp"], |
| 6899 | shared_libs: ["myotherlib"], |
| 6900 | system_shared_libs: [], |
| 6901 | stl: "none", |
| 6902 | apex_available: [ |
| 6903 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6904 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6905 | "//apex_available:platform", |
| 6906 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6907 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6908 | } |
| 6909 | |
| 6910 | cc_library { |
| 6911 | name: "myotherlib", |
| 6912 | srcs: ["mylib.cpp"], |
| 6913 | system_shared_libs: [], |
| 6914 | stl: "none", |
| 6915 | apex_available: [ |
| 6916 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6917 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6918 | "//apex_available:platform", |
| 6919 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6920 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6921 | } |
| 6922 | |
| 6923 | java_library { |
| 6924 | name: "myjar", |
| 6925 | srcs: ["foo/bar/MyClass.java"], |
| 6926 | sdk_version: "none", |
| 6927 | system_modules: "none", |
| 6928 | libs: ["myotherjar"], |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6929 | apex_available: [ |
| 6930 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6931 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6932 | "//apex_available:platform", |
| 6933 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6934 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6935 | } |
| 6936 | |
| 6937 | java_library { |
| 6938 | name: "myotherjar", |
| 6939 | srcs: ["foo/bar/MyClass.java"], |
| 6940 | sdk_version: "none", |
| 6941 | system_modules: "none", |
| 6942 | apex_available: [ |
| 6943 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6944 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6945 | "//apex_available:platform", |
| 6946 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6947 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6948 | } |
| 6949 | ` |
| 6950 | |
| 6951 | ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) { |
| 6952 | for _, f := range files { |
| 6953 | if f.path == file { |
| 6954 | if f.isLink { |
| 6955 | t.Errorf("%q is not a real file", file) |
| 6956 | } |
| 6957 | return |
| 6958 | } |
| 6959 | } |
| 6960 | t.Errorf("%q is not found", file) |
| 6961 | } |
| 6962 | |
| 6963 | ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) { |
| 6964 | for _, f := range files { |
| 6965 | if f.path == file { |
| 6966 | if !f.isLink { |
| 6967 | t.Errorf("%q is not a symlink", file) |
| 6968 | } |
| 6969 | return |
| 6970 | } |
| 6971 | } |
| 6972 | t.Errorf("%q is not found", file) |
| 6973 | } |
| 6974 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6975 | // For unbundled build, symlink shouldn't exist regardless of whether an APEX |
| 6976 | // is updatable or not |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6977 | ctx := testApex(t, bp, withUnbundledBuild) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 6978 | files := getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6979 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6980 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6981 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 6982 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6983 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 6984 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6985 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6986 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 6987 | |
| 6988 | // 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] | 6989 | ctx = testApex(t, bp) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 6990 | files = getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6991 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6992 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6993 | ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6994 | |
| 6995 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 6996 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6997 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6998 | ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6999 | } |
| 7000 | |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 7001 | func TestSymlinksFromApexToSystemRequiredModuleNames(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7002 | ctx := testApex(t, ` |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 7003 | apex { |
| 7004 | name: "myapex", |
| 7005 | key: "myapex.key", |
| 7006 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7007 | updatable: false, |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 7008 | } |
| 7009 | |
| 7010 | apex_key { |
| 7011 | name: "myapex.key", |
| 7012 | public_key: "testkey.avbpubkey", |
| 7013 | private_key: "testkey.pem", |
| 7014 | } |
| 7015 | |
| 7016 | cc_library_shared { |
| 7017 | name: "mylib", |
| 7018 | srcs: ["mylib.cpp"], |
| 7019 | shared_libs: ["myotherlib"], |
| 7020 | system_shared_libs: [], |
| 7021 | stl: "none", |
| 7022 | apex_available: [ |
| 7023 | "myapex", |
| 7024 | "//apex_available:platform", |
| 7025 | ], |
| 7026 | } |
| 7027 | |
| 7028 | cc_prebuilt_library_shared { |
| 7029 | name: "myotherlib", |
| 7030 | srcs: ["prebuilt.so"], |
| 7031 | system_shared_libs: [], |
| 7032 | stl: "none", |
| 7033 | apex_available: [ |
| 7034 | "myapex", |
| 7035 | "//apex_available:platform", |
| 7036 | ], |
| 7037 | } |
| 7038 | `) |
| 7039 | |
| 7040 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 7041 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 7042 | var builder strings.Builder |
| 7043 | data.Custom(&builder, apexBundle.BaseModuleName(), "TARGET_", "", data) |
| 7044 | androidMk := builder.String() |
| 7045 | // `myotherlib` is added to `myapex` as symlink |
| 7046 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 7047 | ensureNotContains(t, androidMk, "LOCAL_MODULE := prebuilt_myotherlib.myapex\n") |
| 7048 | ensureNotContains(t, androidMk, "LOCAL_MODULE := myotherlib.myapex\n") |
| 7049 | // `myapex` should have `myotherlib` in its required line, not `prebuilt_myotherlib` |
Jiyong Park | 57621b2 | 2021-01-20 20:33:11 +0900 | [diff] [blame] | 7050 | 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] | 7051 | } |
| 7052 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 7053 | func TestApexWithJniLibs(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7054 | ctx := testApex(t, ` |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 7055 | apex { |
| 7056 | name: "myapex", |
| 7057 | key: "myapex.key", |
Jiyong Park | 34d5c33 | 2022-02-24 18:02:44 +0900 | [diff] [blame] | 7058 | jni_libs: ["mylib", "libfoo.rust"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7059 | updatable: false, |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 7060 | } |
| 7061 | |
| 7062 | apex_key { |
| 7063 | name: "myapex.key", |
| 7064 | public_key: "testkey.avbpubkey", |
| 7065 | private_key: "testkey.pem", |
| 7066 | } |
| 7067 | |
| 7068 | cc_library { |
| 7069 | name: "mylib", |
| 7070 | srcs: ["mylib.cpp"], |
| 7071 | shared_libs: ["mylib2"], |
| 7072 | system_shared_libs: [], |
| 7073 | stl: "none", |
| 7074 | apex_available: [ "myapex" ], |
| 7075 | } |
| 7076 | |
| 7077 | cc_library { |
| 7078 | name: "mylib2", |
| 7079 | srcs: ["mylib.cpp"], |
| 7080 | system_shared_libs: [], |
| 7081 | stl: "none", |
| 7082 | apex_available: [ "myapex" ], |
| 7083 | } |
Jiyong Park | 34d5c33 | 2022-02-24 18:02:44 +0900 | [diff] [blame] | 7084 | |
| 7085 | rust_ffi_shared { |
| 7086 | name: "libfoo.rust", |
| 7087 | crate_name: "foo", |
| 7088 | srcs: ["foo.rs"], |
| 7089 | shared_libs: ["libfoo.shared_from_rust"], |
| 7090 | prefer_rlib: true, |
| 7091 | apex_available: ["myapex"], |
| 7092 | } |
| 7093 | |
| 7094 | cc_library_shared { |
| 7095 | name: "libfoo.shared_from_rust", |
| 7096 | srcs: ["mylib.cpp"], |
| 7097 | system_shared_libs: [], |
| 7098 | stl: "none", |
| 7099 | stubs: { |
| 7100 | versions: ["10", "11", "12"], |
| 7101 | }, |
| 7102 | } |
| 7103 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 7104 | `) |
| 7105 | |
| 7106 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 7107 | // Notice mylib2.so (transitive dep) is not added as a jni_lib |
Jiyong Park | 34d5c33 | 2022-02-24 18:02:44 +0900 | [diff] [blame] | 7108 | ensureEquals(t, rule.Args["opt"], "-a jniLibs libfoo.rust.so mylib.so") |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 7109 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 7110 | "lib64/mylib.so", |
| 7111 | "lib64/mylib2.so", |
Jiyong Park | 34d5c33 | 2022-02-24 18:02:44 +0900 | [diff] [blame] | 7112 | "lib64/libfoo.rust.so", |
| 7113 | "lib64/libc++.so", // auto-added to libfoo.rust by Soong |
| 7114 | "lib64/liblog.so", // auto-added to libfoo.rust by Soong |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 7115 | }) |
Jiyong Park | 34d5c33 | 2022-02-24 18:02:44 +0900 | [diff] [blame] | 7116 | |
| 7117 | // b/220397949 |
| 7118 | ensureListContains(t, names(rule.Args["requireNativeLibs"]), "libfoo.shared_from_rust.so") |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 7119 | } |
| 7120 | |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 7121 | func TestApexMutatorsDontRunIfDisabled(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7122 | ctx := testApex(t, ` |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 7123 | apex { |
| 7124 | name: "myapex", |
| 7125 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7126 | updatable: false, |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 7127 | } |
| 7128 | apex_key { |
| 7129 | name: "myapex.key", |
| 7130 | public_key: "testkey.avbpubkey", |
| 7131 | private_key: "testkey.pem", |
| 7132 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 7133 | `, |
| 7134 | android.FixtureModifyConfig(func(config android.Config) { |
| 7135 | delete(config.Targets, android.Android) |
| 7136 | config.AndroidCommonTarget = android.Target{} |
| 7137 | }), |
| 7138 | ) |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 7139 | |
| 7140 | if expected, got := []string{""}, ctx.ModuleVariantsForTests("myapex"); !reflect.DeepEqual(expected, got) { |
| 7141 | t.Errorf("Expected variants: %v, but got: %v", expected, got) |
| 7142 | } |
| 7143 | } |
| 7144 | |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 7145 | func TestAppBundle(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7146 | ctx := testApex(t, ` |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 7147 | apex { |
| 7148 | name: "myapex", |
| 7149 | key: "myapex.key", |
| 7150 | apps: ["AppFoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7151 | updatable: false, |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 7152 | } |
| 7153 | |
| 7154 | apex_key { |
| 7155 | name: "myapex.key", |
| 7156 | public_key: "testkey.avbpubkey", |
| 7157 | private_key: "testkey.pem", |
| 7158 | } |
| 7159 | |
| 7160 | android_app { |
| 7161 | name: "AppFoo", |
| 7162 | srcs: ["foo/bar/MyClass.java"], |
| 7163 | sdk_version: "none", |
| 7164 | system_modules: "none", |
| 7165 | apex_available: [ "myapex" ], |
| 7166 | } |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 7167 | `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"})) |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 7168 | |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 7169 | bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("bundle_config.json") |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 7170 | content := bundleConfigRule.Args["content"] |
| 7171 | |
| 7172 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 7173 | ensureContains(t, content, `"apex_config":{"apex_embedded_apk_config":[{"package_name":"com.android.foo","path":"app/AppFoo/AppFoo.apk"}]}`) |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 7174 | } |
| 7175 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 7176 | func TestAppSetBundle(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7177 | ctx := testApex(t, ` |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 7178 | apex { |
| 7179 | name: "myapex", |
| 7180 | key: "myapex.key", |
| 7181 | apps: ["AppSet"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7182 | updatable: false, |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 7183 | } |
| 7184 | |
| 7185 | apex_key { |
| 7186 | name: "myapex.key", |
| 7187 | public_key: "testkey.avbpubkey", |
| 7188 | private_key: "testkey.pem", |
| 7189 | } |
| 7190 | |
| 7191 | android_app_set { |
| 7192 | name: "AppSet", |
| 7193 | set: "AppSet.apks", |
| 7194 | }`) |
| 7195 | mod := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 7196 | bundleConfigRule := mod.Output("bundle_config.json") |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 7197 | content := bundleConfigRule.Args["content"] |
| 7198 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
| 7199 | s := mod.Rule("apexRule").Args["copy_commands"] |
| 7200 | copyCmds := regexp.MustCompile(" *&& *").Split(s, -1) |
| 7201 | if len(copyCmds) != 3 { |
| 7202 | t.Fatalf("Expected 3 commands, got %d in:\n%s", len(copyCmds), s) |
| 7203 | } |
| 7204 | ensureMatches(t, copyCmds[0], "^rm -rf .*/app/AppSet$") |
| 7205 | ensureMatches(t, copyCmds[1], "^mkdir -p .*/app/AppSet$") |
| 7206 | ensureMatches(t, copyCmds[2], "^unzip .*-d .*/app/AppSet .*/AppSet.zip$") |
| 7207 | } |
| 7208 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 7209 | func TestAppSetBundlePrebuilt(t *testing.T) { |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 7210 | bp := ` |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 7211 | apex_set { |
| 7212 | name: "myapex", |
| 7213 | filename: "foo_v2.apex", |
| 7214 | sanitized: { |
| 7215 | none: { set: "myapex.apks", }, |
| 7216 | hwaddress: { set: "myapex.hwasan.apks", }, |
| 7217 | }, |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 7218 | } |
| 7219 | ` |
| 7220 | ctx := testApex(t, bp, prepareForTestWithSantitizeHwaddress) |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 7221 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 7222 | // Check that the extractor produces the correct output file from the correct input file. |
| 7223 | 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] | 7224 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 7225 | m := ctx.ModuleForTests("myapex.apex.extractor", "android_common") |
| 7226 | extractedApex := m.Output(extractorOutput) |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 7227 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 7228 | android.AssertArrayString(t, "extractor input", []string{"myapex.hwasan.apks"}, extractedApex.Inputs.Strings()) |
| 7229 | |
| 7230 | // Ditto for the apex. |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 7231 | m = ctx.ModuleForTests("myapex", "android_common_myapex") |
| 7232 | 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] | 7233 | |
| 7234 | android.AssertStringEquals(t, "myapex input", extractorOutput, copiedApex.Input.String()) |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 7235 | } |
| 7236 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7237 | 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] | 7238 | t.Helper() |
| 7239 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7240 | bp := ` |
| 7241 | java_library { |
| 7242 | name: "some-updatable-apex-lib", |
| 7243 | srcs: ["a.java"], |
| 7244 | sdk_version: "current", |
| 7245 | apex_available: [ |
| 7246 | "some-updatable-apex", |
| 7247 | ], |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7248 | permitted_packages: ["some.updatable.apex.lib"], |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7249 | } |
| 7250 | |
| 7251 | java_library { |
| 7252 | name: "some-non-updatable-apex-lib", |
| 7253 | srcs: ["a.java"], |
| 7254 | apex_available: [ |
| 7255 | "some-non-updatable-apex", |
| 7256 | ], |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7257 | compile_dex: true, |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7258 | permitted_packages: ["some.non.updatable.apex.lib"], |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7259 | } |
| 7260 | |
| 7261 | bootclasspath_fragment { |
| 7262 | name: "some-non-updatable-fragment", |
| 7263 | contents: ["some-non-updatable-apex-lib"], |
| 7264 | apex_available: [ |
| 7265 | "some-non-updatable-apex", |
| 7266 | ], |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7267 | } |
| 7268 | |
| 7269 | java_library { |
| 7270 | name: "some-platform-lib", |
| 7271 | srcs: ["a.java"], |
| 7272 | sdk_version: "current", |
| 7273 | installable: true, |
| 7274 | } |
| 7275 | |
| 7276 | java_library { |
| 7277 | name: "some-art-lib", |
| 7278 | srcs: ["a.java"], |
| 7279 | sdk_version: "current", |
| 7280 | apex_available: [ |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 7281 | "com.android.art.debug", |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7282 | ], |
| 7283 | hostdex: true, |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 7284 | compile_dex: true, |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7285 | } |
| 7286 | |
| 7287 | apex { |
| 7288 | name: "some-updatable-apex", |
| 7289 | key: "some-updatable-apex.key", |
| 7290 | java_libs: ["some-updatable-apex-lib"], |
| 7291 | updatable: true, |
| 7292 | min_sdk_version: "current", |
| 7293 | } |
| 7294 | |
| 7295 | apex { |
| 7296 | name: "some-non-updatable-apex", |
| 7297 | key: "some-non-updatable-apex.key", |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7298 | bootclasspath_fragments: ["some-non-updatable-fragment"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7299 | updatable: false, |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7300 | } |
| 7301 | |
| 7302 | apex_key { |
| 7303 | name: "some-updatable-apex.key", |
| 7304 | } |
| 7305 | |
| 7306 | apex_key { |
| 7307 | name: "some-non-updatable-apex.key", |
| 7308 | } |
| 7309 | |
| 7310 | apex { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 7311 | name: "com.android.art.debug", |
| 7312 | key: "com.android.art.debug.key", |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7313 | bootclasspath_fragments: ["art-bootclasspath-fragment"], |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7314 | updatable: true, |
| 7315 | min_sdk_version: "current", |
| 7316 | } |
| 7317 | |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 7318 | bootclasspath_fragment { |
| 7319 | name: "art-bootclasspath-fragment", |
| 7320 | image_name: "art", |
| 7321 | contents: ["some-art-lib"], |
| 7322 | apex_available: [ |
| 7323 | "com.android.art.debug", |
| 7324 | ], |
| 7325 | } |
| 7326 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7327 | apex_key { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 7328 | name: "com.android.art.debug.key", |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7329 | } |
| 7330 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7331 | filegroup { |
| 7332 | name: "some-updatable-apex-file_contexts", |
| 7333 | srcs: [ |
| 7334 | "system/sepolicy/apex/some-updatable-apex-file_contexts", |
| 7335 | ], |
| 7336 | } |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 7337 | |
| 7338 | filegroup { |
| 7339 | name: "some-non-updatable-apex-file_contexts", |
| 7340 | srcs: [ |
| 7341 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts", |
| 7342 | ], |
| 7343 | } |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7344 | ` |
Paul Duffin | c3bbb96 | 2020-12-10 19:15:49 +0000 | [diff] [blame] | 7345 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7346 | testDexpreoptWithApexes(t, bp, errmsg, preparer, fragments...) |
Paul Duffin | c3bbb96 | 2020-12-10 19:15:49 +0000 | [diff] [blame] | 7347 | } |
| 7348 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7349 | 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] | 7350 | t.Helper() |
| 7351 | |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 7352 | fs := android.MockFS{ |
| 7353 | "a.java": nil, |
| 7354 | "a.jar": nil, |
| 7355 | "apex_manifest.json": nil, |
| 7356 | "AndroidManifest.xml": nil, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 7357 | "system/sepolicy/apex/myapex-file_contexts": nil, |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 7358 | "system/sepolicy/apex/some-updatable-apex-file_contexts": nil, |
| 7359 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts": nil, |
| 7360 | "system/sepolicy/apex/com.android.art.debug-file_contexts": nil, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 7361 | "framework/aidl/a.aidl": nil, |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7362 | } |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7363 | |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 7364 | errorHandler := android.FixtureExpectsNoErrors |
| 7365 | if errmsg != "" { |
| 7366 | errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(errmsg) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7367 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 7368 | |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 7369 | result := android.GroupFixturePreparers( |
| 7370 | cc.PrepareForTestWithCcDefaultModules, |
| 7371 | java.PrepareForTestWithHiddenApiBuildComponents, |
| 7372 | java.PrepareForTestWithJavaDefaultModules, |
| 7373 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 7374 | PrepareForTestWithApexBuildComponents, |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7375 | preparer, |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 7376 | fs.AddToFixture(), |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7377 | android.FixtureModifyMockFS(func(fs android.MockFS) { |
| 7378 | if _, ok := fs["frameworks/base/boot/Android.bp"]; !ok { |
| 7379 | insert := "" |
| 7380 | for _, fragment := range fragments { |
| 7381 | insert += fmt.Sprintf("{apex: %q, module: %q},\n", *fragment.Apex, *fragment.Module) |
| 7382 | } |
| 7383 | fs["frameworks/base/boot/Android.bp"] = []byte(fmt.Sprintf(` |
| 7384 | platform_bootclasspath { |
| 7385 | name: "platform-bootclasspath", |
| 7386 | fragments: [ |
| 7387 | %s |
| 7388 | ], |
| 7389 | } |
| 7390 | `, insert)) |
Paul Duffin | 8f146b9 | 2021-04-12 17:24:18 +0100 | [diff] [blame] | 7391 | } |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7392 | }), |
Jiakai Zhang | 49b1eb6 | 2021-11-26 18:09:27 +0000 | [diff] [blame] | 7393 | dexpreopt.FixtureSetBootImageProfiles("art/build/boot/boot-image-profile.txt"), |
Paul Duffin | 5560712 | 2021-03-30 23:32:51 +0100 | [diff] [blame] | 7394 | ). |
| 7395 | ExtendWithErrorHandler(errorHandler). |
| 7396 | RunTestWithBp(t, bp) |
| 7397 | |
| 7398 | return result.TestContext |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7399 | } |
| 7400 | |
Martin Stjernholm | 43c44b0 | 2021-06-30 16:35:07 +0100 | [diff] [blame] | 7401 | func TestDuplicateDeapexeresFromPrebuiltApexes(t *testing.T) { |
| 7402 | preparers := android.GroupFixturePreparers( |
| 7403 | java.PrepareForTestWithJavaDefaultModules, |
| 7404 | PrepareForTestWithApexBuildComponents, |
| 7405 | ). |
| 7406 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( |
| 7407 | "Multiple installable prebuilt APEXes provide ambiguous deapexers: com.android.myapex and com.mycompany.android.myapex")) |
| 7408 | |
| 7409 | bpBase := ` |
| 7410 | apex_set { |
| 7411 | name: "com.android.myapex", |
| 7412 | installable: true, |
| 7413 | exported_bootclasspath_fragments: ["my-bootclasspath-fragment"], |
| 7414 | set: "myapex.apks", |
| 7415 | } |
| 7416 | |
| 7417 | apex_set { |
| 7418 | name: "com.mycompany.android.myapex", |
| 7419 | apex_name: "com.android.myapex", |
| 7420 | installable: true, |
| 7421 | exported_bootclasspath_fragments: ["my-bootclasspath-fragment"], |
| 7422 | set: "company-myapex.apks", |
| 7423 | } |
| 7424 | |
| 7425 | prebuilt_bootclasspath_fragment { |
| 7426 | name: "my-bootclasspath-fragment", |
| 7427 | apex_available: ["com.android.myapex"], |
| 7428 | %s |
| 7429 | } |
| 7430 | ` |
| 7431 | |
| 7432 | t.Run("java_import", func(t *testing.T) { |
| 7433 | _ = preparers.RunTestWithBp(t, fmt.Sprintf(bpBase, `contents: ["libfoo"]`)+` |
| 7434 | java_import { |
| 7435 | name: "libfoo", |
| 7436 | jars: ["libfoo.jar"], |
| 7437 | apex_available: ["com.android.myapex"], |
| 7438 | } |
| 7439 | `) |
| 7440 | }) |
| 7441 | |
| 7442 | t.Run("java_sdk_library_import", func(t *testing.T) { |
| 7443 | _ = preparers.RunTestWithBp(t, fmt.Sprintf(bpBase, `contents: ["libfoo"]`)+` |
| 7444 | java_sdk_library_import { |
| 7445 | name: "libfoo", |
| 7446 | public: { |
| 7447 | jars: ["libbar.jar"], |
| 7448 | }, |
| 7449 | apex_available: ["com.android.myapex"], |
| 7450 | } |
| 7451 | `) |
| 7452 | }) |
| 7453 | |
| 7454 | t.Run("prebuilt_bootclasspath_fragment", func(t *testing.T) { |
| 7455 | _ = preparers.RunTestWithBp(t, fmt.Sprintf(bpBase, ` |
| 7456 | image_name: "art", |
| 7457 | contents: ["libfoo"], |
| 7458 | `)+` |
| 7459 | java_sdk_library_import { |
| 7460 | name: "libfoo", |
| 7461 | public: { |
| 7462 | jars: ["libbar.jar"], |
| 7463 | }, |
| 7464 | apex_available: ["com.android.myapex"], |
| 7465 | } |
| 7466 | `) |
| 7467 | }) |
| 7468 | } |
| 7469 | |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 7470 | func TestUpdatable_should_set_min_sdk_version(t *testing.T) { |
| 7471 | testApexError(t, `"myapex" .*: updatable: updatable APEXes should set min_sdk_version`, ` |
| 7472 | apex { |
| 7473 | name: "myapex", |
| 7474 | key: "myapex.key", |
| 7475 | updatable: true, |
| 7476 | } |
| 7477 | |
| 7478 | apex_key { |
| 7479 | name: "myapex.key", |
| 7480 | public_key: "testkey.avbpubkey", |
| 7481 | private_key: "testkey.pem", |
| 7482 | } |
| 7483 | `) |
| 7484 | } |
| 7485 | |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7486 | func TestUpdatableDefault_should_set_min_sdk_version(t *testing.T) { |
| 7487 | testApexError(t, `"myapex" .*: updatable: updatable APEXes should set min_sdk_version`, ` |
| 7488 | apex { |
| 7489 | name: "myapex", |
| 7490 | key: "myapex.key", |
| 7491 | } |
| 7492 | |
| 7493 | apex_key { |
| 7494 | name: "myapex.key", |
| 7495 | public_key: "testkey.avbpubkey", |
| 7496 | private_key: "testkey.pem", |
| 7497 | } |
| 7498 | `) |
| 7499 | } |
| 7500 | |
Daniel Norman | 6910911 | 2021-12-02 12:52:42 -0800 | [diff] [blame] | 7501 | func TestUpdatable_cannot_be_vendor_apex(t *testing.T) { |
| 7502 | testApexError(t, `"myapex" .*: updatable: vendor APEXes are not updatable`, ` |
| 7503 | apex { |
| 7504 | name: "myapex", |
| 7505 | key: "myapex.key", |
| 7506 | updatable: true, |
| 7507 | soc_specific: true, |
| 7508 | } |
| 7509 | |
| 7510 | apex_key { |
| 7511 | name: "myapex.key", |
| 7512 | public_key: "testkey.avbpubkey", |
| 7513 | private_key: "testkey.pem", |
| 7514 | } |
| 7515 | `) |
| 7516 | } |
| 7517 | |
satayev | b98371c | 2021-06-15 16:49:50 +0100 | [diff] [blame] | 7518 | func TestUpdatable_should_not_set_generate_classpaths_proto(t *testing.T) { |
| 7519 | testApexError(t, `"mysystemserverclasspathfragment" .* it must not set generate_classpaths_proto to false`, ` |
| 7520 | apex { |
| 7521 | name: "myapex", |
| 7522 | key: "myapex.key", |
| 7523 | systemserverclasspath_fragments: [ |
| 7524 | "mysystemserverclasspathfragment", |
| 7525 | ], |
| 7526 | min_sdk_version: "29", |
| 7527 | updatable: true, |
| 7528 | } |
| 7529 | |
| 7530 | apex_key { |
| 7531 | name: "myapex.key", |
| 7532 | public_key: "testkey.avbpubkey", |
| 7533 | private_key: "testkey.pem", |
| 7534 | } |
| 7535 | |
| 7536 | java_library { |
| 7537 | name: "foo", |
| 7538 | srcs: ["b.java"], |
| 7539 | min_sdk_version: "29", |
| 7540 | installable: true, |
| 7541 | apex_available: [ |
| 7542 | "myapex", |
| 7543 | ], |
| 7544 | } |
| 7545 | |
| 7546 | systemserverclasspath_fragment { |
| 7547 | name: "mysystemserverclasspathfragment", |
| 7548 | generate_classpaths_proto: false, |
| 7549 | contents: [ |
| 7550 | "foo", |
| 7551 | ], |
| 7552 | apex_available: [ |
| 7553 | "myapex", |
| 7554 | ], |
| 7555 | } |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7556 | `, |
| 7557 | dexpreopt.FixtureSetApexSystemServerJars("myapex:foo"), |
| 7558 | ) |
satayev | b98371c | 2021-06-15 16:49:50 +0100 | [diff] [blame] | 7559 | } |
| 7560 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7561 | func TestNoUpdatableJarsInBootImage(t *testing.T) { |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7562 | // Set the BootJars in dexpreopt.GlobalConfig and productVariables to the same value. This can |
| 7563 | // result in an invalid configuration as it does not set the ArtApexJars and allows art apex |
| 7564 | // modules to be included in the BootJars. |
| 7565 | prepareSetBootJars := func(bootJars ...string) android.FixturePreparer { |
| 7566 | return android.GroupFixturePreparers( |
| 7567 | dexpreopt.FixtureSetBootJars(bootJars...), |
| 7568 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 7569 | variables.BootJars = android.CreateTestConfiguredJarList(bootJars) |
| 7570 | }), |
| 7571 | ) |
| 7572 | } |
| 7573 | |
| 7574 | // Set the ArtApexJars and BootJars in dexpreopt.GlobalConfig and productVariables all to the |
| 7575 | // same value. This can result in an invalid configuration as it allows non art apex jars to be |
| 7576 | // specified in the ArtApexJars configuration. |
| 7577 | prepareSetArtJars := func(bootJars ...string) android.FixturePreparer { |
| 7578 | return android.GroupFixturePreparers( |
| 7579 | dexpreopt.FixtureSetArtBootJars(bootJars...), |
| 7580 | dexpreopt.FixtureSetBootJars(bootJars...), |
| 7581 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 7582 | variables.BootJars = android.CreateTestConfiguredJarList(bootJars) |
| 7583 | }), |
| 7584 | ) |
| 7585 | } |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7586 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7587 | 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] | 7588 | preparer := android.GroupFixturePreparers( |
| 7589 | java.FixtureConfigureBootJars("com.android.art.debug:some-art-lib"), |
| 7590 | java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib"), |
| 7591 | ) |
| 7592 | fragments := []java.ApexVariantReference{ |
| 7593 | { |
| 7594 | Apex: proptools.StringPtr("com.android.art.debug"), |
| 7595 | Module: proptools.StringPtr("art-bootclasspath-fragment"), |
| 7596 | }, |
| 7597 | { |
| 7598 | Apex: proptools.StringPtr("some-non-updatable-apex"), |
| 7599 | Module: proptools.StringPtr("some-non-updatable-fragment"), |
| 7600 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7601 | } |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7602 | testNoUpdatableJarsInBootImage(t, "", preparer, fragments...) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7603 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7604 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7605 | 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] | 7606 | err := `module "some-art-lib" from updatable apexes \["com.android.art.debug"\] is not allowed in the framework boot image` |
| 7607 | // Update the dexpreopt BootJars directly. |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7608 | preparer := android.GroupFixturePreparers( |
| 7609 | prepareSetBootJars("com.android.art.debug:some-art-lib"), |
| 7610 | java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib"), |
| 7611 | ) |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7612 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7613 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7614 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7615 | 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] | 7616 | 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] | 7617 | // Update the dexpreopt ArtApexJars directly. |
| 7618 | preparer := prepareSetArtJars("some-updatable-apex:some-updatable-apex-lib") |
| 7619 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7620 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7621 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7622 | 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] | 7623 | 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] | 7624 | // Update the dexpreopt ArtApexJars directly. |
| 7625 | preparer := prepareSetArtJars("some-non-updatable-apex:some-non-updatable-apex-lib") |
| 7626 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7627 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 7628 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7629 | 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] | 7630 | 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] | 7631 | preparer := android.GroupFixturePreparers( |
| 7632 | java.FixtureConfigureBootJars("some-updatable-apex:some-updatable-apex-lib"), |
| 7633 | java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib"), |
| 7634 | ) |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7635 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7636 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7637 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7638 | 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] | 7639 | preparer := java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib") |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7640 | fragment := java.ApexVariantReference{ |
| 7641 | Apex: proptools.StringPtr("some-non-updatable-apex"), |
| 7642 | Module: proptools.StringPtr("some-non-updatable-fragment"), |
| 7643 | } |
| 7644 | testNoUpdatableJarsInBootImage(t, "", preparer, fragment) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7645 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 7646 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7647 | 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] | 7648 | err := `"platform-bootclasspath" depends on undefined module "nonexistent"` |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7649 | preparer := java.FixtureConfigureBootJars("platform:nonexistent") |
| 7650 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7651 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7652 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7653 | 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] | 7654 | err := `"platform-bootclasspath" depends on undefined module "nonexistent"` |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 7655 | preparer := java.FixtureConfigureBootJars("platform:nonexistent") |
| 7656 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7657 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7658 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7659 | 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] | 7660 | 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] | 7661 | // Update the dexpreopt ArtApexJars directly. |
| 7662 | preparer := prepareSetArtJars("platform:some-platform-lib") |
| 7663 | testNoUpdatableJarsInBootImage(t, err, preparer) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7664 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7665 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7666 | 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] | 7667 | preparer := android.GroupFixturePreparers( |
| 7668 | java.FixtureConfigureBootJars("platform:some-platform-lib"), |
| 7669 | java.FixtureConfigureApexBootJars("some-non-updatable-apex:some-non-updatable-apex-lib"), |
| 7670 | ) |
| 7671 | fragments := []java.ApexVariantReference{ |
| 7672 | { |
| 7673 | Apex: proptools.StringPtr("some-non-updatable-apex"), |
| 7674 | Module: proptools.StringPtr("some-non-updatable-fragment"), |
| 7675 | }, |
| 7676 | } |
| 7677 | testNoUpdatableJarsInBootImage(t, "", preparer, fragments...) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 7678 | }) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 7679 | } |
| 7680 | |
| 7681 | func TestDexpreoptAccessDexFilesFromPrebuiltApex(t *testing.T) { |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7682 | preparer := java.FixtureConfigureApexBootJars("myapex:libfoo") |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 7683 | t.Run("prebuilt no source", func(t *testing.T) { |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7684 | fragment := java.ApexVariantReference{ |
| 7685 | Apex: proptools.StringPtr("myapex"), |
| 7686 | Module: proptools.StringPtr("my-bootclasspath-fragment"), |
| 7687 | } |
| 7688 | |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 7689 | testDexpreoptWithApexes(t, ` |
| 7690 | prebuilt_apex { |
| 7691 | name: "myapex" , |
| 7692 | arch: { |
| 7693 | arm64: { |
| 7694 | src: "myapex-arm64.apex", |
| 7695 | }, |
| 7696 | arm: { |
| 7697 | src: "myapex-arm.apex", |
| 7698 | }, |
| 7699 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7700 | exported_bootclasspath_fragments: ["my-bootclasspath-fragment"], |
| 7701 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 7702 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7703 | prebuilt_bootclasspath_fragment { |
| 7704 | name: "my-bootclasspath-fragment", |
| 7705 | contents: ["libfoo"], |
| 7706 | apex_available: ["myapex"], |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 7707 | hidden_api: { |
| 7708 | annotation_flags: "my-bootclasspath-fragment/annotation-flags.csv", |
| 7709 | metadata: "my-bootclasspath-fragment/metadata.csv", |
| 7710 | index: "my-bootclasspath-fragment/index.csv", |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 7711 | signature_patterns: "my-bootclasspath-fragment/signature-patterns.csv", |
| 7712 | filtered_stub_flags: "my-bootclasspath-fragment/filtered-stub-flags.csv", |
| 7713 | filtered_flags: "my-bootclasspath-fragment/filtered-flags.csv", |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 7714 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7715 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 7716 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7717 | java_import { |
| 7718 | name: "libfoo", |
| 7719 | jars: ["libfoo.jar"], |
| 7720 | apex_available: ["myapex"], |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 7721 | permitted_packages: ["libfoo"], |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 7722 | } |
| 7723 | `, "", preparer, fragment) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 7724 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 7725 | } |
| 7726 | |
Spandan Das | f14e254 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 7727 | 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] | 7728 | t.Helper() |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7729 | bp += ` |
| 7730 | apex_key { |
| 7731 | name: "myapex.key", |
| 7732 | public_key: "testkey.avbpubkey", |
| 7733 | private_key: "testkey.pem", |
| 7734 | }` |
Paul Duffin | 45338f0 | 2021-03-30 23:07:52 +0100 | [diff] [blame] | 7735 | fs := android.MockFS{ |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7736 | "lib1/src/A.java": nil, |
| 7737 | "lib2/src/B.java": nil, |
| 7738 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 7739 | } |
| 7740 | |
Paul Duffin | 45338f0 | 2021-03-30 23:07:52 +0100 | [diff] [blame] | 7741 | errorHandler := android.FixtureExpectsNoErrors |
| 7742 | if errmsg != "" { |
| 7743 | errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(errmsg) |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 7744 | } |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 7745 | |
Paul Duffin | 45338f0 | 2021-03-30 23:07:52 +0100 | [diff] [blame] | 7746 | android.GroupFixturePreparers( |
| 7747 | android.PrepareForTestWithAndroidBuildComponents, |
| 7748 | java.PrepareForTestWithJavaBuildComponents, |
| 7749 | PrepareForTestWithApexBuildComponents, |
| 7750 | android.PrepareForTestWithNeverallowRules(rules), |
| 7751 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 7752 | apexBootJars := make([]string, 0, len(bootJars)) |
| 7753 | for _, apexBootJar := range bootJars { |
| 7754 | apexBootJars = append(apexBootJars, "myapex:"+apexBootJar) |
Paul Duffin | 45338f0 | 2021-03-30 23:07:52 +0100 | [diff] [blame] | 7755 | } |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 7756 | variables.ApexBootJars = android.CreateTestConfiguredJarList(apexBootJars) |
Paul Duffin | 45338f0 | 2021-03-30 23:07:52 +0100 | [diff] [blame] | 7757 | }), |
| 7758 | fs.AddToFixture(), |
| 7759 | ). |
| 7760 | ExtendWithErrorHandler(errorHandler). |
| 7761 | RunTestWithBp(t, bp) |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7762 | } |
| 7763 | |
| 7764 | func TestApexPermittedPackagesRules(t *testing.T) { |
| 7765 | testcases := []struct { |
Spandan Das | f14e254 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 7766 | name string |
| 7767 | expectedError string |
| 7768 | bp string |
| 7769 | bootJars []string |
| 7770 | bcpPermittedPackages map[string][]string |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7771 | }{ |
| 7772 | |
| 7773 | { |
| 7774 | name: "Non-Bootclasspath apex jar not satisfying allowed module packages.", |
| 7775 | expectedError: "", |
| 7776 | bp: ` |
| 7777 | java_library { |
| 7778 | name: "bcp_lib1", |
| 7779 | srcs: ["lib1/src/*.java"], |
| 7780 | permitted_packages: ["foo.bar"], |
| 7781 | apex_available: ["myapex"], |
| 7782 | sdk_version: "none", |
| 7783 | system_modules: "none", |
| 7784 | } |
| 7785 | java_library { |
| 7786 | name: "nonbcp_lib2", |
| 7787 | srcs: ["lib2/src/*.java"], |
| 7788 | apex_available: ["myapex"], |
| 7789 | permitted_packages: ["a.b"], |
| 7790 | sdk_version: "none", |
| 7791 | system_modules: "none", |
| 7792 | } |
| 7793 | apex { |
| 7794 | name: "myapex", |
| 7795 | key: "myapex.key", |
| 7796 | java_libs: ["bcp_lib1", "nonbcp_lib2"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7797 | updatable: false, |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7798 | }`, |
| 7799 | bootJars: []string{"bcp_lib1"}, |
Spandan Das | f14e254 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 7800 | bcpPermittedPackages: map[string][]string{ |
| 7801 | "bcp_lib1": []string{ |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7802 | "foo.bar", |
| 7803 | }, |
| 7804 | }, |
| 7805 | }, |
| 7806 | { |
Anton Hansson | e1b1836 | 2021-12-23 15:05:38 +0000 | [diff] [blame] | 7807 | name: "Bootclasspath apex jar not satisfying allowed module packages.", |
Spandan Das | f14e254 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 7808 | 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] | 7809 | bp: ` |
| 7810 | java_library { |
| 7811 | name: "bcp_lib1", |
| 7812 | srcs: ["lib1/src/*.java"], |
| 7813 | apex_available: ["myapex"], |
| 7814 | permitted_packages: ["foo.bar"], |
| 7815 | sdk_version: "none", |
| 7816 | system_modules: "none", |
| 7817 | } |
| 7818 | java_library { |
| 7819 | name: "bcp_lib2", |
| 7820 | srcs: ["lib2/src/*.java"], |
| 7821 | apex_available: ["myapex"], |
| 7822 | permitted_packages: ["foo.bar", "bar.baz"], |
| 7823 | sdk_version: "none", |
| 7824 | system_modules: "none", |
| 7825 | } |
| 7826 | apex { |
| 7827 | name: "myapex", |
| 7828 | key: "myapex.key", |
| 7829 | java_libs: ["bcp_lib1", "bcp_lib2"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7830 | updatable: false, |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7831 | } |
| 7832 | `, |
| 7833 | bootJars: []string{"bcp_lib1", "bcp_lib2"}, |
Spandan Das | f14e254 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 7834 | bcpPermittedPackages: map[string][]string{ |
| 7835 | "bcp_lib1": []string{ |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7836 | "foo.bar", |
| 7837 | }, |
Spandan Das | f14e254 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 7838 | "bcp_lib2": []string{ |
| 7839 | "foo.bar", |
| 7840 | }, |
| 7841 | }, |
| 7842 | }, |
| 7843 | { |
| 7844 | name: "Updateable Bootclasspath apex jar not satisfying allowed module packages.", |
| 7845 | expectedError: "", |
| 7846 | bp: ` |
| 7847 | java_library { |
| 7848 | name: "bcp_lib_restricted", |
| 7849 | srcs: ["lib1/src/*.java"], |
| 7850 | apex_available: ["myapex"], |
| 7851 | permitted_packages: ["foo.bar"], |
| 7852 | sdk_version: "none", |
| 7853 | min_sdk_version: "29", |
| 7854 | system_modules: "none", |
| 7855 | } |
| 7856 | java_library { |
| 7857 | name: "bcp_lib_unrestricted", |
| 7858 | srcs: ["lib2/src/*.java"], |
| 7859 | apex_available: ["myapex"], |
| 7860 | permitted_packages: ["foo.bar", "bar.baz"], |
| 7861 | sdk_version: "none", |
| 7862 | min_sdk_version: "29", |
| 7863 | system_modules: "none", |
| 7864 | } |
| 7865 | apex { |
| 7866 | name: "myapex", |
| 7867 | key: "myapex.key", |
| 7868 | java_libs: ["bcp_lib_restricted", "bcp_lib_unrestricted"], |
| 7869 | updatable: true, |
| 7870 | min_sdk_version: "29", |
| 7871 | } |
| 7872 | `, |
| 7873 | bootJars: []string{"bcp_lib1", "bcp_lib2"}, |
| 7874 | bcpPermittedPackages: map[string][]string{ |
| 7875 | "bcp_lib1_non_updateable": []string{ |
| 7876 | "foo.bar", |
| 7877 | }, |
| 7878 | // bcp_lib2_updateable has no entry here since updateable bcp can contain new packages - tracking via an allowlist is not necessary |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7879 | }, |
| 7880 | }, |
| 7881 | } |
| 7882 | for _, tc := range testcases { |
| 7883 | t.Run(tc.name, func(t *testing.T) { |
Spandan Das | f14e254 | 2021-11-12 00:01:37 +0000 | [diff] [blame] | 7884 | rules := createBcpPermittedPackagesRules(tc.bcpPermittedPackages) |
| 7885 | testBootJarPermittedPackagesRules(t, tc.expectedError, tc.bp, tc.bootJars, rules) |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 7886 | }) |
| 7887 | } |
| 7888 | } |
| 7889 | |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 7890 | func TestTestFor(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7891 | ctx := testApex(t, ` |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 7892 | apex { |
| 7893 | name: "myapex", |
| 7894 | key: "myapex.key", |
| 7895 | native_shared_libs: ["mylib", "myprivlib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7896 | updatable: false, |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 7897 | } |
| 7898 | |
| 7899 | apex_key { |
| 7900 | name: "myapex.key", |
| 7901 | public_key: "testkey.avbpubkey", |
| 7902 | private_key: "testkey.pem", |
| 7903 | } |
| 7904 | |
| 7905 | cc_library { |
| 7906 | name: "mylib", |
| 7907 | srcs: ["mylib.cpp"], |
| 7908 | system_shared_libs: [], |
| 7909 | stl: "none", |
| 7910 | stubs: { |
| 7911 | versions: ["1"], |
| 7912 | }, |
| 7913 | apex_available: ["myapex"], |
| 7914 | } |
| 7915 | |
| 7916 | cc_library { |
| 7917 | name: "myprivlib", |
| 7918 | srcs: ["mylib.cpp"], |
| 7919 | system_shared_libs: [], |
| 7920 | stl: "none", |
| 7921 | apex_available: ["myapex"], |
| 7922 | } |
| 7923 | |
| 7924 | |
| 7925 | cc_test { |
| 7926 | name: "mytest", |
| 7927 | gtest: false, |
| 7928 | srcs: ["mylib.cpp"], |
| 7929 | system_shared_libs: [], |
| 7930 | stl: "none", |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 7931 | shared_libs: ["mylib", "myprivlib", "mytestlib"], |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 7932 | test_for: ["myapex"] |
| 7933 | } |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 7934 | |
| 7935 | cc_library { |
| 7936 | name: "mytestlib", |
| 7937 | srcs: ["mylib.cpp"], |
| 7938 | system_shared_libs: [], |
| 7939 | shared_libs: ["mylib", "myprivlib"], |
| 7940 | stl: "none", |
| 7941 | test_for: ["myapex"], |
| 7942 | } |
| 7943 | |
| 7944 | cc_benchmark { |
| 7945 | name: "mybench", |
| 7946 | srcs: ["mylib.cpp"], |
| 7947 | system_shared_libs: [], |
| 7948 | shared_libs: ["mylib", "myprivlib"], |
| 7949 | stl: "none", |
| 7950 | test_for: ["myapex"], |
| 7951 | } |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 7952 | `) |
| 7953 | |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 7954 | ensureLinkedLibIs := func(mod, variant, linkedLib, expectedVariant string) { |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 7955 | ldFlags := strings.Split(ctx.ModuleForTests(mod, variant).Rule("ld").Args["libFlags"], " ") |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 7956 | mylibLdFlags := android.FilterListPred(ldFlags, func(s string) bool { return strings.HasPrefix(s, linkedLib) }) |
| 7957 | android.AssertArrayString(t, "unexpected "+linkedLib+" link library for "+mod, []string{linkedLib + expectedVariant}, mylibLdFlags) |
| 7958 | } |
| 7959 | |
| 7960 | // These modules are tests for the apex, therefore are linked to the |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 7961 | // actual implementation of mylib instead of its stub. |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 7962 | ensureLinkedLibIs("mytest", "android_arm64_armv8-a", "out/soong/.intermediates/mylib/", "android_arm64_armv8-a_shared/mylib.so") |
| 7963 | ensureLinkedLibIs("mytestlib", "android_arm64_armv8-a_shared", "out/soong/.intermediates/mylib/", "android_arm64_armv8-a_shared/mylib.so") |
| 7964 | ensureLinkedLibIs("mybench", "android_arm64_armv8-a", "out/soong/.intermediates/mylib/", "android_arm64_armv8-a_shared/mylib.so") |
| 7965 | } |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 7966 | |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 7967 | func TestIndirectTestFor(t *testing.T) { |
| 7968 | ctx := testApex(t, ` |
| 7969 | apex { |
| 7970 | name: "myapex", |
| 7971 | key: "myapex.key", |
| 7972 | native_shared_libs: ["mylib", "myprivlib"], |
| 7973 | updatable: false, |
| 7974 | } |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 7975 | |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 7976 | apex_key { |
| 7977 | name: "myapex.key", |
| 7978 | public_key: "testkey.avbpubkey", |
| 7979 | private_key: "testkey.pem", |
| 7980 | } |
| 7981 | |
| 7982 | cc_library { |
| 7983 | name: "mylib", |
| 7984 | srcs: ["mylib.cpp"], |
| 7985 | system_shared_libs: [], |
| 7986 | stl: "none", |
| 7987 | stubs: { |
| 7988 | versions: ["1"], |
| 7989 | }, |
| 7990 | apex_available: ["myapex"], |
| 7991 | } |
| 7992 | |
| 7993 | cc_library { |
| 7994 | name: "myprivlib", |
| 7995 | srcs: ["mylib.cpp"], |
| 7996 | system_shared_libs: [], |
| 7997 | stl: "none", |
| 7998 | shared_libs: ["mylib"], |
| 7999 | apex_available: ["myapex"], |
| 8000 | } |
| 8001 | |
| 8002 | cc_library { |
| 8003 | name: "mytestlib", |
| 8004 | srcs: ["mylib.cpp"], |
| 8005 | system_shared_libs: [], |
| 8006 | shared_libs: ["myprivlib"], |
| 8007 | stl: "none", |
| 8008 | test_for: ["myapex"], |
| 8009 | } |
| 8010 | `) |
| 8011 | |
| 8012 | ensureLinkedLibIs := func(mod, variant, linkedLib, expectedVariant string) { |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 8013 | ldFlags := strings.Split(ctx.ModuleForTests(mod, variant).Rule("ld").Args["libFlags"], " ") |
Martin Stjernholm | 4e6c269 | 2021-03-25 01:25:06 +0000 | [diff] [blame] | 8014 | mylibLdFlags := android.FilterListPred(ldFlags, func(s string) bool { return strings.HasPrefix(s, linkedLib) }) |
| 8015 | android.AssertArrayString(t, "unexpected "+linkedLib+" link library for "+mod, []string{linkedLib + expectedVariant}, mylibLdFlags) |
| 8016 | } |
| 8017 | |
| 8018 | // The platform variant of mytestlib links to the platform variant of the |
| 8019 | // internal myprivlib. |
| 8020 | ensureLinkedLibIs("mytestlib", "android_arm64_armv8-a_shared", "out/soong/.intermediates/myprivlib/", "android_arm64_armv8-a_shared/myprivlib.so") |
| 8021 | |
| 8022 | // The platform variant of myprivlib links to the platform variant of mylib |
| 8023 | // and bypasses its stubs. |
| 8024 | ensureLinkedLibIs("myprivlib", "android_arm64_armv8-a_shared", "out/soong/.intermediates/mylib/", "android_arm64_armv8-a_shared/mylib.so") |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 8025 | } |
| 8026 | |
Martin Stjernholm | ec00900 | 2021-03-27 15:18:31 +0000 | [diff] [blame] | 8027 | func TestTestForForLibInOtherApex(t *testing.T) { |
| 8028 | // This case is only allowed for known overlapping APEXes, i.e. the ART APEXes. |
| 8029 | _ = testApex(t, ` |
| 8030 | apex { |
| 8031 | name: "com.android.art", |
| 8032 | key: "myapex.key", |
| 8033 | native_shared_libs: ["mylib"], |
| 8034 | updatable: false, |
| 8035 | } |
| 8036 | |
| 8037 | apex { |
| 8038 | name: "com.android.art.debug", |
| 8039 | key: "myapex.key", |
| 8040 | native_shared_libs: ["mylib", "mytestlib"], |
| 8041 | updatable: false, |
| 8042 | } |
| 8043 | |
| 8044 | apex_key { |
| 8045 | name: "myapex.key", |
| 8046 | public_key: "testkey.avbpubkey", |
| 8047 | private_key: "testkey.pem", |
| 8048 | } |
| 8049 | |
| 8050 | cc_library { |
| 8051 | name: "mylib", |
| 8052 | srcs: ["mylib.cpp"], |
| 8053 | system_shared_libs: [], |
| 8054 | stl: "none", |
| 8055 | stubs: { |
| 8056 | versions: ["1"], |
| 8057 | }, |
| 8058 | apex_available: ["com.android.art", "com.android.art.debug"], |
| 8059 | } |
| 8060 | |
| 8061 | cc_library { |
| 8062 | name: "mytestlib", |
| 8063 | srcs: ["mylib.cpp"], |
| 8064 | system_shared_libs: [], |
| 8065 | shared_libs: ["mylib"], |
| 8066 | stl: "none", |
| 8067 | apex_available: ["com.android.art.debug"], |
| 8068 | test_for: ["com.android.art"], |
| 8069 | } |
| 8070 | `, |
| 8071 | android.MockFS{ |
| 8072 | "system/sepolicy/apex/com.android.art-file_contexts": nil, |
| 8073 | "system/sepolicy/apex/com.android.art.debug-file_contexts": nil, |
| 8074 | }.AddToFixture()) |
| 8075 | } |
| 8076 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 8077 | // TODO(jungjw): Move this to proptools |
| 8078 | func intPtr(i int) *int { |
| 8079 | return &i |
| 8080 | } |
| 8081 | |
| 8082 | func TestApexSet(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 8083 | ctx := testApex(t, ` |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 8084 | apex_set { |
| 8085 | name: "myapex", |
| 8086 | set: "myapex.apks", |
| 8087 | filename: "foo_v2.apex", |
| 8088 | overrides: ["foo"], |
| 8089 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 8090 | `, |
| 8091 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 8092 | variables.Platform_sdk_version = intPtr(30) |
| 8093 | }), |
| 8094 | android.FixtureModifyConfig(func(config android.Config) { |
| 8095 | config.Targets[android.Android] = []android.Target{ |
| 8096 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}}, |
| 8097 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}}, |
| 8098 | } |
| 8099 | }), |
| 8100 | ) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 8101 | |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 8102 | m := ctx.ModuleForTests("myapex.apex.extractor", "android_common") |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 8103 | |
| 8104 | // Check extract_apks tool parameters. |
Paul Duffin | 2470467 | 2021-04-06 16:09:30 +0100 | [diff] [blame] | 8105 | extractedApex := m.Output("extracted/myapex.apks") |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 8106 | actual := extractedApex.Args["abis"] |
| 8107 | expected := "ARMEABI_V7A,ARM64_V8A" |
| 8108 | if actual != expected { |
| 8109 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 8110 | } |
| 8111 | actual = extractedApex.Args["sdk-version"] |
| 8112 | expected = "30" |
| 8113 | if actual != expected { |
| 8114 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 8115 | } |
| 8116 | |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 8117 | m = ctx.ModuleForTests("myapex", "android_common_myapex") |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 8118 | a := m.Module().(*ApexSet) |
| 8119 | expectedOverrides := []string{"foo"} |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 8120 | actualOverrides := android.AndroidMkEntriesForTest(t, ctx, a)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 8121 | if !reflect.DeepEqual(actualOverrides, expectedOverrides) { |
| 8122 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES - expected %q vs actual %q", expectedOverrides, actualOverrides) |
| 8123 | } |
| 8124 | } |
| 8125 | |
Jiyong Park | 7d95a51 | 2020-05-10 15:16:24 +0900 | [diff] [blame] | 8126 | func TestNoStaticLinkingToStubsLib(t *testing.T) { |
| 8127 | testApexError(t, `.*required by "mylib" is a native library providing stub.*`, ` |
| 8128 | apex { |
| 8129 | name: "myapex", |
| 8130 | key: "myapex.key", |
| 8131 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 8132 | updatable: false, |
Jiyong Park | 7d95a51 | 2020-05-10 15:16:24 +0900 | [diff] [blame] | 8133 | } |
| 8134 | |
| 8135 | apex_key { |
| 8136 | name: "myapex.key", |
| 8137 | public_key: "testkey.avbpubkey", |
| 8138 | private_key: "testkey.pem", |
| 8139 | } |
| 8140 | |
| 8141 | cc_library { |
| 8142 | name: "mylib", |
| 8143 | srcs: ["mylib.cpp"], |
| 8144 | static_libs: ["otherlib"], |
| 8145 | system_shared_libs: [], |
| 8146 | stl: "none", |
| 8147 | apex_available: [ "myapex" ], |
| 8148 | } |
| 8149 | |
| 8150 | cc_library { |
| 8151 | name: "otherlib", |
| 8152 | srcs: ["mylib.cpp"], |
| 8153 | system_shared_libs: [], |
| 8154 | stl: "none", |
| 8155 | stubs: { |
| 8156 | versions: ["1", "2", "3"], |
| 8157 | }, |
| 8158 | apex_available: [ "myapex" ], |
| 8159 | } |
| 8160 | `) |
| 8161 | } |
| 8162 | |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 8163 | func TestApexKeysTxt(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 8164 | ctx := testApex(t, ` |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 8165 | apex { |
| 8166 | name: "myapex", |
| 8167 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 8168 | updatable: false, |
Jooyung Han | 09c11ad | 2021-10-27 03:45:31 +0900 | [diff] [blame] | 8169 | custom_sign_tool: "sign_myapex", |
| 8170 | } |
| 8171 | |
| 8172 | apex_key { |
| 8173 | name: "myapex.key", |
| 8174 | public_key: "testkey.avbpubkey", |
| 8175 | private_key: "testkey.pem", |
| 8176 | } |
| 8177 | `) |
| 8178 | |
| 8179 | apexKeysText := ctx.SingletonForTests("apex_keys_text") |
| 8180 | content := apexKeysText.MaybeDescription("apexkeys.txt").BuildParams.Args["content"] |
| 8181 | 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"`) |
| 8182 | } |
| 8183 | |
| 8184 | func TestApexKeysTxtOverrides(t *testing.T) { |
| 8185 | ctx := testApex(t, ` |
| 8186 | apex { |
| 8187 | name: "myapex", |
| 8188 | key: "myapex.key", |
| 8189 | updatable: false, |
| 8190 | custom_sign_tool: "sign_myapex", |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 8191 | } |
| 8192 | |
| 8193 | apex_key { |
| 8194 | name: "myapex.key", |
| 8195 | public_key: "testkey.avbpubkey", |
| 8196 | private_key: "testkey.pem", |
| 8197 | } |
| 8198 | |
| 8199 | prebuilt_apex { |
| 8200 | name: "myapex", |
| 8201 | prefer: true, |
| 8202 | arch: { |
| 8203 | arm64: { |
| 8204 | src: "myapex-arm64.apex", |
| 8205 | }, |
| 8206 | arm: { |
| 8207 | src: "myapex-arm.apex", |
| 8208 | }, |
| 8209 | }, |
| 8210 | } |
| 8211 | |
| 8212 | apex_set { |
| 8213 | name: "myapex_set", |
| 8214 | set: "myapex.apks", |
| 8215 | filename: "myapex_set.apex", |
| 8216 | overrides: ["myapex"], |
| 8217 | } |
| 8218 | `) |
| 8219 | |
| 8220 | apexKeysText := ctx.SingletonForTests("apex_keys_text") |
| 8221 | content := apexKeysText.MaybeDescription("apexkeys.txt").BuildParams.Args["content"] |
| 8222 | 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] | 8223 | 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] | 8224 | } |
| 8225 | |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 8226 | func TestAllowedFiles(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 8227 | ctx := testApex(t, ` |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 8228 | apex { |
| 8229 | name: "myapex", |
| 8230 | key: "myapex.key", |
| 8231 | apps: ["app"], |
| 8232 | allowed_files: "allowed.txt", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 8233 | updatable: false, |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 8234 | } |
| 8235 | |
| 8236 | apex_key { |
| 8237 | name: "myapex.key", |
| 8238 | public_key: "testkey.avbpubkey", |
| 8239 | private_key: "testkey.pem", |
| 8240 | } |
| 8241 | |
| 8242 | android_app { |
| 8243 | name: "app", |
| 8244 | srcs: ["foo/bar/MyClass.java"], |
| 8245 | package_name: "foo", |
| 8246 | sdk_version: "none", |
| 8247 | system_modules: "none", |
| 8248 | apex_available: [ "myapex" ], |
| 8249 | } |
| 8250 | `, withFiles(map[string][]byte{ |
| 8251 | "sub/Android.bp": []byte(` |
| 8252 | override_apex { |
| 8253 | name: "override_myapex", |
| 8254 | base: "myapex", |
| 8255 | apps: ["override_app"], |
| 8256 | allowed_files: ":allowed", |
| 8257 | } |
| 8258 | // Overridable "path" property should be referenced indirectly |
| 8259 | filegroup { |
| 8260 | name: "allowed", |
| 8261 | srcs: ["allowed.txt"], |
| 8262 | } |
| 8263 | override_android_app { |
| 8264 | name: "override_app", |
| 8265 | base: "app", |
| 8266 | package_name: "bar", |
| 8267 | } |
| 8268 | `), |
| 8269 | })) |
| 8270 | |
| 8271 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("diffApexContentRule") |
| 8272 | if expected, actual := "allowed.txt", rule.Args["allowed_files_file"]; expected != actual { |
| 8273 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 8274 | } |
| 8275 | |
| 8276 | rule2 := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Rule("diffApexContentRule") |
| 8277 | if expected, actual := "sub/allowed.txt", rule2.Args["allowed_files_file"]; expected != actual { |
| 8278 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 8279 | } |
| 8280 | } |
| 8281 | |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 8282 | func TestNonPreferredPrebuiltDependency(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 8283 | testApex(t, ` |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 8284 | apex { |
| 8285 | name: "myapex", |
| 8286 | key: "myapex.key", |
| 8287 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 8288 | updatable: false, |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 8289 | } |
| 8290 | |
| 8291 | apex_key { |
| 8292 | name: "myapex.key", |
| 8293 | public_key: "testkey.avbpubkey", |
| 8294 | private_key: "testkey.pem", |
| 8295 | } |
| 8296 | |
| 8297 | cc_library { |
| 8298 | name: "mylib", |
| 8299 | srcs: ["mylib.cpp"], |
| 8300 | stubs: { |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 8301 | versions: ["current"], |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 8302 | }, |
| 8303 | apex_available: ["myapex"], |
| 8304 | } |
| 8305 | |
| 8306 | cc_prebuilt_library_shared { |
| 8307 | name: "mylib", |
| 8308 | prefer: false, |
| 8309 | srcs: ["prebuilt.so"], |
| 8310 | stubs: { |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 8311 | versions: ["current"], |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 8312 | }, |
| 8313 | apex_available: ["myapex"], |
| 8314 | } |
| 8315 | `) |
| 8316 | } |
| 8317 | |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 8318 | func TestCompressedApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 8319 | ctx := testApex(t, ` |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 8320 | apex { |
| 8321 | name: "myapex", |
| 8322 | key: "myapex.key", |
| 8323 | compressible: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 8324 | updatable: false, |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 8325 | } |
| 8326 | apex_key { |
| 8327 | name: "myapex.key", |
| 8328 | public_key: "testkey.avbpubkey", |
| 8329 | private_key: "testkey.pem", |
| 8330 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 8331 | `, |
| 8332 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 8333 | variables.CompressedApex = proptools.BoolPtr(true) |
| 8334 | }), |
| 8335 | ) |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 8336 | |
| 8337 | compressRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("compressRule") |
| 8338 | ensureContains(t, compressRule.Output.String(), "myapex.capex.unsigned") |
| 8339 | |
| 8340 | signApkRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("sign compressedApex") |
| 8341 | ensureEquals(t, signApkRule.Input.String(), compressRule.Output.String()) |
| 8342 | |
| 8343 | // Make sure output of bundle is .capex |
| 8344 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 8345 | ensureContains(t, ab.outputFile.String(), "myapex.capex") |
| 8346 | |
| 8347 | // Verify android.mk rules |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 8348 | data := android.AndroidMkDataForTest(t, ctx, ab) |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 8349 | var builder strings.Builder |
| 8350 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 8351 | androidMk := builder.String() |
| 8352 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.capex\n") |
| 8353 | } |
| 8354 | |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 8355 | func TestPreferredPrebuiltSharedLibDep(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 8356 | ctx := testApex(t, ` |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 8357 | apex { |
| 8358 | name: "myapex", |
| 8359 | key: "myapex.key", |
| 8360 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 8361 | updatable: false, |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 8362 | } |
| 8363 | |
| 8364 | apex_key { |
| 8365 | name: "myapex.key", |
| 8366 | public_key: "testkey.avbpubkey", |
| 8367 | private_key: "testkey.pem", |
| 8368 | } |
| 8369 | |
| 8370 | cc_library { |
| 8371 | name: "mylib", |
| 8372 | srcs: ["mylib.cpp"], |
| 8373 | apex_available: ["myapex"], |
| 8374 | shared_libs: ["otherlib"], |
| 8375 | system_shared_libs: [], |
| 8376 | } |
| 8377 | |
| 8378 | cc_library { |
| 8379 | name: "otherlib", |
| 8380 | srcs: ["mylib.cpp"], |
| 8381 | stubs: { |
| 8382 | versions: ["current"], |
| 8383 | }, |
| 8384 | } |
| 8385 | |
| 8386 | cc_prebuilt_library_shared { |
| 8387 | name: "otherlib", |
| 8388 | prefer: true, |
| 8389 | srcs: ["prebuilt.so"], |
| 8390 | stubs: { |
| 8391 | versions: ["current"], |
| 8392 | }, |
| 8393 | } |
| 8394 | `) |
| 8395 | |
| 8396 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 8397 | data := android.AndroidMkDataForTest(t, ctx, ab) |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 8398 | var builder strings.Builder |
| 8399 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 8400 | androidMk := builder.String() |
| 8401 | |
| 8402 | // The make level dependency needs to be on otherlib - prebuilt_otherlib isn't |
| 8403 | // a thing there. |
| 8404 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += otherlib\n") |
| 8405 | } |
| 8406 | |
Jiyong Park | e386754 | 2020-12-03 17:28:25 +0900 | [diff] [blame] | 8407 | func TestExcludeDependency(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 8408 | ctx := testApex(t, ` |
Jiyong Park | e386754 | 2020-12-03 17:28:25 +0900 | [diff] [blame] | 8409 | apex { |
| 8410 | name: "myapex", |
| 8411 | key: "myapex.key", |
| 8412 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 8413 | updatable: false, |
Jiyong Park | e386754 | 2020-12-03 17:28:25 +0900 | [diff] [blame] | 8414 | } |
| 8415 | |
| 8416 | apex_key { |
| 8417 | name: "myapex.key", |
| 8418 | public_key: "testkey.avbpubkey", |
| 8419 | private_key: "testkey.pem", |
| 8420 | } |
| 8421 | |
| 8422 | cc_library { |
| 8423 | name: "mylib", |
| 8424 | srcs: ["mylib.cpp"], |
| 8425 | system_shared_libs: [], |
| 8426 | stl: "none", |
| 8427 | apex_available: ["myapex"], |
| 8428 | shared_libs: ["mylib2"], |
| 8429 | target: { |
| 8430 | apex: { |
| 8431 | exclude_shared_libs: ["mylib2"], |
| 8432 | }, |
| 8433 | }, |
| 8434 | } |
| 8435 | |
| 8436 | cc_library { |
| 8437 | name: "mylib2", |
| 8438 | srcs: ["mylib.cpp"], |
| 8439 | system_shared_libs: [], |
| 8440 | stl: "none", |
| 8441 | } |
| 8442 | `) |
| 8443 | |
| 8444 | // Check if mylib is linked to mylib2 for the non-apex target |
| 8445 | ldFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 8446 | ensureContains(t, ldFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
| 8447 | |
| 8448 | // Make sure that the link doesn't occur for the apex target |
| 8449 | ldFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
| 8450 | ensureNotContains(t, ldFlags, "mylib2/android_arm64_armv8-a_shared_apex10000/mylib2.so") |
| 8451 | |
| 8452 | // It shouldn't appear in the copy cmd as well. |
| 8453 | copyCmds := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule").Args["copy_commands"] |
| 8454 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 8455 | } |
| 8456 | |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 8457 | func TestPrebuiltStubLibDep(t *testing.T) { |
| 8458 | bpBase := ` |
| 8459 | apex { |
| 8460 | name: "myapex", |
| 8461 | key: "myapex.key", |
| 8462 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 8463 | updatable: false, |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 8464 | } |
| 8465 | apex_key { |
| 8466 | name: "myapex.key", |
| 8467 | public_key: "testkey.avbpubkey", |
| 8468 | private_key: "testkey.pem", |
| 8469 | } |
| 8470 | cc_library { |
| 8471 | name: "mylib", |
| 8472 | srcs: ["mylib.cpp"], |
| 8473 | apex_available: ["myapex"], |
| 8474 | shared_libs: ["stublib"], |
| 8475 | system_shared_libs: [], |
| 8476 | } |
| 8477 | apex { |
| 8478 | name: "otherapex", |
| 8479 | enabled: %s, |
| 8480 | key: "myapex.key", |
| 8481 | native_shared_libs: ["stublib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 8482 | updatable: false, |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 8483 | } |
| 8484 | ` |
| 8485 | |
| 8486 | stublibSourceBp := ` |
| 8487 | cc_library { |
| 8488 | name: "stublib", |
| 8489 | srcs: ["mylib.cpp"], |
| 8490 | apex_available: ["otherapex"], |
| 8491 | system_shared_libs: [], |
| 8492 | stl: "none", |
| 8493 | stubs: { |
| 8494 | versions: ["1"], |
| 8495 | }, |
| 8496 | } |
| 8497 | ` |
| 8498 | |
| 8499 | stublibPrebuiltBp := ` |
| 8500 | cc_prebuilt_library_shared { |
| 8501 | name: "stublib", |
| 8502 | srcs: ["prebuilt.so"], |
| 8503 | apex_available: ["otherapex"], |
| 8504 | stubs: { |
| 8505 | versions: ["1"], |
| 8506 | }, |
| 8507 | %s |
| 8508 | } |
| 8509 | ` |
| 8510 | |
| 8511 | tests := []struct { |
| 8512 | name string |
| 8513 | stublibBp string |
| 8514 | usePrebuilt bool |
| 8515 | modNames []string // Modules to collect AndroidMkEntries for |
| 8516 | otherApexEnabled []string |
| 8517 | }{ |
| 8518 | { |
| 8519 | name: "only_source", |
| 8520 | stublibBp: stublibSourceBp, |
| 8521 | usePrebuilt: false, |
| 8522 | modNames: []string{"stublib"}, |
| 8523 | otherApexEnabled: []string{"true", "false"}, |
| 8524 | }, |
| 8525 | { |
| 8526 | name: "source_preferred", |
| 8527 | stublibBp: stublibSourceBp + fmt.Sprintf(stublibPrebuiltBp, ""), |
| 8528 | usePrebuilt: false, |
| 8529 | modNames: []string{"stublib", "prebuilt_stublib"}, |
| 8530 | otherApexEnabled: []string{"true", "false"}, |
| 8531 | }, |
| 8532 | { |
| 8533 | name: "prebuilt_preferred", |
| 8534 | stublibBp: stublibSourceBp + fmt.Sprintf(stublibPrebuiltBp, "prefer: true,"), |
| 8535 | usePrebuilt: true, |
| 8536 | modNames: []string{"stublib", "prebuilt_stublib"}, |
| 8537 | otherApexEnabled: []string{"false"}, // No "true" since APEX cannot depend on prebuilt. |
| 8538 | }, |
| 8539 | { |
| 8540 | name: "only_prebuilt", |
| 8541 | stublibBp: fmt.Sprintf(stublibPrebuiltBp, ""), |
| 8542 | usePrebuilt: true, |
| 8543 | modNames: []string{"stublib"}, |
| 8544 | otherApexEnabled: []string{"false"}, // No "true" since APEX cannot depend on prebuilt. |
| 8545 | }, |
| 8546 | } |
| 8547 | |
| 8548 | for _, test := range tests { |
| 8549 | t.Run(test.name, func(t *testing.T) { |
| 8550 | for _, otherApexEnabled := range test.otherApexEnabled { |
| 8551 | t.Run("otherapex_enabled_"+otherApexEnabled, func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 8552 | ctx := testApex(t, fmt.Sprintf(bpBase, otherApexEnabled)+test.stublibBp) |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 8553 | |
| 8554 | type modAndMkEntries struct { |
| 8555 | mod *cc.Module |
| 8556 | mkEntries android.AndroidMkEntries |
| 8557 | } |
| 8558 | entries := []*modAndMkEntries{} |
| 8559 | |
| 8560 | // Gather shared lib modules that are installable |
| 8561 | for _, modName := range test.modNames { |
| 8562 | for _, variant := range ctx.ModuleVariantsForTests(modName) { |
| 8563 | if !strings.HasPrefix(variant, "android_arm64_armv8-a_shared") { |
| 8564 | continue |
| 8565 | } |
| 8566 | mod := ctx.ModuleForTests(modName, variant).Module().(*cc.Module) |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 8567 | if !mod.Enabled() || mod.IsHideFromMake() { |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 8568 | continue |
| 8569 | } |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 8570 | for _, ent := range android.AndroidMkEntriesForTest(t, ctx, mod) { |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 8571 | if ent.Disabled { |
| 8572 | continue |
| 8573 | } |
| 8574 | entries = append(entries, &modAndMkEntries{ |
| 8575 | mod: mod, |
| 8576 | mkEntries: ent, |
| 8577 | }) |
| 8578 | } |
| 8579 | } |
| 8580 | } |
| 8581 | |
| 8582 | var entry *modAndMkEntries = nil |
| 8583 | for _, ent := range entries { |
| 8584 | if strings.Join(ent.mkEntries.EntryMap["LOCAL_MODULE"], ",") == "stublib" { |
| 8585 | if entry != nil { |
| 8586 | t.Errorf("More than one AndroidMk entry for \"stublib\": %s and %s", entry.mod, ent.mod) |
| 8587 | } else { |
| 8588 | entry = ent |
| 8589 | } |
| 8590 | } |
| 8591 | } |
| 8592 | |
| 8593 | if entry == nil { |
| 8594 | t.Errorf("AndroidMk entry for \"stublib\" missing") |
| 8595 | } else { |
| 8596 | isPrebuilt := entry.mod.Prebuilt() != nil |
| 8597 | if isPrebuilt != test.usePrebuilt { |
| 8598 | t.Errorf("Wrong module for \"stublib\" AndroidMk entry: got prebuilt %t, want prebuilt %t", isPrebuilt, test.usePrebuilt) |
| 8599 | } |
| 8600 | if !entry.mod.IsStubs() { |
| 8601 | t.Errorf("Module for \"stublib\" AndroidMk entry isn't a stub: %s", entry.mod) |
| 8602 | } |
| 8603 | if entry.mkEntries.EntryMap["LOCAL_NOT_AVAILABLE_FOR_PLATFORM"] != nil { |
| 8604 | t.Errorf("AndroidMk entry for \"stublib\" has LOCAL_NOT_AVAILABLE_FOR_PLATFORM set: %+v", entry.mkEntries) |
| 8605 | } |
Jiyong Park | 892a98f | 2020-12-14 09:20:00 +0900 | [diff] [blame] | 8606 | cflags := entry.mkEntries.EntryMap["LOCAL_EXPORT_CFLAGS"] |
Jiyong Park | d4a3a13 | 2021-03-17 20:21:35 +0900 | [diff] [blame] | 8607 | expected := "-D__STUBLIB_API__=10000" |
Jiyong Park | 892a98f | 2020-12-14 09:20:00 +0900 | [diff] [blame] | 8608 | if !android.InList(expected, cflags) { |
| 8609 | t.Errorf("LOCAL_EXPORT_CFLAGS expected to have %q, but got %q", expected, cflags) |
| 8610 | } |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 8611 | } |
| 8612 | }) |
| 8613 | } |
| 8614 | }) |
| 8615 | } |
| 8616 | } |
| 8617 | |
Martin Stjernholm | df298b3 | 2021-05-21 20:57:29 +0100 | [diff] [blame] | 8618 | func TestHostApexInHostOnlyBuild(t *testing.T) { |
| 8619 | testApex(t, ` |
| 8620 | apex { |
| 8621 | name: "myapex", |
| 8622 | host_supported: true, |
| 8623 | key: "myapex.key", |
| 8624 | updatable: false, |
| 8625 | payload_type: "zip", |
| 8626 | } |
| 8627 | apex_key { |
| 8628 | name: "myapex.key", |
| 8629 | public_key: "testkey.avbpubkey", |
| 8630 | private_key: "testkey.pem", |
| 8631 | } |
| 8632 | `, |
| 8633 | android.FixtureModifyConfig(func(config android.Config) { |
| 8634 | // We may not have device targets in all builds, e.g. in |
| 8635 | // prebuilts/build-tools/build-prebuilts.sh |
| 8636 | config.Targets[android.Android] = []android.Target{} |
| 8637 | })) |
| 8638 | } |
| 8639 | |
Colin Cross | c33e521 | 2021-05-25 18:16:02 -0700 | [diff] [blame] | 8640 | func TestApexJavaCoverage(t *testing.T) { |
| 8641 | bp := ` |
| 8642 | apex { |
| 8643 | name: "myapex", |
| 8644 | key: "myapex.key", |
| 8645 | java_libs: ["mylib"], |
| 8646 | bootclasspath_fragments: ["mybootclasspathfragment"], |
| 8647 | systemserverclasspath_fragments: ["mysystemserverclasspathfragment"], |
| 8648 | updatable: false, |
| 8649 | } |
| 8650 | |
| 8651 | apex_key { |
| 8652 | name: "myapex.key", |
| 8653 | public_key: "testkey.avbpubkey", |
| 8654 | private_key: "testkey.pem", |
| 8655 | } |
| 8656 | |
| 8657 | java_library { |
| 8658 | name: "mylib", |
| 8659 | srcs: ["mylib.java"], |
| 8660 | apex_available: ["myapex"], |
| 8661 | compile_dex: true, |
| 8662 | } |
| 8663 | |
| 8664 | bootclasspath_fragment { |
| 8665 | name: "mybootclasspathfragment", |
| 8666 | contents: ["mybootclasspathlib"], |
| 8667 | apex_available: ["myapex"], |
| 8668 | } |
| 8669 | |
| 8670 | java_library { |
| 8671 | name: "mybootclasspathlib", |
| 8672 | srcs: ["mybootclasspathlib.java"], |
| 8673 | apex_available: ["myapex"], |
| 8674 | compile_dex: true, |
| 8675 | } |
| 8676 | |
| 8677 | systemserverclasspath_fragment { |
| 8678 | name: "mysystemserverclasspathfragment", |
| 8679 | contents: ["mysystemserverclasspathlib"], |
| 8680 | apex_available: ["myapex"], |
| 8681 | } |
| 8682 | |
| 8683 | java_library { |
| 8684 | name: "mysystemserverclasspathlib", |
| 8685 | srcs: ["mysystemserverclasspathlib.java"], |
| 8686 | apex_available: ["myapex"], |
| 8687 | compile_dex: true, |
| 8688 | } |
| 8689 | ` |
| 8690 | |
| 8691 | result := android.GroupFixturePreparers( |
| 8692 | PrepareForTestWithApexBuildComponents, |
| 8693 | prepareForTestWithMyapex, |
| 8694 | java.PrepareForTestWithJavaDefaultModules, |
| 8695 | android.PrepareForTestWithAndroidBuildComponents, |
| 8696 | android.FixtureWithRootAndroidBp(bp), |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 8697 | dexpreopt.FixtureSetApexBootJars("myapex:mybootclasspathlib"), |
| 8698 | dexpreopt.FixtureSetApexSystemServerJars("myapex:mysystemserverclasspathlib"), |
Colin Cross | c33e521 | 2021-05-25 18:16:02 -0700 | [diff] [blame] | 8699 | android.FixtureMergeEnv(map[string]string{ |
| 8700 | "EMMA_INSTRUMENT": "true", |
| 8701 | }), |
| 8702 | ).RunTest(t) |
| 8703 | |
| 8704 | // Make sure jacoco ran on both mylib and mybootclasspathlib |
| 8705 | if result.ModuleForTests("mylib", "android_common_apex10000").MaybeRule("jacoco").Rule == nil { |
| 8706 | t.Errorf("Failed to find jacoco rule for mylib") |
| 8707 | } |
| 8708 | if result.ModuleForTests("mybootclasspathlib", "android_common_apex10000").MaybeRule("jacoco").Rule == nil { |
| 8709 | t.Errorf("Failed to find jacoco rule for mybootclasspathlib") |
| 8710 | } |
| 8711 | if result.ModuleForTests("mysystemserverclasspathlib", "android_common_apex10000").MaybeRule("jacoco").Rule == nil { |
| 8712 | t.Errorf("Failed to find jacoco rule for mysystemserverclasspathlib") |
| 8713 | } |
| 8714 | } |
| 8715 | |
Jiyong Park | 192600a | 2021-08-03 07:52:17 +0000 | [diff] [blame] | 8716 | func TestProhibitStaticExecutable(t *testing.T) { |
| 8717 | testApexError(t, `executable mybin is static`, ` |
| 8718 | apex { |
| 8719 | name: "myapex", |
| 8720 | key: "myapex.key", |
| 8721 | binaries: ["mybin"], |
| 8722 | min_sdk_version: "29", |
| 8723 | } |
| 8724 | |
| 8725 | apex_key { |
| 8726 | name: "myapex.key", |
| 8727 | public_key: "testkey.avbpubkey", |
| 8728 | private_key: "testkey.pem", |
| 8729 | } |
| 8730 | |
| 8731 | cc_binary { |
| 8732 | name: "mybin", |
| 8733 | srcs: ["mylib.cpp"], |
| 8734 | relative_install_path: "foo/bar", |
| 8735 | static_executable: true, |
| 8736 | system_shared_libs: [], |
| 8737 | stl: "none", |
| 8738 | apex_available: [ "myapex" ], |
Jiyong Park | d12979d | 2021-08-03 13:36:09 +0900 | [diff] [blame] | 8739 | min_sdk_version: "29", |
| 8740 | } |
| 8741 | `) |
| 8742 | |
| 8743 | testApexError(t, `executable mybin.rust is static`, ` |
| 8744 | apex { |
| 8745 | name: "myapex", |
| 8746 | key: "myapex.key", |
| 8747 | binaries: ["mybin.rust"], |
| 8748 | min_sdk_version: "29", |
| 8749 | } |
| 8750 | |
| 8751 | apex_key { |
| 8752 | name: "myapex.key", |
| 8753 | public_key: "testkey.avbpubkey", |
| 8754 | private_key: "testkey.pem", |
| 8755 | } |
| 8756 | |
| 8757 | rust_binary { |
| 8758 | name: "mybin.rust", |
| 8759 | srcs: ["foo.rs"], |
| 8760 | static_executable: true, |
| 8761 | apex_available: ["myapex"], |
| 8762 | min_sdk_version: "29", |
Jiyong Park | 192600a | 2021-08-03 07:52:17 +0000 | [diff] [blame] | 8763 | } |
| 8764 | `) |
| 8765 | } |
| 8766 | |
Jiakai Zhang | 470b7e2 | 2021-09-30 09:34:26 +0000 | [diff] [blame] | 8767 | func TestAndroidMk_DexpreoptBuiltInstalledForApex(t *testing.T) { |
| 8768 | ctx := testApex(t, ` |
| 8769 | apex { |
| 8770 | name: "myapex", |
| 8771 | key: "myapex.key", |
| 8772 | updatable: false, |
| 8773 | java_libs: ["foo"], |
| 8774 | } |
| 8775 | |
| 8776 | apex_key { |
| 8777 | name: "myapex.key", |
| 8778 | public_key: "testkey.avbpubkey", |
| 8779 | private_key: "testkey.pem", |
| 8780 | } |
| 8781 | |
| 8782 | java_library { |
| 8783 | name: "foo", |
| 8784 | srcs: ["foo.java"], |
| 8785 | apex_available: ["myapex"], |
| 8786 | installable: true, |
| 8787 | } |
| 8788 | `, |
| 8789 | dexpreopt.FixtureSetApexSystemServerJars("myapex:foo"), |
| 8790 | ) |
| 8791 | |
| 8792 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 8793 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
| 8794 | var builder strings.Builder |
| 8795 | data.Custom(&builder, apexBundle.BaseModuleName(), "TARGET_", "", data) |
| 8796 | androidMk := builder.String() |
| 8797 | 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") |
| 8798 | } |
| 8799 | |
| 8800 | func TestAndroidMk_DexpreoptBuiltInstalledForApex_Prebuilt(t *testing.T) { |
| 8801 | ctx := testApex(t, ` |
| 8802 | prebuilt_apex { |
| 8803 | name: "myapex", |
| 8804 | arch: { |
| 8805 | arm64: { |
| 8806 | src: "myapex-arm64.apex", |
| 8807 | }, |
| 8808 | arm: { |
| 8809 | src: "myapex-arm.apex", |
| 8810 | }, |
| 8811 | }, |
| 8812 | exported_java_libs: ["foo"], |
| 8813 | } |
| 8814 | |
| 8815 | java_import { |
| 8816 | name: "foo", |
| 8817 | jars: ["foo.jar"], |
Jiakai Zhang | 28bc9a8 | 2021-12-20 15:08:57 +0000 | [diff] [blame] | 8818 | apex_available: ["myapex"], |
Jiakai Zhang | 470b7e2 | 2021-09-30 09:34:26 +0000 | [diff] [blame] | 8819 | } |
| 8820 | `, |
| 8821 | dexpreopt.FixtureSetApexSystemServerJars("myapex:foo"), |
| 8822 | ) |
| 8823 | |
| 8824 | prebuilt := ctx.ModuleForTests("myapex", "android_common_myapex").Module().(*Prebuilt) |
| 8825 | entriesList := android.AndroidMkEntriesForTest(t, ctx, prebuilt) |
| 8826 | mainModuleEntries := entriesList[0] |
| 8827 | android.AssertArrayString(t, |
| 8828 | "LOCAL_REQUIRED_MODULES", |
| 8829 | mainModuleEntries.EntryMap["LOCAL_REQUIRED_MODULES"], |
| 8830 | []string{ |
| 8831 | "foo-dexpreopt-arm64-apex@myapex@javalib@foo.jar@classes.odex", |
| 8832 | "foo-dexpreopt-arm64-apex@myapex@javalib@foo.jar@classes.vdex", |
| 8833 | }) |
| 8834 | } |
| 8835 | |
Jiyong Park | cacc4f3 | 2021-10-28 14:26:03 +0900 | [diff] [blame] | 8836 | func TestAndroidMk_RequiredModules(t *testing.T) { |
| 8837 | ctx := testApex(t, ` |
| 8838 | apex { |
| 8839 | name: "myapex", |
| 8840 | key: "myapex.key", |
| 8841 | updatable: false, |
| 8842 | java_libs: ["foo"], |
| 8843 | required: ["otherapex"], |
| 8844 | } |
| 8845 | |
| 8846 | apex { |
| 8847 | name: "otherapex", |
| 8848 | key: "myapex.key", |
| 8849 | updatable: false, |
| 8850 | java_libs: ["foo"], |
| 8851 | required: ["otherapex"], |
| 8852 | } |
| 8853 | |
| 8854 | apex_key { |
| 8855 | name: "myapex.key", |
| 8856 | public_key: "testkey.avbpubkey", |
| 8857 | private_key: "testkey.pem", |
| 8858 | } |
| 8859 | |
| 8860 | java_library { |
| 8861 | name: "foo", |
| 8862 | srcs: ["foo.java"], |
| 8863 | apex_available: ["myapex", "otherapex"], |
| 8864 | installable: true, |
| 8865 | } |
| 8866 | `) |
| 8867 | |
| 8868 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 8869 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
| 8870 | var builder strings.Builder |
| 8871 | data.Custom(&builder, apexBundle.BaseModuleName(), "TARGET_", "", data) |
| 8872 | androidMk := builder.String() |
| 8873 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += otherapex") |
| 8874 | } |
| 8875 | |
Jiakai Zhang | d70dff7 | 2022-02-24 15:06:05 +0000 | [diff] [blame] | 8876 | func TestAndroidMk_RequiredDeps(t *testing.T) { |
| 8877 | ctx := testApex(t, ` |
| 8878 | apex { |
| 8879 | name: "myapex", |
| 8880 | key: "myapex.key", |
| 8881 | updatable: false, |
| 8882 | } |
| 8883 | |
| 8884 | apex_key { |
| 8885 | name: "myapex.key", |
| 8886 | public_key: "testkey.avbpubkey", |
| 8887 | private_key: "testkey.pem", |
| 8888 | } |
| 8889 | `) |
| 8890 | |
| 8891 | bundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 8892 | bundle.requiredDeps = append(bundle.requiredDeps, "foo") |
| 8893 | data := android.AndroidMkDataForTest(t, ctx, bundle) |
| 8894 | var builder strings.Builder |
| 8895 | data.Custom(&builder, bundle.BaseModuleName(), "TARGET_", "", data) |
| 8896 | androidMk := builder.String() |
| 8897 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += foo") |
| 8898 | |
| 8899 | flattenedBundle := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
| 8900 | flattenedBundle.requiredDeps = append(flattenedBundle.requiredDeps, "foo") |
| 8901 | flattenedData := android.AndroidMkDataForTest(t, ctx, flattenedBundle) |
| 8902 | var flattenedBuilder strings.Builder |
| 8903 | flattenedData.Custom(&flattenedBuilder, flattenedBundle.BaseModuleName(), "TARGET_", "", flattenedData) |
| 8904 | flattenedAndroidMk := flattenedBuilder.String() |
| 8905 | ensureContains(t, flattenedAndroidMk, "LOCAL_REQUIRED_MODULES += foo") |
| 8906 | } |
| 8907 | |
Jooyung Han | a6d3667 | 2022-02-24 13:58:07 +0900 | [diff] [blame] | 8908 | func TestApexOutputFileProducer(t *testing.T) { |
| 8909 | for _, tc := range []struct { |
| 8910 | name string |
| 8911 | ref string |
| 8912 | expected_data []string |
| 8913 | }{ |
| 8914 | { |
| 8915 | name: "test_using_output", |
| 8916 | ref: ":myapex", |
| 8917 | expected_data: []string{"out/soong/.intermediates/myapex/android_common_myapex_image/myapex.capex:myapex.capex"}, |
| 8918 | }, |
| 8919 | { |
| 8920 | name: "test_using_apex", |
| 8921 | ref: ":myapex{.apex}", |
| 8922 | expected_data: []string{"out/soong/.intermediates/myapex/android_common_myapex_image/myapex.apex:myapex.apex"}, |
| 8923 | }, |
| 8924 | } { |
| 8925 | t.Run(tc.name, func(t *testing.T) { |
| 8926 | ctx := testApex(t, ` |
| 8927 | apex { |
| 8928 | name: "myapex", |
| 8929 | key: "myapex.key", |
| 8930 | compressible: true, |
| 8931 | updatable: false, |
| 8932 | } |
| 8933 | |
| 8934 | apex_key { |
| 8935 | name: "myapex.key", |
| 8936 | public_key: "testkey.avbpubkey", |
| 8937 | private_key: "testkey.pem", |
| 8938 | } |
| 8939 | |
| 8940 | java_test { |
| 8941 | name: "`+tc.name+`", |
| 8942 | srcs: ["a.java"], |
| 8943 | data: ["`+tc.ref+`"], |
| 8944 | } |
| 8945 | `, |
| 8946 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 8947 | variables.CompressedApex = proptools.BoolPtr(true) |
| 8948 | })) |
| 8949 | javaTest := ctx.ModuleForTests(tc.name, "android_common").Module().(*java.Test) |
| 8950 | data := android.AndroidMkEntriesForTest(t, ctx, javaTest)[0].EntryMap["LOCAL_COMPATIBILITY_SUPPORT_FILES"] |
| 8951 | android.AssertStringPathsRelativeToTopEquals(t, "data", ctx.Config(), tc.expected_data, data) |
| 8952 | }) |
| 8953 | } |
| 8954 | } |
| 8955 | |
satayev | 758968a | 2021-12-06 11:42:40 +0000 | [diff] [blame] | 8956 | func TestSdkLibraryCanHaveHigherMinSdkVersion(t *testing.T) { |
| 8957 | preparer := android.GroupFixturePreparers( |
| 8958 | PrepareForTestWithApexBuildComponents, |
| 8959 | prepareForTestWithMyapex, |
| 8960 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 8961 | java.PrepareForTestWithJavaDefaultModules, |
| 8962 | android.PrepareForTestWithAndroidBuildComponents, |
| 8963 | dexpreopt.FixtureSetApexBootJars("myapex:mybootclasspathlib"), |
| 8964 | dexpreopt.FixtureSetApexSystemServerJars("myapex:mysystemserverclasspathlib"), |
| 8965 | ) |
| 8966 | |
| 8967 | // Test java_sdk_library in bootclasspath_fragment may define higher min_sdk_version than the apex |
| 8968 | t.Run("bootclasspath_fragment jar has higher min_sdk_version than apex", func(t *testing.T) { |
| 8969 | preparer.RunTestWithBp(t, ` |
| 8970 | apex { |
| 8971 | name: "myapex", |
| 8972 | key: "myapex.key", |
| 8973 | bootclasspath_fragments: ["mybootclasspathfragment"], |
| 8974 | min_sdk_version: "30", |
| 8975 | updatable: false, |
| 8976 | } |
| 8977 | |
| 8978 | apex_key { |
| 8979 | name: "myapex.key", |
| 8980 | public_key: "testkey.avbpubkey", |
| 8981 | private_key: "testkey.pem", |
| 8982 | } |
| 8983 | |
| 8984 | bootclasspath_fragment { |
| 8985 | name: "mybootclasspathfragment", |
| 8986 | contents: ["mybootclasspathlib"], |
| 8987 | apex_available: ["myapex"], |
| 8988 | } |
| 8989 | |
| 8990 | java_sdk_library { |
| 8991 | name: "mybootclasspathlib", |
| 8992 | srcs: ["mybootclasspathlib.java"], |
| 8993 | apex_available: ["myapex"], |
| 8994 | compile_dex: true, |
| 8995 | unsafe_ignore_missing_latest_api: true, |
| 8996 | min_sdk_version: "31", |
| 8997 | static_libs: ["util"], |
| 8998 | } |
| 8999 | |
| 9000 | java_library { |
| 9001 | name: "util", |
| 9002 | srcs: ["a.java"], |
| 9003 | apex_available: ["myapex"], |
| 9004 | min_sdk_version: "31", |
| 9005 | static_libs: ["another_util"], |
| 9006 | } |
| 9007 | |
| 9008 | java_library { |
| 9009 | name: "another_util", |
| 9010 | srcs: ["a.java"], |
| 9011 | min_sdk_version: "31", |
| 9012 | apex_available: ["myapex"], |
| 9013 | } |
| 9014 | `) |
| 9015 | }) |
| 9016 | |
| 9017 | // Test java_sdk_library in systemserverclasspath_fragment may define higher min_sdk_version than the apex |
| 9018 | t.Run("systemserverclasspath_fragment jar has higher min_sdk_version than apex", func(t *testing.T) { |
| 9019 | preparer.RunTestWithBp(t, ` |
| 9020 | apex { |
| 9021 | name: "myapex", |
| 9022 | key: "myapex.key", |
| 9023 | systemserverclasspath_fragments: ["mysystemserverclasspathfragment"], |
| 9024 | min_sdk_version: "30", |
| 9025 | updatable: false, |
| 9026 | } |
| 9027 | |
| 9028 | apex_key { |
| 9029 | name: "myapex.key", |
| 9030 | public_key: "testkey.avbpubkey", |
| 9031 | private_key: "testkey.pem", |
| 9032 | } |
| 9033 | |
| 9034 | systemserverclasspath_fragment { |
| 9035 | name: "mysystemserverclasspathfragment", |
| 9036 | contents: ["mysystemserverclasspathlib"], |
| 9037 | apex_available: ["myapex"], |
| 9038 | } |
| 9039 | |
| 9040 | java_sdk_library { |
| 9041 | name: "mysystemserverclasspathlib", |
| 9042 | srcs: ["mysystemserverclasspathlib.java"], |
| 9043 | apex_available: ["myapex"], |
| 9044 | compile_dex: true, |
| 9045 | min_sdk_version: "32", |
| 9046 | unsafe_ignore_missing_latest_api: true, |
| 9047 | static_libs: ["util"], |
| 9048 | } |
| 9049 | |
| 9050 | java_library { |
| 9051 | name: "util", |
| 9052 | srcs: ["a.java"], |
| 9053 | apex_available: ["myapex"], |
| 9054 | min_sdk_version: "31", |
| 9055 | static_libs: ["another_util"], |
| 9056 | } |
| 9057 | |
| 9058 | java_library { |
| 9059 | name: "another_util", |
| 9060 | srcs: ["a.java"], |
| 9061 | min_sdk_version: "31", |
| 9062 | apex_available: ["myapex"], |
| 9063 | } |
| 9064 | `) |
| 9065 | }) |
| 9066 | |
| 9067 | t.Run("bootclasspath_fragment jar must set min_sdk_version", func(t *testing.T) { |
| 9068 | preparer.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "mybootclasspathlib".*must set min_sdk_version`)). |
| 9069 | RunTestWithBp(t, ` |
| 9070 | apex { |
| 9071 | name: "myapex", |
| 9072 | key: "myapex.key", |
| 9073 | bootclasspath_fragments: ["mybootclasspathfragment"], |
| 9074 | min_sdk_version: "30", |
| 9075 | updatable: false, |
| 9076 | } |
| 9077 | |
| 9078 | apex_key { |
| 9079 | name: "myapex.key", |
| 9080 | public_key: "testkey.avbpubkey", |
| 9081 | private_key: "testkey.pem", |
| 9082 | } |
| 9083 | |
| 9084 | bootclasspath_fragment { |
| 9085 | name: "mybootclasspathfragment", |
| 9086 | contents: ["mybootclasspathlib"], |
| 9087 | apex_available: ["myapex"], |
| 9088 | } |
| 9089 | |
| 9090 | java_sdk_library { |
| 9091 | name: "mybootclasspathlib", |
| 9092 | srcs: ["mybootclasspathlib.java"], |
| 9093 | apex_available: ["myapex"], |
| 9094 | compile_dex: true, |
| 9095 | unsafe_ignore_missing_latest_api: true, |
| 9096 | } |
| 9097 | `) |
| 9098 | }) |
| 9099 | |
| 9100 | t.Run("systemserverclasspath_fragment jar must set min_sdk_version", func(t *testing.T) { |
| 9101 | preparer.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module "mysystemserverclasspathlib".*must set min_sdk_version`)). |
| 9102 | RunTestWithBp(t, ` |
| 9103 | apex { |
| 9104 | name: "myapex", |
| 9105 | key: "myapex.key", |
| 9106 | systemserverclasspath_fragments: ["mysystemserverclasspathfragment"], |
| 9107 | min_sdk_version: "30", |
| 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 | systemserverclasspath_fragment { |
| 9118 | name: "mysystemserverclasspathfragment", |
| 9119 | contents: ["mysystemserverclasspathlib"], |
| 9120 | apex_available: ["myapex"], |
| 9121 | } |
| 9122 | |
| 9123 | java_sdk_library { |
| 9124 | name: "mysystemserverclasspathlib", |
| 9125 | srcs: ["mysystemserverclasspathlib.java"], |
| 9126 | apex_available: ["myapex"], |
| 9127 | compile_dex: true, |
| 9128 | unsafe_ignore_missing_latest_api: true, |
| 9129 | } |
| 9130 | `) |
| 9131 | }) |
| 9132 | } |
| 9133 | |
Jiakai Zhang | 6decef9 | 2022-01-12 17:56:19 +0000 | [diff] [blame] | 9134 | // Verifies that the APEX depends on all the Make modules in the list. |
| 9135 | func ensureContainsRequiredDeps(t *testing.T, ctx *android.TestContext, moduleName, variant string, deps []string) { |
| 9136 | a := ctx.ModuleForTests(moduleName, variant).Module().(*apexBundle) |
| 9137 | for _, dep := range deps { |
| 9138 | android.AssertStringListContains(t, "", a.requiredDeps, dep) |
| 9139 | } |
| 9140 | } |
| 9141 | |
| 9142 | // Verifies that the APEX does not depend on any of the Make modules in the list. |
| 9143 | func ensureDoesNotContainRequiredDeps(t *testing.T, ctx *android.TestContext, moduleName, variant string, deps []string) { |
| 9144 | a := ctx.ModuleForTests(moduleName, variant).Module().(*apexBundle) |
| 9145 | for _, dep := range deps { |
| 9146 | android.AssertStringListDoesNotContain(t, "", a.requiredDeps, dep) |
| 9147 | } |
| 9148 | } |
| 9149 | |
Spandan Das | 6677325 | 2022-01-15 00:23:18 +0000 | [diff] [blame] | 9150 | func TestApexStrictUpdtabilityLint(t *testing.T) { |
| 9151 | bpTemplate := ` |
| 9152 | apex { |
| 9153 | name: "myapex", |
| 9154 | key: "myapex.key", |
| 9155 | java_libs: ["myjavalib"], |
| 9156 | updatable: %v, |
| 9157 | min_sdk_version: "29", |
| 9158 | } |
| 9159 | apex_key { |
| 9160 | name: "myapex.key", |
| 9161 | } |
| 9162 | java_library { |
| 9163 | name: "myjavalib", |
| 9164 | srcs: ["MyClass.java"], |
| 9165 | apex_available: [ "myapex" ], |
| 9166 | lint: { |
| 9167 | strict_updatability_linting: %v, |
| 9168 | }, |
| 9169 | sdk_version: "current", |
| 9170 | min_sdk_version: "29", |
| 9171 | } |
| 9172 | ` |
| 9173 | fs := android.MockFS{ |
| 9174 | "lint-baseline.xml": nil, |
| 9175 | } |
| 9176 | |
| 9177 | testCases := []struct { |
| 9178 | testCaseName string |
| 9179 | apexUpdatable bool |
| 9180 | javaStrictUpdtabilityLint bool |
| 9181 | lintFileExists bool |
| 9182 | disallowedFlagExpected bool |
| 9183 | }{ |
| 9184 | { |
| 9185 | testCaseName: "lint-baseline.xml does not exist, no disallowed flag necessary in lint cmd", |
| 9186 | apexUpdatable: true, |
| 9187 | javaStrictUpdtabilityLint: true, |
| 9188 | lintFileExists: false, |
| 9189 | disallowedFlagExpected: false, |
| 9190 | }, |
| 9191 | { |
| 9192 | testCaseName: "non-updatable apex respects strict_updatability of javalib", |
| 9193 | apexUpdatable: false, |
| 9194 | javaStrictUpdtabilityLint: false, |
| 9195 | lintFileExists: true, |
| 9196 | disallowedFlagExpected: false, |
| 9197 | }, |
| 9198 | { |
| 9199 | testCaseName: "non-updatable apex respects strict updatability of javalib", |
| 9200 | apexUpdatable: false, |
| 9201 | javaStrictUpdtabilityLint: true, |
| 9202 | lintFileExists: true, |
| 9203 | disallowedFlagExpected: true, |
| 9204 | }, |
| 9205 | { |
| 9206 | testCaseName: "updatable apex sets strict updatability of javalib to true", |
| 9207 | apexUpdatable: true, |
| 9208 | javaStrictUpdtabilityLint: false, // will be set to true by mutator |
| 9209 | lintFileExists: true, |
| 9210 | disallowedFlagExpected: true, |
| 9211 | }, |
| 9212 | } |
| 9213 | |
| 9214 | for _, testCase := range testCases { |
| 9215 | bp := fmt.Sprintf(bpTemplate, testCase.apexUpdatable, testCase.javaStrictUpdtabilityLint) |
| 9216 | fixtures := []android.FixturePreparer{} |
| 9217 | if testCase.lintFileExists { |
| 9218 | fixtures = append(fixtures, fs.AddToFixture()) |
| 9219 | } |
| 9220 | |
| 9221 | result := testApex(t, bp, fixtures...) |
| 9222 | myjavalib := result.ModuleForTests("myjavalib", "android_common_apex29") |
| 9223 | sboxProto := android.RuleBuilderSboxProtoForTests(t, myjavalib.Output("lint.sbox.textproto")) |
| 9224 | disallowedFlagActual := strings.Contains(*sboxProto.Commands[0].Command, "--baseline lint-baseline.xml --disallowed_issues NewApi") |
| 9225 | |
| 9226 | if disallowedFlagActual != testCase.disallowedFlagExpected { |
| 9227 | t.Errorf("Failed testcase: %v \nActual lint cmd: %v", testCase.testCaseName, *sboxProto.Commands[0].Command) |
| 9228 | } |
| 9229 | } |
| 9230 | } |
| 9231 | |
Spandan Das | d9c23ab | 2022-02-10 02:34:13 +0000 | [diff] [blame] | 9232 | func TestUpdatabilityLintSkipLibcore(t *testing.T) { |
| 9233 | bp := ` |
| 9234 | apex { |
| 9235 | name: "myapex", |
| 9236 | key: "myapex.key", |
| 9237 | java_libs: ["myjavalib"], |
| 9238 | updatable: true, |
| 9239 | min_sdk_version: "29", |
| 9240 | } |
| 9241 | apex_key { |
| 9242 | name: "myapex.key", |
| 9243 | } |
| 9244 | java_library { |
| 9245 | name: "myjavalib", |
| 9246 | srcs: ["MyClass.java"], |
| 9247 | apex_available: [ "myapex" ], |
| 9248 | sdk_version: "current", |
| 9249 | min_sdk_version: "29", |
| 9250 | } |
| 9251 | ` |
| 9252 | |
| 9253 | testCases := []struct { |
| 9254 | testCaseName string |
| 9255 | moduleDirectory string |
| 9256 | disallowedFlagExpected bool |
| 9257 | }{ |
| 9258 | { |
| 9259 | testCaseName: "lintable module defined outside libcore", |
| 9260 | moduleDirectory: "", |
| 9261 | disallowedFlagExpected: true, |
| 9262 | }, |
| 9263 | { |
| 9264 | testCaseName: "lintable module defined in libcore root directory", |
| 9265 | moduleDirectory: "libcore/", |
| 9266 | disallowedFlagExpected: false, |
| 9267 | }, |
| 9268 | { |
| 9269 | testCaseName: "lintable module defined in libcore child directory", |
| 9270 | moduleDirectory: "libcore/childdir/", |
| 9271 | disallowedFlagExpected: true, |
| 9272 | }, |
| 9273 | } |
| 9274 | |
| 9275 | for _, testCase := range testCases { |
| 9276 | lintFileCreator := android.FixtureAddTextFile(testCase.moduleDirectory+"lint-baseline.xml", "") |
| 9277 | bpFileCreator := android.FixtureAddTextFile(testCase.moduleDirectory+"Android.bp", bp) |
| 9278 | result := testApex(t, "", lintFileCreator, bpFileCreator) |
| 9279 | myjavalib := result.ModuleForTests("myjavalib", "android_common_apex29") |
| 9280 | sboxProto := android.RuleBuilderSboxProtoForTests(t, myjavalib.Output("lint.sbox.textproto")) |
| 9281 | cmdFlags := fmt.Sprintf("--baseline %vlint-baseline.xml --disallowed_issues NewApi", testCase.moduleDirectory) |
| 9282 | disallowedFlagActual := strings.Contains(*sboxProto.Commands[0].Command, cmdFlags) |
| 9283 | |
| 9284 | if disallowedFlagActual != testCase.disallowedFlagExpected { |
| 9285 | t.Errorf("Failed testcase: %v \nActual lint cmd: %v", testCase.testCaseName, *sboxProto.Commands[0].Command) |
| 9286 | } |
| 9287 | } |
| 9288 | } |
| 9289 | |
Spandan Das | 6677325 | 2022-01-15 00:23:18 +0000 | [diff] [blame] | 9290 | // checks transtive deps of an apex coming from bootclasspath_fragment |
| 9291 | func TestApexStrictUpdtabilityLintBcpFragmentDeps(t *testing.T) { |
| 9292 | bp := ` |
| 9293 | apex { |
| 9294 | name: "myapex", |
| 9295 | key: "myapex.key", |
| 9296 | bootclasspath_fragments: ["mybootclasspathfragment"], |
| 9297 | updatable: true, |
| 9298 | min_sdk_version: "29", |
| 9299 | } |
| 9300 | apex_key { |
| 9301 | name: "myapex.key", |
| 9302 | } |
| 9303 | bootclasspath_fragment { |
| 9304 | name: "mybootclasspathfragment", |
| 9305 | contents: ["myjavalib"], |
| 9306 | apex_available: ["myapex"], |
| 9307 | } |
| 9308 | java_library { |
| 9309 | name: "myjavalib", |
| 9310 | srcs: ["MyClass.java"], |
| 9311 | apex_available: [ "myapex" ], |
| 9312 | sdk_version: "current", |
| 9313 | min_sdk_version: "29", |
| 9314 | compile_dex: true, |
| 9315 | } |
| 9316 | ` |
| 9317 | fs := android.MockFS{ |
| 9318 | "lint-baseline.xml": nil, |
| 9319 | } |
| 9320 | |
| 9321 | result := testApex(t, bp, dexpreopt.FixtureSetApexBootJars("myapex:myjavalib"), fs.AddToFixture()) |
| 9322 | myjavalib := result.ModuleForTests("myjavalib", "android_common_apex29") |
| 9323 | sboxProto := android.RuleBuilderSboxProtoForTests(t, myjavalib.Output("lint.sbox.textproto")) |
| 9324 | if !strings.Contains(*sboxProto.Commands[0].Command, "--baseline lint-baseline.xml --disallowed_issues NewApi") { |
| 9325 | t.Errorf("Strict updabality lint missing in myjavalib coming from bootclasspath_fragment mybootclasspath-fragment\nActual lint cmd: %v", *sboxProto.Commands[0].Command) |
| 9326 | } |
| 9327 | } |
| 9328 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 9329 | func TestMain(m *testing.M) { |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 9330 | os.Exit(m.Run()) |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 9331 | } |