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 | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 18 | "io/ioutil" |
| 19 | "os" |
| 20 | "strings" |
| 21 | "testing" |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 22 | |
| 23 | "github.com/google/blueprint/proptools" |
| 24 | |
| 25 | "android/soong/android" |
| 26 | "android/soong/cc" |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 27 | ) |
| 28 | |
| 29 | func testApex(t *testing.T, bp string) *android.TestContext { |
| 30 | config, buildDir := setup(t) |
| 31 | defer teardown(buildDir) |
| 32 | |
| 33 | ctx := android.NewTestArchContext() |
Alex Light | ee25072 | 2018-12-06 14:00:02 -0800 | [diff] [blame] | 34 | ctx.RegisterModuleType("apex", android.ModuleFactoryAdaptor(ApexBundleFactory)) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 35 | ctx.RegisterModuleType("apex_key", android.ModuleFactoryAdaptor(apexKeyFactory)) |
| 36 | |
| 37 | ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 38 | ctx.TopDown("apex_deps", apexDepsMutator) |
| 39 | ctx.BottomUp("apex", apexMutator) |
| 40 | }) |
| 41 | |
| 42 | ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory)) |
| 43 | ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(cc.LibrarySharedFactory)) |
| 44 | ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory)) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 45 | ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory)) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 46 | ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory)) |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 47 | ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory)) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 48 | ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 49 | ctx.BottomUp("image", cc.ImageMutator).Parallel() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 50 | ctx.BottomUp("link", cc.LinkageMutator).Parallel() |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 51 | ctx.BottomUp("vndk", cc.VndkMutator).Parallel() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 52 | ctx.BottomUp("version", cc.VersionMutator).Parallel() |
| 53 | ctx.BottomUp("begin", cc.BeginMutator).Parallel() |
| 54 | }) |
| 55 | |
| 56 | ctx.Register() |
| 57 | |
| 58 | bp = bp + ` |
| 59 | toolchain_library { |
| 60 | name: "libcompiler_rt-extras", |
| 61 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 62 | vendor_available: true, |
| 63 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | toolchain_library { |
| 67 | name: "libatomic", |
| 68 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 69 | vendor_available: true, |
| 70 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | toolchain_library { |
| 74 | name: "libgcc", |
| 75 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 76 | vendor_available: true, |
| 77 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | toolchain_library { |
| 81 | name: "libclang_rt.builtins-aarch64-android", |
| 82 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 83 | vendor_available: true, |
| 84 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | toolchain_library { |
| 88 | name: "libclang_rt.builtins-arm-android", |
| 89 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 90 | vendor_available: true, |
| 91 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | cc_object { |
| 95 | name: "crtbegin_so", |
| 96 | stl: "none", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 97 | vendor_available: true, |
| 98 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | cc_object { |
| 102 | name: "crtend_so", |
| 103 | stl: "none", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 104 | vendor_available: true, |
| 105 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 106 | } |
| 107 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 108 | llndk_library { |
| 109 | name: "libc", |
| 110 | symbol_file: "", |
| 111 | } |
| 112 | |
| 113 | llndk_library { |
| 114 | name: "libm", |
| 115 | symbol_file: "", |
| 116 | } |
| 117 | |
| 118 | llndk_library { |
| 119 | name: "libdl", |
| 120 | symbol_file: "", |
| 121 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 122 | ` |
| 123 | |
| 124 | ctx.MockFileSystem(map[string][]byte{ |
| 125 | "Android.bp": []byte(bp), |
| 126 | "testkey.avbpubkey": nil, |
| 127 | "testkey.pem": nil, |
| 128 | "build/target/product/security": nil, |
| 129 | "apex_manifest.json": nil, |
| 130 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 131 | "mylib.cpp": nil, |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 132 | "myprebuilt": nil, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 133 | }) |
| 134 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 135 | android.FailIfErrored(t, errs) |
| 136 | _, errs = ctx.PrepareBuildActions(config) |
| 137 | android.FailIfErrored(t, errs) |
| 138 | |
| 139 | return ctx |
| 140 | } |
| 141 | |
| 142 | func setup(t *testing.T) (config android.Config, buildDir string) { |
| 143 | buildDir, err := ioutil.TempDir("", "soong_apex_test") |
| 144 | if err != nil { |
| 145 | t.Fatal(err) |
| 146 | } |
| 147 | |
| 148 | config = android.TestArchConfig(buildDir, nil) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 149 | config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 150 | return |
| 151 | } |
| 152 | |
| 153 | func teardown(buildDir string) { |
| 154 | os.RemoveAll(buildDir) |
| 155 | } |
| 156 | |
| 157 | // ensure that 'result' contains 'expected' |
| 158 | func ensureContains(t *testing.T, result string, expected string) { |
| 159 | if !strings.Contains(result, expected) { |
| 160 | t.Errorf("%q is not found in %q", expected, result) |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | // ensures that 'result' does not contain 'notExpected' |
| 165 | func ensureNotContains(t *testing.T, result string, notExpected string) { |
| 166 | if strings.Contains(result, notExpected) { |
| 167 | t.Errorf("%q is found in %q", notExpected, result) |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | func ensureListContains(t *testing.T, result []string, expected string) { |
| 172 | if !android.InList(expected, result) { |
| 173 | t.Errorf("%q is not found in %v", expected, result) |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | func ensureListNotContains(t *testing.T, result []string, notExpected string) { |
| 178 | if android.InList(notExpected, result) { |
| 179 | t.Errorf("%q is found in %v", notExpected, result) |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | // Minimal test |
| 184 | func TestBasicApex(t *testing.T) { |
| 185 | ctx := testApex(t, ` |
| 186 | apex { |
| 187 | name: "myapex", |
| 188 | key: "myapex.key", |
| 189 | native_shared_libs: ["mylib"], |
| 190 | } |
| 191 | |
| 192 | apex_key { |
| 193 | name: "myapex.key", |
| 194 | public_key: "testkey.avbpubkey", |
| 195 | private_key: "testkey.pem", |
| 196 | } |
| 197 | |
| 198 | cc_library { |
| 199 | name: "mylib", |
| 200 | srcs: ["mylib.cpp"], |
| 201 | shared_libs: ["mylib2"], |
| 202 | system_shared_libs: [], |
| 203 | stl: "none", |
| 204 | } |
| 205 | |
| 206 | cc_library { |
| 207 | name: "mylib2", |
| 208 | srcs: ["mylib.cpp"], |
| 209 | system_shared_libs: [], |
| 210 | stl: "none", |
| 211 | } |
| 212 | `) |
| 213 | |
| 214 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 215 | copyCmds := apexRule.Args["copy_commands"] |
| 216 | |
| 217 | // Ensure that main rule creates an output |
| 218 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 219 | |
| 220 | // Ensure that apex variant is created for the direct dep |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 221 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 222 | |
| 223 | // Ensure that apex variant is created for the indirect dep |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 224 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 225 | |
| 226 | // Ensure that both direct and indirect deps are copied into apex |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 227 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 228 | ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 229 | } |
| 230 | |
| 231 | func TestBasicZipApex(t *testing.T) { |
| 232 | ctx := testApex(t, ` |
| 233 | apex { |
| 234 | name: "myapex", |
| 235 | key: "myapex.key", |
| 236 | payload_type: "zip", |
| 237 | native_shared_libs: ["mylib"], |
| 238 | } |
| 239 | |
| 240 | apex_key { |
| 241 | name: "myapex.key", |
| 242 | public_key: "testkey.avbpubkey", |
| 243 | private_key: "testkey.pem", |
| 244 | } |
| 245 | |
| 246 | cc_library { |
| 247 | name: "mylib", |
| 248 | srcs: ["mylib.cpp"], |
| 249 | shared_libs: ["mylib2"], |
| 250 | system_shared_libs: [], |
| 251 | stl: "none", |
| 252 | } |
| 253 | |
| 254 | cc_library { |
| 255 | name: "mylib2", |
| 256 | srcs: ["mylib.cpp"], |
| 257 | system_shared_libs: [], |
| 258 | stl: "none", |
| 259 | } |
| 260 | `) |
| 261 | |
| 262 | zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("zipApexRule") |
| 263 | copyCmds := zipApexRule.Args["copy_commands"] |
| 264 | |
| 265 | // Ensure that main rule creates an output |
| 266 | ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned") |
| 267 | |
| 268 | // Ensure that APEX variant is created for the direct dep |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 269 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 270 | |
| 271 | // Ensure that APEX variant is created for the indirect dep |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 272 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 273 | |
| 274 | // Ensure that both direct and indirect deps are copied into apex |
| 275 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so") |
| 276 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | func TestApexWithStubs(t *testing.T) { |
| 280 | ctx := testApex(t, ` |
| 281 | apex { |
| 282 | name: "myapex", |
| 283 | key: "myapex.key", |
| 284 | native_shared_libs: ["mylib", "mylib3"], |
| 285 | } |
| 286 | |
| 287 | apex_key { |
| 288 | name: "myapex.key", |
| 289 | public_key: "testkey.avbpubkey", |
| 290 | private_key: "testkey.pem", |
| 291 | } |
| 292 | |
| 293 | cc_library { |
| 294 | name: "mylib", |
| 295 | srcs: ["mylib.cpp"], |
| 296 | shared_libs: ["mylib2", "mylib3"], |
| 297 | system_shared_libs: [], |
| 298 | stl: "none", |
| 299 | } |
| 300 | |
| 301 | cc_library { |
| 302 | name: "mylib2", |
| 303 | srcs: ["mylib.cpp"], |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 304 | cflags: ["-include mylib.h"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 305 | system_shared_libs: [], |
| 306 | stl: "none", |
| 307 | stubs: { |
| 308 | versions: ["1", "2", "3"], |
| 309 | }, |
| 310 | } |
| 311 | |
| 312 | cc_library { |
| 313 | name: "mylib3", |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 314 | srcs: ["mylib.cpp"], |
| 315 | shared_libs: ["mylib4"], |
| 316 | system_shared_libs: [], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 317 | stl: "none", |
| 318 | stubs: { |
| 319 | versions: ["10", "11", "12"], |
| 320 | }, |
| 321 | } |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 322 | |
| 323 | cc_library { |
| 324 | name: "mylib4", |
| 325 | srcs: ["mylib.cpp"], |
| 326 | system_shared_libs: [], |
| 327 | stl: "none", |
| 328 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 329 | `) |
| 330 | |
| 331 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 332 | copyCmds := apexRule.Args["copy_commands"] |
| 333 | |
| 334 | // Ensure that direct non-stubs dep is always included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 335 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 336 | |
| 337 | // Ensure that indirect stubs dep is not included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 338 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 339 | |
| 340 | // Ensure that direct stubs dep is included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 341 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 342 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 343 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"] |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 344 | |
| 345 | // Ensure that mylib is linking with the latest version of stubs for mylib2 |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 346 | ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_3_myapex/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 347 | // ... and not linking to the non-stub (impl) variant of mylib2 |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 348 | ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_core_shared_myapex/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 349 | |
| 350 | // Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 351 | ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_myapex/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 352 | // .. and not linking to the stubs variant of mylib3 |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 353 | ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_core_shared_12_myapex/mylib3.so") |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 354 | |
| 355 | // Ensure that stubs libs are built without -include flags |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 356 | mylib2Cflags := ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"] |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 357 | ensureNotContains(t, mylib2Cflags, "-include ") |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 358 | |
| 359 | // Ensure that genstub is invoked with --apex |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 360 | ensureContains(t, "--apex", ctx.ModuleForTests("mylib2", "android_arm64_armv8-a_core_static_3_myapex").Rule("genStubSrc").Args["flags"]) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 361 | } |
| 362 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 363 | func TestApexWithExplicitStubsDependency(t *testing.T) { |
| 364 | ctx := testApex(t, ` |
| 365 | apex { |
| 366 | name: "myapex", |
| 367 | key: "myapex.key", |
| 368 | native_shared_libs: ["mylib"], |
| 369 | } |
| 370 | |
| 371 | apex_key { |
| 372 | name: "myapex.key", |
| 373 | public_key: "testkey.avbpubkey", |
| 374 | private_key: "testkey.pem", |
| 375 | } |
| 376 | |
| 377 | cc_library { |
| 378 | name: "mylib", |
| 379 | srcs: ["mylib.cpp"], |
| 380 | shared_libs: ["libfoo#10"], |
| 381 | system_shared_libs: [], |
| 382 | stl: "none", |
| 383 | } |
| 384 | |
| 385 | cc_library { |
| 386 | name: "libfoo", |
| 387 | srcs: ["mylib.cpp"], |
| 388 | shared_libs: ["libbar"], |
| 389 | system_shared_libs: [], |
| 390 | stl: "none", |
| 391 | stubs: { |
| 392 | versions: ["10", "20", "30"], |
| 393 | }, |
| 394 | } |
| 395 | |
| 396 | cc_library { |
| 397 | name: "libbar", |
| 398 | srcs: ["mylib.cpp"], |
| 399 | system_shared_libs: [], |
| 400 | stl: "none", |
| 401 | } |
| 402 | |
| 403 | `) |
| 404 | |
| 405 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 406 | copyCmds := apexRule.Args["copy_commands"] |
| 407 | |
| 408 | // Ensure that direct non-stubs dep is always included |
| 409 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 410 | |
| 411 | // Ensure that indirect stubs dep is not included |
| 412 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 413 | |
| 414 | // Ensure that dependency of stubs is not included |
| 415 | ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 416 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 417 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"] |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 418 | |
| 419 | // Ensure that mylib is linking with version 10 of libfoo |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 420 | ensureContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_10_myapex/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 421 | // ... and not linking to the non-stub (impl) variant of libfoo |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 422 | ensureNotContains(t, mylibLdFlags, "libfoo/android_arm64_armv8-a_core_shared_myapex/libfoo.so") |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 423 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 424 | libFooStubsLdFlags := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_core_shared_10_myapex").Rule("ld").Args["libFlags"] |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 425 | |
| 426 | // Ensure that libfoo stubs is not linking to libbar (since it is a stubs) |
| 427 | ensureNotContains(t, libFooStubsLdFlags, "libbar.so") |
| 428 | } |
| 429 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 430 | func TestApexWithSystemLibsStubs(t *testing.T) { |
| 431 | ctx := testApex(t, ` |
| 432 | apex { |
| 433 | name: "myapex", |
| 434 | key: "myapex.key", |
| 435 | native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"], |
| 436 | } |
| 437 | |
| 438 | apex_key { |
| 439 | name: "myapex.key", |
| 440 | public_key: "testkey.avbpubkey", |
| 441 | private_key: "testkey.pem", |
| 442 | } |
| 443 | |
| 444 | cc_library { |
| 445 | name: "mylib", |
| 446 | srcs: ["mylib.cpp"], |
| 447 | shared_libs: ["libdl#27"], |
| 448 | stl: "none", |
| 449 | } |
| 450 | |
| 451 | cc_library_shared { |
| 452 | name: "mylib_shared", |
| 453 | srcs: ["mylib.cpp"], |
| 454 | shared_libs: ["libdl#27"], |
| 455 | stl: "none", |
| 456 | } |
| 457 | |
| 458 | cc_library { |
| 459 | name: "libc", |
| 460 | no_libgcc: true, |
| 461 | nocrt: true, |
| 462 | system_shared_libs: [], |
| 463 | stl: "none", |
| 464 | stubs: { |
| 465 | versions: ["27", "28", "29"], |
| 466 | }, |
| 467 | } |
| 468 | |
| 469 | cc_library { |
| 470 | name: "libm", |
| 471 | no_libgcc: true, |
| 472 | nocrt: true, |
| 473 | system_shared_libs: [], |
| 474 | stl: "none", |
| 475 | stubs: { |
| 476 | versions: ["27", "28", "29"], |
| 477 | }, |
| 478 | } |
| 479 | |
| 480 | cc_library { |
| 481 | name: "libdl", |
| 482 | no_libgcc: true, |
| 483 | nocrt: true, |
| 484 | system_shared_libs: [], |
| 485 | stl: "none", |
| 486 | stubs: { |
| 487 | versions: ["27", "28", "29"], |
| 488 | }, |
| 489 | } |
| 490 | `) |
| 491 | |
| 492 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 493 | copyCmds := apexRule.Args["copy_commands"] |
| 494 | |
| 495 | // Ensure that mylib, libm, libdl are included. |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 496 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 497 | ensureContains(t, copyCmds, "image.apex/lib64/libm.so") |
| 498 | ensureContains(t, copyCmds, "image.apex/lib64/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 499 | |
| 500 | // Ensure that libc is not included (since it has stubs and not listed in native_shared_libs) |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 501 | ensureNotContains(t, copyCmds, "image.apex/lib64/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 502 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 503 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"] |
| 504 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"] |
| 505 | mylibSharedCFlags := ctx.ModuleForTests("mylib_shared", "android_arm64_armv8-a_core_shared_myapex").Rule("cc").Args["cFlags"] |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 506 | |
| 507 | // For dependency to libc |
| 508 | // Ensure that mylib is linking with the latest version of stubs |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 509 | ensureContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_29_myapex/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 510 | // ... and not linking to the non-stub (impl) variant |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 511 | ensureNotContains(t, mylibLdFlags, "libc/android_arm64_armv8-a_core_shared_myapex/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 512 | // ... Cflags from stub is correctly exported to mylib |
| 513 | ensureContains(t, mylibCFlags, "__LIBC_API__=29") |
| 514 | ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29") |
| 515 | |
| 516 | // For dependency to libm |
| 517 | // Ensure that mylib is linking with the non-stub (impl) variant |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 518 | ensureContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_myapex/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 519 | // ... and not linking to the stub variant |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 520 | ensureNotContains(t, mylibLdFlags, "libm/android_arm64_armv8-a_core_shared_29_myapex/libm.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 521 | // ... and is not compiling with the stub |
| 522 | ensureNotContains(t, mylibCFlags, "__LIBM_API__=29") |
| 523 | ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29") |
| 524 | |
| 525 | // For dependency to libdl |
| 526 | // Ensure that mylib is linking with the specified version of stubs |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 527 | ensureContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_27_myapex/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 528 | // ... and not linking to the other versions of stubs |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 529 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_28_myapex/libdl.so") |
| 530 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_29_myapex/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 531 | // ... and not linking to the non-stub (impl) variant |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 532 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_myapex/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 533 | // ... Cflags from stub is correctly exported to mylib |
| 534 | ensureContains(t, mylibCFlags, "__LIBDL_API__=27") |
| 535 | ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27") |
| 536 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 537 | |
| 538 | func TestFilesInSubDir(t *testing.T) { |
| 539 | ctx := testApex(t, ` |
| 540 | apex { |
| 541 | name: "myapex", |
| 542 | key: "myapex.key", |
| 543 | prebuilts: ["myetc"], |
| 544 | } |
| 545 | |
| 546 | apex_key { |
| 547 | name: "myapex.key", |
| 548 | public_key: "testkey.avbpubkey", |
| 549 | private_key: "testkey.pem", |
| 550 | } |
| 551 | |
| 552 | prebuilt_etc { |
| 553 | name: "myetc", |
| 554 | src: "myprebuilt", |
| 555 | sub_dir: "foo/bar", |
| 556 | } |
| 557 | `) |
| 558 | |
| 559 | generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("generateFsConfig") |
| 560 | dirs := strings.Split(generateFsRule.Args["exec_paths"], " ") |
| 561 | |
| 562 | // Ensure that etc, etc/foo, and etc/foo/bar are all listed |
| 563 | ensureListContains(t, dirs, "etc") |
| 564 | ensureListContains(t, dirs, "etc/foo") |
| 565 | ensureListContains(t, dirs, "etc/foo/bar") |
| 566 | } |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame^] | 567 | |
| 568 | func TestUseVendor(t *testing.T) { |
| 569 | ctx := testApex(t, ` |
| 570 | apex { |
| 571 | name: "myapex", |
| 572 | key: "myapex.key", |
| 573 | native_shared_libs: ["mylib"], |
| 574 | use_vendor: true, |
| 575 | } |
| 576 | |
| 577 | apex_key { |
| 578 | name: "myapex.key", |
| 579 | public_key: "testkey.avbpubkey", |
| 580 | private_key: "testkey.pem", |
| 581 | } |
| 582 | |
| 583 | cc_library { |
| 584 | name: "mylib", |
| 585 | srcs: ["mylib.cpp"], |
| 586 | shared_libs: ["mylib2"], |
| 587 | system_shared_libs: [], |
| 588 | vendor_available: true, |
| 589 | stl: "none", |
| 590 | } |
| 591 | |
| 592 | cc_library { |
| 593 | name: "mylib2", |
| 594 | srcs: ["mylib.cpp"], |
| 595 | system_shared_libs: [], |
| 596 | vendor_available: true, |
| 597 | stl: "none", |
| 598 | } |
| 599 | `) |
| 600 | |
| 601 | inputsList := []string{} |
| 602 | for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex").Module().BuildParamsForTests() { |
| 603 | for _, implicit := range i.Implicits { |
| 604 | inputsList = append(inputsList, implicit.String()) |
| 605 | } |
| 606 | } |
| 607 | inputsString := strings.Join(inputsList, " ") |
| 608 | |
| 609 | // ensure that the apex includes vendor variants of the direct and indirect deps |
| 610 | ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib.so") |
| 611 | ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib2.so") |
| 612 | |
| 613 | // ensure that the apex does not include core variants |
| 614 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib.so") |
| 615 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib2.so") |
| 616 | } |