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 | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 25 | "strings" |
| 26 | "testing" |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 27 | |
| 28 | "github.com/google/blueprint/proptools" |
| 29 | |
| 30 | "android/soong/android" |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 31 | "android/soong/bpf" |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 32 | "android/soong/cc" |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 33 | "android/soong/dexpreopt" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 34 | prebuilt_etc "android/soong/etc" |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 35 | "android/soong/java" |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 36 | "android/soong/rust" |
Jaewoong Jung | 4b79e98 | 2020-06-01 10:45:49 -0700 | [diff] [blame] | 37 | "android/soong/sh" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 38 | ) |
| 39 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 40 | // names returns name list from white space separated string |
| 41 | func names(s string) (ns []string) { |
| 42 | for _, n := range strings.Split(s, " ") { |
| 43 | if len(n) > 0 { |
| 44 | ns = append(ns, n) |
| 45 | } |
| 46 | } |
| 47 | return |
| 48 | } |
| 49 | |
Paul Duffin | 40b6257 | 2021-03-20 11:39:01 +0000 | [diff] [blame] | 50 | func testApexError(t *testing.T, pattern, bp string, preparers ...android.FixturePreparer) { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 51 | t.Helper() |
Paul Duffin | 40b6257 | 2021-03-20 11:39:01 +0000 | [diff] [blame] | 52 | apexFixtureFactory.Extend(preparers...). |
Paul Duffin | e05480a | 2021-03-08 15:07:14 +0000 | [diff] [blame] | 53 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)). |
Paul Duffin | 40b6257 | 2021-03-20 11:39:01 +0000 | [diff] [blame] | 54 | RunTestWithBp(t, bp) |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 55 | } |
| 56 | |
Paul Duffin | 40b6257 | 2021-03-20 11:39:01 +0000 | [diff] [blame] | 57 | func testApex(t *testing.T, bp string, preparers ...android.FixturePreparer) *android.TestContext { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 58 | t.Helper() |
Paul Duffin | 40b6257 | 2021-03-20 11:39:01 +0000 | [diff] [blame] | 59 | factory := apexFixtureFactory.Extend(preparers...) |
| 60 | if bp != "" { |
| 61 | factory = factory.Extend(android.FixtureWithRootAndroidBp(bp)) |
| 62 | } |
| 63 | result := factory.RunTest(t) |
Paul Duffin | e05480a | 2021-03-08 15:07:14 +0000 | [diff] [blame] | 64 | return result.TestContext |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 65 | } |
| 66 | |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 67 | func withFiles(files android.MockFS) android.FixturePreparer { |
| 68 | return files.AddToFixture() |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 69 | } |
| 70 | |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 71 | func withTargets(targets map[android.OsType][]android.Target) android.FixturePreparer { |
| 72 | return android.FixtureModifyConfig(func(config android.Config) { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 73 | for k, v := range targets { |
| 74 | config.Targets[k] = v |
| 75 | } |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 76 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 77 | } |
| 78 | |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 79 | // withNativeBridgeTargets sets configuration with targets including: |
| 80 | // - X86_64 (primary) |
| 81 | // - X86 (secondary) |
| 82 | // - Arm64 on X86_64 (native bridge) |
| 83 | // - Arm on X86 (native bridge) |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 84 | var withNativeBridgeEnabled = android.FixtureModifyConfig( |
| 85 | func(config android.Config) { |
| 86 | config.Targets[android.Android] = []android.Target{ |
| 87 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86_64, ArchVariant: "silvermont", Abi: []string{"arm64-v8a"}}, |
| 88 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 89 | {Os: android.Android, Arch: android.Arch{ArchType: android.X86, ArchVariant: "silvermont", Abi: []string{"armeabi-v7a"}}, |
| 90 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
| 91 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}, |
| 92 | NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86_64", NativeBridgeRelativePath: "arm64"}, |
| 93 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, |
| 94 | NativeBridge: android.NativeBridgeEnabled, NativeBridgeHostArchName: "x86", NativeBridgeRelativePath: "arm"}, |
| 95 | } |
| 96 | }, |
| 97 | ) |
| 98 | |
| 99 | func withManifestPackageNameOverrides(specs []string) android.FixturePreparer { |
| 100 | return android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 101 | variables.ManifestPackageNameOverrides = specs |
| 102 | }) |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 103 | } |
| 104 | |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 105 | var withBinder32bit = android.FixtureModifyProductVariables( |
| 106 | func(variables android.FixtureProductVariables) { |
| 107 | variables.Binder32bit = proptools.BoolPtr(true) |
| 108 | }, |
| 109 | ) |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 110 | |
Paul Duffin | 810f33d | 2021-03-09 14:12:32 +0000 | [diff] [blame] | 111 | var withUnbundledBuild = android.FixtureModifyProductVariables( |
| 112 | func(variables android.FixtureProductVariables) { |
| 113 | variables.Unbundled_build = proptools.BoolPtr(true) |
| 114 | }, |
| 115 | ) |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 116 | |
Paul Duffin | 37aad60 | 2021-03-08 09:47:16 +0000 | [diff] [blame] | 117 | var apexFixtureFactory = android.NewFixtureFactory( |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 118 | nil, |
Paul Duffin | 37aad60 | 2021-03-08 09:47:16 +0000 | [diff] [blame] | 119 | // General preparers in alphabetical order as test infrastructure will enforce correct |
| 120 | // registration order. |
| 121 | android.PrepareForTestWithAndroidBuildComponents, |
| 122 | bpf.PrepareForTestWithBpf, |
| 123 | cc.PrepareForTestWithCcBuildComponents, |
| 124 | java.PrepareForTestWithJavaDefaultModules, |
| 125 | prebuilt_etc.PrepareForTestWithPrebuiltEtc, |
| 126 | rust.PrepareForTestWithRustDefaultModules, |
| 127 | sh.PrepareForTestWithShBuildComponents, |
| 128 | |
| 129 | PrepareForTestWithApexBuildComponents, |
| 130 | |
| 131 | // Additional apex test specific preparers. |
| 132 | android.FixtureAddTextFile("system/sepolicy/Android.bp", ` |
| 133 | filegroup { |
| 134 | name: "myapex-file_contexts", |
| 135 | srcs: [ |
| 136 | "apex/myapex-file_contexts", |
| 137 | ], |
| 138 | } |
| 139 | `), |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 140 | prepareForTestWithMyapex, |
Paul Duffin | 37aad60 | 2021-03-08 09:47:16 +0000 | [diff] [blame] | 141 | android.FixtureMergeMockFs(android.MockFS{ |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 142 | "a.java": nil, |
| 143 | "PrebuiltAppFoo.apk": nil, |
| 144 | "PrebuiltAppFooPriv.apk": nil, |
| 145 | "apex_manifest.json": nil, |
| 146 | "AndroidManifest.xml": nil, |
Paul Duffin | 37aad60 | 2021-03-08 09:47:16 +0000 | [diff] [blame] | 147 | "system/sepolicy/apex/myapex.updatable-file_contexts": nil, |
| 148 | "system/sepolicy/apex/myapex2-file_contexts": nil, |
| 149 | "system/sepolicy/apex/otherapex-file_contexts": nil, |
| 150 | "system/sepolicy/apex/com.android.vndk-file_contexts": nil, |
| 151 | "system/sepolicy/apex/com.android.vndk.current-file_contexts": nil, |
| 152 | "mylib.cpp": nil, |
| 153 | "mytest.cpp": nil, |
| 154 | "mytest1.cpp": nil, |
| 155 | "mytest2.cpp": nil, |
| 156 | "mytest3.cpp": nil, |
| 157 | "myprebuilt": nil, |
| 158 | "my_include": nil, |
| 159 | "foo/bar/MyClass.java": nil, |
| 160 | "prebuilt.jar": nil, |
| 161 | "prebuilt.so": nil, |
| 162 | "vendor/foo/devkeys/test.x509.pem": nil, |
| 163 | "vendor/foo/devkeys/test.pk8": nil, |
| 164 | "testkey.x509.pem": nil, |
| 165 | "testkey.pk8": nil, |
| 166 | "testkey.override.x509.pem": nil, |
| 167 | "testkey.override.pk8": nil, |
| 168 | "vendor/foo/devkeys/testkey.avbpubkey": nil, |
| 169 | "vendor/foo/devkeys/testkey.pem": nil, |
| 170 | "NOTICE": nil, |
| 171 | "custom_notice": nil, |
| 172 | "custom_notice_for_static_lib": nil, |
| 173 | "testkey2.avbpubkey": nil, |
| 174 | "testkey2.pem": nil, |
| 175 | "myapex-arm64.apex": nil, |
| 176 | "myapex-arm.apex": nil, |
| 177 | "myapex.apks": nil, |
| 178 | "frameworks/base/api/current.txt": nil, |
| 179 | "framework/aidl/a.aidl": nil, |
| 180 | "build/make/core/proguard.flags": nil, |
| 181 | "build/make/core/proguard_basic_keeps.flags": nil, |
| 182 | "dummy.txt": nil, |
| 183 | "baz": nil, |
| 184 | "bar/baz": nil, |
| 185 | "testdata/baz": nil, |
| 186 | "AppSet.apks": nil, |
| 187 | "foo.rs": nil, |
| 188 | "libfoo.jar": nil, |
| 189 | "libbar.jar": nil, |
| 190 | }, |
| 191 | ), |
| 192 | |
| 193 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 194 | variables.DeviceVndkVersion = proptools.StringPtr("current") |
| 195 | variables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test") |
| 196 | variables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"} |
| 197 | variables.Platform_sdk_codename = proptools.StringPtr("Q") |
| 198 | variables.Platform_sdk_final = proptools.BoolPtr(false) |
| 199 | variables.Platform_version_active_codenames = []string{"Q"} |
| 200 | variables.Platform_vndk_version = proptools.StringPtr("VER") |
| 201 | }), |
| 202 | ) |
| 203 | |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 204 | var prepareForTestWithMyapex = android.FixtureMergeMockFs(android.MockFS{ |
| 205 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 206 | }) |
| 207 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 208 | // ensure that 'result' equals 'expected' |
| 209 | func ensureEquals(t *testing.T, result string, expected string) { |
| 210 | t.Helper() |
| 211 | if result != expected { |
| 212 | t.Errorf("%q != %q", expected, result) |
| 213 | } |
| 214 | } |
| 215 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 216 | // ensure that 'result' contains 'expected' |
| 217 | func ensureContains(t *testing.T, result string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 218 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 219 | if !strings.Contains(result, expected) { |
| 220 | t.Errorf("%q is not found in %q", expected, result) |
| 221 | } |
| 222 | } |
| 223 | |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 224 | // ensure that 'result' contains 'expected' exactly one time |
| 225 | func ensureContainsOnce(t *testing.T, result string, expected string) { |
| 226 | t.Helper() |
| 227 | count := strings.Count(result, expected) |
| 228 | if count != 1 { |
| 229 | t.Errorf("%q is found %d times (expected 1 time) in %q", expected, count, result) |
| 230 | } |
| 231 | } |
| 232 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 233 | // ensures that 'result' does not contain 'notExpected' |
| 234 | func ensureNotContains(t *testing.T, result string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 235 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 236 | if strings.Contains(result, notExpected) { |
| 237 | t.Errorf("%q is found in %q", notExpected, result) |
| 238 | } |
| 239 | } |
| 240 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 241 | func ensureMatches(t *testing.T, result string, expectedRex string) { |
| 242 | ok, err := regexp.MatchString(expectedRex, result) |
| 243 | if err != nil { |
| 244 | t.Fatalf("regexp failure trying to match %s against `%s` expression: %s", result, expectedRex, err) |
| 245 | return |
| 246 | } |
| 247 | if !ok { |
| 248 | t.Errorf("%s does not match regular expession %s", result, expectedRex) |
| 249 | } |
| 250 | } |
| 251 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 252 | func ensureListContains(t *testing.T, result []string, expected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 253 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 254 | if !android.InList(expected, result) { |
| 255 | t.Errorf("%q is not found in %v", expected, result) |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | func ensureListNotContains(t *testing.T, result []string, notExpected string) { |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 260 | t.Helper() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 261 | if android.InList(notExpected, result) { |
| 262 | t.Errorf("%q is found in %v", notExpected, result) |
| 263 | } |
| 264 | } |
| 265 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 266 | func ensureListEmpty(t *testing.T, result []string) { |
| 267 | t.Helper() |
| 268 | if len(result) > 0 { |
| 269 | t.Errorf("%q is expected to be empty", result) |
| 270 | } |
| 271 | } |
| 272 | |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 273 | func ensureListNotEmpty(t *testing.T, result []string) { |
| 274 | t.Helper() |
| 275 | if len(result) == 0 { |
| 276 | t.Errorf("%q is expected to be not empty", result) |
| 277 | } |
| 278 | } |
| 279 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 280 | // Minimal test |
| 281 | func TestBasicApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 282 | ctx := testApex(t, ` |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 283 | apex_defaults { |
| 284 | name: "myapex-defaults", |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 285 | manifest: ":myapex.manifest", |
| 286 | androidManifest: ":myapex.androidmanifest", |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 287 | key: "myapex.key", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 288 | binaries: ["foo.rust"], |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 289 | native_shared_libs: [ |
| 290 | "mylib", |
| 291 | "libfoo.ffi", |
| 292 | ], |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 293 | rust_dyn_libs: ["libfoo.dylib.rust"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 294 | multilib: { |
| 295 | both: { |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 296 | binaries: ["foo"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 297 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 298 | }, |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 299 | java_libs: [ |
| 300 | "myjar", |
| 301 | "myjar_dex", |
| 302 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 303 | updatable: false, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 304 | } |
| 305 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame] | 306 | apex { |
| 307 | name: "myapex", |
| 308 | defaults: ["myapex-defaults"], |
| 309 | } |
| 310 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 311 | apex_key { |
| 312 | name: "myapex.key", |
| 313 | public_key: "testkey.avbpubkey", |
| 314 | private_key: "testkey.pem", |
| 315 | } |
| 316 | |
Jiyong Park | 809bb72 | 2019-02-13 21:33:49 +0900 | [diff] [blame] | 317 | filegroup { |
| 318 | name: "myapex.manifest", |
| 319 | srcs: ["apex_manifest.json"], |
| 320 | } |
| 321 | |
| 322 | filegroup { |
| 323 | name: "myapex.androidmanifest", |
| 324 | srcs: ["AndroidManifest.xml"], |
| 325 | } |
| 326 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 327 | cc_library { |
| 328 | name: "mylib", |
| 329 | srcs: ["mylib.cpp"], |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 330 | shared_libs: [ |
| 331 | "mylib2", |
| 332 | "libbar.ffi", |
| 333 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 334 | system_shared_libs: [], |
| 335 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 336 | // TODO: remove //apex_available:platform |
| 337 | apex_available: [ |
| 338 | "//apex_available:platform", |
| 339 | "myapex", |
| 340 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 341 | } |
| 342 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 343 | cc_binary { |
| 344 | name: "foo", |
| 345 | srcs: ["mylib.cpp"], |
| 346 | compile_multilib: "both", |
| 347 | multilib: { |
| 348 | lib32: { |
| 349 | suffix: "32", |
| 350 | }, |
| 351 | lib64: { |
| 352 | suffix: "64", |
| 353 | }, |
| 354 | }, |
| 355 | symlinks: ["foo_link_"], |
| 356 | symlink_preferred_arch: true, |
| 357 | system_shared_libs: [], |
| 358 | static_executable: true, |
| 359 | stl: "none", |
Yifan Hong | d22a84a | 2020-07-28 17:37:46 -0700 | [diff] [blame] | 360 | apex_available: [ "myapex", "com.android.gki.*" ], |
| 361 | } |
| 362 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 363 | rust_binary { |
Artur Satayev | 533b98c | 2021-03-11 18:03:42 +0000 | [diff] [blame] | 364 | name: "foo.rust", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 365 | srcs: ["foo.rs"], |
| 366 | rlibs: ["libfoo.rlib.rust"], |
| 367 | dylibs: ["libfoo.dylib.rust"], |
| 368 | apex_available: ["myapex"], |
| 369 | } |
| 370 | |
| 371 | rust_library_rlib { |
Artur Satayev | 533b98c | 2021-03-11 18:03:42 +0000 | [diff] [blame] | 372 | name: "libfoo.rlib.rust", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 373 | srcs: ["foo.rs"], |
| 374 | crate_name: "foo", |
| 375 | apex_available: ["myapex"], |
| 376 | } |
| 377 | |
| 378 | rust_library_dylib { |
Artur Satayev | 533b98c | 2021-03-11 18:03:42 +0000 | [diff] [blame] | 379 | name: "libfoo.dylib.rust", |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 380 | srcs: ["foo.rs"], |
| 381 | crate_name: "foo", |
| 382 | apex_available: ["myapex"], |
| 383 | } |
| 384 | |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 385 | rust_ffi_shared { |
| 386 | name: "libfoo.ffi", |
| 387 | srcs: ["foo.rs"], |
| 388 | crate_name: "foo", |
| 389 | apex_available: ["myapex"], |
| 390 | } |
| 391 | |
| 392 | rust_ffi_shared { |
| 393 | name: "libbar.ffi", |
| 394 | srcs: ["foo.rs"], |
| 395 | crate_name: "bar", |
| 396 | apex_available: ["myapex"], |
| 397 | } |
| 398 | |
Yifan Hong | d22a84a | 2020-07-28 17:37:46 -0700 | [diff] [blame] | 399 | apex { |
| 400 | name: "com.android.gki.fake", |
| 401 | binaries: ["foo"], |
| 402 | key: "myapex.key", |
| 403 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 404 | updatable: false, |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 405 | } |
| 406 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 407 | cc_library_shared { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 408 | name: "mylib2", |
| 409 | srcs: ["mylib.cpp"], |
| 410 | system_shared_libs: [], |
| 411 | stl: "none", |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 412 | notice: "custom_notice", |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 413 | static_libs: ["libstatic"], |
| 414 | // TODO: remove //apex_available:platform |
| 415 | apex_available: [ |
| 416 | "//apex_available:platform", |
| 417 | "myapex", |
| 418 | ], |
| 419 | } |
| 420 | |
Paul Duffin | dddd546 | 2020-04-07 15:25:44 +0100 | [diff] [blame] | 421 | cc_prebuilt_library_shared { |
| 422 | name: "mylib2", |
| 423 | srcs: ["prebuilt.so"], |
| 424 | // TODO: remove //apex_available:platform |
| 425 | apex_available: [ |
| 426 | "//apex_available:platform", |
| 427 | "myapex", |
| 428 | ], |
| 429 | } |
| 430 | |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 431 | cc_library_static { |
| 432 | name: "libstatic", |
| 433 | srcs: ["mylib.cpp"], |
| 434 | system_shared_libs: [], |
| 435 | stl: "none", |
| 436 | notice: "custom_notice_for_static_lib", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 437 | // TODO: remove //apex_available:platform |
| 438 | apex_available: [ |
| 439 | "//apex_available:platform", |
| 440 | "myapex", |
| 441 | ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 442 | } |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 443 | |
| 444 | java_library { |
| 445 | name: "myjar", |
| 446 | srcs: ["foo/bar/MyClass.java"], |
Jiyong Park | a62aa23 | 2020-05-28 23:46:55 +0900 | [diff] [blame] | 447 | stem: "myjar_stem", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 448 | sdk_version: "none", |
| 449 | system_modules: "none", |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 450 | static_libs: ["myotherjar"], |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 451 | libs: ["mysharedjar"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 452 | // TODO: remove //apex_available:platform |
| 453 | apex_available: [ |
| 454 | "//apex_available:platform", |
| 455 | "myapex", |
| 456 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 457 | } |
| 458 | |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 459 | dex_import { |
| 460 | name: "myjar_dex", |
| 461 | jars: ["prebuilt.jar"], |
| 462 | apex_available: [ |
| 463 | "//apex_available:platform", |
| 464 | "myapex", |
| 465 | ], |
| 466 | } |
| 467 | |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 468 | java_library { |
| 469 | name: "myotherjar", |
| 470 | srcs: ["foo/bar/MyClass.java"], |
| 471 | sdk_version: "none", |
| 472 | system_modules: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 473 | // TODO: remove //apex_available:platform |
| 474 | apex_available: [ |
| 475 | "//apex_available:platform", |
| 476 | "myapex", |
| 477 | ], |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 478 | } |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 479 | |
| 480 | java_library { |
| 481 | name: "mysharedjar", |
| 482 | srcs: ["foo/bar/MyClass.java"], |
| 483 | sdk_version: "none", |
| 484 | system_modules: "none", |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 485 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 486 | `) |
| 487 | |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 488 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule").RelativeToTop() |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 489 | |
Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 490 | // Make sure that Android.mk is created |
| 491 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 492 | data := android.AndroidMkDataForTest(t, ctx, ab) |
Jiyong Park | 9e83f0b | 2020-06-11 00:35:03 +0900 | [diff] [blame] | 493 | var builder strings.Builder |
| 494 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 495 | |
| 496 | androidMk := builder.String() |
| 497 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 498 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
| 499 | |
Jiyong Park | 42cca6c | 2019-04-01 11:15:50 +0900 | [diff] [blame] | 500 | optFlags := apexRule.Args["opt_flags"] |
| 501 | ensureContains(t, optFlags, "--pubkey vendor/foo/devkeys/testkey.avbpubkey") |
Jaewoong Jung | 14f5ff6 | 2019-06-18 13:09:13 -0700 | [diff] [blame] | 502 | // Ensure that the NOTICE output is being packaged as an asset. |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 503 | 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] | 504 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 505 | copyCmds := apexRule.Args["copy_commands"] |
| 506 | |
| 507 | // Ensure that main rule creates an output |
| 508 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 509 | |
| 510 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 511 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
| 512 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common_apex10000") |
| 513 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar_dex"), "android_common_apex10000") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 514 | ensureListContains(t, ctx.ModuleVariantsForTests("foo.rust"), "android_arm64_armv8-a_apex10000") |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 515 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.ffi"), "android_arm64_armv8-a_shared_apex10000") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 516 | |
| 517 | // Ensure that apex variant is created for the indirect dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 518 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
| 519 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common_apex10000") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 520 | ensureListContains(t, ctx.ModuleVariantsForTests("libfoo.rlib.rust"), "android_arm64_armv8-a_rlib_dylib-std_apex10000") |
| 521 | 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] | 522 | ensureListContains(t, ctx.ModuleVariantsForTests("libbar.ffi"), "android_arm64_armv8-a_shared_apex10000") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 523 | |
| 524 | // Ensure that both direct and indirect deps are copied into apex |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 525 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 526 | ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | a62aa23 | 2020-05-28 23:46:55 +0900 | [diff] [blame] | 527 | ensureContains(t, copyCmds, "image.apex/javalib/myjar_stem.jar") |
Jiyong Park | 77acec6 | 2020-06-01 21:39:15 +0900 | [diff] [blame] | 528 | ensureContains(t, copyCmds, "image.apex/javalib/myjar_dex.jar") |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 529 | ensureContains(t, copyCmds, "image.apex/lib64/libfoo.dylib.rust.dylib.so") |
Jiyong Park | f2cc1b7 | 2020-12-09 00:20:45 +0900 | [diff] [blame] | 530 | ensureContains(t, copyCmds, "image.apex/lib64/libfoo.ffi.so") |
| 531 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.ffi.so") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 532 | // .. but not for java libs |
| 533 | ensureNotContains(t, copyCmds, "image.apex/javalib/myotherjar.jar") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 534 | ensureNotContains(t, copyCmds, "image.apex/javalib/msharedjar.jar") |
Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 535 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 536 | // Ensure that the platform variant ends with _shared or _common |
| 537 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 538 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Jiyong Park | 7f7766d | 2019-07-25 22:02:35 +0900 | [diff] [blame] | 539 | ensureListContains(t, ctx.ModuleVariantsForTests("myjar"), "android_common") |
| 540 | ensureListContains(t, ctx.ModuleVariantsForTests("myotherjar"), "android_common") |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 541 | ensureListContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common") |
| 542 | |
| 543 | // Ensure that dynamic dependency to java libs are not included |
| 544 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mysharedjar"), "android_common_myapex") |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 545 | |
| 546 | // Ensure that all symlinks are present. |
| 547 | found_foo_link_64 := false |
| 548 | found_foo := false |
| 549 | for _, cmd := range strings.Split(copyCmds, " && ") { |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 550 | if strings.HasPrefix(cmd, "ln -sfn foo64") { |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 551 | if strings.HasSuffix(cmd, "bin/foo") { |
| 552 | found_foo = true |
| 553 | } else if strings.HasSuffix(cmd, "bin/foo_link_64") { |
| 554 | found_foo_link_64 = true |
| 555 | } |
| 556 | } |
| 557 | } |
| 558 | good := found_foo && found_foo_link_64 |
| 559 | if !good { |
| 560 | t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds) |
| 561 | } |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 562 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 563 | mergeNoticesRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("mergeNoticesRule") |
Jaewoong Jung | 5b425e2 | 2019-06-17 17:40:56 -0700 | [diff] [blame] | 564 | noticeInputs := mergeNoticesRule.Inputs.Strings() |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 565 | if len(noticeInputs) != 3 { |
| 566 | t.Errorf("number of input notice files: expected = 3, actual = %q", len(noticeInputs)) |
Jiyong Park | 52818fc | 2019-03-18 12:01:38 +0900 | [diff] [blame] | 567 | } |
| 568 | ensureListContains(t, noticeInputs, "NOTICE") |
| 569 | ensureListContains(t, noticeInputs, "custom_notice") |
Jiyong Park | 9918e1a | 2020-03-17 19:16:40 +0900 | [diff] [blame] | 570 | ensureListContains(t, noticeInputs, "custom_notice_for_static_lib") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 571 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 572 | 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] | 573 | ensureListContains(t, fullDepsInfo, " myjar(minSdkVersion:(no version)) <- myapex") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 574 | ensureListContains(t, fullDepsInfo, " mylib2(minSdkVersion:(no version)) <- mylib") |
| 575 | ensureListContains(t, fullDepsInfo, " myotherjar(minSdkVersion:(no version)) <- myjar") |
| 576 | ensureListContains(t, fullDepsInfo, " mysharedjar(minSdkVersion:(no version)) (external) <- myjar") |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 577 | |
| 578 | 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] | 579 | ensureListContains(t, flatDepsInfo, "myjar(minSdkVersion:(no version))") |
Artur Satayev | 4e1f2bd | 2020-05-14 15:15:01 +0100 | [diff] [blame] | 580 | ensureListContains(t, flatDepsInfo, "mylib2(minSdkVersion:(no version))") |
| 581 | ensureListContains(t, flatDepsInfo, "myotherjar(minSdkVersion:(no version))") |
| 582 | ensureListContains(t, flatDepsInfo, "mysharedjar(minSdkVersion:(no version)) (external)") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 583 | } |
| 584 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 585 | func TestDefaults(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 586 | ctx := testApex(t, ` |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 587 | apex_defaults { |
| 588 | name: "myapex-defaults", |
| 589 | key: "myapex.key", |
| 590 | prebuilts: ["myetc"], |
| 591 | native_shared_libs: ["mylib"], |
| 592 | java_libs: ["myjar"], |
| 593 | apps: ["AppFoo"], |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 594 | rros: ["rro"], |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 595 | bpfs: ["bpf"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 596 | updatable: false, |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | prebuilt_etc { |
| 600 | name: "myetc", |
| 601 | src: "myprebuilt", |
| 602 | } |
| 603 | |
| 604 | apex { |
| 605 | name: "myapex", |
| 606 | defaults: ["myapex-defaults"], |
| 607 | } |
| 608 | |
| 609 | apex_key { |
| 610 | name: "myapex.key", |
| 611 | public_key: "testkey.avbpubkey", |
| 612 | private_key: "testkey.pem", |
| 613 | } |
| 614 | |
| 615 | cc_library { |
| 616 | name: "mylib", |
| 617 | system_shared_libs: [], |
| 618 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 619 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | java_library { |
| 623 | name: "myjar", |
| 624 | srcs: ["foo/bar/MyClass.java"], |
| 625 | sdk_version: "none", |
| 626 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 627 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | android_app { |
| 631 | name: "AppFoo", |
| 632 | srcs: ["foo/bar/MyClass.java"], |
| 633 | sdk_version: "none", |
| 634 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 635 | apex_available: [ "myapex" ], |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 636 | } |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 637 | |
| 638 | runtime_resource_overlay { |
| 639 | name: "rro", |
| 640 | theme: "blue", |
| 641 | } |
| 642 | |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 643 | bpf { |
| 644 | name: "bpf", |
| 645 | srcs: ["bpf.c", "bpf2.c"], |
| 646 | } |
| 647 | |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 648 | `) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 649 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 650 | "etc/myetc", |
| 651 | "javalib/myjar.jar", |
| 652 | "lib64/mylib.so", |
| 653 | "app/AppFoo/AppFoo.apk", |
Jiyong Park | 69aeba9 | 2020-04-24 21:16:36 +0900 | [diff] [blame] | 654 | "overlay/blue/rro.apk", |
markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 655 | "etc/bpf/bpf.o", |
| 656 | "etc/bpf/bpf2.o", |
Jooyung Han | f21c797 | 2019-12-16 22:32:06 +0900 | [diff] [blame] | 657 | }) |
| 658 | } |
| 659 | |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 660 | func TestApexManifest(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 661 | ctx := testApex(t, ` |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 662 | apex { |
| 663 | name: "myapex", |
| 664 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 665 | updatable: false, |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | apex_key { |
| 669 | name: "myapex.key", |
| 670 | public_key: "testkey.avbpubkey", |
| 671 | private_key: "testkey.pem", |
| 672 | } |
| 673 | `) |
| 674 | |
| 675 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 676 | args := module.Rule("apexRule").Args |
| 677 | if manifest := args["manifest"]; manifest != module.Output("apex_manifest.pb").Output.String() { |
| 678 | t.Error("manifest should be apex_manifest.pb, but " + manifest) |
| 679 | } |
Jooyung Han | 01a3ee2 | 2019-11-02 02:52:25 +0900 | [diff] [blame] | 680 | } |
| 681 | |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 682 | func TestBasicZipApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 683 | ctx := testApex(t, ` |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 684 | apex { |
| 685 | name: "myapex", |
| 686 | key: "myapex.key", |
| 687 | payload_type: "zip", |
| 688 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 689 | updatable: false, |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | apex_key { |
| 693 | name: "myapex.key", |
| 694 | public_key: "testkey.avbpubkey", |
| 695 | private_key: "testkey.pem", |
| 696 | } |
| 697 | |
| 698 | cc_library { |
| 699 | name: "mylib", |
| 700 | srcs: ["mylib.cpp"], |
| 701 | shared_libs: ["mylib2"], |
| 702 | system_shared_libs: [], |
| 703 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 704 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | cc_library { |
| 708 | name: "mylib2", |
| 709 | srcs: ["mylib.cpp"], |
| 710 | system_shared_libs: [], |
| 711 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 712 | apex_available: [ "myapex" ], |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 713 | } |
| 714 | `) |
| 715 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 716 | zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex_zip").Rule("zipApexRule") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 717 | copyCmds := zipApexRule.Args["copy_commands"] |
| 718 | |
| 719 | // Ensure that main rule creates an output |
| 720 | ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned") |
| 721 | |
| 722 | // Ensure that APEX variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 723 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 724 | |
| 725 | // Ensure that APEX variant is created for the indirect dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 726 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 727 | |
| 728 | // Ensure that both direct and indirect deps are copied into apex |
| 729 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so") |
| 730 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | func TestApexWithStubs(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 734 | ctx := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 735 | apex { |
| 736 | name: "myapex", |
| 737 | key: "myapex.key", |
| 738 | native_shared_libs: ["mylib", "mylib3"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 739 | updatable: false, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | apex_key { |
| 743 | name: "myapex.key", |
| 744 | public_key: "testkey.avbpubkey", |
| 745 | private_key: "testkey.pem", |
| 746 | } |
| 747 | |
| 748 | cc_library { |
| 749 | name: "mylib", |
| 750 | srcs: ["mylib.cpp"], |
| 751 | shared_libs: ["mylib2", "mylib3"], |
| 752 | system_shared_libs: [], |
| 753 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 754 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | cc_library { |
| 758 | name: "mylib2", |
| 759 | srcs: ["mylib.cpp"], |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 760 | cflags: ["-include mylib.h"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 761 | system_shared_libs: [], |
| 762 | stl: "none", |
| 763 | stubs: { |
| 764 | versions: ["1", "2", "3"], |
| 765 | }, |
| 766 | } |
| 767 | |
| 768 | cc_library { |
| 769 | name: "mylib3", |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 770 | srcs: ["mylib.cpp"], |
| 771 | shared_libs: ["mylib4"], |
| 772 | system_shared_libs: [], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 773 | stl: "none", |
| 774 | stubs: { |
| 775 | versions: ["10", "11", "12"], |
| 776 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 777 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 778 | } |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 779 | |
| 780 | cc_library { |
| 781 | name: "mylib4", |
| 782 | srcs: ["mylib.cpp"], |
| 783 | system_shared_libs: [], |
| 784 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 785 | apex_available: [ "myapex" ], |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 786 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 787 | `) |
| 788 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 789 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 790 | copyCmds := apexRule.Args["copy_commands"] |
| 791 | |
| 792 | // Ensure that direct non-stubs dep is always included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 793 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 794 | |
| 795 | // Ensure that indirect stubs dep is not included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 796 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 797 | |
| 798 | // Ensure that direct stubs dep is included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 799 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 800 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 801 | 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] | 802 | |
| 803 | // Ensure that mylib is linking with the latest version of stubs for mylib2 |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 804 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_3/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 805 | // ... and not linking to the non-stub (impl) variant of mylib2 |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 806 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 807 | |
| 808 | // 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] | 809 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_apex10000/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 810 | // .. and not linking to the stubs variant of mylib3 |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 811 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12/mylib3.so") |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 812 | |
| 813 | // Ensure that stubs libs are built without -include flags |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 814 | mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 815 | ensureNotContains(t, mylib2Cflags, "-include ") |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 816 | |
| 817 | // Ensure that genstub is invoked with --apex |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 818 | 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] | 819 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 820 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 671f1ce | 2019-12-17 12:47:13 +0900 | [diff] [blame] | 821 | "lib64/mylib.so", |
| 822 | "lib64/mylib3.so", |
| 823 | "lib64/mylib4.so", |
| 824 | }) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 825 | } |
| 826 | |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 827 | func TestApexWithStubsWithMinSdkVersion(t *testing.T) { |
| 828 | t.Parallel() |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 829 | ctx := testApex(t, ` |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 830 | apex { |
| 831 | name: "myapex", |
| 832 | key: "myapex.key", |
| 833 | native_shared_libs: ["mylib", "mylib3"], |
| 834 | min_sdk_version: "29", |
| 835 | } |
| 836 | |
| 837 | apex_key { |
| 838 | name: "myapex.key", |
| 839 | public_key: "testkey.avbpubkey", |
| 840 | private_key: "testkey.pem", |
| 841 | } |
| 842 | |
| 843 | cc_library { |
| 844 | name: "mylib", |
| 845 | srcs: ["mylib.cpp"], |
| 846 | shared_libs: ["mylib2", "mylib3"], |
| 847 | system_shared_libs: [], |
| 848 | stl: "none", |
| 849 | apex_available: [ "myapex" ], |
| 850 | min_sdk_version: "28", |
| 851 | } |
| 852 | |
| 853 | cc_library { |
| 854 | name: "mylib2", |
| 855 | srcs: ["mylib.cpp"], |
| 856 | cflags: ["-include mylib.h"], |
| 857 | system_shared_libs: [], |
| 858 | stl: "none", |
| 859 | stubs: { |
| 860 | versions: ["28", "29", "30", "current"], |
| 861 | }, |
| 862 | min_sdk_version: "28", |
| 863 | } |
| 864 | |
| 865 | cc_library { |
| 866 | name: "mylib3", |
| 867 | srcs: ["mylib.cpp"], |
| 868 | shared_libs: ["mylib4"], |
| 869 | system_shared_libs: [], |
| 870 | stl: "none", |
| 871 | stubs: { |
| 872 | versions: ["28", "29", "30", "current"], |
| 873 | }, |
| 874 | apex_available: [ "myapex" ], |
| 875 | min_sdk_version: "28", |
| 876 | } |
| 877 | |
| 878 | cc_library { |
| 879 | name: "mylib4", |
| 880 | srcs: ["mylib.cpp"], |
| 881 | system_shared_libs: [], |
| 882 | stl: "none", |
| 883 | apex_available: [ "myapex" ], |
| 884 | min_sdk_version: "28", |
| 885 | } |
| 886 | `) |
| 887 | |
| 888 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 889 | copyCmds := apexRule.Args["copy_commands"] |
| 890 | |
| 891 | // Ensure that direct non-stubs dep is always included |
| 892 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 893 | |
| 894 | // Ensure that indirect stubs dep is not included |
| 895 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 896 | |
| 897 | // Ensure that direct stubs dep is included |
| 898 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
| 899 | |
| 900 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex29").Rule("ld").Args["libFlags"] |
| 901 | |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 902 | // Ensure that mylib is linking with the latest version of stub for mylib2 |
| 903 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_current/mylib2.so") |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 904 | // ... and not linking to the non-stub (impl) variant of mylib2 |
| 905 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
| 906 | |
| 907 | // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex) |
| 908 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_apex29/mylib3.so") |
| 909 | // .. and not linking to the stubs variant of mylib3 |
| 910 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_29/mylib3.so") |
| 911 | |
| 912 | // Ensure that stubs libs are built without -include flags |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 913 | 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] | 914 | ensureNotContains(t, mylib2Cflags, "-include ") |
| 915 | |
| 916 | // Ensure that genstub is invoked with --apex |
Colin Cross | a717db7 | 2020-10-23 14:53:06 -0700 | [diff] [blame] | 917 | 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] | 918 | |
| 919 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 920 | "lib64/mylib.so", |
| 921 | "lib64/mylib3.so", |
| 922 | "lib64/mylib4.so", |
| 923 | }) |
| 924 | } |
| 925 | |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 926 | func TestApex_PlatformUsesLatestStubFromApex(t *testing.T) { |
| 927 | t.Parallel() |
| 928 | // myapex (Z) |
| 929 | // mylib -----------------. |
| 930 | // | |
| 931 | // otherapex (29) | |
| 932 | // libstub's versions: 29 Z current |
| 933 | // | |
| 934 | // <platform> | |
| 935 | // libplatform ----------------' |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 936 | ctx := testApex(t, ` |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 937 | apex { |
| 938 | name: "myapex", |
| 939 | key: "myapex.key", |
| 940 | native_shared_libs: ["mylib"], |
| 941 | min_sdk_version: "Z", // non-final |
| 942 | } |
| 943 | |
| 944 | cc_library { |
| 945 | name: "mylib", |
| 946 | srcs: ["mylib.cpp"], |
| 947 | shared_libs: ["libstub"], |
| 948 | apex_available: ["myapex"], |
| 949 | min_sdk_version: "Z", |
| 950 | } |
| 951 | |
| 952 | apex_key { |
| 953 | name: "myapex.key", |
| 954 | public_key: "testkey.avbpubkey", |
| 955 | private_key: "testkey.pem", |
| 956 | } |
| 957 | |
| 958 | apex { |
| 959 | name: "otherapex", |
| 960 | key: "myapex.key", |
| 961 | native_shared_libs: ["libstub"], |
| 962 | min_sdk_version: "29", |
| 963 | } |
| 964 | |
| 965 | cc_library { |
| 966 | name: "libstub", |
| 967 | srcs: ["mylib.cpp"], |
| 968 | stubs: { |
| 969 | versions: ["29", "Z", "current"], |
| 970 | }, |
| 971 | apex_available: ["otherapex"], |
| 972 | min_sdk_version: "29", |
| 973 | } |
| 974 | |
| 975 | // platform module depending on libstub from otherapex should use the latest stub("current") |
| 976 | cc_library { |
| 977 | name: "libplatform", |
| 978 | srcs: ["mylib.cpp"], |
| 979 | shared_libs: ["libstub"], |
| 980 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 981 | `, |
| 982 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 983 | variables.Platform_sdk_codename = proptools.StringPtr("Z") |
| 984 | variables.Platform_sdk_final = proptools.BoolPtr(false) |
| 985 | variables.Platform_version_active_codenames = []string{"Z"} |
| 986 | }), |
| 987 | ) |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 988 | |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 989 | // Ensure that mylib from myapex is built against the latest stub (current) |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 990 | 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] | 991 | ensureContains(t, mylibCflags, "-D__LIBSTUB_API__=10000 ") |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 992 | 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] | 993 | ensureContains(t, mylibLdflags, "libstub/android_arm64_armv8-a_shared_current/libstub.so ") |
Jooyung Han | 11b0fbd | 2021-02-05 02:28:22 +0900 | [diff] [blame] | 994 | |
| 995 | // Ensure that libplatform is built against latest stub ("current") of mylib3 from the apex |
| 996 | libplatformCflags := ctx.ModuleForTests("libplatform", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 997 | ensureContains(t, libplatformCflags, "-D__LIBSTUB_API__=10000 ") // "current" maps to 10000 |
| 998 | libplatformLdflags := ctx.ModuleForTests("libplatform", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 999 | ensureContains(t, libplatformLdflags, "libstub/android_arm64_armv8-a_shared_current/libstub.so ") |
| 1000 | } |
| 1001 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1002 | func TestApexWithExplicitStubsDependency(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1003 | ctx := testApex(t, ` |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1004 | apex { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1005 | name: "myapex2", |
| 1006 | key: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1007 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1008 | updatable: false, |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | apex_key { |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1012 | name: "myapex2.key", |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1013 | public_key: "testkey.avbpubkey", |
| 1014 | private_key: "testkey.pem", |
| 1015 | } |
| 1016 | |
| 1017 | cc_library { |
| 1018 | name: "mylib", |
| 1019 | srcs: ["mylib.cpp"], |
| 1020 | shared_libs: ["libfoo#10"], |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1021 | static_libs: ["libbaz"], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1022 | system_shared_libs: [], |
| 1023 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1024 | apex_available: [ "myapex2" ], |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | cc_library { |
| 1028 | name: "libfoo", |
| 1029 | srcs: ["mylib.cpp"], |
| 1030 | shared_libs: ["libbar"], |
| 1031 | system_shared_libs: [], |
| 1032 | stl: "none", |
| 1033 | stubs: { |
| 1034 | versions: ["10", "20", "30"], |
| 1035 | }, |
| 1036 | } |
| 1037 | |
| 1038 | cc_library { |
| 1039 | name: "libbar", |
| 1040 | srcs: ["mylib.cpp"], |
| 1041 | system_shared_libs: [], |
| 1042 | stl: "none", |
| 1043 | } |
| 1044 | |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1045 | cc_library_static { |
| 1046 | name: "libbaz", |
| 1047 | srcs: ["mylib.cpp"], |
| 1048 | system_shared_libs: [], |
| 1049 | stl: "none", |
| 1050 | apex_available: [ "myapex2" ], |
| 1051 | } |
| 1052 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1053 | `) |
| 1054 | |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1055 | apexRule := ctx.ModuleForTests("myapex2", "android_common_myapex2_image").Rule("apexRule") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1056 | copyCmds := apexRule.Args["copy_commands"] |
| 1057 | |
| 1058 | // Ensure that direct non-stubs dep is always included |
| 1059 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1060 | |
| 1061 | // Ensure that indirect stubs dep is not included |
| 1062 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 1063 | |
| 1064 | // Ensure that dependency of stubs is not included |
| 1065 | ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 1066 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1067 | 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] | 1068 | |
| 1069 | // Ensure that mylib is linking with version 10 of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1070 | ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared_10/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1071 | // ... and not linking to the non-stub (impl) variant of libfoo |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1072 | ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_shared/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1073 | |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1074 | 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] | 1075 | |
| 1076 | // Ensure that libfoo stubs is not linking to libbar (since it is a stubs) |
| 1077 | ensureNotContains(t, libFooStubsLdFlags, "libbar.so") |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 1078 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 1079 | 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] | 1080 | ensureListContains(t, fullDepsInfo, " libfoo(minSdkVersion:(no version)) (external) <- mylib") |
Jiyong Park | 678c881 | 2020-02-07 17:25:49 +0900 | [diff] [blame] | 1081 | |
Artur Satayev | a8bd113 | 2020-04-27 18:07:06 +0100 | [diff] [blame] | 1082 | 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] | 1083 | ensureListContains(t, flatDepsInfo, "libfoo(minSdkVersion:(no version)) (external)") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1084 | } |
| 1085 | |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1086 | func TestApexWithRuntimeLibsDependency(t *testing.T) { |
| 1087 | /* |
| 1088 | myapex |
| 1089 | | |
| 1090 | v (runtime_libs) |
| 1091 | mylib ------+------> libfoo [provides stub] |
| 1092 | | |
| 1093 | `------> libbar |
| 1094 | */ |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1095 | ctx := testApex(t, ` |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1096 | apex { |
| 1097 | name: "myapex", |
| 1098 | key: "myapex.key", |
| 1099 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1100 | updatable: false, |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | apex_key { |
| 1104 | name: "myapex.key", |
| 1105 | public_key: "testkey.avbpubkey", |
| 1106 | private_key: "testkey.pem", |
| 1107 | } |
| 1108 | |
| 1109 | cc_library { |
| 1110 | name: "mylib", |
| 1111 | srcs: ["mylib.cpp"], |
| 1112 | runtime_libs: ["libfoo", "libbar"], |
| 1113 | system_shared_libs: [], |
| 1114 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1115 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | cc_library { |
| 1119 | name: "libfoo", |
| 1120 | srcs: ["mylib.cpp"], |
| 1121 | system_shared_libs: [], |
| 1122 | stl: "none", |
| 1123 | stubs: { |
| 1124 | versions: ["10", "20", "30"], |
| 1125 | }, |
| 1126 | } |
| 1127 | |
| 1128 | cc_library { |
| 1129 | name: "libbar", |
| 1130 | srcs: ["mylib.cpp"], |
| 1131 | system_shared_libs: [], |
| 1132 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1133 | apex_available: [ "myapex" ], |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | `) |
| 1137 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1138 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1139 | copyCmds := apexRule.Args["copy_commands"] |
| 1140 | |
| 1141 | // Ensure that direct non-stubs dep is always included |
| 1142 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 1143 | |
| 1144 | // Ensure that indirect stubs dep is not included |
| 1145 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 1146 | |
| 1147 | // Ensure that runtime_libs dep in included |
| 1148 | ensureContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 1149 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1150 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 1151 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 1152 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libfoo.so") |
Jooyung Han | d363955 | 2019-08-09 12:57:43 +0900 | [diff] [blame] | 1153 | |
| 1154 | } |
| 1155 | |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1156 | var prepareForTestOfRuntimeApexWithHwasan = android.GroupFixturePreparers( |
| 1157 | cc.PrepareForTestWithCcBuildComponents, |
| 1158 | PrepareForTestWithApexBuildComponents, |
| 1159 | android.FixtureAddTextFile("bionic/apex/Android.bp", ` |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1160 | apex { |
| 1161 | name: "com.android.runtime", |
| 1162 | key: "com.android.runtime.key", |
| 1163 | native_shared_libs: ["libc"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1164 | updatable: false, |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | apex_key { |
| 1168 | name: "com.android.runtime.key", |
| 1169 | public_key: "testkey.avbpubkey", |
| 1170 | private_key: "testkey.pem", |
| 1171 | } |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1172 | `), |
| 1173 | android.FixtureAddFile("system/sepolicy/apex/com.android.runtime-file_contexts", nil), |
| 1174 | ) |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1175 | |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1176 | func TestRuntimeApexShouldInstallHwasanIfLibcDependsOnIt(t *testing.T) { |
Paul Duffin | 70d3bee | 2021-03-21 11:26:05 +0000 | [diff] [blame] | 1177 | result := android.GroupFixturePreparers(prepareForTestOfRuntimeApexWithHwasan).RunTestWithBp(t, ` |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1178 | cc_library { |
| 1179 | name: "libc", |
| 1180 | no_libcrt: true, |
| 1181 | nocrt: true, |
| 1182 | stl: "none", |
| 1183 | system_shared_libs: [], |
| 1184 | stubs: { versions: ["1"] }, |
| 1185 | apex_available: ["com.android.runtime"], |
| 1186 | |
| 1187 | sanitize: { |
| 1188 | hwaddress: true, |
| 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | cc_prebuilt_library_shared { |
| 1193 | name: "libclang_rt.hwasan-aarch64-android", |
| 1194 | no_libcrt: true, |
| 1195 | nocrt: true, |
| 1196 | stl: "none", |
| 1197 | system_shared_libs: [], |
| 1198 | srcs: [""], |
| 1199 | stubs: { versions: ["1"] }, |
| 1200 | |
| 1201 | sanitize: { |
| 1202 | never: true, |
| 1203 | }, |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1204 | } `) |
| 1205 | ctx := result.TestContext |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1206 | |
| 1207 | ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ |
| 1208 | "lib64/bionic/libc.so", |
| 1209 | "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", |
| 1210 | }) |
| 1211 | |
| 1212 | hwasan := ctx.ModuleForTests("libclang_rt.hwasan-aarch64-android", "android_arm64_armv8-a_shared") |
| 1213 | |
| 1214 | installed := hwasan.Description("install libclang_rt.hwasan") |
| 1215 | ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") |
| 1216 | |
| 1217 | symlink := hwasan.Description("install symlink libclang_rt.hwasan") |
| 1218 | ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so") |
| 1219 | ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so") |
| 1220 | } |
| 1221 | |
| 1222 | func TestRuntimeApexShouldInstallHwasanIfHwaddressSanitized(t *testing.T) { |
Paul Duffin | 70d3bee | 2021-03-21 11:26:05 +0000 | [diff] [blame] | 1223 | result := android.GroupFixturePreparers( |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1224 | prepareForTestOfRuntimeApexWithHwasan, |
| 1225 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1226 | variables.SanitizeDevice = []string{"hwaddress"} |
| 1227 | }), |
| 1228 | ).RunTestWithBp(t, ` |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1229 | cc_library { |
| 1230 | name: "libc", |
| 1231 | no_libcrt: true, |
| 1232 | nocrt: true, |
| 1233 | stl: "none", |
| 1234 | system_shared_libs: [], |
| 1235 | stubs: { versions: ["1"] }, |
| 1236 | apex_available: ["com.android.runtime"], |
| 1237 | } |
| 1238 | |
| 1239 | cc_prebuilt_library_shared { |
| 1240 | name: "libclang_rt.hwasan-aarch64-android", |
| 1241 | no_libcrt: true, |
| 1242 | nocrt: true, |
| 1243 | stl: "none", |
| 1244 | system_shared_libs: [], |
| 1245 | srcs: [""], |
| 1246 | stubs: { versions: ["1"] }, |
| 1247 | |
| 1248 | sanitize: { |
| 1249 | never: true, |
| 1250 | }, |
| 1251 | } |
Paul Duffin | a02cae3 | 2021-03-09 01:44:06 +0000 | [diff] [blame] | 1252 | `) |
| 1253 | ctx := result.TestContext |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1254 | |
| 1255 | ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{ |
| 1256 | "lib64/bionic/libc.so", |
| 1257 | "lib64/bionic/libclang_rt.hwasan-aarch64-android.so", |
| 1258 | }) |
| 1259 | |
| 1260 | hwasan := ctx.ModuleForTests("libclang_rt.hwasan-aarch64-android", "android_arm64_armv8-a_shared") |
| 1261 | |
| 1262 | installed := hwasan.Description("install libclang_rt.hwasan") |
| 1263 | ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so") |
| 1264 | |
| 1265 | symlink := hwasan.Description("install symlink libclang_rt.hwasan") |
| 1266 | ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so") |
| 1267 | ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so") |
| 1268 | } |
| 1269 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1270 | func TestApexDependsOnLLNDKTransitively(t *testing.T) { |
| 1271 | testcases := []struct { |
| 1272 | name string |
| 1273 | minSdkVersion string |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1274 | apexVariant string |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1275 | shouldLink string |
| 1276 | shouldNotLink []string |
| 1277 | }{ |
| 1278 | { |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1279 | name: "unspecified version links to the latest", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1280 | minSdkVersion: "", |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1281 | apexVariant: "apex10000", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1282 | shouldLink: "30", |
| 1283 | shouldNotLink: []string{"29"}, |
| 1284 | }, |
| 1285 | { |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1286 | name: "always use the latest", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1287 | minSdkVersion: "min_sdk_version: \"29\",", |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1288 | apexVariant: "apex29", |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1289 | shouldLink: "30", |
| 1290 | shouldNotLink: []string{"29"}, |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1291 | }, |
| 1292 | } |
| 1293 | for _, tc := range testcases { |
| 1294 | t.Run(tc.name, func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1295 | ctx := testApex(t, ` |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1296 | apex { |
| 1297 | name: "myapex", |
| 1298 | key: "myapex.key", |
| 1299 | use_vendor: true, |
| 1300 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1301 | updatable: false, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1302 | `+tc.minSdkVersion+` |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1303 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1304 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1305 | apex_key { |
| 1306 | name: "myapex.key", |
| 1307 | public_key: "testkey.avbpubkey", |
| 1308 | private_key: "testkey.pem", |
| 1309 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1310 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1311 | cc_library { |
| 1312 | name: "mylib", |
| 1313 | srcs: ["mylib.cpp"], |
| 1314 | vendor_available: true, |
| 1315 | shared_libs: ["libbar"], |
| 1316 | system_shared_libs: [], |
| 1317 | stl: "none", |
| 1318 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1319 | min_sdk_version: "29", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1320 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1321 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1322 | cc_library { |
| 1323 | name: "libbar", |
| 1324 | srcs: ["mylib.cpp"], |
| 1325 | system_shared_libs: [], |
| 1326 | stl: "none", |
| 1327 | stubs: { versions: ["29","30"] }, |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1328 | llndk_stubs: "libbar.llndk", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1329 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1330 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1331 | llndk_library { |
Colin Cross | 0477b42 | 2020-10-13 18:43:54 -0700 | [diff] [blame] | 1332 | name: "libbar.llndk", |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1333 | symbol_file: "", |
| 1334 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1335 | `, |
| 1336 | setUseVendorAllowListForTest([]string{"myapex"}), |
| 1337 | withUnbundledBuild, |
| 1338 | ) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1339 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1340 | // Ensure that LLNDK dep is not included |
| 1341 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 1342 | "lib64/mylib.so", |
| 1343 | }) |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1344 | |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1345 | // Ensure that LLNDK dep is required |
| 1346 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 1347 | ensureListEmpty(t, names(apexManifestRule.Args["provideNativeLibs"])) |
| 1348 | ensureListContains(t, names(apexManifestRule.Args["requireNativeLibs"]), "libbar.so") |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1349 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1350 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_shared_"+tc.apexVariant).Rule("ld").Args["libFlags"] |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 1351 | ensureContains(t, mylibLdFlags, "libbar/android_vendor.VER_arm64_armv8-a_shared_"+tc.shouldLink+"/libbar.so") |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1352 | for _, ver := range tc.shouldNotLink { |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 1353 | ensureNotContains(t, mylibLdFlags, "libbar/android_vendor.VER_arm64_armv8-a_shared_"+ver+"/libbar.so") |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1354 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1355 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1356 | mylibCFlags := ctx.ModuleForTests("mylib", "android_vendor.VER_arm64_armv8-a_static_"+tc.apexVariant).Rule("cc").Args["cFlags"] |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 1357 | ensureContains(t, mylibCFlags, "__LIBBAR_API__="+tc.shouldLink) |
| 1358 | }) |
| 1359 | } |
Jooyung Han | 9c80bae | 2019-08-20 17:30:57 +0900 | [diff] [blame] | 1360 | } |
| 1361 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1362 | func TestApexWithSystemLibsStubs(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1363 | ctx := testApex(t, ` |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1364 | apex { |
| 1365 | name: "myapex", |
| 1366 | key: "myapex.key", |
| 1367 | native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1368 | updatable: false, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | apex_key { |
| 1372 | name: "myapex.key", |
| 1373 | public_key: "testkey.avbpubkey", |
| 1374 | private_key: "testkey.pem", |
| 1375 | } |
| 1376 | |
| 1377 | cc_library { |
| 1378 | name: "mylib", |
| 1379 | srcs: ["mylib.cpp"], |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 1380 | system_shared_libs: ["libc", "libm"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1381 | shared_libs: ["libdl#27"], |
| 1382 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1383 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | cc_library_shared { |
| 1387 | name: "mylib_shared", |
| 1388 | srcs: ["mylib.cpp"], |
| 1389 | shared_libs: ["libdl#27"], |
| 1390 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 1391 | apex_available: [ "myapex" ], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | cc_library { |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1395 | name: "libBootstrap", |
| 1396 | srcs: ["mylib.cpp"], |
| 1397 | stl: "none", |
| 1398 | bootstrap: true, |
| 1399 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1400 | `) |
| 1401 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 1402 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1403 | copyCmds := apexRule.Args["copy_commands"] |
| 1404 | |
| 1405 | // Ensure that mylib, libm, libdl are included. |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 1406 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1407 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so") |
| 1408 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1409 | |
| 1410 | // 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] | 1411 | ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1412 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1413 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
| 1414 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex10000").Rule("cc").Args["cFlags"] |
| 1415 | 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] | 1416 | |
| 1417 | // For dependency to libc |
| 1418 | // Ensure that mylib is linking with the latest version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1419 | ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared_29/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1420 | // ... and not linking to the non-stub (impl) variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1421 | ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1422 | // ... Cflags from stub is correctly exported to mylib |
| 1423 | ensureContains(t, mylibCFlags, "__LIBC_API__=29") |
| 1424 | ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29") |
| 1425 | |
| 1426 | // For dependency to libm |
| 1427 | // Ensure that mylib is linking with the non-stub (impl) variant |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1428 | ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_apex10000/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1429 | // ... and not linking to the stub variant |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1430 | ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_shared_29/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1431 | // ... and is not compiling with the stub |
| 1432 | ensureNotContains(t, mylibCFlags, "__LIBM_API__=29") |
| 1433 | ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29") |
| 1434 | |
| 1435 | // For dependency to libdl |
| 1436 | // Ensure that mylib is linking with the specified version of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1437 | ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_27/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1438 | // ... and not linking to the other versions of stubs |
Jiyong Park | 3ff1699 | 2019-12-27 14:11:47 +0900 | [diff] [blame] | 1439 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_28/libdl.so") |
| 1440 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_29/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1441 | // ... and not linking to the non-stub (impl) variant |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1442 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_shared_apex10000/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1443 | // ... Cflags from stub is correctly exported to mylib |
| 1444 | ensureContains(t, mylibCFlags, "__LIBDL_API__=27") |
| 1445 | ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1446 | |
| 1447 | // Ensure that libBootstrap is depending on the platform variant of bionic libs |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 1448 | libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 1449 | ensureContains(t, libFlags, "libc/android_arm64_armv8-a_shared/libc.so") |
| 1450 | ensureContains(t, libFlags, "libm/android_arm64_armv8-a_shared/libm.so") |
| 1451 | ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_shared/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1452 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 1453 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1454 | func TestApexMinSdkVersion_NativeModulesShouldBeBuiltAgainstStubs(t *testing.T) { |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1455 | // there are three links between liba --> libz. |
| 1456 | // 1) myapex -> libx -> liba -> libz : this should be #30 link |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1457 | // 2) otherapex -> liby -> liba -> libz : this should be #30 link |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1458 | // 3) (platform) -> liba -> libz : this should be non-stub link |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1459 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1460 | apex { |
| 1461 | name: "myapex", |
| 1462 | key: "myapex.key", |
| 1463 | native_shared_libs: ["libx"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1464 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | apex { |
| 1468 | name: "otherapex", |
| 1469 | key: "myapex.key", |
| 1470 | native_shared_libs: ["liby"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1471 | min_sdk_version: "30", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1472 | } |
| 1473 | |
| 1474 | apex_key { |
| 1475 | name: "myapex.key", |
| 1476 | public_key: "testkey.avbpubkey", |
| 1477 | private_key: "testkey.pem", |
| 1478 | } |
| 1479 | |
| 1480 | cc_library { |
| 1481 | name: "libx", |
| 1482 | shared_libs: ["liba"], |
| 1483 | system_shared_libs: [], |
| 1484 | stl: "none", |
| 1485 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1486 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | cc_library { |
| 1490 | name: "liby", |
| 1491 | shared_libs: ["liba"], |
| 1492 | system_shared_libs: [], |
| 1493 | stl: "none", |
| 1494 | apex_available: [ "otherapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1495 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | cc_library { |
| 1499 | name: "liba", |
| 1500 | shared_libs: ["libz"], |
| 1501 | system_shared_libs: [], |
| 1502 | stl: "none", |
| 1503 | apex_available: [ |
| 1504 | "//apex_available:anyapex", |
| 1505 | "//apex_available:platform", |
| 1506 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1507 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | cc_library { |
| 1511 | name: "libz", |
| 1512 | system_shared_libs: [], |
| 1513 | stl: "none", |
| 1514 | stubs: { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1515 | versions: ["28", "30"], |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1516 | }, |
| 1517 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1518 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1519 | |
| 1520 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1521 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1522 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1523 | } |
| 1524 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1525 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1526 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1527 | } |
| 1528 | // platform liba is linked to non-stub version |
| 1529 | expectLink("liba", "shared", "libz", "shared") |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 1530 | // liba in myapex is linked to #30 |
| 1531 | expectLink("liba", "shared_apex29", "libz", "shared_30") |
| 1532 | expectNoLink("liba", "shared_apex29", "libz", "shared_28") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1533 | expectNoLink("liba", "shared_apex29", "libz", "shared") |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1534 | // liba in otherapex is linked to #30 |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1535 | expectLink("liba", "shared_apex30", "libz", "shared_30") |
| 1536 | expectNoLink("liba", "shared_apex30", "libz", "shared_28") |
| 1537 | expectNoLink("liba", "shared_apex30", "libz", "shared") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1538 | } |
| 1539 | |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1540 | func TestApexMinSdkVersion_SupportsCodeNames(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1541 | ctx := testApex(t, ` |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1542 | apex { |
| 1543 | name: "myapex", |
| 1544 | key: "myapex.key", |
| 1545 | native_shared_libs: ["libx"], |
| 1546 | min_sdk_version: "R", |
| 1547 | } |
| 1548 | |
| 1549 | apex_key { |
| 1550 | name: "myapex.key", |
| 1551 | public_key: "testkey.avbpubkey", |
| 1552 | private_key: "testkey.pem", |
| 1553 | } |
| 1554 | |
| 1555 | cc_library { |
| 1556 | name: "libx", |
| 1557 | shared_libs: ["libz"], |
| 1558 | system_shared_libs: [], |
| 1559 | stl: "none", |
| 1560 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1561 | min_sdk_version: "R", |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1562 | } |
| 1563 | |
| 1564 | cc_library { |
| 1565 | name: "libz", |
| 1566 | system_shared_libs: [], |
| 1567 | stl: "none", |
| 1568 | stubs: { |
| 1569 | versions: ["29", "R"], |
| 1570 | }, |
| 1571 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1572 | `, |
| 1573 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1574 | variables.Platform_version_active_codenames = []string{"R"} |
| 1575 | }), |
| 1576 | ) |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1577 | |
| 1578 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1579 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1580 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1581 | } |
| 1582 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1583 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1584 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1585 | } |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 1586 | expectLink("libx", "shared_apex10000", "libz", "shared_R") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1587 | expectNoLink("libx", "shared_apex10000", "libz", "shared_29") |
| 1588 | expectNoLink("libx", "shared_apex10000", "libz", "shared") |
Jooyung Han | aed150d | 2020-04-02 01:41:41 +0900 | [diff] [blame] | 1589 | } |
| 1590 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1591 | func TestApexMinSdkVersion_DefaultsToLatest(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1592 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1593 | apex { |
| 1594 | name: "myapex", |
| 1595 | key: "myapex.key", |
| 1596 | native_shared_libs: ["libx"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1597 | updatable: false, |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | apex_key { |
| 1601 | name: "myapex.key", |
| 1602 | public_key: "testkey.avbpubkey", |
| 1603 | private_key: "testkey.pem", |
| 1604 | } |
| 1605 | |
| 1606 | cc_library { |
| 1607 | name: "libx", |
| 1608 | shared_libs: ["libz"], |
| 1609 | system_shared_libs: [], |
| 1610 | stl: "none", |
| 1611 | apex_available: [ "myapex" ], |
| 1612 | } |
| 1613 | |
| 1614 | cc_library { |
| 1615 | name: "libz", |
| 1616 | system_shared_libs: [], |
| 1617 | stl: "none", |
| 1618 | stubs: { |
| 1619 | versions: ["1", "2"], |
| 1620 | }, |
| 1621 | } |
| 1622 | `) |
| 1623 | |
| 1624 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1625 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1626 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1627 | } |
| 1628 | expectNoLink := func(from, from_variant, to, to_variant string) { |
| 1629 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1630 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1631 | } |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1632 | expectLink("libx", "shared_apex10000", "libz", "shared_2") |
| 1633 | expectNoLink("libx", "shared_apex10000", "libz", "shared_1") |
| 1634 | expectNoLink("libx", "shared_apex10000", "libz", "shared") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1635 | } |
| 1636 | |
| 1637 | func TestPlatformUsesLatestStubsFromApexes(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1638 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1639 | apex { |
| 1640 | name: "myapex", |
| 1641 | key: "myapex.key", |
| 1642 | native_shared_libs: ["libx"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1643 | updatable: false, |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1644 | } |
| 1645 | |
| 1646 | apex_key { |
| 1647 | name: "myapex.key", |
| 1648 | public_key: "testkey.avbpubkey", |
| 1649 | private_key: "testkey.pem", |
| 1650 | } |
| 1651 | |
| 1652 | cc_library { |
| 1653 | name: "libx", |
| 1654 | system_shared_libs: [], |
| 1655 | stl: "none", |
| 1656 | apex_available: [ "myapex" ], |
| 1657 | stubs: { |
| 1658 | versions: ["1", "2"], |
| 1659 | }, |
| 1660 | } |
| 1661 | |
| 1662 | cc_library { |
| 1663 | name: "libz", |
| 1664 | shared_libs: ["libx"], |
| 1665 | system_shared_libs: [], |
| 1666 | stl: "none", |
| 1667 | } |
| 1668 | `) |
| 1669 | |
| 1670 | expectLink := func(from, from_variant, to, to_variant string) { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1671 | t.Helper() |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1672 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1673 | ensureContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1674 | } |
| 1675 | expectNoLink := func(from, from_variant, to, to_variant string) { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 1676 | t.Helper() |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1677 | ldArgs := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld").Args["libFlags"] |
| 1678 | ensureNotContains(t, ldArgs, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1679 | } |
| 1680 | expectLink("libz", "shared", "libx", "shared_2") |
| 1681 | expectNoLink("libz", "shared", "libz", "shared_1") |
| 1682 | expectNoLink("libz", "shared", "libz", "shared") |
| 1683 | } |
| 1684 | |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1685 | var prepareForTestWithSantitizeHwaddress = android.FixtureModifyProductVariables( |
| 1686 | func(variables android.FixtureProductVariables) { |
| 1687 | variables.SanitizeDevice = []string{"hwaddress"} |
| 1688 | }, |
| 1689 | ) |
| 1690 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1691 | func TestQApexesUseLatestStubsInBundledBuildsAndHWASAN(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1692 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1693 | apex { |
| 1694 | name: "myapex", |
| 1695 | key: "myapex.key", |
| 1696 | native_shared_libs: ["libx"], |
| 1697 | min_sdk_version: "29", |
| 1698 | } |
| 1699 | |
| 1700 | apex_key { |
| 1701 | name: "myapex.key", |
| 1702 | public_key: "testkey.avbpubkey", |
| 1703 | private_key: "testkey.pem", |
| 1704 | } |
| 1705 | |
| 1706 | cc_library { |
| 1707 | name: "libx", |
| 1708 | shared_libs: ["libbar"], |
| 1709 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1710 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | cc_library { |
| 1714 | name: "libbar", |
| 1715 | stubs: { |
| 1716 | versions: ["29", "30"], |
| 1717 | }, |
| 1718 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 1719 | `, |
| 1720 | prepareForTestWithSantitizeHwaddress, |
| 1721 | ) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1722 | expectLink := func(from, from_variant, to, to_variant string) { |
| 1723 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 1724 | libFlags := ld.Args["libFlags"] |
| 1725 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 1726 | } |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1727 | expectLink("libx", "shared_hwasan_apex29", "libbar", "shared_30") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1728 | } |
| 1729 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1730 | func TestQTargetApexUsesStaticUnwinder(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 1731 | ctx := testApex(t, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1732 | apex { |
| 1733 | name: "myapex", |
| 1734 | key: "myapex.key", |
| 1735 | native_shared_libs: ["libx"], |
| 1736 | min_sdk_version: "29", |
| 1737 | } |
| 1738 | |
| 1739 | apex_key { |
| 1740 | name: "myapex.key", |
| 1741 | public_key: "testkey.avbpubkey", |
| 1742 | private_key: "testkey.pem", |
| 1743 | } |
| 1744 | |
| 1745 | cc_library { |
| 1746 | name: "libx", |
| 1747 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1748 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1749 | } |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1750 | `) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1751 | |
| 1752 | // ensure apex variant of c++ is linked with static unwinder |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 1753 | 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] | 1754 | ensureListContains(t, cm.Properties.AndroidMkStaticLibs, "libunwind") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1755 | // note that platform variant is not. |
| 1756 | cm = ctx.ModuleForTests("libc++", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
Ryan Prichard | b35a85e | 2021-01-13 19:18:53 -0800 | [diff] [blame] | 1757 | ensureListNotContains(t, cm.Properties.AndroidMkStaticLibs, "libunwind") |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1758 | } |
| 1759 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1760 | func TestApexMinSdkVersion_ErrorIfIncompatibleVersion(t *testing.T) { |
| 1761 | testApexError(t, `module "mylib".*: should support min_sdk_version\(29\)`, ` |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1762 | apex { |
| 1763 | name: "myapex", |
| 1764 | key: "myapex.key", |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1765 | native_shared_libs: ["mylib"], |
| 1766 | min_sdk_version: "29", |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | apex_key { |
| 1770 | name: "myapex.key", |
| 1771 | public_key: "testkey.avbpubkey", |
| 1772 | private_key: "testkey.pem", |
| 1773 | } |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1774 | |
| 1775 | cc_library { |
| 1776 | name: "mylib", |
| 1777 | srcs: ["mylib.cpp"], |
| 1778 | system_shared_libs: [], |
| 1779 | stl: "none", |
| 1780 | apex_available: [ |
| 1781 | "myapex", |
| 1782 | ], |
| 1783 | min_sdk_version: "30", |
| 1784 | } |
| 1785 | `) |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 1786 | |
| 1787 | testApexError(t, `module "libfoo.ffi".*: should support min_sdk_version\(29\)`, ` |
| 1788 | apex { |
| 1789 | name: "myapex", |
| 1790 | key: "myapex.key", |
| 1791 | native_shared_libs: ["libfoo.ffi"], |
| 1792 | min_sdk_version: "29", |
| 1793 | } |
| 1794 | |
| 1795 | apex_key { |
| 1796 | name: "myapex.key", |
| 1797 | public_key: "testkey.avbpubkey", |
| 1798 | private_key: "testkey.pem", |
| 1799 | } |
| 1800 | |
| 1801 | rust_ffi_shared { |
| 1802 | name: "libfoo.ffi", |
| 1803 | srcs: ["foo.rs"], |
| 1804 | crate_name: "foo", |
| 1805 | apex_available: [ |
| 1806 | "myapex", |
| 1807 | ], |
| 1808 | min_sdk_version: "30", |
| 1809 | } |
| 1810 | `) |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | func TestApexMinSdkVersion_Okay(t *testing.T) { |
| 1814 | testApex(t, ` |
| 1815 | apex { |
| 1816 | name: "myapex", |
| 1817 | key: "myapex.key", |
| 1818 | native_shared_libs: ["libfoo"], |
| 1819 | java_libs: ["libbar"], |
| 1820 | min_sdk_version: "29", |
| 1821 | } |
| 1822 | |
| 1823 | apex_key { |
| 1824 | name: "myapex.key", |
| 1825 | public_key: "testkey.avbpubkey", |
| 1826 | private_key: "testkey.pem", |
| 1827 | } |
| 1828 | |
| 1829 | cc_library { |
| 1830 | name: "libfoo", |
| 1831 | srcs: ["mylib.cpp"], |
| 1832 | shared_libs: ["libfoo_dep"], |
| 1833 | apex_available: ["myapex"], |
| 1834 | min_sdk_version: "29", |
| 1835 | } |
| 1836 | |
| 1837 | cc_library { |
| 1838 | name: "libfoo_dep", |
| 1839 | srcs: ["mylib.cpp"], |
| 1840 | apex_available: ["myapex"], |
| 1841 | min_sdk_version: "29", |
| 1842 | } |
| 1843 | |
| 1844 | java_library { |
| 1845 | name: "libbar", |
| 1846 | sdk_version: "current", |
| 1847 | srcs: ["a.java"], |
| 1848 | static_libs: ["libbar_dep"], |
| 1849 | apex_available: ["myapex"], |
| 1850 | min_sdk_version: "29", |
| 1851 | } |
| 1852 | |
| 1853 | java_library { |
| 1854 | name: "libbar_dep", |
| 1855 | sdk_version: "current", |
| 1856 | srcs: ["a.java"], |
| 1857 | apex_available: ["myapex"], |
| 1858 | min_sdk_version: "29", |
| 1859 | } |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 1860 | `) |
| 1861 | } |
| 1862 | |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1863 | func TestJavaStableSdkVersion(t *testing.T) { |
| 1864 | testCases := []struct { |
| 1865 | name string |
| 1866 | expectedError string |
| 1867 | bp string |
| 1868 | }{ |
| 1869 | { |
| 1870 | name: "Non-updatable apex with non-stable dep", |
| 1871 | bp: ` |
| 1872 | apex { |
| 1873 | name: "myapex", |
| 1874 | java_libs: ["myjar"], |
| 1875 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 1876 | updatable: false, |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1877 | } |
| 1878 | apex_key { |
| 1879 | name: "myapex.key", |
| 1880 | public_key: "testkey.avbpubkey", |
| 1881 | private_key: "testkey.pem", |
| 1882 | } |
| 1883 | java_library { |
| 1884 | name: "myjar", |
| 1885 | srcs: ["foo/bar/MyClass.java"], |
Paul Duffin | 043f5e7 | 2021-03-05 00:00:01 +0000 | [diff] [blame] | 1886 | sdk_version: "test_current", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1887 | apex_available: ["myapex"], |
| 1888 | } |
| 1889 | `, |
| 1890 | }, |
| 1891 | { |
| 1892 | name: "Updatable apex with stable dep", |
| 1893 | bp: ` |
| 1894 | apex { |
| 1895 | name: "myapex", |
| 1896 | java_libs: ["myjar"], |
| 1897 | key: "myapex.key", |
| 1898 | updatable: true, |
| 1899 | min_sdk_version: "29", |
| 1900 | } |
| 1901 | apex_key { |
| 1902 | name: "myapex.key", |
| 1903 | public_key: "testkey.avbpubkey", |
| 1904 | private_key: "testkey.pem", |
| 1905 | } |
| 1906 | java_library { |
| 1907 | name: "myjar", |
| 1908 | srcs: ["foo/bar/MyClass.java"], |
| 1909 | sdk_version: "current", |
| 1910 | apex_available: ["myapex"], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1911 | min_sdk_version: "29", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1912 | } |
| 1913 | `, |
| 1914 | }, |
| 1915 | { |
| 1916 | name: "Updatable apex with non-stable dep", |
| 1917 | expectedError: "cannot depend on \"myjar\"", |
| 1918 | bp: ` |
| 1919 | apex { |
| 1920 | name: "myapex", |
| 1921 | java_libs: ["myjar"], |
| 1922 | key: "myapex.key", |
| 1923 | updatable: true, |
| 1924 | } |
| 1925 | apex_key { |
| 1926 | name: "myapex.key", |
| 1927 | public_key: "testkey.avbpubkey", |
| 1928 | private_key: "testkey.pem", |
| 1929 | } |
| 1930 | java_library { |
| 1931 | name: "myjar", |
| 1932 | srcs: ["foo/bar/MyClass.java"], |
Paul Duffin | 043f5e7 | 2021-03-05 00:00:01 +0000 | [diff] [blame] | 1933 | sdk_version: "test_current", |
Artur Satayev | 8cf899a | 2020-04-15 17:29:42 +0100 | [diff] [blame] | 1934 | apex_available: ["myapex"], |
| 1935 | } |
| 1936 | `, |
| 1937 | }, |
| 1938 | { |
Paul Duffin | 043f5e7 | 2021-03-05 00:00:01 +0000 | [diff] [blame] | 1939 | name: "Updatable apex with non-stable transitive dep", |
| 1940 | // This is not actually detecting that the transitive dependency is unstable, rather it is |
| 1941 | // detecting that the transitive dependency is building against a wider API surface than the |
| 1942 | // module that depends on it is using. |
Jiyong Park | 670e0f6 | 2021-02-18 13:10:18 +0900 | [diff] [blame] | 1943 | 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] | 1944 | bp: ` |
| 1945 | apex { |
| 1946 | name: "myapex", |
| 1947 | java_libs: ["myjar"], |
| 1948 | key: "myapex.key", |
| 1949 | updatable: true, |
| 1950 | } |
| 1951 | apex_key { |
| 1952 | name: "myapex.key", |
| 1953 | public_key: "testkey.avbpubkey", |
| 1954 | private_key: "testkey.pem", |
| 1955 | } |
| 1956 | java_library { |
| 1957 | name: "myjar", |
| 1958 | srcs: ["foo/bar/MyClass.java"], |
| 1959 | sdk_version: "current", |
| 1960 | apex_available: ["myapex"], |
| 1961 | static_libs: ["transitive-jar"], |
| 1962 | } |
| 1963 | java_library { |
| 1964 | name: "transitive-jar", |
| 1965 | srcs: ["foo/bar/MyClass.java"], |
| 1966 | sdk_version: "core_platform", |
| 1967 | apex_available: ["myapex"], |
| 1968 | } |
| 1969 | `, |
| 1970 | }, |
| 1971 | } |
| 1972 | |
| 1973 | for _, test := range testCases { |
| 1974 | t.Run(test.name, func(t *testing.T) { |
| 1975 | if test.expectedError == "" { |
| 1976 | testApex(t, test.bp) |
| 1977 | } else { |
| 1978 | testApexError(t, test.expectedError, test.bp) |
| 1979 | } |
| 1980 | }) |
| 1981 | } |
| 1982 | } |
| 1983 | |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 1984 | func TestApexMinSdkVersion_ErrorIfDepIsNewer(t *testing.T) { |
| 1985 | testApexError(t, `module "mylib2".*: should support min_sdk_version\(29\) for "myapex"`, ` |
| 1986 | apex { |
| 1987 | name: "myapex", |
| 1988 | key: "myapex.key", |
| 1989 | native_shared_libs: ["mylib"], |
| 1990 | min_sdk_version: "29", |
| 1991 | } |
| 1992 | |
| 1993 | apex_key { |
| 1994 | name: "myapex.key", |
| 1995 | public_key: "testkey.avbpubkey", |
| 1996 | private_key: "testkey.pem", |
| 1997 | } |
| 1998 | |
| 1999 | cc_library { |
| 2000 | name: "mylib", |
| 2001 | srcs: ["mylib.cpp"], |
| 2002 | shared_libs: ["mylib2"], |
| 2003 | system_shared_libs: [], |
| 2004 | stl: "none", |
| 2005 | apex_available: [ |
| 2006 | "myapex", |
| 2007 | ], |
| 2008 | min_sdk_version: "29", |
| 2009 | } |
| 2010 | |
| 2011 | // indirect part of the apex |
| 2012 | cc_library { |
| 2013 | name: "mylib2", |
| 2014 | srcs: ["mylib.cpp"], |
| 2015 | system_shared_libs: [], |
| 2016 | stl: "none", |
| 2017 | apex_available: [ |
| 2018 | "myapex", |
| 2019 | ], |
| 2020 | min_sdk_version: "30", |
| 2021 | } |
| 2022 | `) |
| 2023 | } |
| 2024 | |
| 2025 | func TestApexMinSdkVersion_ErrorIfDepIsNewer_Java(t *testing.T) { |
| 2026 | testApexError(t, `module "bar".*: should support min_sdk_version\(29\) for "myapex"`, ` |
| 2027 | apex { |
| 2028 | name: "myapex", |
| 2029 | key: "myapex.key", |
| 2030 | apps: ["AppFoo"], |
| 2031 | min_sdk_version: "29", |
| 2032 | } |
| 2033 | |
| 2034 | apex_key { |
| 2035 | name: "myapex.key", |
| 2036 | public_key: "testkey.avbpubkey", |
| 2037 | private_key: "testkey.pem", |
| 2038 | } |
| 2039 | |
| 2040 | android_app { |
| 2041 | name: "AppFoo", |
| 2042 | srcs: ["foo/bar/MyClass.java"], |
| 2043 | sdk_version: "current", |
| 2044 | min_sdk_version: "29", |
| 2045 | system_modules: "none", |
| 2046 | stl: "none", |
| 2047 | static_libs: ["bar"], |
| 2048 | apex_available: [ "myapex" ], |
| 2049 | } |
| 2050 | |
| 2051 | java_library { |
| 2052 | name: "bar", |
| 2053 | sdk_version: "current", |
| 2054 | srcs: ["a.java"], |
| 2055 | apex_available: [ "myapex" ], |
| 2056 | } |
| 2057 | `) |
| 2058 | } |
| 2059 | |
| 2060 | func TestApexMinSdkVersion_OkayEvenWhenDepIsNewer_IfItSatisfiesApexMinSdkVersion(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2061 | ctx := testApex(t, ` |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2062 | apex { |
| 2063 | name: "myapex", |
| 2064 | key: "myapex.key", |
| 2065 | native_shared_libs: ["mylib"], |
| 2066 | min_sdk_version: "29", |
| 2067 | } |
| 2068 | |
| 2069 | apex_key { |
| 2070 | name: "myapex.key", |
| 2071 | public_key: "testkey.avbpubkey", |
| 2072 | private_key: "testkey.pem", |
| 2073 | } |
| 2074 | |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 2075 | // mylib in myapex will link to mylib2#30 |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2076 | // mylib in otherapex will link to mylib2(non-stub) in otherapex as well |
| 2077 | cc_library { |
| 2078 | name: "mylib", |
| 2079 | srcs: ["mylib.cpp"], |
| 2080 | shared_libs: ["mylib2"], |
| 2081 | system_shared_libs: [], |
| 2082 | stl: "none", |
| 2083 | apex_available: ["myapex", "otherapex"], |
| 2084 | min_sdk_version: "29", |
| 2085 | } |
| 2086 | |
| 2087 | cc_library { |
| 2088 | name: "mylib2", |
| 2089 | srcs: ["mylib.cpp"], |
| 2090 | system_shared_libs: [], |
| 2091 | stl: "none", |
| 2092 | apex_available: ["otherapex"], |
| 2093 | stubs: { versions: ["29", "30"] }, |
| 2094 | min_sdk_version: "30", |
| 2095 | } |
| 2096 | |
| 2097 | apex { |
| 2098 | name: "otherapex", |
| 2099 | key: "myapex.key", |
| 2100 | native_shared_libs: ["mylib", "mylib2"], |
| 2101 | min_sdk_version: "30", |
| 2102 | } |
| 2103 | `) |
| 2104 | expectLink := func(from, from_variant, to, to_variant string) { |
| 2105 | ld := ctx.ModuleForTests(from, "android_arm64_armv8-a_"+from_variant).Rule("ld") |
| 2106 | libFlags := ld.Args["libFlags"] |
| 2107 | ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so") |
| 2108 | } |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 2109 | expectLink("mylib", "shared_apex29", "mylib2", "shared_30") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2110 | expectLink("mylib", "shared_apex30", "mylib2", "shared_apex30") |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2111 | } |
| 2112 | |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2113 | func TestApexMinSdkVersion_WorksWithSdkCodename(t *testing.T) { |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2114 | withSAsActiveCodeNames := android.FixtureModifyProductVariables( |
| 2115 | func(variables android.FixtureProductVariables) { |
| 2116 | variables.Platform_sdk_codename = proptools.StringPtr("S") |
| 2117 | variables.Platform_version_active_codenames = []string{"S"} |
| 2118 | }, |
| 2119 | ) |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2120 | testApexError(t, `libbar.*: should support min_sdk_version\(S\)`, ` |
| 2121 | apex { |
| 2122 | name: "myapex", |
| 2123 | key: "myapex.key", |
| 2124 | native_shared_libs: ["libfoo"], |
| 2125 | min_sdk_version: "S", |
| 2126 | } |
| 2127 | apex_key { |
| 2128 | name: "myapex.key", |
| 2129 | public_key: "testkey.avbpubkey", |
| 2130 | private_key: "testkey.pem", |
| 2131 | } |
| 2132 | cc_library { |
| 2133 | name: "libfoo", |
| 2134 | shared_libs: ["libbar"], |
| 2135 | apex_available: ["myapex"], |
| 2136 | min_sdk_version: "29", |
| 2137 | } |
| 2138 | cc_library { |
| 2139 | name: "libbar", |
| 2140 | apex_available: ["myapex"], |
| 2141 | } |
| 2142 | `, withSAsActiveCodeNames) |
| 2143 | } |
| 2144 | |
| 2145 | func TestApexMinSdkVersion_WorksWithActiveCodenames(t *testing.T) { |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2146 | withSAsActiveCodeNames := android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 2147 | variables.Platform_sdk_codename = proptools.StringPtr("S") |
| 2148 | variables.Platform_version_active_codenames = []string{"S", "T"} |
| 2149 | }) |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2150 | ctx := testApex(t, ` |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2151 | apex { |
| 2152 | name: "myapex", |
| 2153 | key: "myapex.key", |
| 2154 | native_shared_libs: ["libfoo"], |
| 2155 | min_sdk_version: "S", |
| 2156 | } |
| 2157 | apex_key { |
| 2158 | name: "myapex.key", |
| 2159 | public_key: "testkey.avbpubkey", |
| 2160 | private_key: "testkey.pem", |
| 2161 | } |
| 2162 | cc_library { |
| 2163 | name: "libfoo", |
| 2164 | shared_libs: ["libbar"], |
| 2165 | apex_available: ["myapex"], |
| 2166 | min_sdk_version: "S", |
| 2167 | } |
| 2168 | cc_library { |
| 2169 | name: "libbar", |
| 2170 | stubs: { |
| 2171 | symbol_file: "libbar.map.txt", |
| 2172 | versions: ["30", "S", "T"], |
| 2173 | }, |
| 2174 | } |
| 2175 | `, withSAsActiveCodeNames) |
| 2176 | |
| 2177 | // ensure libfoo is linked with "S" version of libbar stub |
| 2178 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared_apex10000") |
| 2179 | libFlags := libfoo.Rule("ld").Args["libFlags"] |
Jiyong Park | 55549df | 2021-02-26 23:57:23 +0900 | [diff] [blame] | 2180 | ensureContains(t, libFlags, "android_arm64_armv8-a_shared_T/libbar.so") |
Jooyung Han | ed124c3 | 2021-01-26 11:43:46 +0900 | [diff] [blame] | 2181 | } |
| 2182 | |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2183 | func TestFilesInSubDir(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2184 | ctx := testApex(t, ` |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2185 | apex { |
| 2186 | name: "myapex", |
| 2187 | key: "myapex.key", |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2188 | native_shared_libs: ["mylib"], |
| 2189 | binaries: ["mybin"], |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2190 | prebuilts: ["myetc"], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2191 | compile_multilib: "both", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2192 | updatable: false, |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2193 | } |
| 2194 | |
| 2195 | apex_key { |
| 2196 | name: "myapex.key", |
| 2197 | public_key: "testkey.avbpubkey", |
| 2198 | private_key: "testkey.pem", |
| 2199 | } |
| 2200 | |
| 2201 | prebuilt_etc { |
| 2202 | name: "myetc", |
| 2203 | src: "myprebuilt", |
| 2204 | sub_dir: "foo/bar", |
| 2205 | } |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2206 | |
| 2207 | cc_library { |
| 2208 | name: "mylib", |
| 2209 | srcs: ["mylib.cpp"], |
| 2210 | relative_install_path: "foo/bar", |
| 2211 | system_shared_libs: [], |
| 2212 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2213 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2214 | } |
| 2215 | |
| 2216 | cc_binary { |
| 2217 | name: "mybin", |
| 2218 | srcs: ["mylib.cpp"], |
| 2219 | relative_install_path: "foo/bar", |
| 2220 | system_shared_libs: [], |
| 2221 | static_executable: true, |
| 2222 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2223 | apex_available: [ "myapex" ], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2224 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2225 | `) |
| 2226 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2227 | generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("generateFsConfig") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2228 | dirs := strings.Split(generateFsRule.Args["exec_paths"], " ") |
| 2229 | |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2230 | // Ensure that the subdirectories are all listed |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2231 | ensureListContains(t, dirs, "etc") |
| 2232 | ensureListContains(t, dirs, "etc/foo") |
| 2233 | ensureListContains(t, dirs, "etc/foo/bar") |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 2234 | ensureListContains(t, dirs, "lib64") |
| 2235 | ensureListContains(t, dirs, "lib64/foo") |
| 2236 | ensureListContains(t, dirs, "lib64/foo/bar") |
| 2237 | ensureListContains(t, dirs, "lib") |
| 2238 | ensureListContains(t, dirs, "lib/foo") |
| 2239 | ensureListContains(t, dirs, "lib/foo/bar") |
| 2240 | |
Jiyong Park | bd13e44 | 2019-03-15 18:10:35 +0900 | [diff] [blame] | 2241 | ensureListContains(t, dirs, "bin") |
| 2242 | ensureListContains(t, dirs, "bin/foo") |
| 2243 | ensureListContains(t, dirs, "bin/foo/bar") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 2244 | } |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2245 | |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2246 | func TestFilesInSubDirWhenNativeBridgeEnabled(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2247 | ctx := testApex(t, ` |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2248 | apex { |
| 2249 | name: "myapex", |
| 2250 | key: "myapex.key", |
| 2251 | multilib: { |
| 2252 | both: { |
| 2253 | native_shared_libs: ["mylib"], |
| 2254 | binaries: ["mybin"], |
| 2255 | }, |
| 2256 | }, |
| 2257 | compile_multilib: "both", |
| 2258 | native_bridge_supported: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2259 | updatable: false, |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 2260 | } |
| 2261 | |
| 2262 | apex_key { |
| 2263 | name: "myapex.key", |
| 2264 | public_key: "testkey.avbpubkey", |
| 2265 | private_key: "testkey.pem", |
| 2266 | } |
| 2267 | |
| 2268 | cc_library { |
| 2269 | name: "mylib", |
| 2270 | relative_install_path: "foo/bar", |
| 2271 | system_shared_libs: [], |
| 2272 | stl: "none", |
| 2273 | apex_available: [ "myapex" ], |
| 2274 | native_bridge_supported: true, |
| 2275 | } |
| 2276 | |
| 2277 | cc_binary { |
| 2278 | name: "mybin", |
| 2279 | relative_install_path: "foo/bar", |
| 2280 | system_shared_libs: [], |
| 2281 | static_executable: true, |
| 2282 | stl: "none", |
| 2283 | apex_available: [ "myapex" ], |
| 2284 | native_bridge_supported: true, |
| 2285 | compile_multilib: "both", // default is "first" for binary |
| 2286 | multilib: { |
| 2287 | lib64: { |
| 2288 | suffix: "64", |
| 2289 | }, |
| 2290 | }, |
| 2291 | } |
| 2292 | `, withNativeBridgeEnabled) |
| 2293 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2294 | "bin/foo/bar/mybin", |
| 2295 | "bin/foo/bar/mybin64", |
| 2296 | "bin/arm/foo/bar/mybin", |
| 2297 | "bin/arm64/foo/bar/mybin64", |
| 2298 | "lib/foo/bar/mylib.so", |
| 2299 | "lib/arm/foo/bar/mylib.so", |
| 2300 | "lib64/foo/bar/mylib.so", |
| 2301 | "lib64/arm64/foo/bar/mylib.so", |
| 2302 | }) |
| 2303 | } |
| 2304 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2305 | func TestUseVendor(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2306 | ctx := testApex(t, ` |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2307 | apex { |
| 2308 | name: "myapex", |
| 2309 | key: "myapex.key", |
| 2310 | native_shared_libs: ["mylib"], |
| 2311 | use_vendor: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2312 | updatable: false, |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2313 | } |
| 2314 | |
| 2315 | apex_key { |
| 2316 | name: "myapex.key", |
| 2317 | public_key: "testkey.avbpubkey", |
| 2318 | private_key: "testkey.pem", |
| 2319 | } |
| 2320 | |
| 2321 | cc_library { |
| 2322 | name: "mylib", |
| 2323 | srcs: ["mylib.cpp"], |
| 2324 | shared_libs: ["mylib2"], |
| 2325 | system_shared_libs: [], |
| 2326 | vendor_available: true, |
| 2327 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2328 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | cc_library { |
| 2332 | name: "mylib2", |
| 2333 | srcs: ["mylib.cpp"], |
| 2334 | system_shared_libs: [], |
| 2335 | vendor_available: true, |
| 2336 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2337 | apex_available: [ "myapex" ], |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2338 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2339 | `, |
| 2340 | setUseVendorAllowListForTest([]string{"myapex"}), |
| 2341 | ) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2342 | |
| 2343 | inputsList := []string{} |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2344 | for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().BuildParamsForTests() { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2345 | for _, implicit := range i.Implicits { |
| 2346 | inputsList = append(inputsList, implicit.String()) |
| 2347 | } |
| 2348 | } |
| 2349 | inputsString := strings.Join(inputsList, " ") |
| 2350 | |
| 2351 | // ensure that the apex includes vendor variants of the direct and indirect deps |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2352 | ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_apex10000/mylib.so") |
| 2353 | ensureContains(t, inputsString, "android_vendor.VER_arm64_armv8-a_shared_apex10000/mylib2.so") |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2354 | |
| 2355 | // ensure that the apex does not include core variants |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2356 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_apex10000/mylib.so") |
| 2357 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_shared_apex10000/mylib2.so") |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2358 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2359 | |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2360 | func TestUseVendorNotAllowedForSystemApexes(t *testing.T) { |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2361 | testApexError(t, `module "myapex" .*: use_vendor: not allowed`, ` |
| 2362 | apex { |
| 2363 | name: "myapex", |
| 2364 | key: "myapex.key", |
| 2365 | use_vendor: true, |
| 2366 | } |
| 2367 | apex_key { |
| 2368 | name: "myapex.key", |
| 2369 | public_key: "testkey.avbpubkey", |
| 2370 | private_key: "testkey.pem", |
| 2371 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2372 | `, |
| 2373 | setUseVendorAllowListForTest([]string{""}), |
| 2374 | ) |
Colin Cross | 440e0d0 | 2020-06-11 11:32:11 -0700 | [diff] [blame] | 2375 | // no error with allow list |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2376 | testApex(t, ` |
| 2377 | apex { |
| 2378 | name: "myapex", |
| 2379 | key: "myapex.key", |
| 2380 | use_vendor: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2381 | updatable: false, |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2382 | } |
| 2383 | apex_key { |
| 2384 | name: "myapex.key", |
| 2385 | public_key: "testkey.avbpubkey", |
| 2386 | private_key: "testkey.pem", |
| 2387 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2388 | `, |
| 2389 | setUseVendorAllowListForTest([]string{"myapex"}), |
| 2390 | ) |
Jooyung Han | dc78244 | 2019-11-01 03:14:38 +0900 | [diff] [blame] | 2391 | } |
| 2392 | |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2393 | func TestUseVendorFailsIfNotVendorAvailable(t *testing.T) { |
| 2394 | testApexError(t, `dependency "mylib" of "myapex" missing variant:\n.*image:vendor`, ` |
| 2395 | apex { |
| 2396 | name: "myapex", |
| 2397 | key: "myapex.key", |
| 2398 | native_shared_libs: ["mylib"], |
| 2399 | use_vendor: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2400 | updatable: false, |
Jooyung Han | 5c998b9 | 2019-06-27 11:30:33 +0900 | [diff] [blame] | 2401 | } |
| 2402 | |
| 2403 | apex_key { |
| 2404 | name: "myapex.key", |
| 2405 | public_key: "testkey.avbpubkey", |
| 2406 | private_key: "testkey.pem", |
| 2407 | } |
| 2408 | |
| 2409 | cc_library { |
| 2410 | name: "mylib", |
| 2411 | srcs: ["mylib.cpp"], |
| 2412 | system_shared_libs: [], |
| 2413 | stl: "none", |
| 2414 | } |
| 2415 | `) |
| 2416 | } |
| 2417 | |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2418 | func TestVendorApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2419 | ctx := testApex(t, ` |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2420 | apex { |
| 2421 | name: "myapex", |
| 2422 | key: "myapex.key", |
| 2423 | binaries: ["mybin"], |
| 2424 | vendor: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2425 | updatable: false, |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2426 | } |
| 2427 | apex_key { |
| 2428 | name: "myapex.key", |
| 2429 | public_key: "testkey.avbpubkey", |
| 2430 | private_key: "testkey.pem", |
| 2431 | } |
| 2432 | cc_binary { |
| 2433 | name: "mybin", |
| 2434 | vendor: true, |
| 2435 | shared_libs: ["libfoo"], |
| 2436 | } |
| 2437 | cc_library { |
| 2438 | name: "libfoo", |
| 2439 | proprietary: true, |
| 2440 | } |
| 2441 | `) |
| 2442 | |
| 2443 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2444 | "bin/mybin", |
| 2445 | "lib64/libfoo.so", |
| 2446 | // TODO(b/159195575): Add an option to use VNDK libs from VNDK APEX |
| 2447 | "lib64/libc++.so", |
| 2448 | }) |
| 2449 | |
| 2450 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2451 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2452 | name := apexBundle.BaseModuleName() |
| 2453 | prefix := "TARGET_" |
| 2454 | var builder strings.Builder |
| 2455 | data.Custom(&builder, name, prefix, "", data) |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 2456 | androidMk := android.StringRelativeToTop(ctx.Config(), builder.String()) |
| 2457 | installPath := "out/target/product/test_device/vendor/apex" |
Lukacs T. Berki | 7690c09 | 2021-02-26 14:27:36 +0100 | [diff] [blame] | 2458 | ensureContains(t, androidMk, "LOCAL_MODULE_PATH := "+installPath) |
Jooyung Han | 6c4cc9c | 2020-07-29 16:00:54 +0900 | [diff] [blame] | 2459 | |
| 2460 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 2461 | requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"]) |
| 2462 | ensureListNotContains(t, requireNativeLibs, ":vndk") |
Jooyung Han | 85d6176 | 2020-06-24 23:50:26 +0900 | [diff] [blame] | 2463 | } |
| 2464 | |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2465 | func TestVendorApex_use_vndk_as_stable(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2466 | ctx := testApex(t, ` |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2467 | apex { |
| 2468 | name: "myapex", |
| 2469 | key: "myapex.key", |
| 2470 | binaries: ["mybin"], |
| 2471 | vendor: true, |
| 2472 | use_vndk_as_stable: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2473 | updatable: false, |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2474 | } |
| 2475 | apex_key { |
| 2476 | name: "myapex.key", |
| 2477 | public_key: "testkey.avbpubkey", |
| 2478 | private_key: "testkey.pem", |
| 2479 | } |
| 2480 | cc_binary { |
| 2481 | name: "mybin", |
| 2482 | vendor: true, |
| 2483 | shared_libs: ["libvndk", "libvendor"], |
| 2484 | } |
| 2485 | cc_library { |
| 2486 | name: "libvndk", |
| 2487 | vndk: { |
| 2488 | enabled: true, |
| 2489 | }, |
| 2490 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 2491 | product_available: true, |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2492 | } |
| 2493 | cc_library { |
| 2494 | name: "libvendor", |
| 2495 | vendor: true, |
| 2496 | } |
| 2497 | `) |
| 2498 | |
| 2499 | vendorVariant := "android_vendor.VER_arm64_armv8-a" |
| 2500 | |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 2501 | ldRule := ctx.ModuleForTests("mybin", vendorVariant+"_apex10000").Rule("ld").RelativeToTop() |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2502 | libs := names(ldRule.Args["libFlags"]) |
| 2503 | // VNDK libs(libvndk/libc++) as they are |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 2504 | ensureListContains(t, libs, "out/soong/.intermediates/libvndk/"+vendorVariant+"_shared/libvndk.so") |
| 2505 | ensureListContains(t, libs, "out/soong/.intermediates/"+cc.DefaultCcCommonTestModulesDir+"libc++/"+vendorVariant+"_shared/libc++.so") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2506 | // non-stable Vendor libs as APEX variants |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 2507 | ensureListContains(t, libs, "out/soong/.intermediates/libvendor/"+vendorVariant+"_shared_apex10000/libvendor.so") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2508 | |
| 2509 | // VNDK libs are not included when use_vndk_as_stable: true |
| 2510 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2511 | "bin/mybin", |
| 2512 | "lib64/libvendor.so", |
| 2513 | }) |
Jooyung Han | 6c4cc9c | 2020-07-29 16:00:54 +0900 | [diff] [blame] | 2514 | |
| 2515 | apexManifestRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 2516 | requireNativeLibs := names(apexManifestRule.Args["requireNativeLibs"]) |
| 2517 | ensureListContains(t, requireNativeLibs, ":vndk") |
Jooyung Han | df78e21 | 2020-07-22 15:54:47 +0900 | [diff] [blame] | 2518 | } |
| 2519 | |
Justin Yun | 13decfb | 2021-03-08 19:25:55 +0900 | [diff] [blame] | 2520 | func TestProductVariant(t *testing.T) { |
| 2521 | ctx := testApex(t, ` |
| 2522 | apex { |
| 2523 | name: "myapex", |
| 2524 | key: "myapex.key", |
| 2525 | updatable: false, |
| 2526 | product_specific: true, |
| 2527 | binaries: ["foo"], |
| 2528 | } |
| 2529 | |
| 2530 | apex_key { |
| 2531 | name: "myapex.key", |
| 2532 | public_key: "testkey.avbpubkey", |
| 2533 | private_key: "testkey.pem", |
| 2534 | } |
| 2535 | |
| 2536 | cc_binary { |
| 2537 | name: "foo", |
| 2538 | product_available: true, |
| 2539 | apex_available: ["myapex"], |
| 2540 | srcs: ["foo.cpp"], |
| 2541 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2542 | `, android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 2543 | variables.ProductVndkVersion = proptools.StringPtr("current") |
| 2544 | }), |
| 2545 | ) |
Justin Yun | 13decfb | 2021-03-08 19:25:55 +0900 | [diff] [blame] | 2546 | |
| 2547 | cflags := strings.Fields( |
| 2548 | ctx.ModuleForTests("foo", "android_product.VER_arm64_armv8-a_apex10000").Rule("cc").Args["cFlags"]) |
| 2549 | ensureListContains(t, cflags, "-D__ANDROID_VNDK__") |
| 2550 | ensureListContains(t, cflags, "-D__ANDROID_APEX__") |
| 2551 | ensureListContains(t, cflags, "-D__ANDROID_PRODUCT__") |
| 2552 | ensureListNotContains(t, cflags, "-D__ANDROID_VENDOR__") |
| 2553 | } |
| 2554 | |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 2555 | func TestApex_withPrebuiltFirmware(t *testing.T) { |
| 2556 | testCases := []struct { |
| 2557 | name string |
| 2558 | additionalProp string |
| 2559 | }{ |
| 2560 | {"system apex with prebuilt_firmware", ""}, |
| 2561 | {"vendor apex with prebuilt_firmware", "vendor: true,"}, |
| 2562 | } |
| 2563 | for _, tc := range testCases { |
| 2564 | t.Run(tc.name, func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2565 | ctx := testApex(t, ` |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 2566 | apex { |
| 2567 | name: "myapex", |
| 2568 | key: "myapex.key", |
| 2569 | prebuilts: ["myfirmware"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2570 | updatable: false, |
Jooyung Han | 8e5685d | 2020-09-21 11:02:57 +0900 | [diff] [blame] | 2571 | `+tc.additionalProp+` |
| 2572 | } |
| 2573 | apex_key { |
| 2574 | name: "myapex.key", |
| 2575 | public_key: "testkey.avbpubkey", |
| 2576 | private_key: "testkey.pem", |
| 2577 | } |
| 2578 | prebuilt_firmware { |
| 2579 | name: "myfirmware", |
| 2580 | src: "myfirmware.bin", |
| 2581 | filename_from_src: true, |
| 2582 | `+tc.additionalProp+` |
| 2583 | } |
| 2584 | `) |
| 2585 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 2586 | "etc/firmware/myfirmware.bin", |
| 2587 | }) |
| 2588 | }) |
| 2589 | } |
Jooyung Han | 0703fd8 | 2020-08-26 22:11:53 +0900 | [diff] [blame] | 2590 | } |
| 2591 | |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2592 | func TestAndroidMk_UseVendorRequired(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2593 | ctx := testApex(t, ` |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2594 | apex { |
| 2595 | name: "myapex", |
| 2596 | key: "myapex.key", |
| 2597 | use_vendor: true, |
| 2598 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2599 | updatable: false, |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2600 | } |
| 2601 | |
| 2602 | apex_key { |
| 2603 | name: "myapex.key", |
| 2604 | public_key: "testkey.avbpubkey", |
| 2605 | private_key: "testkey.pem", |
| 2606 | } |
| 2607 | |
| 2608 | cc_library { |
| 2609 | name: "mylib", |
| 2610 | vendor_available: true, |
| 2611 | apex_available: ["myapex"], |
| 2612 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 2613 | `, |
| 2614 | setUseVendorAllowListForTest([]string{"myapex"}), |
| 2615 | ) |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2616 | |
| 2617 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2618 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2619 | name := apexBundle.BaseModuleName() |
| 2620 | prefix := "TARGET_" |
| 2621 | var builder strings.Builder |
| 2622 | data.Custom(&builder, name, prefix, "", data) |
| 2623 | androidMk := builder.String() |
| 2624 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += libc libm libdl\n") |
| 2625 | } |
| 2626 | |
| 2627 | func TestAndroidMk_VendorApexRequired(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2628 | ctx := testApex(t, ` |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2629 | apex { |
| 2630 | name: "myapex", |
| 2631 | key: "myapex.key", |
| 2632 | vendor: true, |
| 2633 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2634 | updatable: false, |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2635 | } |
| 2636 | |
| 2637 | apex_key { |
| 2638 | name: "myapex.key", |
| 2639 | public_key: "testkey.avbpubkey", |
| 2640 | private_key: "testkey.pem", |
| 2641 | } |
| 2642 | |
| 2643 | cc_library { |
| 2644 | name: "mylib", |
| 2645 | vendor_available: true, |
| 2646 | } |
| 2647 | `) |
| 2648 | |
| 2649 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2650 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jooyung Han | efb184e | 2020-06-25 17:14:25 +0900 | [diff] [blame] | 2651 | name := apexBundle.BaseModuleName() |
| 2652 | prefix := "TARGET_" |
| 2653 | var builder strings.Builder |
| 2654 | data.Custom(&builder, name, prefix, "", data) |
| 2655 | androidMk := builder.String() |
| 2656 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += libc.vendor libm.vendor libdl.vendor\n") |
| 2657 | } |
| 2658 | |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2659 | func TestAndroidMkWritesCommonProperties(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2660 | ctx := testApex(t, ` |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2661 | apex { |
| 2662 | name: "myapex", |
| 2663 | key: "myapex.key", |
| 2664 | vintf_fragments: ["fragment.xml"], |
| 2665 | init_rc: ["init.rc"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2666 | updatable: false, |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2667 | } |
| 2668 | apex_key { |
| 2669 | name: "myapex.key", |
| 2670 | public_key: "testkey.avbpubkey", |
| 2671 | private_key: "testkey.pem", |
| 2672 | } |
| 2673 | cc_binary { |
| 2674 | name: "mybin", |
| 2675 | } |
| 2676 | `) |
| 2677 | |
| 2678 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 2679 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jooyung Han | 2ed99d0 | 2020-06-24 23:26:26 +0900 | [diff] [blame] | 2680 | name := apexBundle.BaseModuleName() |
| 2681 | prefix := "TARGET_" |
| 2682 | var builder strings.Builder |
| 2683 | data.Custom(&builder, name, prefix, "", data) |
| 2684 | androidMk := builder.String() |
| 2685 | ensureContains(t, androidMk, "LOCAL_VINTF_FRAGMENTS := fragment.xml\n") |
| 2686 | ensureContains(t, androidMk, "LOCAL_INIT_RC := init.rc\n") |
| 2687 | } |
| 2688 | |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2689 | func TestStaticLinking(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2690 | ctx := testApex(t, ` |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2691 | apex { |
| 2692 | name: "myapex", |
| 2693 | key: "myapex.key", |
| 2694 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2695 | updatable: false, |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2696 | } |
| 2697 | |
| 2698 | apex_key { |
| 2699 | name: "myapex.key", |
| 2700 | public_key: "testkey.avbpubkey", |
| 2701 | private_key: "testkey.pem", |
| 2702 | } |
| 2703 | |
| 2704 | cc_library { |
| 2705 | name: "mylib", |
| 2706 | srcs: ["mylib.cpp"], |
| 2707 | system_shared_libs: [], |
| 2708 | stl: "none", |
| 2709 | stubs: { |
| 2710 | versions: ["1", "2", "3"], |
| 2711 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2712 | apex_available: [ |
| 2713 | "//apex_available:platform", |
| 2714 | "myapex", |
| 2715 | ], |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2716 | } |
| 2717 | |
| 2718 | cc_binary { |
| 2719 | name: "not_in_apex", |
| 2720 | srcs: ["mylib.cpp"], |
| 2721 | static_libs: ["mylib"], |
| 2722 | static_executable: true, |
| 2723 | system_shared_libs: [], |
| 2724 | stl: "none", |
| 2725 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2726 | `) |
| 2727 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2728 | 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] | 2729 | |
| 2730 | // 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] | 2731 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_static/mylib.a") |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 2732 | } |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2733 | |
| 2734 | func TestKeys(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2735 | ctx := testApex(t, ` |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2736 | apex { |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2737 | name: "myapex_keytest", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2738 | key: "myapex.key", |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2739 | certificate: ":myapex.certificate", |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2740 | native_shared_libs: ["mylib"], |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 2741 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2742 | updatable: false, |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2743 | } |
| 2744 | |
| 2745 | cc_library { |
| 2746 | name: "mylib", |
| 2747 | srcs: ["mylib.cpp"], |
| 2748 | system_shared_libs: [], |
| 2749 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2750 | apex_available: [ "myapex_keytest" ], |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2751 | } |
| 2752 | |
| 2753 | apex_key { |
| 2754 | name: "myapex.key", |
| 2755 | public_key: "testkey.avbpubkey", |
| 2756 | private_key: "testkey.pem", |
| 2757 | } |
| 2758 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2759 | android_app_certificate { |
| 2760 | name: "myapex.certificate", |
| 2761 | certificate: "testkey", |
| 2762 | } |
| 2763 | |
| 2764 | android_app_certificate { |
| 2765 | name: "myapex.certificate.override", |
| 2766 | certificate: "testkey.override", |
| 2767 | } |
| 2768 | |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2769 | `) |
| 2770 | |
| 2771 | // check the APEX keys |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 2772 | keys := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2773 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 2774 | if keys.publicKeyFile.String() != "vendor/foo/devkeys/testkey.avbpubkey" { |
| 2775 | t.Errorf("public key %q is not %q", keys.publicKeyFile.String(), |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2776 | "vendor/foo/devkeys/testkey.avbpubkey") |
| 2777 | } |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 2778 | if keys.privateKeyFile.String() != "vendor/foo/devkeys/testkey.pem" { |
| 2779 | t.Errorf("private key %q is not %q", keys.privateKeyFile.String(), |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2780 | "vendor/foo/devkeys/testkey.pem") |
| 2781 | } |
| 2782 | |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2783 | // check the APK certs. It should be overridden to myapex.certificate.override |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 2784 | 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] | 2785 | if certs != "testkey.override.x509.pem testkey.override.pk8" { |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2786 | t.Errorf("cert and private key %q are not %q", certs, |
Jiyong Park | b2742fd | 2019-02-11 11:38:15 +0900 | [diff] [blame] | 2787 | "testkey.override.509.pem testkey.override.pk8") |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 2788 | } |
| 2789 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2790 | |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2791 | func TestCertificate(t *testing.T) { |
| 2792 | t.Run("if unspecified, it defaults to DefaultAppCertificate", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2793 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2794 | apex { |
| 2795 | name: "myapex", |
| 2796 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2797 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2798 | } |
| 2799 | apex_key { |
| 2800 | name: "myapex.key", |
| 2801 | public_key: "testkey.avbpubkey", |
| 2802 | private_key: "testkey.pem", |
| 2803 | }`) |
| 2804 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2805 | expected := "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8" |
| 2806 | if actual := rule.Args["certificates"]; actual != expected { |
| 2807 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2808 | } |
| 2809 | }) |
| 2810 | t.Run("override when unspecified", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2811 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2812 | apex { |
| 2813 | name: "myapex_keytest", |
| 2814 | key: "myapex.key", |
| 2815 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2816 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2817 | } |
| 2818 | apex_key { |
| 2819 | name: "myapex.key", |
| 2820 | public_key: "testkey.avbpubkey", |
| 2821 | private_key: "testkey.pem", |
| 2822 | } |
| 2823 | android_app_certificate { |
| 2824 | name: "myapex.certificate.override", |
| 2825 | certificate: "testkey.override", |
| 2826 | }`) |
| 2827 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2828 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2829 | if actual := rule.Args["certificates"]; actual != expected { |
| 2830 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2831 | } |
| 2832 | }) |
| 2833 | 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] | 2834 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2835 | apex { |
| 2836 | name: "myapex", |
| 2837 | key: "myapex.key", |
| 2838 | certificate: ":myapex.certificate", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2839 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2840 | } |
| 2841 | apex_key { |
| 2842 | name: "myapex.key", |
| 2843 | public_key: "testkey.avbpubkey", |
| 2844 | private_key: "testkey.pem", |
| 2845 | } |
| 2846 | android_app_certificate { |
| 2847 | name: "myapex.certificate", |
| 2848 | certificate: "testkey", |
| 2849 | }`) |
| 2850 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2851 | expected := "testkey.x509.pem testkey.pk8" |
| 2852 | if actual := rule.Args["certificates"]; actual != expected { |
| 2853 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2854 | } |
| 2855 | }) |
| 2856 | t.Run("override when specifiec as <:module>", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2857 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2858 | apex { |
| 2859 | name: "myapex_keytest", |
| 2860 | key: "myapex.key", |
| 2861 | file_contexts: ":myapex-file_contexts", |
| 2862 | certificate: ":myapex.certificate", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2863 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2864 | } |
| 2865 | apex_key { |
| 2866 | name: "myapex.key", |
| 2867 | public_key: "testkey.avbpubkey", |
| 2868 | private_key: "testkey.pem", |
| 2869 | } |
| 2870 | android_app_certificate { |
| 2871 | name: "myapex.certificate.override", |
| 2872 | certificate: "testkey.override", |
| 2873 | }`) |
| 2874 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2875 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2876 | if actual := rule.Args["certificates"]; actual != expected { |
| 2877 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2878 | } |
| 2879 | }) |
| 2880 | 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] | 2881 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2882 | apex { |
| 2883 | name: "myapex", |
| 2884 | key: "myapex.key", |
| 2885 | certificate: "testkey", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2886 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2887 | } |
| 2888 | apex_key { |
| 2889 | name: "myapex.key", |
| 2890 | public_key: "testkey.avbpubkey", |
| 2891 | private_key: "testkey.pem", |
| 2892 | }`) |
| 2893 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("signapk") |
| 2894 | expected := "vendor/foo/devkeys/testkey.x509.pem vendor/foo/devkeys/testkey.pk8" |
| 2895 | if actual := rule.Args["certificates"]; actual != expected { |
| 2896 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2897 | } |
| 2898 | }) |
| 2899 | t.Run("override when specified as <name>", func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2900 | ctx := testApex(t, ` |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2901 | apex { |
| 2902 | name: "myapex_keytest", |
| 2903 | key: "myapex.key", |
| 2904 | file_contexts: ":myapex-file_contexts", |
| 2905 | certificate: "testkey", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2906 | updatable: false, |
Jooyung Han | f121a65 | 2019-12-17 14:30:11 +0900 | [diff] [blame] | 2907 | } |
| 2908 | apex_key { |
| 2909 | name: "myapex.key", |
| 2910 | public_key: "testkey.avbpubkey", |
| 2911 | private_key: "testkey.pem", |
| 2912 | } |
| 2913 | android_app_certificate { |
| 2914 | name: "myapex.certificate.override", |
| 2915 | certificate: "testkey.override", |
| 2916 | }`) |
| 2917 | rule := ctx.ModuleForTests("myapex_keytest", "android_common_myapex_keytest_image").Rule("signapk") |
| 2918 | expected := "testkey.override.x509.pem testkey.override.pk8" |
| 2919 | if actual := rule.Args["certificates"]; actual != expected { |
| 2920 | t.Errorf("certificates should be %q, not %q", expected, actual) |
| 2921 | } |
| 2922 | }) |
| 2923 | } |
| 2924 | |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2925 | func TestMacro(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 2926 | ctx := testApex(t, ` |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2927 | apex { |
| 2928 | name: "myapex", |
| 2929 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2930 | native_shared_libs: ["mylib", "mylib2"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 2931 | updatable: false, |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2932 | } |
| 2933 | |
| 2934 | apex { |
| 2935 | name: "otherapex", |
| 2936 | key: "myapex.key", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2937 | native_shared_libs: ["mylib", "mylib2"], |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2938 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2939 | } |
| 2940 | |
| 2941 | apex_key { |
| 2942 | name: "myapex.key", |
| 2943 | public_key: "testkey.avbpubkey", |
| 2944 | private_key: "testkey.pem", |
| 2945 | } |
| 2946 | |
| 2947 | cc_library { |
| 2948 | name: "mylib", |
| 2949 | srcs: ["mylib.cpp"], |
| 2950 | system_shared_libs: [], |
| 2951 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2952 | apex_available: [ |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 2953 | "myapex", |
| 2954 | "otherapex", |
| 2955 | ], |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 2956 | recovery_available: true, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2957 | min_sdk_version: "29", |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2958 | } |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2959 | cc_library { |
| 2960 | name: "mylib2", |
| 2961 | srcs: ["mylib.cpp"], |
| 2962 | system_shared_libs: [], |
| 2963 | stl: "none", |
| 2964 | apex_available: [ |
| 2965 | "myapex", |
| 2966 | "otherapex", |
| 2967 | ], |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2968 | static_libs: ["mylib3"], |
| 2969 | recovery_available: true, |
| 2970 | min_sdk_version: "29", |
| 2971 | } |
| 2972 | cc_library { |
| 2973 | name: "mylib3", |
| 2974 | srcs: ["mylib.cpp"], |
| 2975 | system_shared_libs: [], |
| 2976 | stl: "none", |
| 2977 | apex_available: [ |
| 2978 | "myapex", |
| 2979 | "otherapex", |
| 2980 | ], |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2981 | use_apex_name_macro: true, |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2982 | recovery_available: true, |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 2983 | min_sdk_version: "29", |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2984 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 2985 | `) |
| 2986 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2987 | // non-APEX variant does not have __ANDROID_APEX__ defined |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 2988 | 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] | 2989 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 2990 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2991 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2992 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2993 | 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] | 2994 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 2995 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__=10000") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 2996 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 2997 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 2998 | // APEX variant has __ANDROID_APEX__ and __ANDROID_APEX_SDK__ defined |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2999 | 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] | 3000 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3001 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__=29") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 3002 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3003 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3004 | // When a cc_library sets use_apex_name_macro: true each apex gets a unique variant and |
| 3005 | // each variant defines additional macros to distinguish which apex variant it is built for |
| 3006 | |
| 3007 | // non-APEX variant does not have __ANDROID_APEX__ defined |
| 3008 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 3009 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3010 | |
| 3011 | // APEX variant has __ANDROID_APEX__ defined |
| 3012 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
| 3013 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3014 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 3015 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
| 3016 | |
| 3017 | // APEX variant has __ANDROID_APEX__ defined |
| 3018 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"] |
| 3019 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3020 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
| 3021 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
| 3022 | |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3023 | // recovery variant does not set __ANDROID_APEX_MIN_SDK_VERSION__ |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3024 | mylibCFlags = ctx.ModuleForTests("mylib3", "android_recovery_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 3025 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3026 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3027 | |
| 3028 | // When a dependency of a cc_library sets use_apex_name_macro: true each apex gets a unique |
| 3029 | // variant. |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3030 | |
| 3031 | // non-APEX variant does not have __ANDROID_APEX__ defined |
| 3032 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"] |
| 3033 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
| 3034 | |
| 3035 | // APEX variant has __ANDROID_APEX__ defined |
| 3036 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_myapex").Rule("cc").Args["cFlags"] |
Jooyung Han | 6b8459b | 2019-10-30 08:29:25 +0900 | [diff] [blame] | 3037 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3038 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 3039 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3040 | |
Jooyung Han | c87a059 | 2020-03-02 17:44:33 +0900 | [diff] [blame] | 3041 | // APEX variant has __ANDROID_APEX__ defined |
| 3042 | mylibCFlags = ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_static_otherapex").Rule("cc").Args["cFlags"] |
Jooyung Han | 6b8459b | 2019-10-30 08:29:25 +0900 | [diff] [blame] | 3043 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Jooyung Han | 7798857 | 2019-10-18 16:26:16 +0900 | [diff] [blame] | 3044 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MYAPEX__") |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3045 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_OTHERAPEX__") |
Jooyung Han | 2428277 | 2020-03-21 23:20:55 +0900 | [diff] [blame] | 3046 | |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3047 | // recovery variant does not set __ANDROID_APEX_MIN_SDK_VERSION__ |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3048 | 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] | 3049 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__") |
Dan Albert | b19953d | 2020-11-17 15:29:36 -0800 | [diff] [blame] | 3050 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX_MIN_SDK_VERSION__") |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 3051 | } |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3052 | |
| 3053 | func TestHeaderLibsDependency(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3054 | ctx := testApex(t, ` |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3055 | apex { |
| 3056 | name: "myapex", |
| 3057 | key: "myapex.key", |
| 3058 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3059 | updatable: false, |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3060 | } |
| 3061 | |
| 3062 | apex_key { |
| 3063 | name: "myapex.key", |
| 3064 | public_key: "testkey.avbpubkey", |
| 3065 | private_key: "testkey.pem", |
| 3066 | } |
| 3067 | |
| 3068 | cc_library_headers { |
| 3069 | name: "mylib_headers", |
| 3070 | export_include_dirs: ["my_include"], |
| 3071 | system_shared_libs: [], |
| 3072 | stl: "none", |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 3073 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3074 | } |
| 3075 | |
| 3076 | cc_library { |
| 3077 | name: "mylib", |
| 3078 | srcs: ["mylib.cpp"], |
| 3079 | system_shared_libs: [], |
| 3080 | stl: "none", |
| 3081 | header_libs: ["mylib_headers"], |
| 3082 | export_header_lib_headers: ["mylib_headers"], |
| 3083 | stubs: { |
| 3084 | versions: ["1", "2", "3"], |
| 3085 | }, |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3086 | apex_available: [ "myapex" ], |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 3087 | } |
| 3088 | |
| 3089 | cc_library { |
| 3090 | name: "otherlib", |
| 3091 | srcs: ["mylib.cpp"], |
| 3092 | system_shared_libs: [], |
| 3093 | stl: "none", |
| 3094 | shared_libs: ["mylib"], |
| 3095 | } |
| 3096 | `) |
| 3097 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3098 | 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] | 3099 | |
| 3100 | // Ensure that the include path of the header lib is exported to 'otherlib' |
| 3101 | ensureContains(t, cFlags, "-Imy_include") |
| 3102 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3103 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3104 | type fileInApex struct { |
| 3105 | path string // path in apex |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3106 | src string // src path |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3107 | isLink bool |
| 3108 | } |
| 3109 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3110 | func getFiles(t *testing.T, ctx *android.TestContext, moduleName, variant string) []fileInApex { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3111 | t.Helper() |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3112 | apexRule := ctx.ModuleForTests(moduleName, variant).Rule("apexRule") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3113 | copyCmds := apexRule.Args["copy_commands"] |
| 3114 | imageApexDir := "/image.apex/" |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3115 | var ret []fileInApex |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3116 | for _, cmd := range strings.Split(copyCmds, "&&") { |
| 3117 | cmd = strings.TrimSpace(cmd) |
| 3118 | if cmd == "" { |
| 3119 | continue |
| 3120 | } |
| 3121 | terms := strings.Split(cmd, " ") |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3122 | var dst, src string |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3123 | var isLink bool |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3124 | switch terms[0] { |
| 3125 | case "mkdir": |
| 3126 | case "cp": |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3127 | if len(terms) != 3 && len(terms) != 4 { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3128 | t.Fatal("copyCmds contains invalid cp command", cmd) |
| 3129 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3130 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3131 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3132 | isLink = false |
| 3133 | case "ln": |
| 3134 | if len(terms) != 3 && len(terms) != 4 { |
| 3135 | // ln LINK TARGET or ln -s LINK TARGET |
| 3136 | t.Fatal("copyCmds contains invalid ln command", cmd) |
| 3137 | } |
| 3138 | dst = terms[len(terms)-1] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3139 | src = terms[len(terms)-2] |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3140 | isLink = true |
| 3141 | default: |
| 3142 | t.Fatalf("copyCmds should contain mkdir/cp commands only: %q", cmd) |
| 3143 | } |
| 3144 | if dst != "" { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3145 | index := strings.Index(dst, imageApexDir) |
| 3146 | if index == -1 { |
| 3147 | t.Fatal("copyCmds should copy a file to image.apex/", cmd) |
| 3148 | } |
| 3149 | dstFile := dst[index+len(imageApexDir):] |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3150 | ret = append(ret, fileInApex{path: dstFile, src: src, isLink: isLink}) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3151 | } |
| 3152 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3153 | return ret |
| 3154 | } |
| 3155 | |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3156 | func ensureExactContents(t *testing.T, ctx *android.TestContext, moduleName, variant string, files []string) { |
| 3157 | t.Helper() |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3158 | var failed bool |
| 3159 | var surplus []string |
| 3160 | filesMatched := make(map[string]bool) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3161 | for _, file := range getFiles(t, ctx, moduleName, variant) { |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3162 | mactchFound := false |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3163 | for _, expected := range files { |
| 3164 | if matched, _ := path.Match(expected, file.path); matched { |
| 3165 | filesMatched[expected] = true |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3166 | mactchFound = true |
| 3167 | break |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3168 | } |
| 3169 | } |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3170 | if !mactchFound { |
| 3171 | surplus = append(surplus, file.path) |
| 3172 | } |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 3173 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3174 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3175 | if len(surplus) > 0 { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3176 | sort.Strings(surplus) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3177 | t.Log("surplus files", surplus) |
| 3178 | failed = true |
| 3179 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3180 | |
| 3181 | if len(files) > len(filesMatched) { |
| 3182 | var missing []string |
| 3183 | for _, expected := range files { |
| 3184 | if !filesMatched[expected] { |
| 3185 | missing = append(missing, expected) |
| 3186 | } |
| 3187 | } |
| 3188 | sort.Strings(missing) |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3189 | t.Log("missing files", missing) |
| 3190 | failed = true |
| 3191 | } |
| 3192 | if failed { |
| 3193 | t.Fail() |
| 3194 | } |
| 3195 | } |
| 3196 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3197 | func TestVndkApexCurrent(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3198 | ctx := testApex(t, ` |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3199 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3200 | name: "com.android.vndk.current", |
| 3201 | key: "com.android.vndk.current.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3202 | updatable: false, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3203 | } |
| 3204 | |
| 3205 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3206 | name: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3207 | public_key: "testkey.avbpubkey", |
| 3208 | private_key: "testkey.pem", |
| 3209 | } |
| 3210 | |
| 3211 | cc_library { |
| 3212 | name: "libvndk", |
| 3213 | srcs: ["mylib.cpp"], |
| 3214 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3215 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3216 | vndk: { |
| 3217 | enabled: true, |
| 3218 | }, |
| 3219 | system_shared_libs: [], |
| 3220 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3221 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3222 | } |
| 3223 | |
| 3224 | cc_library { |
| 3225 | name: "libvndksp", |
| 3226 | srcs: ["mylib.cpp"], |
| 3227 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3228 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3229 | vndk: { |
| 3230 | enabled: true, |
| 3231 | support_system_process: true, |
| 3232 | }, |
| 3233 | system_shared_libs: [], |
| 3234 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3235 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3236 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3237 | `+vndkLibrariesTxtFiles("current")) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3238 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3239 | ensureExactContents(t, ctx, "com.android.vndk.current", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3240 | "lib/libvndk.so", |
| 3241 | "lib/libvndksp.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3242 | "lib/libc++.so", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3243 | "lib64/libvndk.so", |
| 3244 | "lib64/libvndksp.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3245 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3246 | "etc/llndk.libraries.VER.txt", |
| 3247 | "etc/vndkcore.libraries.VER.txt", |
| 3248 | "etc/vndksp.libraries.VER.txt", |
| 3249 | "etc/vndkprivate.libraries.VER.txt", |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3250 | "etc/vndkproduct.libraries.VER.txt", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3251 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3252 | } |
| 3253 | |
| 3254 | func TestVndkApexWithPrebuilt(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3255 | ctx := testApex(t, ` |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3256 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3257 | name: "com.android.vndk.current", |
| 3258 | key: "com.android.vndk.current.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3259 | updatable: false, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3260 | } |
| 3261 | |
| 3262 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3263 | name: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3264 | public_key: "testkey.avbpubkey", |
| 3265 | private_key: "testkey.pem", |
| 3266 | } |
| 3267 | |
| 3268 | cc_prebuilt_library_shared { |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3269 | name: "libvndk", |
| 3270 | srcs: ["libvndk.so"], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3271 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3272 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3273 | vndk: { |
| 3274 | enabled: true, |
| 3275 | }, |
| 3276 | system_shared_libs: [], |
| 3277 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3278 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3279 | } |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3280 | |
| 3281 | cc_prebuilt_library_shared { |
| 3282 | name: "libvndk.arm", |
| 3283 | srcs: ["libvndk.arm.so"], |
| 3284 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3285 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3286 | vndk: { |
| 3287 | enabled: true, |
| 3288 | }, |
| 3289 | enabled: false, |
| 3290 | arch: { |
| 3291 | arm: { |
| 3292 | enabled: true, |
| 3293 | }, |
| 3294 | }, |
| 3295 | system_shared_libs: [], |
| 3296 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3297 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3298 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3299 | `+vndkLibrariesTxtFiles("current"), |
| 3300 | withFiles(map[string][]byte{ |
| 3301 | "libvndk.so": nil, |
| 3302 | "libvndk.arm.so": nil, |
| 3303 | })) |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3304 | ensureExactContents(t, ctx, "com.android.vndk.current", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3305 | "lib/libvndk.so", |
| 3306 | "lib/libvndk.arm.so", |
| 3307 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3308 | "lib/libc++.so", |
| 3309 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3310 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3311 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3312 | } |
| 3313 | |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3314 | func vndkLibrariesTxtFiles(vers ...string) (result string) { |
| 3315 | for _, v := range vers { |
| 3316 | if v == "current" { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3317 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate", "vndkproduct"} { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3318 | result += ` |
Colin Cross | e4e44bc | 2020-12-28 13:50:21 -0800 | [diff] [blame] | 3319 | ` + txt + `_libraries_txt { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3320 | name: "` + txt + `.libraries.txt", |
| 3321 | } |
| 3322 | ` |
| 3323 | } |
| 3324 | } else { |
Justin Yun | 8a2600c | 2020-12-07 12:44:03 +0900 | [diff] [blame] | 3325 | for _, txt := range []string{"llndk", "vndkcore", "vndksp", "vndkprivate", "vndkproduct"} { |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3326 | result += ` |
| 3327 | prebuilt_etc { |
| 3328 | name: "` + txt + `.libraries.` + v + `.txt", |
| 3329 | src: "dummy.txt", |
| 3330 | } |
| 3331 | ` |
| 3332 | } |
| 3333 | } |
| 3334 | } |
| 3335 | return |
| 3336 | } |
| 3337 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3338 | func TestVndkApexVersion(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3339 | ctx := testApex(t, ` |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3340 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3341 | name: "com.android.vndk.v27", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3342 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3343 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3344 | vndk_version: "27", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3345 | updatable: false, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3346 | } |
| 3347 | |
| 3348 | apex_key { |
| 3349 | name: "myapex.key", |
| 3350 | public_key: "testkey.avbpubkey", |
| 3351 | private_key: "testkey.pem", |
| 3352 | } |
| 3353 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3354 | vndk_prebuilt_shared { |
| 3355 | name: "libvndk27", |
| 3356 | version: "27", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3357 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3358 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3359 | vndk: { |
| 3360 | enabled: true, |
| 3361 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3362 | target_arch: "arm64", |
| 3363 | arch: { |
| 3364 | arm: { |
| 3365 | srcs: ["libvndk27_arm.so"], |
| 3366 | }, |
| 3367 | arm64: { |
| 3368 | srcs: ["libvndk27_arm64.so"], |
| 3369 | }, |
| 3370 | }, |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3371 | apex_available: [ "com.android.vndk.v27" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3372 | } |
| 3373 | |
| 3374 | vndk_prebuilt_shared { |
| 3375 | name: "libvndk27", |
| 3376 | version: "27", |
| 3377 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3378 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3379 | vndk: { |
| 3380 | enabled: true, |
| 3381 | }, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3382 | target_arch: "x86_64", |
| 3383 | arch: { |
| 3384 | x86: { |
| 3385 | srcs: ["libvndk27_x86.so"], |
| 3386 | }, |
| 3387 | x86_64: { |
| 3388 | srcs: ["libvndk27_x86_64.so"], |
| 3389 | }, |
| 3390 | }, |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3391 | } |
| 3392 | `+vndkLibrariesTxtFiles("27"), |
| 3393 | withFiles(map[string][]byte{ |
| 3394 | "libvndk27_arm.so": nil, |
| 3395 | "libvndk27_arm64.so": nil, |
| 3396 | "libvndk27_x86.so": nil, |
| 3397 | "libvndk27_x86_64.so": nil, |
| 3398 | })) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3399 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3400 | ensureExactContents(t, ctx, "com.android.vndk.v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3401 | "lib/libvndk27_arm.so", |
| 3402 | "lib64/libvndk27_arm64.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3403 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3404 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3405 | } |
| 3406 | |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3407 | func TestVndkApexNameRule(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3408 | ctx := testApex(t, ` |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3409 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3410 | name: "com.android.vndk.current", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3411 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3412 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3413 | updatable: false, |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3414 | } |
| 3415 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3416 | name: "com.android.vndk.v28", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3417 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3418 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3419 | vndk_version: "28", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3420 | updatable: false, |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3421 | } |
| 3422 | apex_key { |
| 3423 | name: "myapex.key", |
| 3424 | public_key: "testkey.avbpubkey", |
| 3425 | private_key: "testkey.pem", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3426 | }`+vndkLibrariesTxtFiles("28", "current")) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3427 | |
| 3428 | assertApexName := func(expected, moduleName string) { |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 3429 | bundle := ctx.ModuleForTests(moduleName, "android_common_image").Module().(*apexBundle) |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3430 | actual := proptools.String(bundle.properties.Apex_name) |
| 3431 | if !reflect.DeepEqual(actual, expected) { |
| 3432 | t.Errorf("Got '%v', expected '%v'", actual, expected) |
| 3433 | } |
| 3434 | } |
| 3435 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3436 | assertApexName("com.android.vndk.vVER", "com.android.vndk.current") |
| 3437 | assertApexName("com.android.vndk.v28", "com.android.vndk.v28") |
Jooyung Han | 90eee02 | 2019-10-01 20:02:42 +0900 | [diff] [blame] | 3438 | } |
| 3439 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3440 | func TestVndkApexSkipsNativeBridgeSupportedModules(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3441 | ctx := testApex(t, ` |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3442 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3443 | name: "com.android.vndk.current", |
| 3444 | key: "com.android.vndk.current.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3445 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3446 | updatable: false, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3447 | } |
| 3448 | |
| 3449 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3450 | name: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3451 | public_key: "testkey.avbpubkey", |
| 3452 | private_key: "testkey.pem", |
| 3453 | } |
| 3454 | |
| 3455 | cc_library { |
| 3456 | name: "libvndk", |
| 3457 | srcs: ["mylib.cpp"], |
| 3458 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3459 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3460 | native_bridge_supported: true, |
| 3461 | host_supported: true, |
| 3462 | vndk: { |
| 3463 | enabled: true, |
| 3464 | }, |
| 3465 | system_shared_libs: [], |
| 3466 | stl: "none", |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3467 | apex_available: [ "com.android.vndk.current" ], |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3468 | } |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3469 | `+vndkLibrariesTxtFiles("current"), |
| 3470 | withNativeBridgeEnabled) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3471 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3472 | ensureExactContents(t, ctx, "com.android.vndk.current", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3473 | "lib/libvndk.so", |
| 3474 | "lib64/libvndk.so", |
Jooyung Han | e6436d7 | 2020-02-27 13:31:56 +0900 | [diff] [blame] | 3475 | "lib/libc++.so", |
| 3476 | "lib64/libc++.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3477 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3478 | }) |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3479 | } |
| 3480 | |
| 3481 | func TestVndkApexDoesntSupportNativeBridgeSupported(t *testing.T) { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3482 | 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] | 3483 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3484 | name: "com.android.vndk.current", |
| 3485 | key: "com.android.vndk.current.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3486 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3487 | native_bridge_supported: true, |
| 3488 | } |
| 3489 | |
| 3490 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3491 | name: "com.android.vndk.current.key", |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3492 | public_key: "testkey.avbpubkey", |
| 3493 | private_key: "testkey.pem", |
| 3494 | } |
| 3495 | |
| 3496 | cc_library { |
| 3497 | name: "libvndk", |
| 3498 | srcs: ["mylib.cpp"], |
| 3499 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3500 | product_available: true, |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 3501 | native_bridge_supported: true, |
| 3502 | host_supported: true, |
| 3503 | vndk: { |
| 3504 | enabled: true, |
| 3505 | }, |
| 3506 | system_shared_libs: [], |
| 3507 | stl: "none", |
| 3508 | } |
| 3509 | `) |
| 3510 | } |
| 3511 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3512 | func TestVndkApexWithBinder32(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3513 | ctx := testApex(t, ` |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3514 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3515 | name: "com.android.vndk.v27", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3516 | key: "myapex.key", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3517 | file_contexts: ":myapex-file_contexts", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3518 | vndk_version: "27", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3519 | updatable: false, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | apex_key { |
| 3523 | name: "myapex.key", |
| 3524 | public_key: "testkey.avbpubkey", |
| 3525 | private_key: "testkey.pem", |
| 3526 | } |
| 3527 | |
| 3528 | vndk_prebuilt_shared { |
| 3529 | name: "libvndk27", |
| 3530 | version: "27", |
| 3531 | target_arch: "arm", |
| 3532 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3533 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3534 | vndk: { |
| 3535 | enabled: true, |
| 3536 | }, |
| 3537 | arch: { |
| 3538 | arm: { |
| 3539 | srcs: ["libvndk27.so"], |
| 3540 | } |
| 3541 | }, |
| 3542 | } |
| 3543 | |
| 3544 | vndk_prebuilt_shared { |
| 3545 | name: "libvndk27", |
| 3546 | version: "27", |
| 3547 | target_arch: "arm", |
| 3548 | binder32bit: true, |
| 3549 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3550 | product_available: true, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3551 | vndk: { |
| 3552 | enabled: true, |
| 3553 | }, |
| 3554 | arch: { |
| 3555 | arm: { |
| 3556 | srcs: ["libvndk27binder32.so"], |
| 3557 | } |
| 3558 | }, |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3559 | apex_available: [ "com.android.vndk.v27" ], |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3560 | } |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3561 | `+vndkLibrariesTxtFiles("27"), |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3562 | withFiles(map[string][]byte{ |
| 3563 | "libvndk27.so": nil, |
| 3564 | "libvndk27binder32.so": nil, |
| 3565 | }), |
| 3566 | withBinder32bit, |
| 3567 | withTargets(map[android.OsType][]android.Target{ |
| 3568 | android.Android: []android.Target{ |
Jooyung Han | 35155c4 | 2020-02-06 17:33:20 +0900 | [diff] [blame] | 3569 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}, |
| 3570 | NativeBridge: android.NativeBridgeDisabled, NativeBridgeHostArchName: "", NativeBridgeRelativePath: ""}, |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3571 | }, |
| 3572 | }), |
| 3573 | ) |
| 3574 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3575 | ensureExactContents(t, ctx, "com.android.vndk.v27", "android_common_image", []string{ |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3576 | "lib/libvndk27binder32.so", |
Jooyung Han | 39edb6c | 2019-11-06 16:53:07 +0900 | [diff] [blame] | 3577 | "etc/*", |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 3578 | }) |
| 3579 | } |
| 3580 | |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3581 | func TestVndkApexShouldNotProvideNativeLibs(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3582 | ctx := testApex(t, ` |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3583 | apex_vndk { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3584 | name: "com.android.vndk.current", |
| 3585 | key: "com.android.vndk.current.key", |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3586 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3587 | updatable: false, |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3588 | } |
| 3589 | |
| 3590 | apex_key { |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3591 | name: "com.android.vndk.current.key", |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3592 | public_key: "testkey.avbpubkey", |
| 3593 | private_key: "testkey.pem", |
| 3594 | } |
| 3595 | |
| 3596 | cc_library { |
| 3597 | name: "libz", |
| 3598 | vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 3599 | product_available: true, |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3600 | vndk: { |
| 3601 | enabled: true, |
| 3602 | }, |
| 3603 | stubs: { |
| 3604 | symbol_file: "libz.map.txt", |
| 3605 | versions: ["30"], |
| 3606 | } |
| 3607 | } |
| 3608 | `+vndkLibrariesTxtFiles("current"), withFiles(map[string][]byte{ |
| 3609 | "libz.map.txt": nil, |
| 3610 | })) |
| 3611 | |
Colin Cross | 2807f00 | 2021-03-02 10:15:29 -0800 | [diff] [blame] | 3612 | apexManifestRule := ctx.ModuleForTests("com.android.vndk.current", "android_common_image").Rule("apexManifestRule") |
Jooyung Han | 45a9677 | 2020-06-15 14:59:42 +0900 | [diff] [blame] | 3613 | provideNativeLibs := names(apexManifestRule.Args["provideNativeLibs"]) |
| 3614 | ensureListEmpty(t, provideNativeLibs) |
| 3615 | } |
| 3616 | |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3617 | func TestDependenciesInApexManifest(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3618 | ctx := testApex(t, ` |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3619 | apex { |
| 3620 | name: "myapex_nodep", |
| 3621 | key: "myapex.key", |
| 3622 | native_shared_libs: ["lib_nodep"], |
| 3623 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3624 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3625 | updatable: false, |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3626 | } |
| 3627 | |
| 3628 | apex { |
| 3629 | name: "myapex_dep", |
| 3630 | key: "myapex.key", |
| 3631 | native_shared_libs: ["lib_dep"], |
| 3632 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3633 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3634 | updatable: false, |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3635 | } |
| 3636 | |
| 3637 | apex { |
| 3638 | name: "myapex_provider", |
| 3639 | key: "myapex.key", |
| 3640 | native_shared_libs: ["libfoo"], |
| 3641 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3642 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3643 | updatable: false, |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3644 | } |
| 3645 | |
| 3646 | apex { |
| 3647 | name: "myapex_selfcontained", |
| 3648 | key: "myapex.key", |
| 3649 | native_shared_libs: ["lib_dep", "libfoo"], |
| 3650 | compile_multilib: "both", |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 3651 | file_contexts: ":myapex-file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3652 | updatable: false, |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3653 | } |
| 3654 | |
| 3655 | apex_key { |
| 3656 | name: "myapex.key", |
| 3657 | public_key: "testkey.avbpubkey", |
| 3658 | private_key: "testkey.pem", |
| 3659 | } |
| 3660 | |
| 3661 | cc_library { |
| 3662 | name: "lib_nodep", |
| 3663 | srcs: ["mylib.cpp"], |
| 3664 | system_shared_libs: [], |
| 3665 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3666 | apex_available: [ "myapex_nodep" ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3667 | } |
| 3668 | |
| 3669 | cc_library { |
| 3670 | name: "lib_dep", |
| 3671 | srcs: ["mylib.cpp"], |
| 3672 | shared_libs: ["libfoo"], |
| 3673 | system_shared_libs: [], |
| 3674 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3675 | apex_available: [ |
| 3676 | "myapex_dep", |
| 3677 | "myapex_provider", |
| 3678 | "myapex_selfcontained", |
| 3679 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3680 | } |
| 3681 | |
| 3682 | cc_library { |
| 3683 | name: "libfoo", |
| 3684 | srcs: ["mytest.cpp"], |
| 3685 | stubs: { |
| 3686 | versions: ["1"], |
| 3687 | }, |
| 3688 | system_shared_libs: [], |
| 3689 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3690 | apex_available: [ |
| 3691 | "myapex_provider", |
| 3692 | "myapex_selfcontained", |
| 3693 | ], |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3694 | } |
| 3695 | `) |
| 3696 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3697 | var apexManifestRule android.TestingBuildParams |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3698 | var provideNativeLibs, requireNativeLibs []string |
| 3699 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3700 | apexManifestRule = ctx.ModuleForTests("myapex_nodep", "android_common_myapex_nodep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3701 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3702 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3703 | ensureListEmpty(t, provideNativeLibs) |
| 3704 | ensureListEmpty(t, requireNativeLibs) |
| 3705 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3706 | apexManifestRule = ctx.ModuleForTests("myapex_dep", "android_common_myapex_dep_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3707 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3708 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3709 | ensureListEmpty(t, provideNativeLibs) |
| 3710 | ensureListContains(t, requireNativeLibs, "libfoo.so") |
| 3711 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3712 | apexManifestRule = ctx.ModuleForTests("myapex_provider", "android_common_myapex_provider_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3713 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3714 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3715 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 3716 | ensureListEmpty(t, requireNativeLibs) |
| 3717 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3718 | apexManifestRule = ctx.ModuleForTests("myapex_selfcontained", "android_common_myapex_selfcontained_image").Rule("apexManifestRule") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3719 | provideNativeLibs = names(apexManifestRule.Args["provideNativeLibs"]) |
| 3720 | requireNativeLibs = names(apexManifestRule.Args["requireNativeLibs"]) |
Jooyung Han | e163303 | 2019-08-01 17:41:43 +0900 | [diff] [blame] | 3721 | ensureListContains(t, provideNativeLibs, "libfoo.so") |
| 3722 | ensureListEmpty(t, requireNativeLibs) |
| 3723 | } |
| 3724 | |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3725 | func TestApexName(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3726 | ctx := testApex(t, ` |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3727 | apex { |
| 3728 | name: "myapex", |
| 3729 | key: "myapex.key", |
| 3730 | apex_name: "com.android.myapex", |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3731 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3732 | updatable: false, |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3733 | } |
| 3734 | |
| 3735 | apex_key { |
| 3736 | name: "myapex.key", |
| 3737 | public_key: "testkey.avbpubkey", |
| 3738 | private_key: "testkey.pem", |
| 3739 | } |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3740 | |
| 3741 | cc_library { |
| 3742 | name: "mylib", |
| 3743 | srcs: ["mylib.cpp"], |
| 3744 | system_shared_libs: [], |
| 3745 | stl: "none", |
| 3746 | apex_available: [ |
| 3747 | "//apex_available:platform", |
| 3748 | "myapex", |
| 3749 | ], |
| 3750 | } |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3751 | `) |
| 3752 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3753 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3754 | apexManifestRule := module.Rule("apexManifestRule") |
| 3755 | ensureContains(t, apexManifestRule.Args["opt"], "-v name com.android.myapex") |
| 3756 | apexRule := module.Rule("apexRule") |
| 3757 | ensureContains(t, apexRule.Args["opt_flags"], "--do_not_check_keyname") |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3758 | |
| 3759 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 3760 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jiyong Park | db33486 | 2020-02-05 17:19:28 +0900 | [diff] [blame] | 3761 | name := apexBundle.BaseModuleName() |
| 3762 | prefix := "TARGET_" |
| 3763 | var builder strings.Builder |
| 3764 | data.Custom(&builder, name, prefix, "", data) |
| 3765 | androidMk := builder.String() |
| 3766 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 3767 | ensureNotContains(t, androidMk, "LOCAL_MODULE := mylib.com.android.myapex\n") |
Jooyung Han | d15aa1f | 2019-09-27 00:38:03 +0900 | [diff] [blame] | 3768 | } |
| 3769 | |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3770 | func TestNonTestApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3771 | ctx := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3772 | apex { |
| 3773 | name: "myapex", |
| 3774 | key: "myapex.key", |
| 3775 | native_shared_libs: ["mylib_common"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3776 | updatable: false, |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3777 | } |
| 3778 | |
| 3779 | apex_key { |
| 3780 | name: "myapex.key", |
| 3781 | public_key: "testkey.avbpubkey", |
| 3782 | private_key: "testkey.pem", |
| 3783 | } |
| 3784 | |
| 3785 | cc_library { |
| 3786 | name: "mylib_common", |
| 3787 | srcs: ["mylib.cpp"], |
| 3788 | system_shared_libs: [], |
| 3789 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3790 | apex_available: [ |
| 3791 | "//apex_available:platform", |
| 3792 | "myapex", |
| 3793 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3794 | } |
| 3795 | `) |
| 3796 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3797 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3798 | apexRule := module.Rule("apexRule") |
| 3799 | copyCmds := apexRule.Args["copy_commands"] |
| 3800 | |
| 3801 | if apex, ok := module.Module().(*apexBundle); !ok || apex.testApex { |
| 3802 | t.Log("Apex was a test apex!") |
| 3803 | t.Fail() |
| 3804 | } |
| 3805 | // Ensure that main rule creates an output |
| 3806 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3807 | |
| 3808 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3809 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3810 | |
| 3811 | // Ensure that both direct and indirect deps are copied into apex |
| 3812 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 3813 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3814 | // Ensure that the platform variant ends with _shared |
| 3815 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3816 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame] | 3817 | 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] | 3818 | t.Log("Found mylib_common not in any apex!") |
| 3819 | t.Fail() |
| 3820 | } |
| 3821 | } |
| 3822 | |
| 3823 | func TestTestApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3824 | ctx := testApex(t, ` |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3825 | apex_test { |
| 3826 | name: "myapex", |
| 3827 | key: "myapex.key", |
| 3828 | native_shared_libs: ["mylib_common_test"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3829 | updatable: false, |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3830 | } |
| 3831 | |
| 3832 | apex_key { |
| 3833 | name: "myapex.key", |
| 3834 | public_key: "testkey.avbpubkey", |
| 3835 | private_key: "testkey.pem", |
| 3836 | } |
| 3837 | |
| 3838 | cc_library { |
| 3839 | name: "mylib_common_test", |
| 3840 | srcs: ["mylib.cpp"], |
| 3841 | system_shared_libs: [], |
| 3842 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3843 | // TODO: remove //apex_available:platform |
| 3844 | apex_available: [ |
| 3845 | "//apex_available:platform", |
| 3846 | "myapex", |
| 3847 | ], |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3848 | } |
| 3849 | `) |
| 3850 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3851 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3852 | apexRule := module.Rule("apexRule") |
| 3853 | copyCmds := apexRule.Args["copy_commands"] |
| 3854 | |
| 3855 | if apex, ok := module.Module().(*apexBundle); !ok || !apex.testApex { |
| 3856 | t.Log("Apex was not a test apex!") |
| 3857 | t.Fail() |
| 3858 | } |
| 3859 | // Ensure that main rule creates an output |
| 3860 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3861 | |
| 3862 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3863 | 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] | 3864 | |
| 3865 | // Ensure that both direct and indirect deps are copied into apex |
| 3866 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common_test.so") |
| 3867 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3868 | // Ensure that the platform variant ends with _shared |
| 3869 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common_test"), "android_arm64_armv8-a_shared") |
Alex Light | 0851b88 | 2019-02-07 13:20:53 -0800 | [diff] [blame] | 3870 | } |
| 3871 | |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3872 | func TestApexWithTarget(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3873 | ctx := testApex(t, ` |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3874 | apex { |
| 3875 | name: "myapex", |
| 3876 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3877 | updatable: false, |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3878 | multilib: { |
| 3879 | first: { |
| 3880 | native_shared_libs: ["mylib_common"], |
| 3881 | } |
| 3882 | }, |
| 3883 | target: { |
| 3884 | android: { |
| 3885 | multilib: { |
| 3886 | first: { |
| 3887 | native_shared_libs: ["mylib"], |
| 3888 | } |
| 3889 | } |
| 3890 | }, |
| 3891 | host: { |
| 3892 | multilib: { |
| 3893 | first: { |
| 3894 | native_shared_libs: ["mylib2"], |
| 3895 | } |
| 3896 | } |
| 3897 | } |
| 3898 | } |
| 3899 | } |
| 3900 | |
| 3901 | apex_key { |
| 3902 | name: "myapex.key", |
| 3903 | public_key: "testkey.avbpubkey", |
| 3904 | private_key: "testkey.pem", |
| 3905 | } |
| 3906 | |
| 3907 | cc_library { |
| 3908 | name: "mylib", |
| 3909 | srcs: ["mylib.cpp"], |
| 3910 | system_shared_libs: [], |
| 3911 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3912 | // TODO: remove //apex_available:platform |
| 3913 | apex_available: [ |
| 3914 | "//apex_available:platform", |
| 3915 | "myapex", |
| 3916 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3917 | } |
| 3918 | |
| 3919 | cc_library { |
| 3920 | name: "mylib_common", |
| 3921 | srcs: ["mylib.cpp"], |
| 3922 | system_shared_libs: [], |
| 3923 | stl: "none", |
| 3924 | compile_multilib: "first", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 3925 | // TODO: remove //apex_available:platform |
| 3926 | apex_available: [ |
| 3927 | "//apex_available:platform", |
| 3928 | "myapex", |
| 3929 | ], |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3930 | } |
| 3931 | |
| 3932 | cc_library { |
| 3933 | name: "mylib2", |
| 3934 | srcs: ["mylib.cpp"], |
| 3935 | system_shared_libs: [], |
| 3936 | stl: "none", |
| 3937 | compile_multilib: "first", |
| 3938 | } |
| 3939 | `) |
| 3940 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 3941 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3942 | copyCmds := apexRule.Args["copy_commands"] |
| 3943 | |
| 3944 | // Ensure that main rule creates an output |
| 3945 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 3946 | |
| 3947 | // Ensure that apex variant is created for the direct dep |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3948 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared_apex10000") |
| 3949 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared_apex10000") |
| 3950 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared_apex10000") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3951 | |
| 3952 | // Ensure that both direct and indirect deps are copied into apex |
| 3953 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 3954 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 3955 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 3956 | |
Colin Cross | 7113d20 | 2019-11-20 16:39:12 -0800 | [diff] [blame] | 3957 | // Ensure that the platform variant ends with _shared |
| 3958 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_shared") |
| 3959 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_shared") |
| 3960 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_shared") |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 3961 | } |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 3962 | |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 3963 | func TestApexWithArch(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 3964 | ctx := testApex(t, ` |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 3965 | apex { |
| 3966 | name: "myapex", |
| 3967 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 3968 | updatable: false, |
Jiyong Park | 5914030 | 2020-12-14 18:44:04 +0900 | [diff] [blame] | 3969 | arch: { |
| 3970 | arm64: { |
| 3971 | native_shared_libs: ["mylib.arm64"], |
| 3972 | }, |
| 3973 | x86_64: { |
| 3974 | native_shared_libs: ["mylib.x64"], |
| 3975 | }, |
| 3976 | } |
| 3977 | } |
| 3978 | |
| 3979 | apex_key { |
| 3980 | name: "myapex.key", |
| 3981 | public_key: "testkey.avbpubkey", |
| 3982 | private_key: "testkey.pem", |
| 3983 | } |
| 3984 | |
| 3985 | cc_library { |
| 3986 | name: "mylib.arm64", |
| 3987 | srcs: ["mylib.cpp"], |
| 3988 | system_shared_libs: [], |
| 3989 | stl: "none", |
| 3990 | // TODO: remove //apex_available:platform |
| 3991 | apex_available: [ |
| 3992 | "//apex_available:platform", |
| 3993 | "myapex", |
| 3994 | ], |
| 3995 | } |
| 3996 | |
| 3997 | cc_library { |
| 3998 | name: "mylib.x64", |
| 3999 | srcs: ["mylib.cpp"], |
| 4000 | system_shared_libs: [], |
| 4001 | stl: "none", |
| 4002 | // TODO: remove //apex_available:platform |
| 4003 | apex_available: [ |
| 4004 | "//apex_available:platform", |
| 4005 | "myapex", |
| 4006 | ], |
| 4007 | } |
| 4008 | `) |
| 4009 | |
| 4010 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
| 4011 | copyCmds := apexRule.Args["copy_commands"] |
| 4012 | |
| 4013 | // Ensure that apex variant is created for the direct dep |
| 4014 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib.arm64"), "android_arm64_armv8-a_shared_apex10000") |
| 4015 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib.x64"), "android_arm64_armv8-a_shared_apex10000") |
| 4016 | |
| 4017 | // Ensure that both direct and indirect deps are copied into apex |
| 4018 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.arm64.so") |
| 4019 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib.x64.so") |
| 4020 | } |
| 4021 | |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4022 | func TestApexWithShBinary(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4023 | ctx := testApex(t, ` |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4024 | apex { |
| 4025 | name: "myapex", |
| 4026 | key: "myapex.key", |
| 4027 | binaries: ["myscript"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4028 | updatable: false, |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4029 | } |
| 4030 | |
| 4031 | apex_key { |
| 4032 | name: "myapex.key", |
| 4033 | public_key: "testkey.avbpubkey", |
| 4034 | private_key: "testkey.pem", |
| 4035 | } |
| 4036 | |
| 4037 | sh_binary { |
| 4038 | name: "myscript", |
| 4039 | src: "mylib.cpp", |
| 4040 | filename: "myscript.sh", |
| 4041 | sub_dir: "script", |
| 4042 | } |
| 4043 | `) |
| 4044 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4045 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 4046 | copyCmds := apexRule.Args["copy_commands"] |
| 4047 | |
| 4048 | ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh") |
| 4049 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4050 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4051 | func TestApexInVariousPartition(t *testing.T) { |
| 4052 | testcases := []struct { |
| 4053 | propName, parition, flattenedPartition string |
| 4054 | }{ |
| 4055 | {"", "system", "system_ext"}, |
| 4056 | {"product_specific: true", "product", "product"}, |
| 4057 | {"soc_specific: true", "vendor", "vendor"}, |
| 4058 | {"proprietary: true", "vendor", "vendor"}, |
| 4059 | {"vendor: true", "vendor", "vendor"}, |
| 4060 | {"system_ext_specific: true", "system_ext", "system_ext"}, |
| 4061 | } |
| 4062 | for _, tc := range testcases { |
| 4063 | t.Run(tc.propName+":"+tc.parition, func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4064 | ctx := testApex(t, ` |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4065 | apex { |
| 4066 | name: "myapex", |
| 4067 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4068 | updatable: false, |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4069 | `+tc.propName+` |
| 4070 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4071 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4072 | apex_key { |
| 4073 | name: "myapex.key", |
| 4074 | public_key: "testkey.avbpubkey", |
| 4075 | private_key: "testkey.pem", |
| 4076 | } |
| 4077 | `) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4078 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4079 | apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 4080 | expected := "out/soong/target/product/test_device/" + tc.parition + "/apex" |
| 4081 | actual := apex.installDir.RelativeToTop().String() |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4082 | if actual != expected { |
| 4083 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 4084 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4085 | |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4086 | flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 4087 | expected = "out/soong/target/product/test_device/" + tc.flattenedPartition + "/apex" |
| 4088 | actual = flattened.installDir.RelativeToTop().String() |
Jooyung Han | 91df208 | 2019-11-20 01:49:42 +0900 | [diff] [blame] | 4089 | if actual != expected { |
| 4090 | t.Errorf("wrong install path. expected %q. actual %q", expected, actual) |
| 4091 | } |
| 4092 | }) |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4093 | } |
Jiyong Park | d1e293d | 2019-03-15 02:13:21 +0900 | [diff] [blame] | 4094 | } |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4095 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4096 | func TestFileContexts_FindInDefaultLocationIfNotSet(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4097 | ctx := testApex(t, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4098 | apex { |
| 4099 | name: "myapex", |
| 4100 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4101 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4102 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4103 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4104 | apex_key { |
| 4105 | name: "myapex.key", |
| 4106 | public_key: "testkey.avbpubkey", |
| 4107 | private_key: "testkey.pem", |
| 4108 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4109 | `) |
| 4110 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4111 | rule := module.Output("file_contexts") |
| 4112 | ensureContains(t, rule.RuleParams.Command, "cat system/sepolicy/apex/myapex-file_contexts") |
| 4113 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4114 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4115 | func TestFileContexts_ShouldBeUnderSystemSepolicyForSystemApexes(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4116 | testApexError(t, `"myapex" .*: file_contexts: should be under system/sepolicy`, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4117 | apex { |
| 4118 | name: "myapex", |
| 4119 | key: "myapex.key", |
| 4120 | file_contexts: "my_own_file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4121 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4122 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4123 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4124 | apex_key { |
| 4125 | name: "myapex.key", |
| 4126 | public_key: "testkey.avbpubkey", |
| 4127 | private_key: "testkey.pem", |
| 4128 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4129 | `, withFiles(map[string][]byte{ |
| 4130 | "my_own_file_contexts": nil, |
| 4131 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4132 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4133 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4134 | func TestFileContexts_ProductSpecificApexes(t *testing.T) { |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4135 | testApexError(t, `"myapex" .*: file_contexts: cannot find`, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4136 | apex { |
| 4137 | name: "myapex", |
| 4138 | key: "myapex.key", |
| 4139 | product_specific: true, |
| 4140 | file_contexts: "product_specific_file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4141 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4142 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4143 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4144 | apex_key { |
| 4145 | name: "myapex.key", |
| 4146 | public_key: "testkey.avbpubkey", |
| 4147 | private_key: "testkey.pem", |
| 4148 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4149 | `) |
| 4150 | |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4151 | ctx := testApex(t, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4152 | apex { |
| 4153 | name: "myapex", |
| 4154 | key: "myapex.key", |
| 4155 | product_specific: true, |
| 4156 | file_contexts: "product_specific_file_contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4157 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4158 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4159 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4160 | apex_key { |
| 4161 | name: "myapex.key", |
| 4162 | public_key: "testkey.avbpubkey", |
| 4163 | private_key: "testkey.pem", |
| 4164 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4165 | `, withFiles(map[string][]byte{ |
| 4166 | "product_specific_file_contexts": nil, |
| 4167 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4168 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4169 | rule := module.Output("file_contexts") |
| 4170 | ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") |
| 4171 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4172 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4173 | func TestFileContexts_SetViaFileGroup(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4174 | ctx := testApex(t, ` |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4175 | apex { |
| 4176 | name: "myapex", |
| 4177 | key: "myapex.key", |
| 4178 | product_specific: true, |
| 4179 | file_contexts: ":my-file-contexts", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4180 | updatable: false, |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4181 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4182 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4183 | apex_key { |
| 4184 | name: "myapex.key", |
| 4185 | public_key: "testkey.avbpubkey", |
| 4186 | private_key: "testkey.pem", |
| 4187 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4188 | |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4189 | filegroup { |
| 4190 | name: "my-file-contexts", |
| 4191 | srcs: ["product_specific_file_contexts"], |
| 4192 | } |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4193 | `, withFiles(map[string][]byte{ |
| 4194 | "product_specific_file_contexts": nil, |
| 4195 | })) |
Jooyung Han | 580eb4f | 2020-06-24 19:33:06 +0900 | [diff] [blame] | 4196 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4197 | rule := module.Output("file_contexts") |
| 4198 | ensureContains(t, rule.RuleParams.Command, "cat product_specific_file_contexts") |
Jooyung Han | 54aca7b | 2019-11-20 02:26:02 +0900 | [diff] [blame] | 4199 | } |
| 4200 | |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4201 | func TestApexKeyFromOtherModule(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4202 | ctx := testApex(t, ` |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4203 | apex_key { |
| 4204 | name: "myapex.key", |
| 4205 | public_key: ":my.avbpubkey", |
| 4206 | private_key: ":my.pem", |
| 4207 | product_specific: true, |
| 4208 | } |
| 4209 | |
| 4210 | filegroup { |
| 4211 | name: "my.avbpubkey", |
| 4212 | srcs: ["testkey2.avbpubkey"], |
| 4213 | } |
| 4214 | |
| 4215 | filegroup { |
| 4216 | name: "my.pem", |
| 4217 | srcs: ["testkey2.pem"], |
| 4218 | } |
| 4219 | `) |
| 4220 | |
| 4221 | apex_key := ctx.ModuleForTests("myapex.key", "android_common").Module().(*apexKey) |
| 4222 | expected_pubkey := "testkey2.avbpubkey" |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 4223 | actual_pubkey := apex_key.publicKeyFile.String() |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4224 | if actual_pubkey != expected_pubkey { |
| 4225 | t.Errorf("wrong public key path. expected %q. actual %q", expected_pubkey, actual_pubkey) |
| 4226 | } |
| 4227 | expected_privkey := "testkey2.pem" |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 4228 | actual_privkey := apex_key.privateKeyFile.String() |
Jiyong Park | 6788256 | 2019-03-21 01:11:21 +0900 | [diff] [blame] | 4229 | if actual_privkey != expected_privkey { |
| 4230 | t.Errorf("wrong private key path. expected %q. actual %q", expected_privkey, actual_privkey) |
| 4231 | } |
| 4232 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4233 | |
| 4234 | func TestPrebuilt(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4235 | ctx := testApex(t, ` |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4236 | prebuilt_apex { |
| 4237 | name: "myapex", |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 4238 | arch: { |
| 4239 | arm64: { |
| 4240 | src: "myapex-arm64.apex", |
| 4241 | }, |
| 4242 | arm: { |
| 4243 | src: "myapex-arm.apex", |
| 4244 | }, |
| 4245 | }, |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4246 | } |
| 4247 | `) |
| 4248 | |
| 4249 | prebuilt := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 4250 | |
Jiyong Park | c95714e | 2019-03-29 14:23:10 +0900 | [diff] [blame] | 4251 | expectedInput := "myapex-arm64.apex" |
| 4252 | if prebuilt.inputApex.String() != expectedInput { |
| 4253 | t.Errorf("inputApex invalid. expected: %q, actual: %q", expectedInput, prebuilt.inputApex.String()) |
| 4254 | } |
Jaewoong Jung | 939ebd5 | 2019-03-26 15:07:36 -0700 | [diff] [blame] | 4255 | } |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4256 | |
| 4257 | func TestPrebuiltFilenameOverride(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4258 | ctx := testApex(t, ` |
Nikita Ioffe | 7a41ebd | 2019-04-04 18:09:48 +0100 | [diff] [blame] | 4259 | prebuilt_apex { |
| 4260 | name: "myapex", |
| 4261 | src: "myapex-arm.apex", |
| 4262 | filename: "notmyapex.apex", |
| 4263 | } |
| 4264 | `) |
| 4265 | |
| 4266 | p := ctx.ModuleForTests("myapex", "android_common").Module().(*Prebuilt) |
| 4267 | |
| 4268 | expected := "notmyapex.apex" |
| 4269 | if p.installFilename != expected { |
| 4270 | t.Errorf("installFilename invalid. expected: %q, actual: %q", expected, p.installFilename) |
| 4271 | } |
| 4272 | } |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 4273 | |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4274 | func TestPrebuiltOverrides(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4275 | ctx := testApex(t, ` |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4276 | prebuilt_apex { |
| 4277 | name: "myapex.prebuilt", |
| 4278 | src: "myapex-arm.apex", |
| 4279 | overrides: [ |
| 4280 | "myapex", |
| 4281 | ], |
| 4282 | } |
| 4283 | `) |
| 4284 | |
| 4285 | p := ctx.ModuleForTests("myapex.prebuilt", "android_common").Module().(*Prebuilt) |
| 4286 | |
| 4287 | expected := []string{"myapex"} |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 4288 | actual := android.AndroidMkEntriesForTest(t, ctx, p)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4289 | if !reflect.DeepEqual(actual, expected) { |
Jiyong Park | b0a012c | 2019-11-14 17:17:03 +0900 | [diff] [blame] | 4290 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES value '%s', expected '%s'", actual, expected) |
Jaewoong Jung | 22f7d18 | 2019-07-16 18:25:41 -0700 | [diff] [blame] | 4291 | } |
| 4292 | } |
| 4293 | |
Paul Duffin | 092153d | 2021-01-26 11:42:39 +0000 | [diff] [blame] | 4294 | // These tests verify that the prebuilt_apex/deapexer to java_import wiring allows for the |
| 4295 | // 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] | 4296 | func TestPrebuiltExportDexImplementationJars(t *testing.T) { |
| 4297 | transform := func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | 092153d | 2021-01-26 11:42:39 +0000 | [diff] [blame] | 4298 | // Empty transformation. |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4299 | } |
| 4300 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4301 | checkDexJarBuildPath := func(t *testing.T, ctx *android.TestContext, name string) { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4302 | // 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] | 4303 | p := ctx.ModuleForTests(name, "android_common_myapex").Module().(java.UsesLibraryDependency) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4304 | dexJarBuildPath := p.DexJarBuildPath() |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4305 | stem := android.RemoveOptionalPrebuiltPrefix(name) |
| 4306 | if expected, actual := ".intermediates/myapex.deapexer/android_common/deapexer/javalib/"+stem+".jar", android.NormalizePathForTesting(dexJarBuildPath); actual != expected { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4307 | t.Errorf("Incorrect DexJarBuildPath value '%s', expected '%s'", actual, expected) |
| 4308 | } |
| 4309 | } |
| 4310 | |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4311 | ensureNoSourceVariant := func(t *testing.T, ctx *android.TestContext, name string) { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4312 | // Make sure that an apex variant is not created for the source module. |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4313 | if expected, actual := []string{"android_common"}, ctx.ModuleVariantsForTests(name); !reflect.DeepEqual(expected, actual) { |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4314 | t.Errorf("invalid set of variants for %q: expected %q, found %q", "libfoo", expected, actual) |
| 4315 | } |
| 4316 | } |
| 4317 | |
| 4318 | t.Run("prebuilt only", func(t *testing.T) { |
| 4319 | bp := ` |
| 4320 | prebuilt_apex { |
| 4321 | name: "myapex", |
| 4322 | arch: { |
| 4323 | arm64: { |
| 4324 | src: "myapex-arm64.apex", |
| 4325 | }, |
| 4326 | arm: { |
| 4327 | src: "myapex-arm.apex", |
| 4328 | }, |
| 4329 | }, |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4330 | exported_java_libs: ["libfoo", "libbar"], |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4331 | } |
| 4332 | |
| 4333 | java_import { |
| 4334 | name: "libfoo", |
| 4335 | jars: ["libfoo.jar"], |
| 4336 | } |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4337 | |
| 4338 | java_sdk_library_import { |
| 4339 | name: "libbar", |
| 4340 | public: { |
| 4341 | jars: ["libbar.jar"], |
| 4342 | }, |
| 4343 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4344 | ` |
| 4345 | |
| 4346 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4347 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4348 | |
Paul Duffin | f6932af | 2021-02-26 18:21:56 +0000 | [diff] [blame] | 4349 | // Make sure that the deapexer has the correct input APEX. |
| 4350 | deapexer := ctx.ModuleForTests("myapex.deapexer", "android_common") |
| 4351 | rule := deapexer.Rule("deapexer") |
| 4352 | if expected, actual := []string{"myapex-arm64.apex"}, android.NormalizePathsForTesting(rule.Implicits); !reflect.DeepEqual(expected, actual) { |
| 4353 | t.Errorf("expected: %q, found: %q", expected, actual) |
| 4354 | } |
| 4355 | |
Paul Duffin | 0d10c3c | 2021-03-01 17:09:32 +0000 | [diff] [blame] | 4356 | // Make sure that the prebuilt_apex has the correct input APEX. |
| 4357 | prebuiltApex := ctx.ModuleForTests("myapex", "android_common") |
| 4358 | rule = prebuiltApex.Rule("android/soong/android.Cp") |
| 4359 | if expected, actual := "myapex-arm64.apex", android.NormalizePathForTesting(rule.Input); !reflect.DeepEqual(expected, actual) { |
| 4360 | t.Errorf("expected: %q, found: %q", expected, actual) |
| 4361 | } |
| 4362 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4363 | checkDexJarBuildPath(t, ctx, "libfoo") |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4364 | |
| 4365 | checkDexJarBuildPath(t, ctx, "libbar") |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4366 | }) |
| 4367 | |
| 4368 | t.Run("prebuilt with source preferred", func(t *testing.T) { |
| 4369 | |
| 4370 | bp := ` |
| 4371 | prebuilt_apex { |
| 4372 | name: "myapex", |
| 4373 | arch: { |
| 4374 | arm64: { |
| 4375 | src: "myapex-arm64.apex", |
| 4376 | }, |
| 4377 | arm: { |
| 4378 | src: "myapex-arm.apex", |
| 4379 | }, |
| 4380 | }, |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4381 | exported_java_libs: ["libfoo", "libbar"], |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4382 | } |
| 4383 | |
| 4384 | java_import { |
| 4385 | name: "libfoo", |
| 4386 | jars: ["libfoo.jar"], |
| 4387 | } |
| 4388 | |
| 4389 | java_library { |
| 4390 | name: "libfoo", |
| 4391 | } |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4392 | |
| 4393 | java_sdk_library_import { |
| 4394 | name: "libbar", |
| 4395 | public: { |
| 4396 | jars: ["libbar.jar"], |
| 4397 | }, |
| 4398 | } |
| 4399 | |
| 4400 | java_sdk_library { |
| 4401 | name: "libbar", |
| 4402 | srcs: ["foo/bar/MyClass.java"], |
| 4403 | unsafe_ignore_missing_latest_api: true, |
| 4404 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4405 | ` |
| 4406 | |
| 4407 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4408 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4409 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4410 | checkDexJarBuildPath(t, ctx, "prebuilt_libfoo") |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4411 | ensureNoSourceVariant(t, ctx, "libfoo") |
| 4412 | |
| 4413 | checkDexJarBuildPath(t, ctx, "prebuilt_libbar") |
| 4414 | ensureNoSourceVariant(t, ctx, "libbar") |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4415 | }) |
| 4416 | |
| 4417 | t.Run("prebuilt preferred with source", func(t *testing.T) { |
| 4418 | bp := ` |
| 4419 | prebuilt_apex { |
| 4420 | name: "myapex", |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4421 | arch: { |
| 4422 | arm64: { |
| 4423 | src: "myapex-arm64.apex", |
| 4424 | }, |
| 4425 | arm: { |
| 4426 | src: "myapex-arm.apex", |
| 4427 | }, |
| 4428 | }, |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4429 | exported_java_libs: ["libfoo", "libbar"], |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4430 | } |
| 4431 | |
| 4432 | java_import { |
| 4433 | name: "libfoo", |
Paul Duffin | 092153d | 2021-01-26 11:42:39 +0000 | [diff] [blame] | 4434 | prefer: true, |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4435 | jars: ["libfoo.jar"], |
| 4436 | } |
| 4437 | |
| 4438 | java_library { |
| 4439 | name: "libfoo", |
| 4440 | } |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4441 | |
| 4442 | java_sdk_library_import { |
| 4443 | name: "libbar", |
| 4444 | prefer: true, |
| 4445 | public: { |
| 4446 | jars: ["libbar.jar"], |
| 4447 | }, |
| 4448 | } |
| 4449 | |
| 4450 | java_sdk_library { |
| 4451 | name: "libbar", |
| 4452 | srcs: ["foo/bar/MyClass.java"], |
| 4453 | unsafe_ignore_missing_latest_api: true, |
| 4454 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4455 | ` |
| 4456 | |
| 4457 | // Make sure that dexpreopt can access dex implementation files from the prebuilt. |
| 4458 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
| 4459 | |
Paul Duffin | 89886cb | 2021-02-05 16:44:03 +0000 | [diff] [blame] | 4460 | checkDexJarBuildPath(t, ctx, "prebuilt_libfoo") |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 4461 | ensureNoSourceVariant(t, ctx, "libfoo") |
| 4462 | |
| 4463 | checkDexJarBuildPath(t, ctx, "prebuilt_libbar") |
| 4464 | ensureNoSourceVariant(t, ctx, "libbar") |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 4465 | }) |
| 4466 | } |
| 4467 | |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4468 | func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { |
| 4469 | transform := func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4470 | config.BootJars = android.CreateTestConfiguredJarList([]string{"myapex:libfoo", "myapex:libbar"}) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4471 | } |
| 4472 | |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4473 | checkBootDexJarPath := func(t *testing.T, ctx *android.TestContext, stem string, bootDexJarPath string) { |
| 4474 | t.Helper() |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4475 | s := ctx.SingletonForTests("dex_bootjars") |
| 4476 | foundLibfooJar := false |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4477 | base := stem + ".jar" |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4478 | for _, output := range s.AllOutputs() { |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4479 | if filepath.Base(output) == base { |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4480 | foundLibfooJar = true |
| 4481 | buildRule := s.Output(output) |
| 4482 | actual := android.NormalizePathForTesting(buildRule.Input) |
| 4483 | if actual != bootDexJarPath { |
| 4484 | t.Errorf("Incorrect boot dex jar path '%s', expected '%s'", actual, bootDexJarPath) |
| 4485 | } |
| 4486 | } |
| 4487 | } |
| 4488 | if !foundLibfooJar { |
| 4489 | t.Errorf("Rule for libfoo.jar missing in dex_bootjars singleton outputs") |
| 4490 | } |
| 4491 | } |
| 4492 | |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4493 | checkHiddenAPIIndexInputs := func(t *testing.T, ctx *android.TestContext, expectedInputs string) { |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4494 | t.Helper() |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4495 | hiddenAPIIndex := ctx.SingletonForTests("hiddenapi_index") |
| 4496 | indexRule := hiddenAPIIndex.Rule("singleton-merged-hiddenapi-index") |
| 4497 | java.CheckHiddenAPIRuleInputs(t, expectedInputs, indexRule) |
| 4498 | } |
| 4499 | |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4500 | t.Run("prebuilt only", func(t *testing.T) { |
| 4501 | bp := ` |
| 4502 | prebuilt_apex { |
| 4503 | name: "myapex", |
| 4504 | arch: { |
| 4505 | arm64: { |
| 4506 | src: "myapex-arm64.apex", |
| 4507 | }, |
| 4508 | arm: { |
| 4509 | src: "myapex-arm.apex", |
| 4510 | }, |
| 4511 | }, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4512 | exported_java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4513 | } |
| 4514 | |
| 4515 | java_import { |
| 4516 | name: "libfoo", |
| 4517 | jars: ["libfoo.jar"], |
| 4518 | apex_available: ["myapex"], |
| 4519 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4520 | |
| 4521 | java_sdk_library_import { |
| 4522 | name: "libbar", |
| 4523 | public: { |
| 4524 | jars: ["libbar.jar"], |
| 4525 | }, |
| 4526 | apex_available: ["myapex"], |
| 4527 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4528 | ` |
| 4529 | |
| 4530 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4531 | checkBootDexJarPath(t, ctx, "libfoo", ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
| 4532 | checkBootDexJarPath(t, ctx, "libbar", ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4533 | |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4534 | // Make sure that the dex file from the prebuilt_apex contributes to the hiddenapi index file. |
| 4535 | checkHiddenAPIIndexInputs(t, ctx, ` |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4536 | .intermediates/libbar/android_common_myapex/hiddenapi/index.csv |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4537 | .intermediates/libfoo/android_common_myapex/hiddenapi/index.csv |
| 4538 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4539 | }) |
| 4540 | |
| 4541 | t.Run("prebuilt with source library preferred", func(t *testing.T) { |
| 4542 | bp := ` |
| 4543 | prebuilt_apex { |
| 4544 | name: "myapex", |
| 4545 | arch: { |
| 4546 | arm64: { |
| 4547 | src: "myapex-arm64.apex", |
| 4548 | }, |
| 4549 | arm: { |
| 4550 | src: "myapex-arm.apex", |
| 4551 | }, |
| 4552 | }, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4553 | exported_java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4554 | } |
| 4555 | |
| 4556 | java_import { |
| 4557 | name: "libfoo", |
| 4558 | jars: ["libfoo.jar"], |
| 4559 | apex_available: ["myapex"], |
| 4560 | } |
| 4561 | |
| 4562 | java_library { |
| 4563 | name: "libfoo", |
| 4564 | srcs: ["foo/bar/MyClass.java"], |
| 4565 | apex_available: ["myapex"], |
| 4566 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4567 | |
| 4568 | java_sdk_library_import { |
| 4569 | name: "libbar", |
| 4570 | public: { |
| 4571 | jars: ["libbar.jar"], |
| 4572 | }, |
| 4573 | apex_available: ["myapex"], |
| 4574 | } |
| 4575 | |
| 4576 | java_sdk_library { |
| 4577 | name: "libbar", |
| 4578 | srcs: ["foo/bar/MyClass.java"], |
| 4579 | unsafe_ignore_missing_latest_api: true, |
| 4580 | apex_available: ["myapex"], |
| 4581 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4582 | ` |
| 4583 | |
| 4584 | // In this test the source (java_library) libfoo is active since the |
| 4585 | // prebuilt (java_import) defaults to prefer:false. However the |
| 4586 | // prebuilt_apex module always depends on the prebuilt, and so it doesn't |
| 4587 | // find the dex boot jar in it. We either need to disable the source libfoo |
| 4588 | // or make the prebuilt libfoo preferred. |
| 4589 | testDexpreoptWithApexes(t, bp, "failed to find a dex jar path for module 'libfoo'", transform) |
| 4590 | }) |
| 4591 | |
| 4592 | t.Run("prebuilt library preferred with source", func(t *testing.T) { |
| 4593 | bp := ` |
| 4594 | prebuilt_apex { |
| 4595 | name: "myapex", |
| 4596 | arch: { |
| 4597 | arm64: { |
| 4598 | src: "myapex-arm64.apex", |
| 4599 | }, |
| 4600 | arm: { |
| 4601 | src: "myapex-arm.apex", |
| 4602 | }, |
| 4603 | }, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4604 | exported_java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4605 | } |
| 4606 | |
| 4607 | java_import { |
| 4608 | name: "libfoo", |
| 4609 | prefer: true, |
| 4610 | jars: ["libfoo.jar"], |
| 4611 | apex_available: ["myapex"], |
| 4612 | } |
| 4613 | |
| 4614 | java_library { |
| 4615 | name: "libfoo", |
| 4616 | srcs: ["foo/bar/MyClass.java"], |
| 4617 | apex_available: ["myapex"], |
| 4618 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4619 | |
| 4620 | java_sdk_library_import { |
| 4621 | name: "libbar", |
| 4622 | prefer: true, |
| 4623 | public: { |
| 4624 | jars: ["libbar.jar"], |
| 4625 | }, |
| 4626 | apex_available: ["myapex"], |
| 4627 | } |
| 4628 | |
| 4629 | java_sdk_library { |
| 4630 | name: "libbar", |
| 4631 | srcs: ["foo/bar/MyClass.java"], |
| 4632 | unsafe_ignore_missing_latest_api: true, |
| 4633 | apex_available: ["myapex"], |
| 4634 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4635 | ` |
| 4636 | |
| 4637 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4638 | checkBootDexJarPath(t, ctx, "libfoo", ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
| 4639 | checkBootDexJarPath(t, ctx, "libbar", ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4640 | |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4641 | // Make sure that the dex file from the prebuilt_apex contributes to the hiddenapi index file. |
| 4642 | checkHiddenAPIIndexInputs(t, ctx, ` |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4643 | .intermediates/prebuilt_libbar/android_common_myapex/hiddenapi/index.csv |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4644 | .intermediates/prebuilt_libfoo/android_common_myapex/hiddenapi/index.csv |
| 4645 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4646 | }) |
| 4647 | |
| 4648 | t.Run("prebuilt with source apex preferred", func(t *testing.T) { |
| 4649 | bp := ` |
| 4650 | apex { |
| 4651 | name: "myapex", |
| 4652 | key: "myapex.key", |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4653 | java_libs: ["libfoo", "libbar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4654 | updatable: false, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4655 | } |
| 4656 | |
| 4657 | apex_key { |
| 4658 | name: "myapex.key", |
| 4659 | public_key: "testkey.avbpubkey", |
| 4660 | private_key: "testkey.pem", |
| 4661 | } |
| 4662 | |
| 4663 | prebuilt_apex { |
| 4664 | name: "myapex", |
| 4665 | arch: { |
| 4666 | arm64: { |
| 4667 | src: "myapex-arm64.apex", |
| 4668 | }, |
| 4669 | arm: { |
| 4670 | src: "myapex-arm.apex", |
| 4671 | }, |
| 4672 | }, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4673 | exported_java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4674 | } |
| 4675 | |
| 4676 | java_import { |
| 4677 | name: "libfoo", |
| 4678 | jars: ["libfoo.jar"], |
| 4679 | apex_available: ["myapex"], |
| 4680 | } |
| 4681 | |
| 4682 | java_library { |
| 4683 | name: "libfoo", |
| 4684 | srcs: ["foo/bar/MyClass.java"], |
| 4685 | apex_available: ["myapex"], |
| 4686 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4687 | |
| 4688 | java_sdk_library_import { |
| 4689 | name: "libbar", |
| 4690 | public: { |
| 4691 | jars: ["libbar.jar"], |
| 4692 | }, |
| 4693 | apex_available: ["myapex"], |
| 4694 | } |
| 4695 | |
| 4696 | java_sdk_library { |
| 4697 | name: "libbar", |
| 4698 | srcs: ["foo/bar/MyClass.java"], |
| 4699 | unsafe_ignore_missing_latest_api: true, |
| 4700 | apex_available: ["myapex"], |
| 4701 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4702 | ` |
| 4703 | |
| 4704 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4705 | checkBootDexJarPath(t, ctx, "libfoo", ".intermediates/libfoo/android_common_apex10000/hiddenapi/libfoo.jar") |
| 4706 | checkBootDexJarPath(t, ctx, "libbar", ".intermediates/libbar/android_common_myapex/hiddenapi/libbar.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4707 | |
| 4708 | // Make sure that the dex file from the prebuilt_apex contributes to the hiddenapi index file. |
| 4709 | checkHiddenAPIIndexInputs(t, ctx, ` |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4710 | .intermediates/libbar/android_common_myapex/hiddenapi/index.csv |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4711 | .intermediates/libfoo/android_common_apex10000/hiddenapi/index.csv |
| 4712 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4713 | }) |
| 4714 | |
| 4715 | t.Run("prebuilt preferred with source apex disabled", func(t *testing.T) { |
| 4716 | bp := ` |
| 4717 | apex { |
| 4718 | name: "myapex", |
| 4719 | enabled: false, |
| 4720 | key: "myapex.key", |
| 4721 | java_libs: ["libfoo"], |
| 4722 | } |
| 4723 | |
| 4724 | apex_key { |
| 4725 | name: "myapex.key", |
| 4726 | public_key: "testkey.avbpubkey", |
| 4727 | private_key: "testkey.pem", |
| 4728 | } |
| 4729 | |
| 4730 | prebuilt_apex { |
| 4731 | name: "myapex", |
| 4732 | arch: { |
| 4733 | arm64: { |
| 4734 | src: "myapex-arm64.apex", |
| 4735 | }, |
| 4736 | arm: { |
| 4737 | src: "myapex-arm.apex", |
| 4738 | }, |
| 4739 | }, |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4740 | exported_java_libs: ["libfoo", "libbar"], |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4741 | } |
| 4742 | |
| 4743 | java_import { |
| 4744 | name: "libfoo", |
| 4745 | prefer: true, |
| 4746 | jars: ["libfoo.jar"], |
| 4747 | apex_available: ["myapex"], |
| 4748 | } |
| 4749 | |
| 4750 | java_library { |
| 4751 | name: "libfoo", |
| 4752 | srcs: ["foo/bar/MyClass.java"], |
| 4753 | apex_available: ["myapex"], |
| 4754 | } |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4755 | |
| 4756 | java_sdk_library_import { |
| 4757 | name: "libbar", |
| 4758 | prefer: true, |
| 4759 | public: { |
| 4760 | jars: ["libbar.jar"], |
| 4761 | }, |
| 4762 | apex_available: ["myapex"], |
| 4763 | } |
| 4764 | |
| 4765 | java_sdk_library { |
| 4766 | name: "libbar", |
| 4767 | srcs: ["foo/bar/MyClass.java"], |
| 4768 | unsafe_ignore_missing_latest_api: true, |
| 4769 | apex_available: ["myapex"], |
| 4770 | } |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4771 | ` |
| 4772 | |
| 4773 | ctx := testDexpreoptWithApexes(t, bp, "", transform) |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4774 | checkBootDexJarPath(t, ctx, "libfoo", ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar") |
| 4775 | checkBootDexJarPath(t, ctx, "libbar", ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libbar.jar") |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4776 | |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4777 | // Make sure that the dex file from the prebuilt_apex contributes to the hiddenapi index file. |
| 4778 | checkHiddenAPIIndexInputs(t, ctx, ` |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 4779 | .intermediates/prebuilt_libbar/android_common_prebuilt_myapex/hiddenapi/index.csv |
Paul Duffin | 9d67ca6 | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 4780 | .intermediates/prebuilt_libfoo/android_common_prebuilt_myapex/hiddenapi/index.csv |
| 4781 | `) |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 4782 | }) |
| 4783 | } |
| 4784 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4785 | func TestApexWithTests(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4786 | ctx := testApex(t, ` |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4787 | apex_test { |
| 4788 | name: "myapex", |
| 4789 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4790 | updatable: false, |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4791 | tests: [ |
| 4792 | "mytest", |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4793 | "mytests", |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4794 | ], |
| 4795 | } |
| 4796 | |
| 4797 | apex_key { |
| 4798 | name: "myapex.key", |
| 4799 | public_key: "testkey.avbpubkey", |
| 4800 | private_key: "testkey.pem", |
| 4801 | } |
| 4802 | |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 4803 | filegroup { |
| 4804 | name: "fg", |
| 4805 | srcs: [ |
| 4806 | "baz", |
| 4807 | "bar/baz" |
| 4808 | ], |
| 4809 | } |
| 4810 | |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4811 | cc_test { |
| 4812 | name: "mytest", |
| 4813 | gtest: false, |
| 4814 | srcs: ["mytest.cpp"], |
| 4815 | relative_install_path: "test", |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4816 | shared_libs: ["mylib"], |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4817 | system_shared_libs: [], |
| 4818 | static_executable: true, |
| 4819 | stl: "none", |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 4820 | data: [":fg"], |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4821 | } |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4822 | |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4823 | cc_library { |
| 4824 | name: "mylib", |
| 4825 | srcs: ["mylib.cpp"], |
| 4826 | system_shared_libs: [], |
| 4827 | stl: "none", |
| 4828 | } |
| 4829 | |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 4830 | filegroup { |
| 4831 | name: "fg2", |
| 4832 | srcs: [ |
| 4833 | "testdata/baz" |
| 4834 | ], |
| 4835 | } |
| 4836 | |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4837 | cc_test { |
| 4838 | name: "mytests", |
| 4839 | gtest: false, |
| 4840 | srcs: [ |
| 4841 | "mytest1.cpp", |
| 4842 | "mytest2.cpp", |
| 4843 | "mytest3.cpp", |
| 4844 | ], |
| 4845 | test_per_src: true, |
| 4846 | relative_install_path: "test", |
| 4847 | system_shared_libs: [], |
| 4848 | static_executable: true, |
| 4849 | stl: "none", |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 4850 | data: [ |
| 4851 | ":fg", |
| 4852 | ":fg2", |
| 4853 | ], |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4854 | } |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4855 | `) |
| 4856 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 4857 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4858 | copyCmds := apexRule.Args["copy_commands"] |
| 4859 | |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4860 | // Ensure that test dep (and their transitive dependencies) are copied into apex. |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4861 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest") |
Jiyong Park | af9539f | 2020-05-04 10:31:32 +0900 | [diff] [blame] | 4862 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4863 | |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 4864 | //Ensure that test data are copied into apex. |
| 4865 | ensureContains(t, copyCmds, "image.apex/bin/test/baz") |
| 4866 | ensureContains(t, copyCmds, "image.apex/bin/test/bar/baz") |
| 4867 | |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 4868 | // Ensure that test deps built with `test_per_src` are copied into apex. |
| 4869 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest1") |
| 4870 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest2") |
| 4871 | ensureContains(t, copyCmds, "image.apex/bin/test/mytest3") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4872 | |
| 4873 | // Ensure the module is correctly translated. |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 4874 | bundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 4875 | data := android.AndroidMkDataForTest(t, ctx, bundle) |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 4876 | name := bundle.BaseModuleName() |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4877 | prefix := "TARGET_" |
| 4878 | var builder strings.Builder |
| 4879 | data.Custom(&builder, name, prefix, "", data) |
| 4880 | androidMk := builder.String() |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 4881 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest.myapex\n") |
| 4882 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest1.myapex\n") |
| 4883 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest2.myapex\n") |
| 4884 | ensureContains(t, androidMk, "LOCAL_MODULE := mytest3.myapex\n") |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 4885 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex\n") |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 4886 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_pubkey.myapex\n") |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 4887 | ensureContains(t, androidMk, "LOCAL_MODULE := myapex\n") |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 4888 | |
| 4889 | flatBundle := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 4890 | data = android.AndroidMkDataForTest(t, ctx, flatBundle) |
Liz Kammer | 81faaaf | 2020-05-20 09:57:08 -0700 | [diff] [blame] | 4891 | data.Custom(&builder, name, prefix, "", data) |
| 4892 | flatAndroidMk := builder.String() |
Liz Kammer | 5bd365f | 2020-05-27 15:15:11 -0700 | [diff] [blame] | 4893 | ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :baz :bar/baz\n") |
| 4894 | ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :testdata/baz\n") |
Roland Levillain | 630846d | 2019-06-26 12:48:34 +0100 | [diff] [blame] | 4895 | } |
| 4896 | |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 4897 | func TestInstallExtraFlattenedApexes(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4898 | ctx := testApex(t, ` |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 4899 | apex { |
| 4900 | name: "myapex", |
| 4901 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4902 | updatable: false, |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 4903 | } |
| 4904 | apex_key { |
| 4905 | name: "myapex.key", |
| 4906 | public_key: "testkey.avbpubkey", |
| 4907 | private_key: "testkey.pem", |
| 4908 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 4909 | `, |
| 4910 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 4911 | variables.InstallExtraFlattenedApexes = proptools.BoolPtr(true) |
| 4912 | }), |
| 4913 | ) |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 4914 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Jiyong Park | 83dc74b | 2020-01-14 18:38:44 +0900 | [diff] [blame] | 4915 | ensureListContains(t, ab.requiredDeps, "myapex.flattened") |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 4916 | mk := android.AndroidMkDataForTest(t, ctx, ab) |
Jooyung Han | 3ab2c3e | 2019-12-05 16:27:44 +0900 | [diff] [blame] | 4917 | var builder strings.Builder |
| 4918 | mk.Custom(&builder, ab.Name(), "TARGET_", "", mk) |
| 4919 | androidMk := builder.String() |
| 4920 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += myapex.flattened") |
| 4921 | } |
| 4922 | |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4923 | func TestErrorsIfDepsAreNotEnabled(t *testing.T) { |
| 4924 | testApexError(t, `module "myapex" .* depends on disabled module "libfoo"`, ` |
| 4925 | apex { |
| 4926 | name: "myapex", |
| 4927 | key: "myapex.key", |
| 4928 | native_shared_libs: ["libfoo"], |
| 4929 | } |
| 4930 | |
| 4931 | apex_key { |
| 4932 | name: "myapex.key", |
| 4933 | public_key: "testkey.avbpubkey", |
| 4934 | private_key: "testkey.pem", |
| 4935 | } |
| 4936 | |
| 4937 | cc_library { |
| 4938 | name: "libfoo", |
| 4939 | stl: "none", |
| 4940 | system_shared_libs: [], |
| 4941 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4942 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4943 | } |
| 4944 | `) |
| 4945 | testApexError(t, `module "myapex" .* depends on disabled module "myjar"`, ` |
| 4946 | apex { |
| 4947 | name: "myapex", |
| 4948 | key: "myapex.key", |
| 4949 | java_libs: ["myjar"], |
| 4950 | } |
| 4951 | |
| 4952 | apex_key { |
| 4953 | name: "myapex.key", |
| 4954 | public_key: "testkey.avbpubkey", |
| 4955 | private_key: "testkey.pem", |
| 4956 | } |
| 4957 | |
| 4958 | java_library { |
| 4959 | name: "myjar", |
| 4960 | srcs: ["foo/bar/MyClass.java"], |
| 4961 | sdk_version: "none", |
| 4962 | system_modules: "none", |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4963 | enabled: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 4964 | apex_available: ["myapex"], |
Jooyung Han | d48f3c3 | 2019-08-23 11:18:57 +0900 | [diff] [blame] | 4965 | } |
| 4966 | `) |
| 4967 | } |
| 4968 | |
Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 4969 | func TestApexWithJavaImport(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4970 | ctx := testApex(t, ` |
Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 4971 | apex { |
| 4972 | name: "myapex", |
| 4973 | key: "myapex.key", |
| 4974 | java_libs: ["myjavaimport"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 4975 | updatable: false, |
Bill Peckham | a41a696 | 2021-01-11 10:58:54 -0800 | [diff] [blame] | 4976 | } |
| 4977 | |
| 4978 | apex_key { |
| 4979 | name: "myapex.key", |
| 4980 | public_key: "testkey.avbpubkey", |
| 4981 | private_key: "testkey.pem", |
| 4982 | } |
| 4983 | |
| 4984 | java_import { |
| 4985 | name: "myjavaimport", |
| 4986 | apex_available: ["myapex"], |
| 4987 | jars: ["my.jar"], |
| 4988 | compile_dex: true, |
| 4989 | } |
| 4990 | `) |
| 4991 | |
| 4992 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 4993 | apexRule := module.Rule("apexRule") |
| 4994 | copyCmds := apexRule.Args["copy_commands"] |
| 4995 | ensureContains(t, copyCmds, "image.apex/javalib/myjavaimport.jar") |
| 4996 | } |
| 4997 | |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 4998 | func TestApexWithApps(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 4999 | ctx := testApex(t, ` |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5000 | apex { |
| 5001 | name: "myapex", |
| 5002 | key: "myapex.key", |
| 5003 | apps: [ |
| 5004 | "AppFoo", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5005 | "AppFooPriv", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5006 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5007 | updatable: false, |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5008 | } |
| 5009 | |
| 5010 | apex_key { |
| 5011 | name: "myapex.key", |
| 5012 | public_key: "testkey.avbpubkey", |
| 5013 | private_key: "testkey.pem", |
| 5014 | } |
| 5015 | |
| 5016 | android_app { |
| 5017 | name: "AppFoo", |
| 5018 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5019 | sdk_version: "current", |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5020 | system_modules: "none", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 5021 | jni_libs: ["libjni"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5022 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5023 | apex_available: [ "myapex" ], |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5024 | } |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5025 | |
| 5026 | android_app { |
| 5027 | name: "AppFooPriv", |
| 5028 | srcs: ["foo/bar/MyClass.java"], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5029 | sdk_version: "current", |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5030 | system_modules: "none", |
| 5031 | privileged: true, |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5032 | stl: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5033 | apex_available: [ "myapex" ], |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5034 | } |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 5035 | |
| 5036 | cc_library_shared { |
| 5037 | name: "libjni", |
| 5038 | srcs: ["mylib.cpp"], |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5039 | shared_libs: ["libfoo"], |
| 5040 | stl: "none", |
| 5041 | system_shared_libs: [], |
| 5042 | apex_available: [ "myapex" ], |
| 5043 | sdk_version: "current", |
| 5044 | } |
| 5045 | |
| 5046 | cc_library_shared { |
| 5047 | name: "libfoo", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 5048 | stl: "none", |
| 5049 | system_shared_libs: [], |
Jiyong Park | 0f80c18 | 2020-01-31 02:49:53 +0900 | [diff] [blame] | 5050 | apex_available: [ "myapex" ], |
Colin Cross | 094cde4 | 2020-02-15 10:38:00 -0800 | [diff] [blame] | 5051 | sdk_version: "current", |
Jiyong Park | 8be103b | 2019-11-08 15:53:48 +0900 | [diff] [blame] | 5052 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5053 | `) |
| 5054 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 5055 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5056 | apexRule := module.Rule("apexRule") |
| 5057 | copyCmds := apexRule.Args["copy_commands"] |
| 5058 | |
| 5059 | ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk") |
Jiyong Park | f748731 | 2019-10-17 12:54:30 +0900 | [diff] [blame] | 5060 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 5061 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 5062 | appZipRule := ctx.ModuleForTests("AppFoo", "android_common_apex10000").Description("zip jni libs") |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5063 | // JNI libraries are uncompressed |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 5064 | if args := appZipRule.Args["jarArgs"]; !strings.Contains(args, "-L 0") { |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5065 | t.Errorf("jni libs are not uncompressed for AppFoo") |
Jiyong Park | 52cd06f | 2019-11-11 10:14:32 +0900 | [diff] [blame] | 5066 | } |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5067 | // JNI libraries including transitive deps are |
| 5068 | for _, jni := range []string{"libjni", "libfoo"} { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 5069 | jniOutput := ctx.ModuleForTests(jni, "android_arm64_armv8-a_sdk_shared_apex10000").Module().(*cc.Module).OutputFile() |
Jooyung Han | b7bebe2 | 2020-02-25 16:59:29 +0900 | [diff] [blame] | 5070 | // ... embedded inside APK (jnilibs.zip) |
| 5071 | ensureListContains(t, appZipRule.Implicits.Strings(), jniOutput.String()) |
| 5072 | // ... and not directly inside the APEX |
| 5073 | ensureNotContains(t, copyCmds, "image.apex/lib64/"+jni+".so") |
| 5074 | } |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5075 | } |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5076 | |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5077 | func TestApexWithAppImports(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5078 | ctx := testApex(t, ` |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5079 | apex { |
| 5080 | name: "myapex", |
| 5081 | key: "myapex.key", |
| 5082 | apps: [ |
| 5083 | "AppFooPrebuilt", |
| 5084 | "AppFooPrivPrebuilt", |
| 5085 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5086 | updatable: false, |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5087 | } |
| 5088 | |
| 5089 | apex_key { |
| 5090 | name: "myapex.key", |
| 5091 | public_key: "testkey.avbpubkey", |
| 5092 | private_key: "testkey.pem", |
| 5093 | } |
| 5094 | |
| 5095 | android_app_import { |
| 5096 | name: "AppFooPrebuilt", |
| 5097 | apk: "PrebuiltAppFoo.apk", |
| 5098 | presigned: true, |
| 5099 | dex_preopt: { |
| 5100 | enabled: false, |
| 5101 | }, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5102 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5103 | } |
| 5104 | |
| 5105 | android_app_import { |
| 5106 | name: "AppFooPrivPrebuilt", |
| 5107 | apk: "PrebuiltAppFooPriv.apk", |
| 5108 | privileged: true, |
| 5109 | presigned: true, |
| 5110 | dex_preopt: { |
| 5111 | enabled: false, |
| 5112 | }, |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5113 | filename: "AwesomePrebuiltAppFooPriv.apk", |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5114 | apex_available: ["myapex"], |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5115 | } |
| 5116 | `) |
| 5117 | |
Sundong Ahn | abb6443 | 2019-10-22 13:58:29 +0900 | [diff] [blame] | 5118 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Dario Freni | cde2a03 | 2019-10-27 00:29:22 +0100 | [diff] [blame] | 5119 | apexRule := module.Rule("apexRule") |
| 5120 | copyCmds := apexRule.Args["copy_commands"] |
| 5121 | |
| 5122 | ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5123 | ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AwesomePrebuiltAppFooPriv.apk") |
| 5124 | } |
| 5125 | |
| 5126 | func TestApexWithAppImportsPrefer(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5127 | ctx := testApex(t, ` |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5128 | apex { |
| 5129 | name: "myapex", |
| 5130 | key: "myapex.key", |
| 5131 | apps: [ |
| 5132 | "AppFoo", |
| 5133 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5134 | updatable: false, |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5135 | } |
| 5136 | |
| 5137 | apex_key { |
| 5138 | name: "myapex.key", |
| 5139 | public_key: "testkey.avbpubkey", |
| 5140 | private_key: "testkey.pem", |
| 5141 | } |
| 5142 | |
| 5143 | android_app { |
| 5144 | name: "AppFoo", |
| 5145 | srcs: ["foo/bar/MyClass.java"], |
| 5146 | sdk_version: "none", |
| 5147 | system_modules: "none", |
| 5148 | apex_available: [ "myapex" ], |
| 5149 | } |
| 5150 | |
| 5151 | android_app_import { |
| 5152 | name: "AppFoo", |
| 5153 | apk: "AppFooPrebuilt.apk", |
| 5154 | filename: "AppFooPrebuilt.apk", |
| 5155 | presigned: true, |
| 5156 | prefer: true, |
Jiyong Park | 592a6a4 | 2020-04-21 22:34:28 +0900 | [diff] [blame] | 5157 | apex_available: ["myapex"], |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5158 | } |
| 5159 | `, withFiles(map[string][]byte{ |
| 5160 | "AppFooPrebuilt.apk": nil, |
| 5161 | })) |
| 5162 | |
| 5163 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 86feead | 2021-03-08 13:11:48 +0900 | [diff] [blame] | 5164 | "app/AppFoo/AppFooPrebuilt.apk", |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5165 | }) |
Sundong Ahn | e1f05aa | 2019-08-27 13:55:42 +0900 | [diff] [blame] | 5166 | } |
| 5167 | |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5168 | func TestApexWithTestHelperApp(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5169 | ctx := testApex(t, ` |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5170 | apex { |
| 5171 | name: "myapex", |
| 5172 | key: "myapex.key", |
| 5173 | apps: [ |
| 5174 | "TesterHelpAppFoo", |
| 5175 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5176 | updatable: false, |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5177 | } |
| 5178 | |
| 5179 | apex_key { |
| 5180 | name: "myapex.key", |
| 5181 | public_key: "testkey.avbpubkey", |
| 5182 | private_key: "testkey.pem", |
| 5183 | } |
| 5184 | |
| 5185 | android_test_helper_app { |
| 5186 | name: "TesterHelpAppFoo", |
| 5187 | srcs: ["foo/bar/MyClass.java"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5188 | apex_available: [ "myapex" ], |
Dario Freni | 6f3937c | 2019-12-20 22:58:03 +0000 | [diff] [blame] | 5189 | } |
| 5190 | |
| 5191 | `) |
| 5192 | |
| 5193 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 5194 | apexRule := module.Rule("apexRule") |
| 5195 | copyCmds := apexRule.Args["copy_commands"] |
| 5196 | |
| 5197 | ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk") |
| 5198 | } |
| 5199 | |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 5200 | func TestApexPropertiesShouldBeDefaultable(t *testing.T) { |
| 5201 | // libfoo's apex_available comes from cc_defaults |
Steven Moreland | 6e36cd6 | 2020-10-22 01:08:35 +0000 | [diff] [blame] | 5202 | 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] | 5203 | apex { |
| 5204 | name: "myapex", |
| 5205 | key: "myapex.key", |
| 5206 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5207 | updatable: false, |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 5208 | } |
| 5209 | |
| 5210 | apex_key { |
| 5211 | name: "myapex.key", |
| 5212 | public_key: "testkey.avbpubkey", |
| 5213 | private_key: "testkey.pem", |
| 5214 | } |
| 5215 | |
| 5216 | apex { |
| 5217 | name: "otherapex", |
| 5218 | key: "myapex.key", |
| 5219 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5220 | updatable: false, |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 5221 | } |
| 5222 | |
| 5223 | cc_defaults { |
| 5224 | name: "libfoo-defaults", |
| 5225 | apex_available: ["otherapex"], |
| 5226 | } |
| 5227 | |
| 5228 | cc_library { |
| 5229 | name: "libfoo", |
| 5230 | defaults: ["libfoo-defaults"], |
| 5231 | stl: "none", |
| 5232 | system_shared_libs: [], |
| 5233 | }`) |
| 5234 | } |
| 5235 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5236 | func TestApexAvailable_DirectDep(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5237 | // libfoo is not available to myapex, but only to otherapex |
Steven Moreland | 6e36cd6 | 2020-10-22 01:08:35 +0000 | [diff] [blame] | 5238 | 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] | 5239 | apex { |
| 5240 | name: "myapex", |
| 5241 | key: "myapex.key", |
| 5242 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5243 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5244 | } |
| 5245 | |
| 5246 | apex_key { |
| 5247 | name: "myapex.key", |
| 5248 | public_key: "testkey.avbpubkey", |
| 5249 | private_key: "testkey.pem", |
| 5250 | } |
| 5251 | |
| 5252 | apex { |
| 5253 | name: "otherapex", |
| 5254 | key: "otherapex.key", |
| 5255 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5256 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5257 | } |
| 5258 | |
| 5259 | apex_key { |
| 5260 | name: "otherapex.key", |
| 5261 | public_key: "testkey.avbpubkey", |
| 5262 | private_key: "testkey.pem", |
| 5263 | } |
| 5264 | |
| 5265 | cc_library { |
| 5266 | name: "libfoo", |
| 5267 | stl: "none", |
| 5268 | system_shared_libs: [], |
| 5269 | apex_available: ["otherapex"], |
| 5270 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5271 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5272 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5273 | func TestApexAvailable_IndirectDep(t *testing.T) { |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5274 | // libbbaz is an indirect dep |
Jiyong Park | 767dbd9 | 2021-03-04 13:03:10 +0900 | [diff] [blame] | 5275 | 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] | 5276 | .*via tag apex\.dependencyTag.*name:sharedLib.* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 5277 | .*-> libfoo.*link:shared.* |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 5278 | .*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.* |
Paul Duffin | df915ff | 2020-03-30 17:58:21 +0100 | [diff] [blame] | 5279 | .*-> libbar.*link:shared.* |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 5280 | .*via tag cc\.libraryDependencyTag.*Kind:sharedLibraryDependency.* |
Paul Duffin | 6534770 | 2020-03-31 15:23:40 +0100 | [diff] [blame] | 5281 | .*-> libbaz.*link:shared.*`, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5282 | apex { |
| 5283 | name: "myapex", |
| 5284 | key: "myapex.key", |
| 5285 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5286 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5287 | } |
| 5288 | |
| 5289 | apex_key { |
| 5290 | name: "myapex.key", |
| 5291 | public_key: "testkey.avbpubkey", |
| 5292 | private_key: "testkey.pem", |
| 5293 | } |
| 5294 | |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5295 | cc_library { |
| 5296 | name: "libfoo", |
| 5297 | stl: "none", |
| 5298 | shared_libs: ["libbar"], |
| 5299 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5300 | apex_available: ["myapex"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5301 | } |
| 5302 | |
| 5303 | cc_library { |
| 5304 | name: "libbar", |
| 5305 | stl: "none", |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5306 | shared_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5307 | system_shared_libs: [], |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5308 | apex_available: ["myapex"], |
| 5309 | } |
| 5310 | |
| 5311 | cc_library { |
| 5312 | name: "libbaz", |
| 5313 | stl: "none", |
| 5314 | system_shared_libs: [], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5315 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5316 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5317 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5318 | func TestApexAvailable_InvalidApexName(t *testing.T) { |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5319 | testApexError(t, "\"otherapex\" is not a valid module name", ` |
| 5320 | apex { |
| 5321 | name: "myapex", |
| 5322 | key: "myapex.key", |
| 5323 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5324 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5325 | } |
| 5326 | |
| 5327 | apex_key { |
| 5328 | name: "myapex.key", |
| 5329 | public_key: "testkey.avbpubkey", |
| 5330 | private_key: "testkey.pem", |
| 5331 | } |
| 5332 | |
| 5333 | cc_library { |
| 5334 | name: "libfoo", |
| 5335 | stl: "none", |
| 5336 | system_shared_libs: [], |
| 5337 | apex_available: ["otherapex"], |
| 5338 | }`) |
| 5339 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5340 | testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5341 | apex { |
| 5342 | name: "myapex", |
| 5343 | key: "myapex.key", |
| 5344 | native_shared_libs: ["libfoo", "libbar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5345 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5346 | } |
| 5347 | |
| 5348 | apex_key { |
| 5349 | name: "myapex.key", |
| 5350 | public_key: "testkey.avbpubkey", |
| 5351 | private_key: "testkey.pem", |
| 5352 | } |
| 5353 | |
| 5354 | cc_library { |
| 5355 | name: "libfoo", |
| 5356 | stl: "none", |
| 5357 | system_shared_libs: [], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 5358 | runtime_libs: ["libbaz"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5359 | apex_available: ["myapex"], |
| 5360 | } |
| 5361 | |
| 5362 | cc_library { |
| 5363 | name: "libbar", |
| 5364 | stl: "none", |
| 5365 | system_shared_libs: [], |
| 5366 | apex_available: ["//apex_available:anyapex"], |
Jiyong Park | 323a4c3 | 2020-03-01 17:29:06 +0900 | [diff] [blame] | 5367 | } |
| 5368 | |
| 5369 | cc_library { |
| 5370 | name: "libbaz", |
| 5371 | stl: "none", |
| 5372 | system_shared_libs: [], |
| 5373 | stubs: { |
| 5374 | versions: ["10", "20", "30"], |
| 5375 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5376 | }`) |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5377 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5378 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5379 | func TestApexAvailable_CheckForPlatform(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5380 | ctx := testApex(t, ` |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5381 | apex { |
| 5382 | name: "myapex", |
| 5383 | key: "myapex.key", |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5384 | native_shared_libs: ["libbar", "libbaz"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5385 | updatable: false, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5386 | } |
| 5387 | |
| 5388 | apex_key { |
| 5389 | name: "myapex.key", |
| 5390 | public_key: "testkey.avbpubkey", |
| 5391 | private_key: "testkey.pem", |
| 5392 | } |
| 5393 | |
| 5394 | cc_library { |
| 5395 | name: "libfoo", |
| 5396 | stl: "none", |
| 5397 | system_shared_libs: [], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5398 | shared_libs: ["libbar"], |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5399 | apex_available: ["//apex_available:platform"], |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5400 | } |
| 5401 | |
| 5402 | cc_library { |
| 5403 | name: "libfoo2", |
| 5404 | stl: "none", |
| 5405 | system_shared_libs: [], |
| 5406 | shared_libs: ["libbaz"], |
| 5407 | apex_available: ["//apex_available:platform"], |
| 5408 | } |
| 5409 | |
| 5410 | cc_library { |
| 5411 | name: "libbar", |
| 5412 | stl: "none", |
| 5413 | system_shared_libs: [], |
| 5414 | apex_available: ["myapex"], |
| 5415 | } |
| 5416 | |
| 5417 | cc_library { |
| 5418 | name: "libbaz", |
| 5419 | stl: "none", |
| 5420 | system_shared_libs: [], |
| 5421 | apex_available: ["myapex"], |
| 5422 | stubs: { |
| 5423 | versions: ["1"], |
| 5424 | }, |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5425 | }`) |
| 5426 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5427 | // libfoo shouldn't be available to platform even though it has "//apex_available:platform", |
| 5428 | // because it depends on libbar which isn't available to platform |
| 5429 | libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 5430 | if libfoo.NotAvailableForPlatform() != true { |
| 5431 | t.Errorf("%q shouldn't be available to platform", libfoo.String()) |
| 5432 | } |
| 5433 | |
| 5434 | // libfoo2 however can be available to platform because it depends on libbaz which provides |
| 5435 | // stubs |
| 5436 | libfoo2 := ctx.ModuleForTests("libfoo2", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 5437 | if libfoo2.NotAvailableForPlatform() == true { |
| 5438 | t.Errorf("%q should be available to platform", libfoo2.String()) |
| 5439 | } |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5440 | } |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 5441 | |
Paul Duffin | e52e66f | 2020-03-30 17:54:29 +0100 | [diff] [blame] | 5442 | func TestApexAvailable_CreatedForApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5443 | ctx := testApex(t, ` |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 5444 | apex { |
| 5445 | name: "myapex", |
| 5446 | key: "myapex.key", |
| 5447 | native_shared_libs: ["libfoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5448 | updatable: false, |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 5449 | } |
| 5450 | |
| 5451 | apex_key { |
| 5452 | name: "myapex.key", |
| 5453 | public_key: "testkey.avbpubkey", |
| 5454 | private_key: "testkey.pem", |
| 5455 | } |
| 5456 | |
| 5457 | cc_library { |
| 5458 | name: "libfoo", |
| 5459 | stl: "none", |
| 5460 | system_shared_libs: [], |
| 5461 | apex_available: ["myapex"], |
| 5462 | static: { |
| 5463 | apex_available: ["//apex_available:platform"], |
| 5464 | }, |
| 5465 | }`) |
| 5466 | |
Jiyong Park | 89e850a | 2020-04-07 16:37:39 +0900 | [diff] [blame] | 5467 | libfooShared := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Module().(*cc.Module) |
| 5468 | if libfooShared.NotAvailableForPlatform() != true { |
| 5469 | t.Errorf("%q shouldn't be available to platform", libfooShared.String()) |
| 5470 | } |
| 5471 | libfooStatic := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Module().(*cc.Module) |
| 5472 | if libfooStatic.NotAvailableForPlatform() != false { |
| 5473 | t.Errorf("%q should be available to platform", libfooStatic.String()) |
| 5474 | } |
Jiyong Park | 127b40b | 2019-09-30 16:04:35 +0900 | [diff] [blame] | 5475 | } |
| 5476 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5477 | func TestOverrideApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5478 | ctx := testApex(t, ` |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5479 | apex { |
| 5480 | name: "myapex", |
| 5481 | key: "myapex.key", |
| 5482 | apps: ["app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 5483 | overrides: ["oldapex"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5484 | updatable: false, |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5485 | } |
| 5486 | |
| 5487 | override_apex { |
| 5488 | name: "override_myapex", |
| 5489 | base: "myapex", |
| 5490 | apps: ["override_app"], |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 5491 | overrides: ["unknownapex"], |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 5492 | logging_parent: "com.foo.bar", |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 5493 | package_name: "test.overridden.package", |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5494 | } |
| 5495 | |
| 5496 | apex_key { |
| 5497 | name: "myapex.key", |
| 5498 | public_key: "testkey.avbpubkey", |
| 5499 | private_key: "testkey.pem", |
| 5500 | } |
| 5501 | |
| 5502 | android_app { |
| 5503 | name: "app", |
| 5504 | srcs: ["foo/bar/MyClass.java"], |
| 5505 | package_name: "foo", |
| 5506 | sdk_version: "none", |
| 5507 | system_modules: "none", |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5508 | apex_available: [ "myapex" ], |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5509 | } |
| 5510 | |
| 5511 | override_android_app { |
| 5512 | name: "override_app", |
| 5513 | base: "app", |
| 5514 | package_name: "bar", |
| 5515 | } |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 5516 | `, withManifestPackageNameOverrides([]string{"myapex:com.android.myapex"})) |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5517 | |
Jiyong Park | 317645e | 2019-12-05 13:20:58 +0900 | [diff] [blame] | 5518 | originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule) |
| 5519 | overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule) |
| 5520 | if originalVariant.GetOverriddenBy() != "" { |
| 5521 | t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy()) |
| 5522 | } |
| 5523 | if overriddenVariant.GetOverriddenBy() != "override_myapex" { |
| 5524 | t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy()) |
| 5525 | } |
| 5526 | |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5527 | module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image") |
| 5528 | apexRule := module.Rule("apexRule") |
| 5529 | copyCmds := apexRule.Args["copy_commands"] |
| 5530 | |
| 5531 | ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk") |
Jooyung Han | 39ee119 | 2020-03-23 20:21:11 +0900 | [diff] [blame] | 5532 | ensureContains(t, copyCmds, "image.apex/app/override_app/override_app.apk") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5533 | |
| 5534 | apexBundle := module.Module().(*apexBundle) |
| 5535 | name := apexBundle.Name() |
| 5536 | if name != "override_myapex" { |
| 5537 | t.Errorf("name should be \"override_myapex\", but was %q", name) |
| 5538 | } |
| 5539 | |
Baligh Uddin | 004d717 | 2020-02-19 21:29:28 -0800 | [diff] [blame] | 5540 | if apexBundle.overridableProperties.Logging_parent != "com.foo.bar" { |
| 5541 | t.Errorf("override_myapex should have logging parent (com.foo.bar), but was %q.", apexBundle.overridableProperties.Logging_parent) |
| 5542 | } |
| 5543 | |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 5544 | optFlags := apexRule.Args["opt_flags"] |
Baligh Uddin | 5b57dba | 2020-03-15 13:01:05 -0700 | [diff] [blame] | 5545 | ensureContains(t, optFlags, "--override_apk_package_name test.overridden.package") |
Jiyong Park | 20bacab | 2020-03-03 11:45:41 +0900 | [diff] [blame] | 5546 | |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 5547 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5548 | var builder strings.Builder |
| 5549 | data.Custom(&builder, name, "TARGET_", "", data) |
| 5550 | androidMk := builder.String() |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 5551 | ensureContains(t, androidMk, "LOCAL_MODULE := override_app.override_myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5552 | ensureContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.override_myapex") |
| 5553 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := override_myapex.apex") |
Jaewoong Jung | 7abcf8e | 2019-12-19 17:32:06 -0800 | [diff] [blame] | 5554 | ensureContains(t, androidMk, "LOCAL_OVERRIDES_MODULES := unknownapex myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5555 | ensureNotContains(t, androidMk, "LOCAL_MODULE := app.myapex") |
Jiyong Park | f653b05 | 2019-11-18 15:39:01 +0900 | [diff] [blame] | 5556 | ensureNotContains(t, androidMk, "LOCAL_MODULE := override_app.myapex") |
Jaewoong Jung | 1670ca0 | 2019-11-22 14:50:42 -0800 | [diff] [blame] | 5557 | ensureNotContains(t, androidMk, "LOCAL_MODULE := apex_manifest.pb.myapex") |
| 5558 | ensureNotContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.apex") |
Jiyong Park | 5d790c3 | 2019-11-15 18:40:32 +0900 | [diff] [blame] | 5559 | } |
| 5560 | |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5561 | func TestLegacyAndroid10Support(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5562 | ctx := testApex(t, ` |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5563 | apex { |
| 5564 | name: "myapex", |
| 5565 | key: "myapex.key", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5566 | native_shared_libs: ["mylib"], |
Jooyung Han | 5417f77 | 2020-03-12 18:37:20 +0900 | [diff] [blame] | 5567 | min_sdk_version: "29", |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5568 | } |
| 5569 | |
| 5570 | apex_key { |
| 5571 | name: "myapex.key", |
| 5572 | public_key: "testkey.avbpubkey", |
| 5573 | private_key: "testkey.pem", |
| 5574 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5575 | |
| 5576 | cc_library { |
| 5577 | name: "mylib", |
| 5578 | srcs: ["mylib.cpp"], |
| 5579 | stl: "libc++", |
| 5580 | system_shared_libs: [], |
| 5581 | apex_available: [ "myapex" ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 5582 | min_sdk_version: "29", |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5583 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5584 | `, withUnbundledBuild) |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5585 | |
| 5586 | module := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
| 5587 | args := module.Rule("apexRule").Args |
| 5588 | 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] | 5589 | ensureNotContains(t, args["opt_flags"], "--no_hashtree") |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 5590 | |
| 5591 | // The copies of the libraries in the apex should have one more dependency than |
| 5592 | // the ones outside the apex, namely the unwinder. Ideally we should check |
| 5593 | // the dependency names directly here but for some reason the names are blank in |
| 5594 | // this test. |
| 5595 | for _, lib := range []string{"libc++", "mylib"} { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 5596 | 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] | 5597 | nonApexImplicits := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld").Implicits |
| 5598 | if len(apexImplicits) != len(nonApexImplicits)+1 { |
| 5599 | t.Errorf("%q missing unwinder dep", lib) |
| 5600 | } |
| 5601 | } |
Jooyung Han | 214bf37 | 2019-11-12 13:03:50 +0900 | [diff] [blame] | 5602 | } |
| 5603 | |
Paul Duffin | e05480a | 2021-03-08 15:07:14 +0000 | [diff] [blame] | 5604 | var filesForSdkLibrary = android.MockFS{ |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5605 | "api/current.txt": nil, |
| 5606 | "api/removed.txt": nil, |
| 5607 | "api/system-current.txt": nil, |
| 5608 | "api/system-removed.txt": nil, |
| 5609 | "api/test-current.txt": nil, |
| 5610 | "api/test-removed.txt": nil, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5611 | |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5612 | "100/public/api/foo.txt": nil, |
| 5613 | "100/public/api/foo-removed.txt": nil, |
| 5614 | "100/system/api/foo.txt": nil, |
| 5615 | "100/system/api/foo-removed.txt": nil, |
| 5616 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5617 | // For java_sdk_library_import |
| 5618 | "a.jar": nil, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5619 | } |
| 5620 | |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5621 | func TestJavaSDKLibrary(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5622 | ctx := testApex(t, ` |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5623 | apex { |
| 5624 | name: "myapex", |
| 5625 | key: "myapex.key", |
| 5626 | java_libs: ["foo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5627 | updatable: false, |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5628 | } |
| 5629 | |
| 5630 | apex_key { |
| 5631 | name: "myapex.key", |
| 5632 | public_key: "testkey.avbpubkey", |
| 5633 | private_key: "testkey.pem", |
| 5634 | } |
| 5635 | |
| 5636 | java_sdk_library { |
| 5637 | name: "foo", |
| 5638 | srcs: ["a.java"], |
| 5639 | api_packages: ["foo"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5640 | apex_available: [ "myapex" ], |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5641 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5642 | |
| 5643 | prebuilt_apis { |
| 5644 | name: "sdk", |
| 5645 | api_dirs: ["100"], |
| 5646 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5647 | `, withFiles(filesForSdkLibrary)) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5648 | |
| 5649 | // java_sdk_library installs both impl jar and permission XML |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 5650 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5651 | "javalib/foo.jar", |
| 5652 | "etc/permissions/foo.xml", |
| 5653 | }) |
| 5654 | // 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] | 5655 | sdkLibrary := ctx.ModuleForTests("foo.xml", "android_common_myapex").Rule("java_sdk_xml") |
| 5656 | ensureContains(t, sdkLibrary.RuleParams.Command, `<library name=\"foo\" file=\"/apex/myapex/javalib/foo.jar\"`) |
Jooyung Han | 58f26ab | 2019-12-18 15:34:32 +0900 | [diff] [blame] | 5657 | } |
| 5658 | |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5659 | func TestJavaSDKLibrary_WithinApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5660 | ctx := testApex(t, ` |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5661 | apex { |
| 5662 | name: "myapex", |
| 5663 | key: "myapex.key", |
| 5664 | java_libs: ["foo", "bar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5665 | updatable: false, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5666 | } |
| 5667 | |
| 5668 | apex_key { |
| 5669 | name: "myapex.key", |
| 5670 | public_key: "testkey.avbpubkey", |
| 5671 | private_key: "testkey.pem", |
| 5672 | } |
| 5673 | |
| 5674 | java_sdk_library { |
| 5675 | name: "foo", |
| 5676 | srcs: ["a.java"], |
| 5677 | api_packages: ["foo"], |
| 5678 | apex_available: ["myapex"], |
| 5679 | sdk_version: "none", |
| 5680 | system_modules: "none", |
| 5681 | } |
| 5682 | |
| 5683 | java_library { |
| 5684 | name: "bar", |
| 5685 | srcs: ["a.java"], |
| 5686 | libs: ["foo"], |
| 5687 | apex_available: ["myapex"], |
| 5688 | sdk_version: "none", |
| 5689 | system_modules: "none", |
| 5690 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5691 | |
| 5692 | prebuilt_apis { |
| 5693 | name: "sdk", |
| 5694 | api_dirs: ["100"], |
| 5695 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5696 | `, withFiles(filesForSdkLibrary)) |
| 5697 | |
| 5698 | // java_sdk_library installs both impl jar and permission XML |
| 5699 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5700 | "javalib/bar.jar", |
| 5701 | "javalib/foo.jar", |
| 5702 | "etc/permissions/foo.xml", |
| 5703 | }) |
| 5704 | |
| 5705 | // The bar library should depend on the implementation jar. |
| 5706 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
Paul Duffin | cf8d7db | 2021-03-29 00:29:53 +0100 | [diff] [blame^] | 5707 | 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] | 5708 | t.Errorf("expected %q, found %#q", expected, actual) |
| 5709 | } |
| 5710 | } |
| 5711 | |
| 5712 | func TestJavaSDKLibrary_CrossBoundary(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5713 | ctx := testApex(t, ` |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5714 | apex { |
| 5715 | name: "myapex", |
| 5716 | key: "myapex.key", |
| 5717 | java_libs: ["foo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5718 | updatable: false, |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5719 | } |
| 5720 | |
| 5721 | apex_key { |
| 5722 | name: "myapex.key", |
| 5723 | public_key: "testkey.avbpubkey", |
| 5724 | private_key: "testkey.pem", |
| 5725 | } |
| 5726 | |
| 5727 | java_sdk_library { |
| 5728 | name: "foo", |
| 5729 | srcs: ["a.java"], |
| 5730 | api_packages: ["foo"], |
| 5731 | apex_available: ["myapex"], |
| 5732 | sdk_version: "none", |
| 5733 | system_modules: "none", |
| 5734 | } |
| 5735 | |
| 5736 | java_library { |
| 5737 | name: "bar", |
| 5738 | srcs: ["a.java"], |
| 5739 | libs: ["foo"], |
| 5740 | sdk_version: "none", |
| 5741 | system_modules: "none", |
| 5742 | } |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5743 | |
| 5744 | prebuilt_apis { |
| 5745 | name: "sdk", |
| 5746 | api_dirs: ["100"], |
| 5747 | } |
Paul Duffin | 9b87959 | 2020-05-26 13:21:35 +0100 | [diff] [blame] | 5748 | `, withFiles(filesForSdkLibrary)) |
| 5749 | |
| 5750 | // java_sdk_library installs both impl jar and permission XML |
| 5751 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5752 | "javalib/foo.jar", |
| 5753 | "etc/permissions/foo.xml", |
| 5754 | }) |
| 5755 | |
| 5756 | // The bar library should depend on the stubs jar. |
| 5757 | barLibrary := ctx.ModuleForTests("bar", "android_common").Rule("javac") |
Paul Duffin | cf8d7db | 2021-03-29 00:29:53 +0100 | [diff] [blame^] | 5758 | 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] | 5759 | t.Errorf("expected %q, found %#q", expected, actual) |
| 5760 | } |
| 5761 | } |
| 5762 | |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5763 | func TestJavaSDKLibrary_ImportPreferred(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5764 | ctx := testApex(t, ` |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5765 | prebuilt_apis { |
| 5766 | name: "sdk", |
| 5767 | api_dirs: ["100"], |
| 5768 | }`, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5769 | withFiles(map[string][]byte{ |
| 5770 | "apex/a.java": nil, |
| 5771 | "apex/apex_manifest.json": nil, |
| 5772 | "apex/Android.bp": []byte(` |
| 5773 | package { |
| 5774 | default_visibility: ["//visibility:private"], |
| 5775 | } |
| 5776 | |
| 5777 | apex { |
| 5778 | name: "myapex", |
| 5779 | key: "myapex.key", |
| 5780 | java_libs: ["foo", "bar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5781 | updatable: false, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5782 | } |
| 5783 | |
| 5784 | apex_key { |
| 5785 | name: "myapex.key", |
| 5786 | public_key: "testkey.avbpubkey", |
| 5787 | private_key: "testkey.pem", |
| 5788 | } |
| 5789 | |
| 5790 | java_library { |
| 5791 | name: "bar", |
| 5792 | srcs: ["a.java"], |
| 5793 | libs: ["foo"], |
| 5794 | apex_available: ["myapex"], |
| 5795 | sdk_version: "none", |
| 5796 | system_modules: "none", |
| 5797 | } |
| 5798 | `), |
| 5799 | "source/a.java": nil, |
| 5800 | "source/api/current.txt": nil, |
| 5801 | "source/api/removed.txt": nil, |
| 5802 | "source/Android.bp": []byte(` |
| 5803 | package { |
| 5804 | default_visibility: ["//visibility:private"], |
| 5805 | } |
| 5806 | |
| 5807 | java_sdk_library { |
| 5808 | name: "foo", |
| 5809 | visibility: ["//apex"], |
| 5810 | srcs: ["a.java"], |
| 5811 | api_packages: ["foo"], |
| 5812 | apex_available: ["myapex"], |
| 5813 | sdk_version: "none", |
| 5814 | system_modules: "none", |
| 5815 | public: { |
| 5816 | enabled: true, |
| 5817 | }, |
| 5818 | } |
| 5819 | `), |
| 5820 | "prebuilt/a.jar": nil, |
| 5821 | "prebuilt/Android.bp": []byte(` |
| 5822 | package { |
| 5823 | default_visibility: ["//visibility:private"], |
| 5824 | } |
| 5825 | |
| 5826 | java_sdk_library_import { |
| 5827 | name: "foo", |
| 5828 | visibility: ["//apex", "//source"], |
| 5829 | apex_available: ["myapex"], |
| 5830 | prefer: true, |
| 5831 | public: { |
| 5832 | jars: ["a.jar"], |
| 5833 | }, |
| 5834 | } |
| 5835 | `), |
Anton Hansson | dff2c78 | 2020-12-21 17:10:01 +0000 | [diff] [blame] | 5836 | }), withFiles(filesForSdkLibrary), |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5837 | ) |
| 5838 | |
| 5839 | // java_sdk_library installs both impl jar and permission XML |
| 5840 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5841 | "javalib/bar.jar", |
| 5842 | "javalib/foo.jar", |
| 5843 | "etc/permissions/foo.xml", |
| 5844 | }) |
| 5845 | |
| 5846 | // The bar library should depend on the implementation jar. |
| 5847 | barLibrary := ctx.ModuleForTests("bar", "android_common_myapex").Rule("javac") |
Paul Duffin | cf8d7db | 2021-03-29 00:29:53 +0100 | [diff] [blame^] | 5848 | 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] | 5849 | t.Errorf("expected %q, found %#q", expected, actual) |
| 5850 | } |
| 5851 | } |
| 5852 | |
| 5853 | func TestJavaSDKLibrary_ImportOnly(t *testing.T) { |
| 5854 | testApexError(t, `java_libs: "foo" is not configured to be compiled into dex`, ` |
| 5855 | apex { |
| 5856 | name: "myapex", |
| 5857 | key: "myapex.key", |
| 5858 | java_libs: ["foo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5859 | updatable: false, |
Paul Duffin | eedc5d5 | 2020-06-12 17:46:39 +0100 | [diff] [blame] | 5860 | } |
| 5861 | |
| 5862 | apex_key { |
| 5863 | name: "myapex.key", |
| 5864 | public_key: "testkey.avbpubkey", |
| 5865 | private_key: "testkey.pem", |
| 5866 | } |
| 5867 | |
| 5868 | java_sdk_library_import { |
| 5869 | name: "foo", |
| 5870 | apex_available: ["myapex"], |
| 5871 | prefer: true, |
| 5872 | public: { |
| 5873 | jars: ["a.jar"], |
| 5874 | }, |
| 5875 | } |
| 5876 | |
| 5877 | `, withFiles(filesForSdkLibrary)) |
| 5878 | } |
| 5879 | |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5880 | func TestCompatConfig(t *testing.T) { |
Paul Duffin | a369c7b | 2021-03-09 03:08:05 +0000 | [diff] [blame] | 5881 | result := apexFixtureFactory. |
| 5882 | Extend(java.PrepareForTestWithPlatformCompatConfig). |
| 5883 | RunTestWithBp(t, ` |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5884 | apex { |
| 5885 | name: "myapex", |
| 5886 | key: "myapex.key", |
Paul Duffin | 3abc174 | 2021-03-15 19:32:23 +0000 | [diff] [blame] | 5887 | compat_configs: ["myjar-platform-compat-config"], |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5888 | java_libs: ["myjar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5889 | updatable: false, |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5890 | } |
| 5891 | |
| 5892 | apex_key { |
| 5893 | name: "myapex.key", |
| 5894 | public_key: "testkey.avbpubkey", |
| 5895 | private_key: "testkey.pem", |
| 5896 | } |
| 5897 | |
| 5898 | platform_compat_config { |
| 5899 | name: "myjar-platform-compat-config", |
| 5900 | src: ":myjar", |
| 5901 | } |
| 5902 | |
| 5903 | java_library { |
| 5904 | name: "myjar", |
| 5905 | srcs: ["foo/bar/MyClass.java"], |
| 5906 | sdk_version: "none", |
| 5907 | system_modules: "none", |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5908 | apex_available: [ "myapex" ], |
| 5909 | } |
Paul Duffin | 1b29e00 | 2021-03-16 15:06:54 +0000 | [diff] [blame] | 5910 | |
| 5911 | // Make sure that a preferred prebuilt does not affect the apex contents. |
| 5912 | prebuilt_platform_compat_config { |
| 5913 | name: "myjar-platform-compat-config", |
| 5914 | metadata: "compat-config/metadata.xml", |
| 5915 | prefer: true, |
| 5916 | } |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5917 | `) |
Paul Duffin | a369c7b | 2021-03-09 03:08:05 +0000 | [diff] [blame] | 5918 | ctx := result.TestContext |
atrost | 6e12625 | 2020-01-27 17:01:16 +0000 | [diff] [blame] | 5919 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 5920 | "etc/compatconfig/myjar-platform-compat-config.xml", |
| 5921 | "javalib/myjar.jar", |
| 5922 | }) |
| 5923 | } |
| 5924 | |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 5925 | func TestRejectNonInstallableJavaLibrary(t *testing.T) { |
| 5926 | testApexError(t, `"myjar" is not configured to be compiled into dex`, ` |
| 5927 | apex { |
| 5928 | name: "myapex", |
| 5929 | key: "myapex.key", |
| 5930 | java_libs: ["myjar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5931 | updatable: false, |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 5932 | } |
| 5933 | |
| 5934 | apex_key { |
| 5935 | name: "myapex.key", |
| 5936 | public_key: "testkey.avbpubkey", |
| 5937 | private_key: "testkey.pem", |
| 5938 | } |
| 5939 | |
| 5940 | java_library { |
| 5941 | name: "myjar", |
| 5942 | srcs: ["foo/bar/MyClass.java"], |
| 5943 | sdk_version: "none", |
| 5944 | system_modules: "none", |
Jiyong Park | 6b21c7d | 2020-02-11 09:16:01 +0900 | [diff] [blame] | 5945 | compile_dex: false, |
Jooyung Han | 5e9013b | 2020-03-10 06:23:13 +0900 | [diff] [blame] | 5946 | apex_available: ["myapex"], |
Jiyong Park | 479321d | 2019-12-16 11:47:12 +0900 | [diff] [blame] | 5947 | } |
| 5948 | `) |
| 5949 | } |
| 5950 | |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 5951 | func TestCarryRequiredModuleNames(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 5952 | ctx := testApex(t, ` |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 5953 | apex { |
| 5954 | name: "myapex", |
| 5955 | key: "myapex.key", |
| 5956 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5957 | updatable: false, |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 5958 | } |
| 5959 | |
| 5960 | apex_key { |
| 5961 | name: "myapex.key", |
| 5962 | public_key: "testkey.avbpubkey", |
| 5963 | private_key: "testkey.pem", |
| 5964 | } |
| 5965 | |
| 5966 | cc_library { |
| 5967 | name: "mylib", |
| 5968 | srcs: ["mylib.cpp"], |
| 5969 | system_shared_libs: [], |
| 5970 | stl: "none", |
| 5971 | required: ["a", "b"], |
| 5972 | host_required: ["c", "d"], |
| 5973 | target_required: ["e", "f"], |
Anton Hansson | eec79eb | 2020-01-10 15:12:39 +0000 | [diff] [blame] | 5974 | apex_available: [ "myapex" ], |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 5975 | } |
| 5976 | `) |
| 5977 | |
| 5978 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 5979 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Jiyong Park | 7afd107 | 2019-12-30 16:56:33 +0900 | [diff] [blame] | 5980 | name := apexBundle.BaseModuleName() |
| 5981 | prefix := "TARGET_" |
| 5982 | var builder strings.Builder |
| 5983 | data.Custom(&builder, name, prefix, "", data) |
| 5984 | androidMk := builder.String() |
| 5985 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n") |
| 5986 | ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n") |
| 5987 | ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n") |
| 5988 | } |
| 5989 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5990 | func TestSymlinksFromApexToSystem(t *testing.T) { |
| 5991 | bp := ` |
| 5992 | apex { |
| 5993 | name: "myapex", |
| 5994 | key: "myapex.key", |
| 5995 | native_shared_libs: ["mylib"], |
| 5996 | java_libs: ["myjar"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 5997 | updatable: false, |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 5998 | } |
| 5999 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6000 | apex { |
| 6001 | name: "myapex.updatable", |
| 6002 | key: "myapex.key", |
| 6003 | native_shared_libs: ["mylib"], |
| 6004 | java_libs: ["myjar"], |
| 6005 | updatable: true, |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 6006 | min_sdk_version: "current", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6007 | } |
| 6008 | |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6009 | apex_key { |
| 6010 | name: "myapex.key", |
| 6011 | public_key: "testkey.avbpubkey", |
| 6012 | private_key: "testkey.pem", |
| 6013 | } |
| 6014 | |
| 6015 | cc_library { |
| 6016 | name: "mylib", |
| 6017 | srcs: ["mylib.cpp"], |
| 6018 | shared_libs: ["myotherlib"], |
| 6019 | system_shared_libs: [], |
| 6020 | stl: "none", |
| 6021 | apex_available: [ |
| 6022 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6023 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6024 | "//apex_available:platform", |
| 6025 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6026 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6027 | } |
| 6028 | |
| 6029 | cc_library { |
| 6030 | name: "myotherlib", |
| 6031 | srcs: ["mylib.cpp"], |
| 6032 | system_shared_libs: [], |
| 6033 | stl: "none", |
| 6034 | apex_available: [ |
| 6035 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6036 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6037 | "//apex_available:platform", |
| 6038 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6039 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6040 | } |
| 6041 | |
| 6042 | java_library { |
| 6043 | name: "myjar", |
| 6044 | srcs: ["foo/bar/MyClass.java"], |
| 6045 | sdk_version: "none", |
| 6046 | system_modules: "none", |
| 6047 | libs: ["myotherjar"], |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6048 | apex_available: [ |
| 6049 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6050 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6051 | "//apex_available:platform", |
| 6052 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6053 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6054 | } |
| 6055 | |
| 6056 | java_library { |
| 6057 | name: "myotherjar", |
| 6058 | srcs: ["foo/bar/MyClass.java"], |
| 6059 | sdk_version: "none", |
| 6060 | system_modules: "none", |
| 6061 | apex_available: [ |
| 6062 | "myapex", |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6063 | "myapex.updatable", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6064 | "//apex_available:platform", |
| 6065 | ], |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 6066 | min_sdk_version: "current", |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6067 | } |
| 6068 | ` |
| 6069 | |
| 6070 | ensureRealfileExists := func(t *testing.T, files []fileInApex, file string) { |
| 6071 | for _, f := range files { |
| 6072 | if f.path == file { |
| 6073 | if f.isLink { |
| 6074 | t.Errorf("%q is not a real file", file) |
| 6075 | } |
| 6076 | return |
| 6077 | } |
| 6078 | } |
| 6079 | t.Errorf("%q is not found", file) |
| 6080 | } |
| 6081 | |
| 6082 | ensureSymlinkExists := func(t *testing.T, files []fileInApex, file string) { |
| 6083 | for _, f := range files { |
| 6084 | if f.path == file { |
| 6085 | if !f.isLink { |
| 6086 | t.Errorf("%q is not a symlink", file) |
| 6087 | } |
| 6088 | return |
| 6089 | } |
| 6090 | } |
| 6091 | t.Errorf("%q is not found", file) |
| 6092 | } |
| 6093 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6094 | // For unbundled build, symlink shouldn't exist regardless of whether an APEX |
| 6095 | // is updatable or not |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6096 | ctx := testApex(t, bp, withUnbundledBuild) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 6097 | files := getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6098 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6099 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6100 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 6101 | |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6102 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 6103 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6104 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6105 | ensureRealfileExists(t, files, "lib64/myotherlib.so") |
| 6106 | |
| 6107 | // 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] | 6108 | ctx = testApex(t, bp) |
Jooyung Han | a57af4a | 2020-01-23 05:36:59 +0000 | [diff] [blame] | 6109 | files = getFiles(t, ctx, "myapex", "android_common_myapex_image") |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6110 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6111 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6112 | ensureSymlinkExists(t, files, "lib64/myotherlib.so") // this is symlink |
Jiyong Park | 9d67720 | 2020-02-19 16:29:35 +0900 | [diff] [blame] | 6113 | |
| 6114 | files = getFiles(t, ctx, "myapex.updatable", "android_common_myapex.updatable_image") |
| 6115 | ensureRealfileExists(t, files, "javalib/myjar.jar") |
| 6116 | ensureRealfileExists(t, files, "lib64/mylib.so") |
| 6117 | ensureRealfileExists(t, files, "lib64/myotherlib.so") // this is a real file |
Jiyong Park | 7cd10e3 | 2020-01-14 09:22:18 +0900 | [diff] [blame] | 6118 | } |
| 6119 | |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 6120 | func TestSymlinksFromApexToSystemRequiredModuleNames(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6121 | ctx := testApex(t, ` |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 6122 | apex { |
| 6123 | name: "myapex", |
| 6124 | key: "myapex.key", |
| 6125 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6126 | updatable: false, |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 6127 | } |
| 6128 | |
| 6129 | apex_key { |
| 6130 | name: "myapex.key", |
| 6131 | public_key: "testkey.avbpubkey", |
| 6132 | private_key: "testkey.pem", |
| 6133 | } |
| 6134 | |
| 6135 | cc_library_shared { |
| 6136 | name: "mylib", |
| 6137 | srcs: ["mylib.cpp"], |
| 6138 | shared_libs: ["myotherlib"], |
| 6139 | system_shared_libs: [], |
| 6140 | stl: "none", |
| 6141 | apex_available: [ |
| 6142 | "myapex", |
| 6143 | "//apex_available:platform", |
| 6144 | ], |
| 6145 | } |
| 6146 | |
| 6147 | cc_prebuilt_library_shared { |
| 6148 | name: "myotherlib", |
| 6149 | srcs: ["prebuilt.so"], |
| 6150 | system_shared_libs: [], |
| 6151 | stl: "none", |
| 6152 | apex_available: [ |
| 6153 | "myapex", |
| 6154 | "//apex_available:platform", |
| 6155 | ], |
| 6156 | } |
| 6157 | `) |
| 6158 | |
| 6159 | apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 6160 | data := android.AndroidMkDataForTest(t, ctx, apexBundle) |
Yo Chiang | e812805 | 2020-07-23 20:09:18 +0800 | [diff] [blame] | 6161 | var builder strings.Builder |
| 6162 | data.Custom(&builder, apexBundle.BaseModuleName(), "TARGET_", "", data) |
| 6163 | androidMk := builder.String() |
| 6164 | // `myotherlib` is added to `myapex` as symlink |
| 6165 | ensureContains(t, androidMk, "LOCAL_MODULE := mylib.myapex\n") |
| 6166 | ensureNotContains(t, androidMk, "LOCAL_MODULE := prebuilt_myotherlib.myapex\n") |
| 6167 | ensureNotContains(t, androidMk, "LOCAL_MODULE := myotherlib.myapex\n") |
| 6168 | // `myapex` should have `myotherlib` in its required line, not `prebuilt_myotherlib` |
Jiyong Park | 57621b2 | 2021-01-20 20:33:11 +0900 | [diff] [blame] | 6169 | 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] | 6170 | } |
| 6171 | |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 6172 | func TestApexWithJniLibs(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6173 | ctx := testApex(t, ` |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 6174 | apex { |
| 6175 | name: "myapex", |
| 6176 | key: "myapex.key", |
| 6177 | jni_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6178 | updatable: false, |
Jooyung Han | 643adc4 | 2020-02-27 13:50:06 +0900 | [diff] [blame] | 6179 | } |
| 6180 | |
| 6181 | apex_key { |
| 6182 | name: "myapex.key", |
| 6183 | public_key: "testkey.avbpubkey", |
| 6184 | private_key: "testkey.pem", |
| 6185 | } |
| 6186 | |
| 6187 | cc_library { |
| 6188 | name: "mylib", |
| 6189 | srcs: ["mylib.cpp"], |
| 6190 | shared_libs: ["mylib2"], |
| 6191 | system_shared_libs: [], |
| 6192 | stl: "none", |
| 6193 | apex_available: [ "myapex" ], |
| 6194 | } |
| 6195 | |
| 6196 | cc_library { |
| 6197 | name: "mylib2", |
| 6198 | srcs: ["mylib.cpp"], |
| 6199 | system_shared_libs: [], |
| 6200 | stl: "none", |
| 6201 | apex_available: [ "myapex" ], |
| 6202 | } |
| 6203 | `) |
| 6204 | |
| 6205 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexManifestRule") |
| 6206 | // Notice mylib2.so (transitive dep) is not added as a jni_lib |
| 6207 | ensureEquals(t, rule.Args["opt"], "-a jniLibs mylib.so") |
| 6208 | ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ |
| 6209 | "lib64/mylib.so", |
| 6210 | "lib64/mylib2.so", |
| 6211 | }) |
| 6212 | } |
| 6213 | |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 6214 | func TestApexMutatorsDontRunIfDisabled(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6215 | ctx := testApex(t, ` |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 6216 | apex { |
| 6217 | name: "myapex", |
| 6218 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6219 | updatable: false, |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 6220 | } |
| 6221 | apex_key { |
| 6222 | name: "myapex.key", |
| 6223 | public_key: "testkey.avbpubkey", |
| 6224 | private_key: "testkey.pem", |
| 6225 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 6226 | `, |
| 6227 | android.FixtureModifyConfig(func(config android.Config) { |
| 6228 | delete(config.Targets, android.Android) |
| 6229 | config.AndroidCommonTarget = android.Target{} |
| 6230 | }), |
| 6231 | ) |
Jooyung Han | 49f6701 | 2020-04-17 13:43:10 +0900 | [diff] [blame] | 6232 | |
| 6233 | if expected, got := []string{""}, ctx.ModuleVariantsForTests("myapex"); !reflect.DeepEqual(expected, got) { |
| 6234 | t.Errorf("Expected variants: %v, but got: %v", expected, got) |
| 6235 | } |
| 6236 | } |
| 6237 | |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6238 | func TestAppBundle(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6239 | ctx := testApex(t, ` |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6240 | apex { |
| 6241 | name: "myapex", |
| 6242 | key: "myapex.key", |
| 6243 | apps: ["AppFoo"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6244 | updatable: false, |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6245 | } |
| 6246 | |
| 6247 | apex_key { |
| 6248 | name: "myapex.key", |
| 6249 | public_key: "testkey.avbpubkey", |
| 6250 | private_key: "testkey.pem", |
| 6251 | } |
| 6252 | |
| 6253 | android_app { |
| 6254 | name: "AppFoo", |
| 6255 | srcs: ["foo/bar/MyClass.java"], |
| 6256 | sdk_version: "none", |
| 6257 | system_modules: "none", |
| 6258 | apex_available: [ "myapex" ], |
| 6259 | } |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 6260 | `, withManifestPackageNameOverrides([]string{"AppFoo:com.android.foo"})) |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6261 | |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 6262 | bundleConfigRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Output("bundle_config.json") |
Jiyong Park | bd15961 | 2020-02-28 15:22:21 +0900 | [diff] [blame] | 6263 | content := bundleConfigRule.Args["content"] |
| 6264 | |
| 6265 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
Jiyong Park | cfaa164 | 2020-02-28 16:51:07 +0900 | [diff] [blame] | 6266 | 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] | 6267 | } |
| 6268 | |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6269 | func TestAppSetBundle(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6270 | ctx := testApex(t, ` |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6271 | apex { |
| 6272 | name: "myapex", |
| 6273 | key: "myapex.key", |
| 6274 | apps: ["AppSet"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6275 | updatable: false, |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6276 | } |
| 6277 | |
| 6278 | apex_key { |
| 6279 | name: "myapex.key", |
| 6280 | public_key: "testkey.avbpubkey", |
| 6281 | private_key: "testkey.pem", |
| 6282 | } |
| 6283 | |
| 6284 | android_app_set { |
| 6285 | name: "AppSet", |
| 6286 | set: "AppSet.apks", |
| 6287 | }`) |
| 6288 | mod := ctx.ModuleForTests("myapex", "android_common_myapex_image") |
Colin Cross | cf371cc | 2020-11-13 11:48:42 -0800 | [diff] [blame] | 6289 | bundleConfigRule := mod.Output("bundle_config.json") |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6290 | content := bundleConfigRule.Args["content"] |
| 6291 | ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) |
| 6292 | s := mod.Rule("apexRule").Args["copy_commands"] |
| 6293 | copyCmds := regexp.MustCompile(" *&& *").Split(s, -1) |
| 6294 | if len(copyCmds) != 3 { |
| 6295 | t.Fatalf("Expected 3 commands, got %d in:\n%s", len(copyCmds), s) |
| 6296 | } |
| 6297 | ensureMatches(t, copyCmds[0], "^rm -rf .*/app/AppSet$") |
| 6298 | ensureMatches(t, copyCmds[1], "^mkdir -p .*/app/AppSet$") |
| 6299 | ensureMatches(t, copyCmds[2], "^unzip .*-d .*/app/AppSet .*/AppSet.zip$") |
| 6300 | } |
| 6301 | |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 6302 | func TestAppSetBundlePrebuilt(t *testing.T) { |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 6303 | ctx := testApex(t, "", android.FixtureModifyMockFS(func(fs android.MockFS) { |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 6304 | bp := ` |
| 6305 | apex_set { |
| 6306 | name: "myapex", |
| 6307 | filename: "foo_v2.apex", |
| 6308 | sanitized: { |
| 6309 | none: { set: "myapex.apks", }, |
| 6310 | hwaddress: { set: "myapex.hwasan.apks", }, |
| 6311 | }, |
| 6312 | }` |
| 6313 | fs["Android.bp"] = []byte(bp) |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 6314 | }), |
| 6315 | prepareForTestWithSantitizeHwaddress, |
| 6316 | ) |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 6317 | |
| 6318 | m := ctx.ModuleForTests("myapex", "android_common") |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 6319 | extractedApex := m.Output("out/soong/.intermediates/myapex/android_common/foo_v2.apex") |
Evgenii Stepanov | 2080bfe | 2020-07-24 15:35:40 -0700 | [diff] [blame] | 6320 | |
| 6321 | actual := extractedApex.Inputs |
| 6322 | if len(actual) != 1 { |
| 6323 | t.Errorf("expected a single input") |
| 6324 | } |
| 6325 | |
| 6326 | expected := "myapex.hwasan.apks" |
| 6327 | if actual[0].String() != expected { |
| 6328 | t.Errorf("expected %s, got %s", expected, actual[0].String()) |
| 6329 | } |
| 6330 | } |
| 6331 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6332 | func testNoUpdatableJarsInBootImage(t *testing.T, errmsg string, transformDexpreoptConfig func(*dexpreopt.GlobalConfig)) { |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6333 | t.Helper() |
| 6334 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6335 | bp := ` |
| 6336 | java_library { |
| 6337 | name: "some-updatable-apex-lib", |
| 6338 | srcs: ["a.java"], |
| 6339 | sdk_version: "current", |
| 6340 | apex_available: [ |
| 6341 | "some-updatable-apex", |
| 6342 | ], |
| 6343 | } |
| 6344 | |
| 6345 | java_library { |
| 6346 | name: "some-non-updatable-apex-lib", |
| 6347 | srcs: ["a.java"], |
| 6348 | apex_available: [ |
| 6349 | "some-non-updatable-apex", |
| 6350 | ], |
| 6351 | } |
| 6352 | |
| 6353 | java_library { |
| 6354 | name: "some-platform-lib", |
| 6355 | srcs: ["a.java"], |
| 6356 | sdk_version: "current", |
| 6357 | installable: true, |
| 6358 | } |
| 6359 | |
| 6360 | java_library { |
| 6361 | name: "some-art-lib", |
| 6362 | srcs: ["a.java"], |
| 6363 | sdk_version: "current", |
| 6364 | apex_available: [ |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6365 | "com.android.art.debug", |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6366 | ], |
| 6367 | hostdex: true, |
| 6368 | } |
| 6369 | |
| 6370 | apex { |
| 6371 | name: "some-updatable-apex", |
| 6372 | key: "some-updatable-apex.key", |
| 6373 | java_libs: ["some-updatable-apex-lib"], |
| 6374 | updatable: true, |
| 6375 | min_sdk_version: "current", |
| 6376 | } |
| 6377 | |
| 6378 | apex { |
| 6379 | name: "some-non-updatable-apex", |
| 6380 | key: "some-non-updatable-apex.key", |
| 6381 | java_libs: ["some-non-updatable-apex-lib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6382 | updatable: false, |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6383 | } |
| 6384 | |
| 6385 | apex_key { |
| 6386 | name: "some-updatable-apex.key", |
| 6387 | } |
| 6388 | |
| 6389 | apex_key { |
| 6390 | name: "some-non-updatable-apex.key", |
| 6391 | } |
| 6392 | |
| 6393 | apex { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6394 | name: "com.android.art.debug", |
| 6395 | key: "com.android.art.debug.key", |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6396 | java_libs: ["some-art-lib"], |
| 6397 | updatable: true, |
| 6398 | min_sdk_version: "current", |
| 6399 | } |
| 6400 | |
| 6401 | apex_key { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6402 | name: "com.android.art.debug.key", |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6403 | } |
| 6404 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6405 | filegroup { |
| 6406 | name: "some-updatable-apex-file_contexts", |
| 6407 | srcs: [ |
| 6408 | "system/sepolicy/apex/some-updatable-apex-file_contexts", |
| 6409 | ], |
| 6410 | } |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 6411 | |
| 6412 | filegroup { |
| 6413 | name: "some-non-updatable-apex-file_contexts", |
| 6414 | srcs: [ |
| 6415 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts", |
| 6416 | ], |
| 6417 | } |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6418 | ` |
Paul Duffin | c3bbb96 | 2020-12-10 19:15:49 +0000 | [diff] [blame] | 6419 | |
| 6420 | testDexpreoptWithApexes(t, bp, errmsg, transformDexpreoptConfig) |
| 6421 | } |
| 6422 | |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 6423 | func testDexpreoptWithApexes(t *testing.T, bp, errmsg string, transformDexpreoptConfig func(*dexpreopt.GlobalConfig)) *android.TestContext { |
Paul Duffin | c3bbb96 | 2020-12-10 19:15:49 +0000 | [diff] [blame] | 6424 | t.Helper() |
| 6425 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6426 | bp += cc.GatherRequiredDepsForTest(android.Android) |
| 6427 | bp += java.GatherRequiredDepsForTest() |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6428 | |
| 6429 | fs := map[string][]byte{ |
| 6430 | "a.java": nil, |
| 6431 | "a.jar": nil, |
| 6432 | "build/make/target/product/security": nil, |
| 6433 | "apex_manifest.json": nil, |
| 6434 | "AndroidManifest.xml": nil, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 6435 | "system/sepolicy/apex/myapex-file_contexts": nil, |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6436 | "system/sepolicy/apex/some-updatable-apex-file_contexts": nil, |
| 6437 | "system/sepolicy/apex/some-non-updatable-apex-file_contexts": nil, |
| 6438 | "system/sepolicy/apex/com.android.art.debug-file_contexts": nil, |
Martin Stjernholm | 1dc0d6d | 2021-01-17 21:05:12 +0000 | [diff] [blame] | 6439 | "framework/aidl/a.aidl": nil, |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6440 | } |
| 6441 | cc.GatherRequiredFilesForTest(fs) |
| 6442 | |
Paul Duffin | 3985351 | 2021-02-26 11:09:39 +0000 | [diff] [blame] | 6443 | for k, v := range filesForSdkLibrary { |
| 6444 | fs[k] = v |
| 6445 | } |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 6446 | config := android.TestArchConfig(t.TempDir(), nil, bp, fs) |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 6447 | |
| 6448 | ctx := android.NewTestArchContext(config) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6449 | ctx.RegisterModuleType("apex", BundleFactory) |
| 6450 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 6451 | ctx.RegisterModuleType("prebuilt_apex", PrebuiltFactory) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6452 | ctx.RegisterModuleType("filegroup", android.FileGroupFactory) |
Paul Duffin | c988c8e | 2020-04-29 18:27:14 +0100 | [diff] [blame] | 6453 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
Paul Duffin | 3785673 | 2021-02-26 14:24:15 +0000 | [diff] [blame] | 6454 | ctx.PreArchMutators(android.RegisterComponentsMutator) |
Paul Duffin | 021f4e5 | 2020-07-30 16:04:17 +0100 | [diff] [blame] | 6455 | android.RegisterPrebuiltMutators(ctx) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6456 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
Paul Duffin | c059c8c | 2021-01-20 17:13:52 +0000 | [diff] [blame] | 6457 | java.RegisterRequiredBuildComponentsForTest(ctx) |
Paul Duffin | f38931c | 2021-02-05 16:58:28 +0000 | [diff] [blame] | 6458 | java.RegisterHiddenApiSingletonComponents(ctx) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6459 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 6460 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
| 6461 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
| 6462 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 6463 | ctx.Register() |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6464 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6465 | pathCtx := android.PathContextForTesting(config) |
| 6466 | dexpreoptConfig := dexpreopt.GlobalConfigForTests(pathCtx) |
| 6467 | transformDexpreoptConfig(dexpreoptConfig) |
| 6468 | dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig) |
| 6469 | |
Paul Duffin | f38931c | 2021-02-05 16:58:28 +0000 | [diff] [blame] | 6470 | // Make sure that any changes to these dexpreopt properties are mirrored in the corresponding |
Paul Duffin | 4fd997b | 2021-02-03 20:06:33 +0000 | [diff] [blame] | 6471 | // product variables. |
Paul Duffin | f38931c | 2021-02-05 16:58:28 +0000 | [diff] [blame] | 6472 | config.TestProductVariables.BootJars = dexpreoptConfig.BootJars |
| 6473 | config.TestProductVariables.UpdatableBootJars = dexpreoptConfig.UpdatableBootJars |
| 6474 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6475 | _, errs := ctx.ParseBlueprintsFiles("Android.bp") |
| 6476 | android.FailIfErrored(t, errs) |
| 6477 | |
| 6478 | _, errs = ctx.PrepareBuildActions(config) |
| 6479 | if errmsg == "" { |
| 6480 | android.FailIfErrored(t, errs) |
| 6481 | } else if len(errs) > 0 { |
| 6482 | android.FailIfNoMatchingErrors(t, errmsg, errs) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6483 | } else { |
| 6484 | t.Fatalf("missing expected error %q (0 errors are returned)", errmsg) |
| 6485 | } |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 6486 | |
| 6487 | return ctx |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6488 | } |
| 6489 | |
Jooyung Han | 548640b | 2020-04-27 12:10:30 +0900 | [diff] [blame] | 6490 | func TestUpdatable_should_set_min_sdk_version(t *testing.T) { |
| 6491 | testApexError(t, `"myapex" .*: updatable: updatable APEXes should set min_sdk_version`, ` |
| 6492 | apex { |
| 6493 | name: "myapex", |
| 6494 | key: "myapex.key", |
| 6495 | updatable: true, |
| 6496 | } |
| 6497 | |
| 6498 | apex_key { |
| 6499 | name: "myapex.key", |
| 6500 | public_key: "testkey.avbpubkey", |
| 6501 | private_key: "testkey.pem", |
| 6502 | } |
| 6503 | `) |
| 6504 | } |
| 6505 | |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6506 | func TestUpdatableDefault_should_set_min_sdk_version(t *testing.T) { |
| 6507 | testApexError(t, `"myapex" .*: updatable: updatable APEXes should set min_sdk_version`, ` |
| 6508 | apex { |
| 6509 | name: "myapex", |
| 6510 | key: "myapex.key", |
| 6511 | } |
| 6512 | |
| 6513 | apex_key { |
| 6514 | name: "myapex.key", |
| 6515 | public_key: "testkey.avbpubkey", |
| 6516 | private_key: "testkey.pem", |
| 6517 | } |
| 6518 | `) |
| 6519 | } |
| 6520 | |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6521 | func TestNoUpdatableJarsInBootImage(t *testing.T) { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6522 | var err string |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6523 | var transform func(*dexpreopt.GlobalConfig) |
| 6524 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6525 | t.Run("updatable jar from ART apex in the ART boot image => ok", func(t *testing.T) { |
| 6526 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6527 | config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"com.android.art.debug:some-art-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6528 | } |
| 6529 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 6530 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6531 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6532 | t.Run("updatable jar from ART apex in the framework boot image => error", func(t *testing.T) { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6533 | err = `module "some-art-lib" from updatable apexes \["com.android.art.debug"\] is not allowed in the framework boot image` |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6534 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | d376f79 | 2021-01-26 11:59:35 +0000 | [diff] [blame] | 6535 | config.BootJars = android.CreateTestConfiguredJarList([]string{"com.android.art.debug:some-art-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6536 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6537 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6538 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6539 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6540 | t.Run("updatable jar from some other apex in the ART boot image => error", func(t *testing.T) { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 6541 | err = `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the ART boot image` |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6542 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6543 | config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"some-updatable-apex:some-updatable-apex-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6544 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6545 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6546 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6547 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6548 | t.Run("non-updatable jar from some other apex in the ART boot image => error", func(t *testing.T) { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 6549 | err = `module "some-non-updatable-apex-lib" is not allowed in the ART boot image` |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6550 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6551 | config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"some-non-updatable-apex:some-non-updatable-apex-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6552 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6553 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6554 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 6555 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6556 | t.Run("updatable jar from some other apex in the framework boot image => error", func(t *testing.T) { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 6557 | err = `module "some-updatable-apex-lib" from updatable apexes \["some-updatable-apex"\] is not allowed in the framework boot image` |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6558 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6559 | config.BootJars = android.CreateTestConfiguredJarList([]string{"some-updatable-apex:some-updatable-apex-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6560 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6561 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6562 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6563 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6564 | t.Run("non-updatable jar from some other apex in the framework boot image => ok", func(t *testing.T) { |
| 6565 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6566 | config.BootJars = android.CreateTestConfiguredJarList([]string{"some-non-updatable-apex:some-non-updatable-apex-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6567 | } |
| 6568 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 6569 | }) |
Ulya Trafimovich | 7c140d8 | 2020-04-22 18:05:58 +0100 | [diff] [blame] | 6570 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6571 | t.Run("nonexistent jar in the ART boot image => error", func(t *testing.T) { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6572 | err = "failed to find a dex jar path for module 'nonexistent'" |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6573 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6574 | config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"platform:nonexistent"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6575 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6576 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6577 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6578 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6579 | t.Run("nonexistent jar in the framework boot image => error", func(t *testing.T) { |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6580 | err = "failed to find a dex jar path for module 'nonexistent'" |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6581 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6582 | config.BootJars = android.CreateTestConfiguredJarList([]string{"platform:nonexistent"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6583 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6584 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6585 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6586 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6587 | t.Run("platform jar in the ART boot image => error", func(t *testing.T) { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 6588 | err = `module "some-platform-lib" is not allowed in the ART boot image` |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6589 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6590 | config.ArtApexJars = android.CreateTestConfiguredJarList([]string{"platform:some-platform-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6591 | } |
Sasha Smundak | 18d98bc | 2020-05-27 16:36:07 -0700 | [diff] [blame] | 6592 | testNoUpdatableJarsInBootImage(t, err, transform) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6593 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6594 | |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6595 | t.Run("platform jar in the framework boot image => ok", func(t *testing.T) { |
| 6596 | transform = func(config *dexpreopt.GlobalConfig) { |
Paul Duffin | e10dfa4 | 2020-10-23 21:23:44 +0100 | [diff] [blame] | 6597 | config.BootJars = android.CreateTestConfiguredJarList([]string{"platform:some-platform-lib"}) |
Ulya Trafimovich | 7caef20 | 2020-05-19 12:00:52 +0100 | [diff] [blame] | 6598 | } |
| 6599 | testNoUpdatableJarsInBootImage(t, "", transform) |
| 6600 | }) |
Paul Duffin | 064b70c | 2020-11-02 17:32:38 +0000 | [diff] [blame] | 6601 | |
| 6602 | } |
| 6603 | |
| 6604 | func TestDexpreoptAccessDexFilesFromPrebuiltApex(t *testing.T) { |
| 6605 | transform := func(config *dexpreopt.GlobalConfig) { |
| 6606 | config.BootJars = android.CreateTestConfiguredJarList([]string{"myapex:libfoo"}) |
| 6607 | } |
| 6608 | t.Run("prebuilt no source", func(t *testing.T) { |
| 6609 | testDexpreoptWithApexes(t, ` |
| 6610 | prebuilt_apex { |
| 6611 | name: "myapex" , |
| 6612 | arch: { |
| 6613 | arm64: { |
| 6614 | src: "myapex-arm64.apex", |
| 6615 | }, |
| 6616 | arm: { |
| 6617 | src: "myapex-arm.apex", |
| 6618 | }, |
| 6619 | }, |
| 6620 | exported_java_libs: ["libfoo"], |
| 6621 | } |
| 6622 | |
| 6623 | java_import { |
| 6624 | name: "libfoo", |
| 6625 | jars: ["libfoo.jar"], |
| 6626 | } |
| 6627 | `, "", transform) |
| 6628 | }) |
| 6629 | |
| 6630 | t.Run("prebuilt no source", func(t *testing.T) { |
| 6631 | testDexpreoptWithApexes(t, ` |
| 6632 | prebuilt_apex { |
| 6633 | name: "myapex" , |
| 6634 | arch: { |
| 6635 | arm64: { |
| 6636 | src: "myapex-arm64.apex", |
| 6637 | }, |
| 6638 | arm: { |
| 6639 | src: "myapex-arm.apex", |
| 6640 | }, |
| 6641 | }, |
| 6642 | exported_java_libs: ["libfoo"], |
| 6643 | } |
| 6644 | |
| 6645 | java_import { |
| 6646 | name: "libfoo", |
| 6647 | jars: ["libfoo.jar"], |
| 6648 | } |
| 6649 | `, "", transform) |
| 6650 | }) |
Ulya Trafimovich | b28cc37 | 2020-01-13 15:18:16 +0000 | [diff] [blame] | 6651 | } |
| 6652 | |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6653 | func testApexPermittedPackagesRules(t *testing.T, errmsg, bp string, apexBootJars []string, rules []android.Rule) { |
| 6654 | t.Helper() |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6655 | bp += ` |
| 6656 | apex_key { |
| 6657 | name: "myapex.key", |
| 6658 | public_key: "testkey.avbpubkey", |
| 6659 | private_key: "testkey.pem", |
| 6660 | }` |
| 6661 | fs := map[string][]byte{ |
| 6662 | "lib1/src/A.java": nil, |
| 6663 | "lib2/src/B.java": nil, |
| 6664 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 6665 | } |
| 6666 | |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 6667 | config := android.TestArchConfig(t.TempDir(), nil, bp, fs) |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 6668 | android.SetTestNeverallowRules(config, rules) |
| 6669 | updatableBootJars := make([]string, 0, len(apexBootJars)) |
| 6670 | for _, apexBootJar := range apexBootJars { |
| 6671 | updatableBootJars = append(updatableBootJars, "myapex:"+apexBootJar) |
| 6672 | } |
| 6673 | config.TestProductVariables.UpdatableBootJars = android.CreateTestConfiguredJarList(updatableBootJars) |
| 6674 | |
| 6675 | ctx := android.NewTestArchContext(config) |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6676 | ctx.RegisterModuleType("apex", BundleFactory) |
| 6677 | ctx.RegisterModuleType("apex_key", ApexKeyFactory) |
| 6678 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
| 6679 | cc.RegisterRequiredBuildComponentsForTest(ctx) |
Paul Duffin | c059c8c | 2021-01-20 17:13:52 +0000 | [diff] [blame] | 6680 | java.RegisterRequiredBuildComponentsForTest(ctx) |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6681 | ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) |
| 6682 | ctx.PreDepsMutators(RegisterPreDepsMutators) |
| 6683 | ctx.PostDepsMutators(RegisterPostDepsMutators) |
| 6684 | ctx.PostDepsMutators(android.RegisterNeverallowMutator) |
| 6685 | |
Colin Cross | ae8600b | 2020-10-29 17:09:13 -0700 | [diff] [blame] | 6686 | ctx.Register() |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6687 | |
| 6688 | _, errs := ctx.ParseBlueprintsFiles("Android.bp") |
| 6689 | android.FailIfErrored(t, errs) |
| 6690 | |
| 6691 | _, errs = ctx.PrepareBuildActions(config) |
| 6692 | if errmsg == "" { |
| 6693 | android.FailIfErrored(t, errs) |
| 6694 | } else if len(errs) > 0 { |
| 6695 | android.FailIfNoMatchingErrors(t, errmsg, errs) |
| 6696 | return |
| 6697 | } else { |
| 6698 | t.Fatalf("missing expected error %q (0 errors are returned)", errmsg) |
| 6699 | } |
| 6700 | } |
| 6701 | |
| 6702 | func TestApexPermittedPackagesRules(t *testing.T) { |
| 6703 | testcases := []struct { |
| 6704 | name string |
| 6705 | expectedError string |
| 6706 | bp string |
| 6707 | bootJars []string |
| 6708 | modulesPackages map[string][]string |
| 6709 | }{ |
| 6710 | |
| 6711 | { |
| 6712 | name: "Non-Bootclasspath apex jar not satisfying allowed module packages.", |
| 6713 | expectedError: "", |
| 6714 | bp: ` |
| 6715 | java_library { |
| 6716 | name: "bcp_lib1", |
| 6717 | srcs: ["lib1/src/*.java"], |
| 6718 | permitted_packages: ["foo.bar"], |
| 6719 | apex_available: ["myapex"], |
| 6720 | sdk_version: "none", |
| 6721 | system_modules: "none", |
| 6722 | } |
| 6723 | java_library { |
| 6724 | name: "nonbcp_lib2", |
| 6725 | srcs: ["lib2/src/*.java"], |
| 6726 | apex_available: ["myapex"], |
| 6727 | permitted_packages: ["a.b"], |
| 6728 | sdk_version: "none", |
| 6729 | system_modules: "none", |
| 6730 | } |
| 6731 | apex { |
| 6732 | name: "myapex", |
| 6733 | key: "myapex.key", |
| 6734 | java_libs: ["bcp_lib1", "nonbcp_lib2"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6735 | updatable: false, |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6736 | }`, |
| 6737 | bootJars: []string{"bcp_lib1"}, |
| 6738 | modulesPackages: map[string][]string{ |
| 6739 | "myapex": []string{ |
| 6740 | "foo.bar", |
| 6741 | }, |
| 6742 | }, |
| 6743 | }, |
| 6744 | { |
| 6745 | name: "Bootclasspath apex jar not satisfying allowed module packages.", |
| 6746 | expectedError: `module "bcp_lib2" .* which is restricted because jars that are part of the myapex module may only allow these packages: foo.bar. Please jarjar or move code around.`, |
| 6747 | bp: ` |
| 6748 | java_library { |
| 6749 | name: "bcp_lib1", |
| 6750 | srcs: ["lib1/src/*.java"], |
| 6751 | apex_available: ["myapex"], |
| 6752 | permitted_packages: ["foo.bar"], |
| 6753 | sdk_version: "none", |
| 6754 | system_modules: "none", |
| 6755 | } |
| 6756 | java_library { |
| 6757 | name: "bcp_lib2", |
| 6758 | srcs: ["lib2/src/*.java"], |
| 6759 | apex_available: ["myapex"], |
| 6760 | permitted_packages: ["foo.bar", "bar.baz"], |
| 6761 | sdk_version: "none", |
| 6762 | system_modules: "none", |
| 6763 | } |
| 6764 | apex { |
| 6765 | name: "myapex", |
| 6766 | key: "myapex.key", |
| 6767 | java_libs: ["bcp_lib1", "bcp_lib2"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6768 | updatable: false, |
Andrei Onea | 115e7e7 | 2020-06-05 21:14:03 +0100 | [diff] [blame] | 6769 | } |
| 6770 | `, |
| 6771 | bootJars: []string{"bcp_lib1", "bcp_lib2"}, |
| 6772 | modulesPackages: map[string][]string{ |
| 6773 | "myapex": []string{ |
| 6774 | "foo.bar", |
| 6775 | }, |
| 6776 | }, |
| 6777 | }, |
| 6778 | } |
| 6779 | for _, tc := range testcases { |
| 6780 | t.Run(tc.name, func(t *testing.T) { |
| 6781 | rules := createApexPermittedPackagesRules(tc.modulesPackages) |
| 6782 | testApexPermittedPackagesRules(t, tc.expectedError, tc.bp, tc.bootJars, rules) |
| 6783 | }) |
| 6784 | } |
| 6785 | } |
| 6786 | |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6787 | func TestTestFor(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6788 | ctx := testApex(t, ` |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6789 | apex { |
| 6790 | name: "myapex", |
| 6791 | key: "myapex.key", |
| 6792 | native_shared_libs: ["mylib", "myprivlib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6793 | updatable: false, |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6794 | } |
| 6795 | |
| 6796 | apex_key { |
| 6797 | name: "myapex.key", |
| 6798 | public_key: "testkey.avbpubkey", |
| 6799 | private_key: "testkey.pem", |
| 6800 | } |
| 6801 | |
| 6802 | cc_library { |
| 6803 | name: "mylib", |
| 6804 | srcs: ["mylib.cpp"], |
| 6805 | system_shared_libs: [], |
| 6806 | stl: "none", |
| 6807 | stubs: { |
| 6808 | versions: ["1"], |
| 6809 | }, |
| 6810 | apex_available: ["myapex"], |
| 6811 | } |
| 6812 | |
| 6813 | cc_library { |
| 6814 | name: "myprivlib", |
| 6815 | srcs: ["mylib.cpp"], |
| 6816 | system_shared_libs: [], |
| 6817 | stl: "none", |
| 6818 | apex_available: ["myapex"], |
| 6819 | } |
| 6820 | |
| 6821 | |
| 6822 | cc_test { |
| 6823 | name: "mytest", |
| 6824 | gtest: false, |
| 6825 | srcs: ["mylib.cpp"], |
| 6826 | system_shared_libs: [], |
| 6827 | stl: "none", |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 6828 | shared_libs: ["mylib", "myprivlib", "mytestlib"], |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6829 | test_for: ["myapex"] |
| 6830 | } |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 6831 | |
| 6832 | cc_library { |
| 6833 | name: "mytestlib", |
| 6834 | srcs: ["mylib.cpp"], |
| 6835 | system_shared_libs: [], |
| 6836 | shared_libs: ["mylib", "myprivlib"], |
| 6837 | stl: "none", |
| 6838 | test_for: ["myapex"], |
| 6839 | } |
| 6840 | |
| 6841 | cc_benchmark { |
| 6842 | name: "mybench", |
| 6843 | srcs: ["mylib.cpp"], |
| 6844 | system_shared_libs: [], |
| 6845 | shared_libs: ["mylib", "myprivlib"], |
| 6846 | stl: "none", |
| 6847 | test_for: ["myapex"], |
| 6848 | } |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6849 | `) |
| 6850 | |
| 6851 | // the test 'mytest' is a test for the apex, therefore is linked to the |
| 6852 | // actual implementation of mylib instead of its stub. |
| 6853 | ldFlags := ctx.ModuleForTests("mytest", "android_arm64_armv8-a").Rule("ld").Args["libFlags"] |
| 6854 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared/mylib.so") |
| 6855 | ensureNotContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared_1/mylib.so") |
Jiyong Park | 46a512f | 2020-12-04 18:02:13 +0900 | [diff] [blame] | 6856 | |
| 6857 | // The same should be true for cc_library |
| 6858 | ldFlags = ctx.ModuleForTests("mytestlib", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 6859 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared/mylib.so") |
| 6860 | ensureNotContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared_1/mylib.so") |
| 6861 | |
| 6862 | // ... and for cc_benchmark |
| 6863 | ldFlags = ctx.ModuleForTests("mybench", "android_arm64_armv8-a").Rule("ld").Args["libFlags"] |
| 6864 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared/mylib.so") |
| 6865 | ensureNotContains(t, ldFlags, "mylib/android_arm64_armv8-a_shared_1/mylib.so") |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 6866 | } |
| 6867 | |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 6868 | // TODO(jungjw): Move this to proptools |
| 6869 | func intPtr(i int) *int { |
| 6870 | return &i |
| 6871 | } |
| 6872 | |
| 6873 | func TestApexSet(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6874 | ctx := testApex(t, ` |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 6875 | apex_set { |
| 6876 | name: "myapex", |
| 6877 | set: "myapex.apks", |
| 6878 | filename: "foo_v2.apex", |
| 6879 | overrides: ["foo"], |
| 6880 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 6881 | `, |
| 6882 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 6883 | variables.Platform_sdk_version = intPtr(30) |
| 6884 | }), |
| 6885 | android.FixtureModifyConfig(func(config android.Config) { |
| 6886 | config.Targets[android.Android] = []android.Target{ |
| 6887 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm, ArchVariant: "armv7-a-neon", Abi: []string{"armeabi-v7a"}}}, |
| 6888 | {Os: android.Android, Arch: android.Arch{ArchType: android.Arm64, ArchVariant: "armv8-a", Abi: []string{"arm64-v8a"}}}, |
| 6889 | } |
| 6890 | }), |
| 6891 | ) |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 6892 | |
| 6893 | m := ctx.ModuleForTests("myapex", "android_common") |
| 6894 | |
| 6895 | // Check extract_apks tool parameters. |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 6896 | extractedApex := m.Output("out/soong/.intermediates/myapex/android_common/foo_v2.apex") |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 6897 | actual := extractedApex.Args["abis"] |
| 6898 | expected := "ARMEABI_V7A,ARM64_V8A" |
| 6899 | if actual != expected { |
| 6900 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 6901 | } |
| 6902 | actual = extractedApex.Args["sdk-version"] |
| 6903 | expected = "30" |
| 6904 | if actual != expected { |
| 6905 | t.Errorf("Unexpected abis parameter - expected %q vs actual %q", expected, actual) |
| 6906 | } |
| 6907 | |
| 6908 | a := m.Module().(*ApexSet) |
| 6909 | expectedOverrides := []string{"foo"} |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 6910 | actualOverrides := android.AndroidMkEntriesForTest(t, ctx, a)[0].EntryMap["LOCAL_OVERRIDES_MODULES"] |
Jaewoong Jung | fa00c06 | 2020-05-14 14:15:24 -0700 | [diff] [blame] | 6911 | if !reflect.DeepEqual(actualOverrides, expectedOverrides) { |
| 6912 | t.Errorf("Incorrect LOCAL_OVERRIDES_MODULES - expected %q vs actual %q", expectedOverrides, actualOverrides) |
| 6913 | } |
| 6914 | } |
| 6915 | |
Jiyong Park | 7d95a51 | 2020-05-10 15:16:24 +0900 | [diff] [blame] | 6916 | func TestNoStaticLinkingToStubsLib(t *testing.T) { |
| 6917 | testApexError(t, `.*required by "mylib" is a native library providing stub.*`, ` |
| 6918 | apex { |
| 6919 | name: "myapex", |
| 6920 | key: "myapex.key", |
| 6921 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6922 | updatable: false, |
Jiyong Park | 7d95a51 | 2020-05-10 15:16:24 +0900 | [diff] [blame] | 6923 | } |
| 6924 | |
| 6925 | apex_key { |
| 6926 | name: "myapex.key", |
| 6927 | public_key: "testkey.avbpubkey", |
| 6928 | private_key: "testkey.pem", |
| 6929 | } |
| 6930 | |
| 6931 | cc_library { |
| 6932 | name: "mylib", |
| 6933 | srcs: ["mylib.cpp"], |
| 6934 | static_libs: ["otherlib"], |
| 6935 | system_shared_libs: [], |
| 6936 | stl: "none", |
| 6937 | apex_available: [ "myapex" ], |
| 6938 | } |
| 6939 | |
| 6940 | cc_library { |
| 6941 | name: "otherlib", |
| 6942 | srcs: ["mylib.cpp"], |
| 6943 | system_shared_libs: [], |
| 6944 | stl: "none", |
| 6945 | stubs: { |
| 6946 | versions: ["1", "2", "3"], |
| 6947 | }, |
| 6948 | apex_available: [ "myapex" ], |
| 6949 | } |
| 6950 | `) |
| 6951 | } |
| 6952 | |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 6953 | func TestApexKeysTxt(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6954 | ctx := testApex(t, ` |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 6955 | apex { |
| 6956 | name: "myapex", |
| 6957 | key: "myapex.key", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 6958 | updatable: false, |
Jiyong Park | 8d6c51e | 2020-06-12 17:26:31 +0900 | [diff] [blame] | 6959 | } |
| 6960 | |
| 6961 | apex_key { |
| 6962 | name: "myapex.key", |
| 6963 | public_key: "testkey.avbpubkey", |
| 6964 | private_key: "testkey.pem", |
| 6965 | } |
| 6966 | |
| 6967 | prebuilt_apex { |
| 6968 | name: "myapex", |
| 6969 | prefer: true, |
| 6970 | arch: { |
| 6971 | arm64: { |
| 6972 | src: "myapex-arm64.apex", |
| 6973 | }, |
| 6974 | arm: { |
| 6975 | src: "myapex-arm.apex", |
| 6976 | }, |
| 6977 | }, |
| 6978 | } |
| 6979 | |
| 6980 | apex_set { |
| 6981 | name: "myapex_set", |
| 6982 | set: "myapex.apks", |
| 6983 | filename: "myapex_set.apex", |
| 6984 | overrides: ["myapex"], |
| 6985 | } |
| 6986 | `) |
| 6987 | |
| 6988 | apexKeysText := ctx.SingletonForTests("apex_keys_text") |
| 6989 | content := apexKeysText.MaybeDescription("apexkeys.txt").BuildParams.Args["content"] |
| 6990 | 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] | 6991 | 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] | 6992 | } |
| 6993 | |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 6994 | func TestAllowedFiles(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 6995 | ctx := testApex(t, ` |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 6996 | apex { |
| 6997 | name: "myapex", |
| 6998 | key: "myapex.key", |
| 6999 | apps: ["app"], |
| 7000 | allowed_files: "allowed.txt", |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7001 | updatable: false, |
Jooyung Han | 938b593 | 2020-06-20 12:47:47 +0900 | [diff] [blame] | 7002 | } |
| 7003 | |
| 7004 | apex_key { |
| 7005 | name: "myapex.key", |
| 7006 | public_key: "testkey.avbpubkey", |
| 7007 | private_key: "testkey.pem", |
| 7008 | } |
| 7009 | |
| 7010 | android_app { |
| 7011 | name: "app", |
| 7012 | srcs: ["foo/bar/MyClass.java"], |
| 7013 | package_name: "foo", |
| 7014 | sdk_version: "none", |
| 7015 | system_modules: "none", |
| 7016 | apex_available: [ "myapex" ], |
| 7017 | } |
| 7018 | `, withFiles(map[string][]byte{ |
| 7019 | "sub/Android.bp": []byte(` |
| 7020 | override_apex { |
| 7021 | name: "override_myapex", |
| 7022 | base: "myapex", |
| 7023 | apps: ["override_app"], |
| 7024 | allowed_files: ":allowed", |
| 7025 | } |
| 7026 | // Overridable "path" property should be referenced indirectly |
| 7027 | filegroup { |
| 7028 | name: "allowed", |
| 7029 | srcs: ["allowed.txt"], |
| 7030 | } |
| 7031 | override_android_app { |
| 7032 | name: "override_app", |
| 7033 | base: "app", |
| 7034 | package_name: "bar", |
| 7035 | } |
| 7036 | `), |
| 7037 | })) |
| 7038 | |
| 7039 | rule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("diffApexContentRule") |
| 7040 | if expected, actual := "allowed.txt", rule.Args["allowed_files_file"]; expected != actual { |
| 7041 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 7042 | } |
| 7043 | |
| 7044 | rule2 := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Rule("diffApexContentRule") |
| 7045 | if expected, actual := "sub/allowed.txt", rule2.Args["allowed_files_file"]; expected != actual { |
| 7046 | t.Errorf("allowed_files_file: expected %q but got %q", expected, actual) |
| 7047 | } |
| 7048 | } |
| 7049 | |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 7050 | func TestNonPreferredPrebuiltDependency(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7051 | testApex(t, ` |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 7052 | apex { |
| 7053 | name: "myapex", |
| 7054 | key: "myapex.key", |
| 7055 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7056 | updatable: false, |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 7057 | } |
| 7058 | |
| 7059 | apex_key { |
| 7060 | name: "myapex.key", |
| 7061 | public_key: "testkey.avbpubkey", |
| 7062 | private_key: "testkey.pem", |
| 7063 | } |
| 7064 | |
| 7065 | cc_library { |
| 7066 | name: "mylib", |
| 7067 | srcs: ["mylib.cpp"], |
| 7068 | stubs: { |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 7069 | versions: ["current"], |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 7070 | }, |
| 7071 | apex_available: ["myapex"], |
| 7072 | } |
| 7073 | |
| 7074 | cc_prebuilt_library_shared { |
| 7075 | name: "mylib", |
| 7076 | prefer: false, |
| 7077 | srcs: ["prebuilt.so"], |
| 7078 | stubs: { |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 7079 | versions: ["current"], |
Martin Stjernholm | 58c33f0 | 2020-07-06 22:56:01 +0100 | [diff] [blame] | 7080 | }, |
| 7081 | apex_available: ["myapex"], |
| 7082 | } |
| 7083 | `) |
| 7084 | } |
| 7085 | |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 7086 | func TestCompressedApex(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7087 | ctx := testApex(t, ` |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 7088 | apex { |
| 7089 | name: "myapex", |
| 7090 | key: "myapex.key", |
| 7091 | compressible: true, |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7092 | updatable: false, |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 7093 | } |
| 7094 | apex_key { |
| 7095 | name: "myapex.key", |
| 7096 | public_key: "testkey.avbpubkey", |
| 7097 | private_key: "testkey.pem", |
| 7098 | } |
Paul Duffin | 0a49fdc | 2021-03-08 11:28:25 +0000 | [diff] [blame] | 7099 | `, |
| 7100 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 7101 | variables.CompressedApex = proptools.BoolPtr(true) |
| 7102 | }), |
| 7103 | ) |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 7104 | |
| 7105 | compressRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("compressRule") |
| 7106 | ensureContains(t, compressRule.Output.String(), "myapex.capex.unsigned") |
| 7107 | |
| 7108 | signApkRule := ctx.ModuleForTests("myapex", "android_common_myapex_image").Description("sign compressedApex") |
| 7109 | ensureEquals(t, signApkRule.Input.String(), compressRule.Output.String()) |
| 7110 | |
| 7111 | // Make sure output of bundle is .capex |
| 7112 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
| 7113 | ensureContains(t, ab.outputFile.String(), "myapex.capex") |
| 7114 | |
| 7115 | // Verify android.mk rules |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 7116 | data := android.AndroidMkDataForTest(t, ctx, ab) |
Mohammad Samiul Islam | 3cd005d | 2020-11-26 13:32:26 +0000 | [diff] [blame] | 7117 | var builder strings.Builder |
| 7118 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 7119 | androidMk := builder.String() |
| 7120 | ensureContains(t, androidMk, "LOCAL_MODULE_STEM := myapex.capex\n") |
| 7121 | } |
| 7122 | |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 7123 | func TestPreferredPrebuiltSharedLibDep(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7124 | ctx := testApex(t, ` |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 7125 | apex { |
| 7126 | name: "myapex", |
| 7127 | key: "myapex.key", |
| 7128 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7129 | updatable: false, |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 7130 | } |
| 7131 | |
| 7132 | apex_key { |
| 7133 | name: "myapex.key", |
| 7134 | public_key: "testkey.avbpubkey", |
| 7135 | private_key: "testkey.pem", |
| 7136 | } |
| 7137 | |
| 7138 | cc_library { |
| 7139 | name: "mylib", |
| 7140 | srcs: ["mylib.cpp"], |
| 7141 | apex_available: ["myapex"], |
| 7142 | shared_libs: ["otherlib"], |
| 7143 | system_shared_libs: [], |
| 7144 | } |
| 7145 | |
| 7146 | cc_library { |
| 7147 | name: "otherlib", |
| 7148 | srcs: ["mylib.cpp"], |
| 7149 | stubs: { |
| 7150 | versions: ["current"], |
| 7151 | }, |
| 7152 | } |
| 7153 | |
| 7154 | cc_prebuilt_library_shared { |
| 7155 | name: "otherlib", |
| 7156 | prefer: true, |
| 7157 | srcs: ["prebuilt.so"], |
| 7158 | stubs: { |
| 7159 | versions: ["current"], |
| 7160 | }, |
| 7161 | } |
| 7162 | `) |
| 7163 | |
| 7164 | ab := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 7165 | data := android.AndroidMkDataForTest(t, ctx, ab) |
Martin Stjernholm | 2856c66 | 2020-12-02 15:03:42 +0000 | [diff] [blame] | 7166 | var builder strings.Builder |
| 7167 | data.Custom(&builder, ab.BaseModuleName(), "TARGET_", "", data) |
| 7168 | androidMk := builder.String() |
| 7169 | |
| 7170 | // The make level dependency needs to be on otherlib - prebuilt_otherlib isn't |
| 7171 | // a thing there. |
| 7172 | ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += otherlib\n") |
| 7173 | } |
| 7174 | |
Jiyong Park | e386754 | 2020-12-03 17:28:25 +0900 | [diff] [blame] | 7175 | func TestExcludeDependency(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7176 | ctx := testApex(t, ` |
Jiyong Park | e386754 | 2020-12-03 17:28:25 +0900 | [diff] [blame] | 7177 | apex { |
| 7178 | name: "myapex", |
| 7179 | key: "myapex.key", |
| 7180 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7181 | updatable: false, |
Jiyong Park | e386754 | 2020-12-03 17:28:25 +0900 | [diff] [blame] | 7182 | } |
| 7183 | |
| 7184 | apex_key { |
| 7185 | name: "myapex.key", |
| 7186 | public_key: "testkey.avbpubkey", |
| 7187 | private_key: "testkey.pem", |
| 7188 | } |
| 7189 | |
| 7190 | cc_library { |
| 7191 | name: "mylib", |
| 7192 | srcs: ["mylib.cpp"], |
| 7193 | system_shared_libs: [], |
| 7194 | stl: "none", |
| 7195 | apex_available: ["myapex"], |
| 7196 | shared_libs: ["mylib2"], |
| 7197 | target: { |
| 7198 | apex: { |
| 7199 | exclude_shared_libs: ["mylib2"], |
| 7200 | }, |
| 7201 | }, |
| 7202 | } |
| 7203 | |
| 7204 | cc_library { |
| 7205 | name: "mylib2", |
| 7206 | srcs: ["mylib.cpp"], |
| 7207 | system_shared_libs: [], |
| 7208 | stl: "none", |
| 7209 | } |
| 7210 | `) |
| 7211 | |
| 7212 | // Check if mylib is linked to mylib2 for the non-apex target |
| 7213 | ldFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared").Rule("ld").Args["libFlags"] |
| 7214 | ensureContains(t, ldFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so") |
| 7215 | |
| 7216 | // Make sure that the link doesn't occur for the apex target |
| 7217 | ldFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"] |
| 7218 | ensureNotContains(t, ldFlags, "mylib2/android_arm64_armv8-a_shared_apex10000/mylib2.so") |
| 7219 | |
| 7220 | // It shouldn't appear in the copy cmd as well. |
| 7221 | copyCmds := ctx.ModuleForTests("myapex", "android_common_myapex_image").Rule("apexRule").Args["copy_commands"] |
| 7222 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 7223 | } |
| 7224 | |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7225 | func TestPrebuiltStubLibDep(t *testing.T) { |
| 7226 | bpBase := ` |
| 7227 | apex { |
| 7228 | name: "myapex", |
| 7229 | key: "myapex.key", |
| 7230 | native_shared_libs: ["mylib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7231 | updatable: false, |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7232 | } |
| 7233 | apex_key { |
| 7234 | name: "myapex.key", |
| 7235 | public_key: "testkey.avbpubkey", |
| 7236 | private_key: "testkey.pem", |
| 7237 | } |
| 7238 | cc_library { |
| 7239 | name: "mylib", |
| 7240 | srcs: ["mylib.cpp"], |
| 7241 | apex_available: ["myapex"], |
| 7242 | shared_libs: ["stublib"], |
| 7243 | system_shared_libs: [], |
| 7244 | } |
| 7245 | apex { |
| 7246 | name: "otherapex", |
| 7247 | enabled: %s, |
| 7248 | key: "myapex.key", |
| 7249 | native_shared_libs: ["stublib"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 7250 | updatable: false, |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7251 | } |
| 7252 | ` |
| 7253 | |
| 7254 | stublibSourceBp := ` |
| 7255 | cc_library { |
| 7256 | name: "stublib", |
| 7257 | srcs: ["mylib.cpp"], |
| 7258 | apex_available: ["otherapex"], |
| 7259 | system_shared_libs: [], |
| 7260 | stl: "none", |
| 7261 | stubs: { |
| 7262 | versions: ["1"], |
| 7263 | }, |
| 7264 | } |
| 7265 | ` |
| 7266 | |
| 7267 | stublibPrebuiltBp := ` |
| 7268 | cc_prebuilt_library_shared { |
| 7269 | name: "stublib", |
| 7270 | srcs: ["prebuilt.so"], |
| 7271 | apex_available: ["otherapex"], |
| 7272 | stubs: { |
| 7273 | versions: ["1"], |
| 7274 | }, |
| 7275 | %s |
| 7276 | } |
| 7277 | ` |
| 7278 | |
| 7279 | tests := []struct { |
| 7280 | name string |
| 7281 | stublibBp string |
| 7282 | usePrebuilt bool |
| 7283 | modNames []string // Modules to collect AndroidMkEntries for |
| 7284 | otherApexEnabled []string |
| 7285 | }{ |
| 7286 | { |
| 7287 | name: "only_source", |
| 7288 | stublibBp: stublibSourceBp, |
| 7289 | usePrebuilt: false, |
| 7290 | modNames: []string{"stublib"}, |
| 7291 | otherApexEnabled: []string{"true", "false"}, |
| 7292 | }, |
| 7293 | { |
| 7294 | name: "source_preferred", |
| 7295 | stublibBp: stublibSourceBp + fmt.Sprintf(stublibPrebuiltBp, ""), |
| 7296 | usePrebuilt: false, |
| 7297 | modNames: []string{"stublib", "prebuilt_stublib"}, |
| 7298 | otherApexEnabled: []string{"true", "false"}, |
| 7299 | }, |
| 7300 | { |
| 7301 | name: "prebuilt_preferred", |
| 7302 | stublibBp: stublibSourceBp + fmt.Sprintf(stublibPrebuiltBp, "prefer: true,"), |
| 7303 | usePrebuilt: true, |
| 7304 | modNames: []string{"stublib", "prebuilt_stublib"}, |
| 7305 | otherApexEnabled: []string{"false"}, // No "true" since APEX cannot depend on prebuilt. |
| 7306 | }, |
| 7307 | { |
| 7308 | name: "only_prebuilt", |
| 7309 | stublibBp: fmt.Sprintf(stublibPrebuiltBp, ""), |
| 7310 | usePrebuilt: true, |
| 7311 | modNames: []string{"stublib"}, |
| 7312 | otherApexEnabled: []string{"false"}, // No "true" since APEX cannot depend on prebuilt. |
| 7313 | }, |
| 7314 | } |
| 7315 | |
| 7316 | for _, test := range tests { |
| 7317 | t.Run(test.name, func(t *testing.T) { |
| 7318 | for _, otherApexEnabled := range test.otherApexEnabled { |
| 7319 | t.Run("otherapex_enabled_"+otherApexEnabled, func(t *testing.T) { |
Colin Cross | 1c46056 | 2021-02-16 17:55:47 -0800 | [diff] [blame] | 7320 | ctx := testApex(t, fmt.Sprintf(bpBase, otherApexEnabled)+test.stublibBp) |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7321 | |
| 7322 | type modAndMkEntries struct { |
| 7323 | mod *cc.Module |
| 7324 | mkEntries android.AndroidMkEntries |
| 7325 | } |
| 7326 | entries := []*modAndMkEntries{} |
| 7327 | |
| 7328 | // Gather shared lib modules that are installable |
| 7329 | for _, modName := range test.modNames { |
| 7330 | for _, variant := range ctx.ModuleVariantsForTests(modName) { |
| 7331 | if !strings.HasPrefix(variant, "android_arm64_armv8-a_shared") { |
| 7332 | continue |
| 7333 | } |
| 7334 | mod := ctx.ModuleForTests(modName, variant).Module().(*cc.Module) |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 7335 | if !mod.Enabled() || mod.IsHideFromMake() { |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7336 | continue |
| 7337 | } |
Colin Cross | aa25553 | 2020-07-03 13:18:24 -0700 | [diff] [blame] | 7338 | for _, ent := range android.AndroidMkEntriesForTest(t, ctx, mod) { |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7339 | if ent.Disabled { |
| 7340 | continue |
| 7341 | } |
| 7342 | entries = append(entries, &modAndMkEntries{ |
| 7343 | mod: mod, |
| 7344 | mkEntries: ent, |
| 7345 | }) |
| 7346 | } |
| 7347 | } |
| 7348 | } |
| 7349 | |
| 7350 | var entry *modAndMkEntries = nil |
| 7351 | for _, ent := range entries { |
| 7352 | if strings.Join(ent.mkEntries.EntryMap["LOCAL_MODULE"], ",") == "stublib" { |
| 7353 | if entry != nil { |
| 7354 | t.Errorf("More than one AndroidMk entry for \"stublib\": %s and %s", entry.mod, ent.mod) |
| 7355 | } else { |
| 7356 | entry = ent |
| 7357 | } |
| 7358 | } |
| 7359 | } |
| 7360 | |
| 7361 | if entry == nil { |
| 7362 | t.Errorf("AndroidMk entry for \"stublib\" missing") |
| 7363 | } else { |
| 7364 | isPrebuilt := entry.mod.Prebuilt() != nil |
| 7365 | if isPrebuilt != test.usePrebuilt { |
| 7366 | t.Errorf("Wrong module for \"stublib\" AndroidMk entry: got prebuilt %t, want prebuilt %t", isPrebuilt, test.usePrebuilt) |
| 7367 | } |
| 7368 | if !entry.mod.IsStubs() { |
| 7369 | t.Errorf("Module for \"stublib\" AndroidMk entry isn't a stub: %s", entry.mod) |
| 7370 | } |
| 7371 | if entry.mkEntries.EntryMap["LOCAL_NOT_AVAILABLE_FOR_PLATFORM"] != nil { |
| 7372 | t.Errorf("AndroidMk entry for \"stublib\" has LOCAL_NOT_AVAILABLE_FOR_PLATFORM set: %+v", entry.mkEntries) |
| 7373 | } |
Jiyong Park | 892a98f | 2020-12-14 09:20:00 +0900 | [diff] [blame] | 7374 | cflags := entry.mkEntries.EntryMap["LOCAL_EXPORT_CFLAGS"] |
| 7375 | expected := "-D__STUBLIB_API__=1" |
| 7376 | if !android.InList(expected, cflags) { |
| 7377 | t.Errorf("LOCAL_EXPORT_CFLAGS expected to have %q, but got %q", expected, cflags) |
| 7378 | } |
Jiyong Park | f7c3bbe | 2020-12-09 21:18:56 +0900 | [diff] [blame] | 7379 | } |
| 7380 | }) |
| 7381 | } |
| 7382 | }) |
| 7383 | } |
| 7384 | } |
| 7385 | |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 7386 | func TestMain(m *testing.M) { |
Paul Duffin | 37ba344 | 2021-03-29 00:21:08 +0100 | [diff] [blame] | 7387 | os.Exit(m.Run()) |
Jaewoong Jung | c1001ec | 2019-06-25 11:20:53 -0700 | [diff] [blame] | 7388 | } |