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)) |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame^] | 36 | ctx.RegisterModuleType("apex_defaults", android.ModuleFactoryAdaptor(defaultsFactory)) |
| 37 | ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 38 | |
| 39 | ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 40 | ctx.TopDown("apex_deps", apexDepsMutator) |
| 41 | ctx.BottomUp("apex", apexMutator) |
| 42 | }) |
| 43 | |
| 44 | ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory)) |
| 45 | ctx.RegisterModuleType("cc_library_shared", android.ModuleFactoryAdaptor(cc.LibrarySharedFactory)) |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 46 | ctx.RegisterModuleType("cc_library_headers", android.ModuleFactoryAdaptor(cc.LibraryHeaderFactory)) |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 47 | ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(cc.BinaryFactory)) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 48 | ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory)) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 49 | ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory)) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 50 | ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory)) |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 51 | ctx.RegisterModuleType("prebuilt_etc", android.ModuleFactoryAdaptor(android.PrebuiltEtcFactory)) |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 52 | ctx.RegisterModuleType("sh_binary", android.ModuleFactoryAdaptor(android.ShBinaryFactory)) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 53 | ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 54 | ctx.BottomUp("image", cc.ImageMutator).Parallel() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 55 | ctx.BottomUp("link", cc.LinkageMutator).Parallel() |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 56 | ctx.BottomUp("vndk", cc.VndkMutator).Parallel() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 57 | ctx.BottomUp("version", cc.VersionMutator).Parallel() |
| 58 | ctx.BottomUp("begin", cc.BeginMutator).Parallel() |
| 59 | }) |
| 60 | |
| 61 | ctx.Register() |
| 62 | |
| 63 | bp = bp + ` |
| 64 | toolchain_library { |
| 65 | name: "libcompiler_rt-extras", |
| 66 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 67 | vendor_available: true, |
| 68 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | toolchain_library { |
| 72 | name: "libatomic", |
| 73 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 74 | vendor_available: true, |
| 75 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | toolchain_library { |
| 79 | name: "libgcc", |
| 80 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 81 | vendor_available: true, |
| 82 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | toolchain_library { |
| 86 | name: "libclang_rt.builtins-aarch64-android", |
| 87 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 88 | vendor_available: true, |
| 89 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | toolchain_library { |
| 93 | name: "libclang_rt.builtins-arm-android", |
| 94 | src: "", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 95 | vendor_available: true, |
| 96 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | cc_object { |
| 100 | name: "crtbegin_so", |
| 101 | stl: "none", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 102 | vendor_available: true, |
| 103 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | cc_object { |
| 107 | name: "crtend_so", |
| 108 | stl: "none", |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 109 | vendor_available: true, |
| 110 | recovery_available: true, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 111 | } |
| 112 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 113 | cc_object { |
| 114 | name: "crtbegin_static", |
| 115 | stl: "none", |
| 116 | } |
| 117 | |
| 118 | cc_object { |
| 119 | name: "crtend_android", |
| 120 | stl: "none", |
| 121 | } |
| 122 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 123 | llndk_library { |
| 124 | name: "libc", |
| 125 | symbol_file: "", |
| 126 | } |
| 127 | |
| 128 | llndk_library { |
| 129 | name: "libm", |
| 130 | symbol_file: "", |
| 131 | } |
| 132 | |
| 133 | llndk_library { |
| 134 | name: "libdl", |
| 135 | symbol_file: "", |
| 136 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 137 | ` |
| 138 | |
| 139 | ctx.MockFileSystem(map[string][]byte{ |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 140 | "Android.bp": []byte(bp), |
| 141 | "build/target/product/security": nil, |
| 142 | "apex_manifest.json": nil, |
| 143 | "system/sepolicy/apex/myapex-file_contexts": nil, |
| 144 | "system/sepolicy/apex/otherapex-file_contexts": nil, |
| 145 | "mylib.cpp": nil, |
| 146 | "myprebuilt": nil, |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 147 | "my_include": nil, |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 148 | "vendor/foo/devkeys/test.x509.pem": nil, |
| 149 | "vendor/foo/devkeys/test.pk8": nil, |
| 150 | "vendor/foo/devkeys/testkey.avbpubkey": nil, |
| 151 | "vendor/foo/devkeys/testkey.pem": nil, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 152 | }) |
| 153 | _, errs := ctx.ParseFileList(".", []string{"Android.bp"}) |
| 154 | android.FailIfErrored(t, errs) |
| 155 | _, errs = ctx.PrepareBuildActions(config) |
| 156 | android.FailIfErrored(t, errs) |
| 157 | |
| 158 | return ctx |
| 159 | } |
| 160 | |
| 161 | func setup(t *testing.T) (config android.Config, buildDir string) { |
| 162 | buildDir, err := ioutil.TempDir("", "soong_apex_test") |
| 163 | if err != nil { |
| 164 | t.Fatal(err) |
| 165 | } |
| 166 | |
| 167 | config = android.TestArchConfig(buildDir, nil) |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 168 | config.TestProductVariables.DeviceVndkVersion = proptools.StringPtr("current") |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 169 | config.TestProductVariables.DefaultAppCertificate = proptools.StringPtr("vendor/foo/devkeys/test") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 170 | return |
| 171 | } |
| 172 | |
| 173 | func teardown(buildDir string) { |
| 174 | os.RemoveAll(buildDir) |
| 175 | } |
| 176 | |
| 177 | // ensure that 'result' contains 'expected' |
| 178 | func ensureContains(t *testing.T, result string, expected string) { |
| 179 | if !strings.Contains(result, expected) { |
| 180 | t.Errorf("%q is not found in %q", expected, result) |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | // ensures that 'result' does not contain 'notExpected' |
| 185 | func ensureNotContains(t *testing.T, result string, notExpected string) { |
| 186 | if strings.Contains(result, notExpected) { |
| 187 | t.Errorf("%q is found in %q", notExpected, result) |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | func ensureListContains(t *testing.T, result []string, expected string) { |
| 192 | if !android.InList(expected, result) { |
| 193 | t.Errorf("%q is not found in %v", expected, result) |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | func ensureListNotContains(t *testing.T, result []string, notExpected string) { |
| 198 | if android.InList(notExpected, result) { |
| 199 | t.Errorf("%q is found in %v", notExpected, result) |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | // Minimal test |
| 204 | func TestBasicApex(t *testing.T) { |
| 205 | ctx := testApex(t, ` |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame^] | 206 | apex_defaults { |
| 207 | name: "myapex-defaults", |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 208 | key: "myapex.key", |
| 209 | native_shared_libs: ["mylib"], |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 210 | multilib: { |
| 211 | both: { |
| 212 | binaries: ["foo",], |
| 213 | } |
| 214 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 215 | } |
| 216 | |
Jiyong Park | 30ca937 | 2019-02-07 16:27:23 +0900 | [diff] [blame^] | 217 | apex { |
| 218 | name: "myapex", |
| 219 | defaults: ["myapex-defaults"], |
| 220 | } |
| 221 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 222 | apex_key { |
| 223 | name: "myapex.key", |
| 224 | public_key: "testkey.avbpubkey", |
| 225 | private_key: "testkey.pem", |
| 226 | } |
| 227 | |
| 228 | cc_library { |
| 229 | name: "mylib", |
| 230 | srcs: ["mylib.cpp"], |
| 231 | shared_libs: ["mylib2"], |
| 232 | system_shared_libs: [], |
| 233 | stl: "none", |
| 234 | } |
| 235 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 236 | cc_binary { |
| 237 | name: "foo", |
| 238 | srcs: ["mylib.cpp"], |
| 239 | compile_multilib: "both", |
| 240 | multilib: { |
| 241 | lib32: { |
| 242 | suffix: "32", |
| 243 | }, |
| 244 | lib64: { |
| 245 | suffix: "64", |
| 246 | }, |
| 247 | }, |
| 248 | symlinks: ["foo_link_"], |
| 249 | symlink_preferred_arch: true, |
| 250 | system_shared_libs: [], |
| 251 | static_executable: true, |
| 252 | stl: "none", |
| 253 | } |
| 254 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 255 | cc_library { |
| 256 | name: "mylib2", |
| 257 | srcs: ["mylib.cpp"], |
| 258 | system_shared_libs: [], |
| 259 | stl: "none", |
| 260 | } |
| 261 | `) |
| 262 | |
| 263 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 264 | copyCmds := apexRule.Args["copy_commands"] |
| 265 | |
| 266 | // Ensure that main rule creates an output |
| 267 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 268 | |
| 269 | // Ensure that apex variant is created for the direct dep |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 270 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 271 | |
| 272 | // Ensure that apex variant is created for the indirect dep |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 273 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 274 | |
| 275 | // Ensure that both direct and indirect deps are copied into apex |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 276 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 277 | ensureContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 278 | |
| 279 | // Ensure that the platform variant ends with _core_shared |
| 280 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared") |
| 281 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared") |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 282 | |
| 283 | // Ensure that all symlinks are present. |
| 284 | found_foo_link_64 := false |
| 285 | found_foo := false |
| 286 | for _, cmd := range strings.Split(copyCmds, " && ") { |
| 287 | if strings.HasPrefix(cmd, "ln -s foo64") { |
| 288 | if strings.HasSuffix(cmd, "bin/foo") { |
| 289 | found_foo = true |
| 290 | } else if strings.HasSuffix(cmd, "bin/foo_link_64") { |
| 291 | found_foo_link_64 = true |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | good := found_foo && found_foo_link_64 |
| 296 | if !good { |
| 297 | t.Errorf("Could not find all expected symlinks! foo: %t, foo_link_64: %t. Command was %s", found_foo, found_foo_link_64, copyCmds) |
| 298 | } |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | func TestBasicZipApex(t *testing.T) { |
| 302 | ctx := testApex(t, ` |
| 303 | apex { |
| 304 | name: "myapex", |
| 305 | key: "myapex.key", |
| 306 | payload_type: "zip", |
| 307 | native_shared_libs: ["mylib"], |
| 308 | } |
| 309 | |
| 310 | apex_key { |
| 311 | name: "myapex.key", |
| 312 | public_key: "testkey.avbpubkey", |
| 313 | private_key: "testkey.pem", |
| 314 | } |
| 315 | |
| 316 | cc_library { |
| 317 | name: "mylib", |
| 318 | srcs: ["mylib.cpp"], |
| 319 | shared_libs: ["mylib2"], |
| 320 | system_shared_libs: [], |
| 321 | stl: "none", |
| 322 | } |
| 323 | |
| 324 | cc_library { |
| 325 | name: "mylib2", |
| 326 | srcs: ["mylib.cpp"], |
| 327 | system_shared_libs: [], |
| 328 | stl: "none", |
| 329 | } |
| 330 | `) |
| 331 | |
| 332 | zipApexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("zipApexRule") |
| 333 | copyCmds := zipApexRule.Args["copy_commands"] |
| 334 | |
| 335 | // Ensure that main rule creates an output |
| 336 | ensureContains(t, zipApexRule.Output.String(), "myapex.zipapex.unsigned") |
| 337 | |
| 338 | // Ensure that APEX variant is created for the direct dep |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 339 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 340 | |
| 341 | // Ensure that APEX variant is created for the indirect dep |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 342 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex") |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 343 | |
| 344 | // Ensure that both direct and indirect deps are copied into apex |
| 345 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib.so") |
| 346 | ensureContains(t, copyCmds, "image.zipapex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | func TestApexWithStubs(t *testing.T) { |
| 350 | ctx := testApex(t, ` |
| 351 | apex { |
| 352 | name: "myapex", |
| 353 | key: "myapex.key", |
| 354 | native_shared_libs: ["mylib", "mylib3"], |
| 355 | } |
| 356 | |
| 357 | apex_key { |
| 358 | name: "myapex.key", |
| 359 | public_key: "testkey.avbpubkey", |
| 360 | private_key: "testkey.pem", |
| 361 | } |
| 362 | |
| 363 | cc_library { |
| 364 | name: "mylib", |
| 365 | srcs: ["mylib.cpp"], |
| 366 | shared_libs: ["mylib2", "mylib3"], |
| 367 | system_shared_libs: [], |
| 368 | stl: "none", |
| 369 | } |
| 370 | |
| 371 | cc_library { |
| 372 | name: "mylib2", |
| 373 | srcs: ["mylib.cpp"], |
Jiyong Park | 6437995 | 2018-12-13 18:37:29 +0900 | [diff] [blame] | 374 | cflags: ["-include mylib.h"], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 375 | system_shared_libs: [], |
| 376 | stl: "none", |
| 377 | stubs: { |
| 378 | versions: ["1", "2", "3"], |
| 379 | }, |
| 380 | } |
| 381 | |
| 382 | cc_library { |
| 383 | name: "mylib3", |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 384 | srcs: ["mylib.cpp"], |
| 385 | shared_libs: ["mylib4"], |
| 386 | system_shared_libs: [], |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 387 | stl: "none", |
| 388 | stubs: { |
| 389 | versions: ["10", "11", "12"], |
| 390 | }, |
| 391 | } |
Jiyong Park | 28d395a | 2018-12-07 22:42:47 +0900 | [diff] [blame] | 392 | |
| 393 | cc_library { |
| 394 | name: "mylib4", |
| 395 | srcs: ["mylib.cpp"], |
| 396 | system_shared_libs: [], |
| 397 | stl: "none", |
| 398 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 399 | `) |
| 400 | |
| 401 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 402 | copyCmds := apexRule.Args["copy_commands"] |
| 403 | |
| 404 | // Ensure that direct non-stubs dep is always included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 405 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 406 | |
| 407 | // Ensure that indirect stubs dep is not included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 408 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 409 | |
| 410 | // Ensure that direct stubs dep is included |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 411 | ensureContains(t, copyCmds, "image.apex/lib64/mylib3.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 412 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 413 | 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] | 414 | |
| 415 | // 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] | 416 | 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] | 417 | // ... and not linking to the non-stub (impl) variant of mylib2 |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 418 | 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] | 419 | |
| 420 | // 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] | 421 | 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] | 422 | // .. and not linking to the stubs variant of mylib3 |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 423 | 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] | 424 | |
| 425 | // Ensure that stubs libs are built without -include flags |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 426 | 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] | 427 | ensureNotContains(t, mylib2Cflags, "-include ") |
Jiyong Park | 3fd0baf | 2018-12-07 16:25:39 +0900 | [diff] [blame] | 428 | |
| 429 | // Ensure that genstub is invoked with --apex |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 430 | 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] | 431 | } |
| 432 | |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 433 | func TestApexWithExplicitStubsDependency(t *testing.T) { |
| 434 | ctx := testApex(t, ` |
| 435 | apex { |
| 436 | name: "myapex", |
| 437 | key: "myapex.key", |
| 438 | native_shared_libs: ["mylib"], |
| 439 | } |
| 440 | |
| 441 | apex_key { |
| 442 | name: "myapex.key", |
| 443 | public_key: "testkey.avbpubkey", |
| 444 | private_key: "testkey.pem", |
| 445 | } |
| 446 | |
| 447 | cc_library { |
| 448 | name: "mylib", |
| 449 | srcs: ["mylib.cpp"], |
| 450 | shared_libs: ["libfoo#10"], |
| 451 | system_shared_libs: [], |
| 452 | stl: "none", |
| 453 | } |
| 454 | |
| 455 | cc_library { |
| 456 | name: "libfoo", |
| 457 | srcs: ["mylib.cpp"], |
| 458 | shared_libs: ["libbar"], |
| 459 | system_shared_libs: [], |
| 460 | stl: "none", |
| 461 | stubs: { |
| 462 | versions: ["10", "20", "30"], |
| 463 | }, |
| 464 | } |
| 465 | |
| 466 | cc_library { |
| 467 | name: "libbar", |
| 468 | srcs: ["mylib.cpp"], |
| 469 | system_shared_libs: [], |
| 470 | stl: "none", |
| 471 | } |
| 472 | |
| 473 | `) |
| 474 | |
| 475 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 476 | copyCmds := apexRule.Args["copy_commands"] |
| 477 | |
| 478 | // Ensure that direct non-stubs dep is always included |
| 479 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 480 | |
| 481 | // Ensure that indirect stubs dep is not included |
| 482 | ensureNotContains(t, copyCmds, "image.apex/lib64/libfoo.so") |
| 483 | |
| 484 | // Ensure that dependency of stubs is not included |
| 485 | ensureNotContains(t, copyCmds, "image.apex/lib64/libbar.so") |
| 486 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 487 | 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] | 488 | |
| 489 | // Ensure that mylib is linking with version 10 of libfoo |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 490 | 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] | 491 | // ... and not linking to the non-stub (impl) variant of libfoo |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 492 | 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] | 493 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 494 | 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] | 495 | |
| 496 | // Ensure that libfoo stubs is not linking to libbar (since it is a stubs) |
| 497 | ensureNotContains(t, libFooStubsLdFlags, "libbar.so") |
| 498 | } |
| 499 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 500 | func TestApexWithSystemLibsStubs(t *testing.T) { |
| 501 | ctx := testApex(t, ` |
| 502 | apex { |
| 503 | name: "myapex", |
| 504 | key: "myapex.key", |
| 505 | native_shared_libs: ["mylib", "mylib_shared", "libdl", "libm"], |
| 506 | } |
| 507 | |
| 508 | apex_key { |
| 509 | name: "myapex.key", |
| 510 | public_key: "testkey.avbpubkey", |
| 511 | private_key: "testkey.pem", |
| 512 | } |
| 513 | |
| 514 | cc_library { |
| 515 | name: "mylib", |
| 516 | srcs: ["mylib.cpp"], |
| 517 | shared_libs: ["libdl#27"], |
| 518 | stl: "none", |
| 519 | } |
| 520 | |
| 521 | cc_library_shared { |
| 522 | name: "mylib_shared", |
| 523 | srcs: ["mylib.cpp"], |
| 524 | shared_libs: ["libdl#27"], |
| 525 | stl: "none", |
| 526 | } |
| 527 | |
| 528 | cc_library { |
| 529 | name: "libc", |
| 530 | no_libgcc: true, |
| 531 | nocrt: true, |
| 532 | system_shared_libs: [], |
| 533 | stl: "none", |
| 534 | stubs: { |
| 535 | versions: ["27", "28", "29"], |
| 536 | }, |
| 537 | } |
| 538 | |
| 539 | cc_library { |
| 540 | name: "libm", |
| 541 | no_libgcc: true, |
| 542 | nocrt: true, |
| 543 | system_shared_libs: [], |
| 544 | stl: "none", |
| 545 | stubs: { |
| 546 | versions: ["27", "28", "29"], |
| 547 | }, |
| 548 | } |
| 549 | |
| 550 | cc_library { |
| 551 | name: "libdl", |
| 552 | no_libgcc: true, |
| 553 | nocrt: true, |
| 554 | system_shared_libs: [], |
| 555 | stl: "none", |
| 556 | stubs: { |
| 557 | versions: ["27", "28", "29"], |
| 558 | }, |
| 559 | } |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 560 | |
| 561 | cc_library { |
| 562 | name: "libBootstrap", |
| 563 | srcs: ["mylib.cpp"], |
| 564 | stl: "none", |
| 565 | bootstrap: true, |
| 566 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 567 | `) |
| 568 | |
| 569 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 570 | copyCmds := apexRule.Args["copy_commands"] |
| 571 | |
| 572 | // Ensure that mylib, libm, libdl are included. |
Alex Light | 5098a61 | 2018-11-29 17:12:15 -0800 | [diff] [blame] | 573 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 574 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libm.so") |
| 575 | ensureContains(t, copyCmds, "image.apex/lib64/bionic/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 576 | |
| 577 | // 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] | 578 | ensureNotContains(t, copyCmds, "image.apex/lib64/bionic/libc.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 579 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 580 | mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_shared_myapex").Rule("ld").Args["libFlags"] |
| 581 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"] |
| 582 | 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] | 583 | |
| 584 | // For dependency to libc |
| 585 | // Ensure that mylib is linking with the latest version of stubs |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 586 | 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] | 587 | // ... and not linking to the non-stub (impl) variant |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 588 | 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] | 589 | // ... Cflags from stub is correctly exported to mylib |
| 590 | ensureContains(t, mylibCFlags, "__LIBC_API__=29") |
| 591 | ensureContains(t, mylibSharedCFlags, "__LIBC_API__=29") |
| 592 | |
| 593 | // For dependency to libm |
| 594 | // Ensure that mylib is linking with the non-stub (impl) variant |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 595 | 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] | 596 | // ... and not linking to the stub variant |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 597 | 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] | 598 | // ... and is not compiling with the stub |
| 599 | ensureNotContains(t, mylibCFlags, "__LIBM_API__=29") |
| 600 | ensureNotContains(t, mylibSharedCFlags, "__LIBM_API__=29") |
| 601 | |
| 602 | // For dependency to libdl |
| 603 | // Ensure that mylib is linking with the specified version of stubs |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 604 | 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] | 605 | // ... and not linking to the other versions of stubs |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 606 | ensureNotContains(t, mylibLdFlags, "libdl/android_arm64_armv8-a_core_shared_28_myapex/libdl.so") |
| 607 | 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] | 608 | // ... and not linking to the non-stub (impl) variant |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 609 | 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] | 610 | // ... Cflags from stub is correctly exported to mylib |
| 611 | ensureContains(t, mylibCFlags, "__LIBDL_API__=27") |
| 612 | ensureContains(t, mylibSharedCFlags, "__LIBDL_API__=27") |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 613 | |
| 614 | // Ensure that libBootstrap is depending on the platform variant of bionic libs |
| 615 | libFlags := ctx.ModuleForTests("libBootstrap", "android_arm64_armv8-a_core_shared").Rule("ld").Args["libFlags"] |
| 616 | ensureContains(t, libFlags, "libc/android_arm64_armv8-a_core_shared/libc.so") |
| 617 | ensureContains(t, libFlags, "libm/android_arm64_armv8-a_core_shared/libm.so") |
| 618 | ensureContains(t, libFlags, "libdl/android_arm64_armv8-a_core_shared/libdl.so") |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 619 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 620 | |
| 621 | func TestFilesInSubDir(t *testing.T) { |
| 622 | ctx := testApex(t, ` |
| 623 | apex { |
| 624 | name: "myapex", |
| 625 | key: "myapex.key", |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 626 | native_shared_libs: ["mylib"], |
| 627 | binaries: ["mybin"], |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 628 | prebuilts: ["myetc"], |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 629 | compile_multilib: "both", |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | apex_key { |
| 633 | name: "myapex.key", |
| 634 | public_key: "testkey.avbpubkey", |
| 635 | private_key: "testkey.pem", |
| 636 | } |
| 637 | |
| 638 | prebuilt_etc { |
| 639 | name: "myetc", |
| 640 | src: "myprebuilt", |
| 641 | sub_dir: "foo/bar", |
| 642 | } |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 643 | |
| 644 | cc_library { |
| 645 | name: "mylib", |
| 646 | srcs: ["mylib.cpp"], |
| 647 | relative_install_path: "foo/bar", |
| 648 | system_shared_libs: [], |
| 649 | stl: "none", |
| 650 | } |
| 651 | |
| 652 | cc_binary { |
| 653 | name: "mybin", |
| 654 | srcs: ["mylib.cpp"], |
| 655 | relative_install_path: "foo/bar", |
| 656 | system_shared_libs: [], |
| 657 | static_executable: true, |
| 658 | stl: "none", |
| 659 | } |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 660 | `) |
| 661 | |
| 662 | generateFsRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("generateFsConfig") |
| 663 | dirs := strings.Split(generateFsRule.Args["exec_paths"], " ") |
| 664 | |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 665 | // Ensure that the subdirectories are all listed |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 666 | ensureListContains(t, dirs, "etc") |
| 667 | ensureListContains(t, dirs, "etc/foo") |
| 668 | ensureListContains(t, dirs, "etc/foo/bar") |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 669 | ensureListContains(t, dirs, "lib64") |
| 670 | ensureListContains(t, dirs, "lib64/foo") |
| 671 | ensureListContains(t, dirs, "lib64/foo/bar") |
| 672 | ensureListContains(t, dirs, "lib") |
| 673 | ensureListContains(t, dirs, "lib/foo") |
| 674 | ensureListContains(t, dirs, "lib/foo/bar") |
| 675 | |
| 676 | // TODO(b/123721777) respect relative path for binaries |
| 677 | // ensureListContains(t, dirs, "bin") |
| 678 | // ensureListContains(t, dirs, "bin/foo") |
| 679 | // ensureListContains(t, dirs, "bin/foo/bar") |
Jiyong Park | 7c2ee71 | 2018-12-07 00:42:25 +0900 | [diff] [blame] | 680 | } |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 681 | |
| 682 | func TestUseVendor(t *testing.T) { |
| 683 | ctx := testApex(t, ` |
| 684 | apex { |
| 685 | name: "myapex", |
| 686 | key: "myapex.key", |
| 687 | native_shared_libs: ["mylib"], |
| 688 | use_vendor: true, |
| 689 | } |
| 690 | |
| 691 | apex_key { |
| 692 | name: "myapex.key", |
| 693 | public_key: "testkey.avbpubkey", |
| 694 | private_key: "testkey.pem", |
| 695 | } |
| 696 | |
| 697 | cc_library { |
| 698 | name: "mylib", |
| 699 | srcs: ["mylib.cpp"], |
| 700 | shared_libs: ["mylib2"], |
| 701 | system_shared_libs: [], |
| 702 | vendor_available: true, |
| 703 | stl: "none", |
| 704 | } |
| 705 | |
| 706 | cc_library { |
| 707 | name: "mylib2", |
| 708 | srcs: ["mylib.cpp"], |
| 709 | system_shared_libs: [], |
| 710 | vendor_available: true, |
| 711 | stl: "none", |
| 712 | } |
| 713 | `) |
| 714 | |
| 715 | inputsList := []string{} |
| 716 | for _, i := range ctx.ModuleForTests("myapex", "android_common_myapex").Module().BuildParamsForTests() { |
| 717 | for _, implicit := range i.Implicits { |
| 718 | inputsList = append(inputsList, implicit.String()) |
| 719 | } |
| 720 | } |
| 721 | inputsString := strings.Join(inputsList, " ") |
| 722 | |
| 723 | // ensure that the apex includes vendor variants of the direct and indirect deps |
| 724 | ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib.so") |
| 725 | ensureContains(t, inputsString, "android_arm64_armv8-a_vendor_shared_myapex/mylib2.so") |
| 726 | |
| 727 | // ensure that the apex does not include core variants |
| 728 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib.so") |
| 729 | ensureNotContains(t, inputsString, "android_arm64_armv8-a_core_shared_myapex/mylib2.so") |
| 730 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 731 | |
| 732 | func TestStaticLinking(t *testing.T) { |
| 733 | ctx := testApex(t, ` |
| 734 | apex { |
| 735 | name: "myapex", |
| 736 | key: "myapex.key", |
| 737 | native_shared_libs: ["mylib"], |
| 738 | } |
| 739 | |
| 740 | apex_key { |
| 741 | name: "myapex.key", |
| 742 | public_key: "testkey.avbpubkey", |
| 743 | private_key: "testkey.pem", |
| 744 | } |
| 745 | |
| 746 | cc_library { |
| 747 | name: "mylib", |
| 748 | srcs: ["mylib.cpp"], |
| 749 | system_shared_libs: [], |
| 750 | stl: "none", |
| 751 | stubs: { |
| 752 | versions: ["1", "2", "3"], |
| 753 | }, |
| 754 | } |
| 755 | |
| 756 | cc_binary { |
| 757 | name: "not_in_apex", |
| 758 | srcs: ["mylib.cpp"], |
| 759 | static_libs: ["mylib"], |
| 760 | static_executable: true, |
| 761 | system_shared_libs: [], |
| 762 | stl: "none", |
| 763 | } |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 764 | `) |
| 765 | |
| 766 | ldFlags := ctx.ModuleForTests("not_in_apex", "android_arm64_armv8-a_core").Rule("ld").Args["libFlags"] |
| 767 | |
| 768 | // Ensure that not_in_apex is linking with the static variant of mylib |
Logan Chien | 3aeedc9 | 2018-12-26 15:32:21 +0800 | [diff] [blame] | 769 | ensureContains(t, ldFlags, "mylib/android_arm64_armv8-a_core_static/mylib.a") |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 770 | } |
Jiyong Park | 9335a26 | 2018-12-24 11:31:58 +0900 | [diff] [blame] | 771 | |
| 772 | func TestKeys(t *testing.T) { |
| 773 | ctx := testApex(t, ` |
| 774 | apex { |
| 775 | name: "myapex", |
| 776 | key: "myapex.key", |
| 777 | native_shared_libs: ["mylib"], |
| 778 | } |
| 779 | |
| 780 | cc_library { |
| 781 | name: "mylib", |
| 782 | srcs: ["mylib.cpp"], |
| 783 | system_shared_libs: [], |
| 784 | stl: "none", |
| 785 | } |
| 786 | |
| 787 | apex_key { |
| 788 | name: "myapex.key", |
| 789 | public_key: "testkey.avbpubkey", |
| 790 | private_key: "testkey.pem", |
| 791 | } |
| 792 | |
| 793 | `) |
| 794 | |
| 795 | // check the APEX keys |
| 796 | keys := ctx.ModuleForTests("myapex.key", "").Module().(*apexKey) |
| 797 | |
| 798 | if keys.public_key_file.String() != "vendor/foo/devkeys/testkey.avbpubkey" { |
| 799 | t.Errorf("public key %q is not %q", keys.public_key_file.String(), |
| 800 | "vendor/foo/devkeys/testkey.avbpubkey") |
| 801 | } |
| 802 | if keys.private_key_file.String() != "vendor/foo/devkeys/testkey.pem" { |
| 803 | t.Errorf("private key %q is not %q", keys.private_key_file.String(), |
| 804 | "vendor/foo/devkeys/testkey.pem") |
| 805 | } |
| 806 | |
| 807 | // check the APK certs |
| 808 | certs := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("signapk").Args["certificates"] |
| 809 | if certs != "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8" { |
| 810 | t.Errorf("cert and private key %q are not %q", certs, |
| 811 | "vendor/foo/devkeys/test.x509.pem vendor/foo/devkeys/test.pk8") |
| 812 | } |
| 813 | } |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 814 | |
| 815 | func TestMacro(t *testing.T) { |
| 816 | ctx := testApex(t, ` |
| 817 | apex { |
| 818 | name: "myapex", |
| 819 | key: "myapex.key", |
| 820 | native_shared_libs: ["mylib"], |
| 821 | } |
| 822 | |
| 823 | apex { |
| 824 | name: "otherapex", |
| 825 | key: "myapex.key", |
| 826 | native_shared_libs: ["mylib"], |
| 827 | } |
| 828 | |
| 829 | apex_key { |
| 830 | name: "myapex.key", |
| 831 | public_key: "testkey.avbpubkey", |
| 832 | private_key: "testkey.pem", |
| 833 | } |
| 834 | |
| 835 | cc_library { |
| 836 | name: "mylib", |
| 837 | srcs: ["mylib.cpp"], |
| 838 | system_shared_libs: [], |
| 839 | stl: "none", |
| 840 | } |
| 841 | `) |
| 842 | |
| 843 | // non-APEX variant does not have __ANDROID__APEX__ defined |
| 844 | mylibCFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"] |
| 845 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex") |
| 846 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex") |
| 847 | |
| 848 | // APEX variant has __ANDROID_APEX__=<apexname> defined |
| 849 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_myapex").Rule("cc").Args["cFlags"] |
| 850 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex") |
| 851 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex") |
| 852 | |
| 853 | // APEX variant has __ANDROID_APEX__=<apexname> defined |
| 854 | mylibCFlags = ctx.ModuleForTests("mylib", "android_arm64_armv8-a_core_static_otherapex").Rule("cc").Args["cFlags"] |
| 855 | ensureNotContains(t, mylibCFlags, "-D__ANDROID_APEX__=myapex") |
| 856 | ensureContains(t, mylibCFlags, "-D__ANDROID_APEX__=otherapex") |
| 857 | } |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 858 | |
| 859 | func TestHeaderLibsDependency(t *testing.T) { |
| 860 | ctx := testApex(t, ` |
| 861 | apex { |
| 862 | name: "myapex", |
| 863 | key: "myapex.key", |
| 864 | native_shared_libs: ["mylib"], |
| 865 | } |
| 866 | |
| 867 | apex_key { |
| 868 | name: "myapex.key", |
| 869 | public_key: "testkey.avbpubkey", |
| 870 | private_key: "testkey.pem", |
| 871 | } |
| 872 | |
| 873 | cc_library_headers { |
| 874 | name: "mylib_headers", |
| 875 | export_include_dirs: ["my_include"], |
| 876 | system_shared_libs: [], |
| 877 | stl: "none", |
| 878 | } |
| 879 | |
| 880 | cc_library { |
| 881 | name: "mylib", |
| 882 | srcs: ["mylib.cpp"], |
| 883 | system_shared_libs: [], |
| 884 | stl: "none", |
| 885 | header_libs: ["mylib_headers"], |
| 886 | export_header_lib_headers: ["mylib_headers"], |
| 887 | stubs: { |
| 888 | versions: ["1", "2", "3"], |
| 889 | }, |
| 890 | } |
| 891 | |
| 892 | cc_library { |
| 893 | name: "otherlib", |
| 894 | srcs: ["mylib.cpp"], |
| 895 | system_shared_libs: [], |
| 896 | stl: "none", |
| 897 | shared_libs: ["mylib"], |
| 898 | } |
| 899 | `) |
| 900 | |
| 901 | cFlags := ctx.ModuleForTests("otherlib", "android_arm64_armv8-a_core_static").Rule("cc").Args["cFlags"] |
| 902 | |
| 903 | // Ensure that the include path of the header lib is exported to 'otherlib' |
| 904 | ensureContains(t, cFlags, "-Imy_include") |
| 905 | } |
Alex Light | 9670d33 | 2019-01-29 18:07:33 -0800 | [diff] [blame] | 906 | |
| 907 | func TestApexWithTarget(t *testing.T) { |
| 908 | ctx := testApex(t, ` |
| 909 | apex { |
| 910 | name: "myapex", |
| 911 | key: "myapex.key", |
| 912 | multilib: { |
| 913 | first: { |
| 914 | native_shared_libs: ["mylib_common"], |
| 915 | } |
| 916 | }, |
| 917 | target: { |
| 918 | android: { |
| 919 | multilib: { |
| 920 | first: { |
| 921 | native_shared_libs: ["mylib"], |
| 922 | } |
| 923 | } |
| 924 | }, |
| 925 | host: { |
| 926 | multilib: { |
| 927 | first: { |
| 928 | native_shared_libs: ["mylib2"], |
| 929 | } |
| 930 | } |
| 931 | } |
| 932 | } |
| 933 | } |
| 934 | |
| 935 | apex_key { |
| 936 | name: "myapex.key", |
| 937 | public_key: "testkey.avbpubkey", |
| 938 | private_key: "testkey.pem", |
| 939 | } |
| 940 | |
| 941 | cc_library { |
| 942 | name: "mylib", |
| 943 | srcs: ["mylib.cpp"], |
| 944 | system_shared_libs: [], |
| 945 | stl: "none", |
| 946 | } |
| 947 | |
| 948 | cc_library { |
| 949 | name: "mylib_common", |
| 950 | srcs: ["mylib.cpp"], |
| 951 | system_shared_libs: [], |
| 952 | stl: "none", |
| 953 | compile_multilib: "first", |
| 954 | } |
| 955 | |
| 956 | cc_library { |
| 957 | name: "mylib2", |
| 958 | srcs: ["mylib.cpp"], |
| 959 | system_shared_libs: [], |
| 960 | stl: "none", |
| 961 | compile_multilib: "first", |
| 962 | } |
| 963 | `) |
| 964 | |
| 965 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 966 | copyCmds := apexRule.Args["copy_commands"] |
| 967 | |
| 968 | // Ensure that main rule creates an output |
| 969 | ensureContains(t, apexRule.Output.String(), "myapex.apex.unsigned") |
| 970 | |
| 971 | // Ensure that apex variant is created for the direct dep |
| 972 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared_myapex") |
| 973 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared_myapex") |
| 974 | ensureListNotContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared_myapex") |
| 975 | |
| 976 | // Ensure that both direct and indirect deps are copied into apex |
| 977 | ensureContains(t, copyCmds, "image.apex/lib64/mylib.so") |
| 978 | ensureContains(t, copyCmds, "image.apex/lib64/mylib_common.so") |
| 979 | ensureNotContains(t, copyCmds, "image.apex/lib64/mylib2.so") |
| 980 | |
| 981 | // Ensure that the platform variant ends with _core_shared |
| 982 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib"), "android_arm64_armv8-a_core_shared") |
| 983 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib_common"), "android_arm64_armv8-a_core_shared") |
| 984 | ensureListContains(t, ctx.ModuleVariantsForTests("mylib2"), "android_arm64_armv8-a_core_shared") |
| 985 | } |
Jiyong Park | 04480cf | 2019-02-06 00:16:29 +0900 | [diff] [blame] | 986 | |
| 987 | func TestApexWithShBinary(t *testing.T) { |
| 988 | ctx := testApex(t, ` |
| 989 | apex { |
| 990 | name: "myapex", |
| 991 | key: "myapex.key", |
| 992 | binaries: ["myscript"], |
| 993 | } |
| 994 | |
| 995 | apex_key { |
| 996 | name: "myapex.key", |
| 997 | public_key: "testkey.avbpubkey", |
| 998 | private_key: "testkey.pem", |
| 999 | } |
| 1000 | |
| 1001 | sh_binary { |
| 1002 | name: "myscript", |
| 1003 | src: "mylib.cpp", |
| 1004 | filename: "myscript.sh", |
| 1005 | sub_dir: "script", |
| 1006 | } |
| 1007 | `) |
| 1008 | |
| 1009 | apexRule := ctx.ModuleForTests("myapex", "android_common_myapex").Rule("apexRule") |
| 1010 | copyCmds := apexRule.Args["copy_commands"] |
| 1011 | |
| 1012 | ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh") |
| 1013 | } |