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