| Colin Cross | f12db53 | 2021-04-23 14:04:33 -0700 | [diff] [blame] | 1 | // Copyright 2021 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 cc | 
|  | 16 |  | 
|  | 17 | import ( | 
|  | 18 | "strings" | 
|  | 19 | "testing" | 
|  | 20 | ) | 
|  | 21 |  | 
|  | 22 | func TestVendorPublicLibraries(t *testing.T) { | 
|  | 23 | ctx := testCc(t, ` | 
|  | 24 | cc_library_headers { | 
|  | 25 | name: "libvendorpublic_headers", | 
| Colin Cross | b719c01 | 2021-04-26 14:35:38 -0700 | [diff] [blame] | 26 | product_available: true, | 
| Colin Cross | f12db53 | 2021-04-23 14:04:33 -0700 | [diff] [blame] | 27 | export_include_dirs: ["my_include"], | 
|  | 28 | } | 
| Colin Cross | f12db53 | 2021-04-23 14:04:33 -0700 | [diff] [blame] | 29 | cc_library { | 
|  | 30 | name: "libvendorpublic", | 
|  | 31 | srcs: ["foo.c"], | 
|  | 32 | vendor: true, | 
|  | 33 | no_libcrt: true, | 
|  | 34 | nocrt: true, | 
| Colin Cross | 5271fea | 2021-04-27 13:06:04 -0700 | [diff] [blame] | 35 | vendor_public_library: { | 
|  | 36 | symbol_file: "libvendorpublic.map.txt", | 
|  | 37 | export_public_headers: ["libvendorpublic_headers"], | 
|  | 38 | }, | 
| Colin Cross | f12db53 | 2021-04-23 14:04:33 -0700 | [diff] [blame] | 39 | } | 
|  | 40 |  | 
|  | 41 | cc_library { | 
|  | 42 | name: "libsystem", | 
|  | 43 | shared_libs: ["libvendorpublic"], | 
|  | 44 | vendor: false, | 
|  | 45 | srcs: ["foo.c"], | 
|  | 46 | no_libcrt: true, | 
|  | 47 | nocrt: true, | 
|  | 48 | } | 
|  | 49 | cc_library { | 
| Colin Cross | b719c01 | 2021-04-26 14:35:38 -0700 | [diff] [blame] | 50 | name: "libproduct", | 
|  | 51 | shared_libs: ["libvendorpublic"], | 
|  | 52 | product_specific: true, | 
|  | 53 | srcs: ["foo.c"], | 
|  | 54 | no_libcrt: true, | 
|  | 55 | nocrt: true, | 
|  | 56 | } | 
|  | 57 | cc_library { | 
| Colin Cross | f12db53 | 2021-04-23 14:04:33 -0700 | [diff] [blame] | 58 | name: "libvendor", | 
|  | 59 | shared_libs: ["libvendorpublic"], | 
|  | 60 | vendor: true, | 
|  | 61 | srcs: ["foo.c"], | 
|  | 62 | no_libcrt: true, | 
|  | 63 | nocrt: true, | 
|  | 64 | } | 
|  | 65 | `) | 
|  | 66 |  | 
|  | 67 | coreVariant := "android_arm64_armv8-a_shared" | 
|  | 68 | vendorVariant := "android_vendor.29_arm64_armv8-a_shared" | 
| Colin Cross | b719c01 | 2021-04-26 14:35:38 -0700 | [diff] [blame] | 69 | productVariant := "android_product.29_arm64_armv8-a_shared" | 
| Colin Cross | f12db53 | 2021-04-23 14:04:33 -0700 | [diff] [blame] | 70 |  | 
|  | 71 | // test if header search paths are correctly added | 
|  | 72 | // _static variant is used since _shared reuses *.o from the static variant | 
|  | 73 | cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc") | 
|  | 74 | cflags := cc.Args["cFlags"] | 
|  | 75 | if !strings.Contains(cflags, "-Imy_include") { | 
|  | 76 | t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags) | 
|  | 77 | } | 
|  | 78 |  | 
|  | 79 | // test if libsystem is linked to the stub | 
|  | 80 | ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld") | 
|  | 81 | libflags := ld.Args["libFlags"] | 
| Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 82 | stubPaths := GetOutputPaths(ctx, coreVariant, []string{"libvendorpublic"}) | 
| Colin Cross | f12db53 | 2021-04-23 14:04:33 -0700 | [diff] [blame] | 83 | if !strings.Contains(libflags, stubPaths[0].String()) { | 
|  | 84 | t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags) | 
|  | 85 | } | 
|  | 86 |  | 
| Colin Cross | b719c01 | 2021-04-26 14:35:38 -0700 | [diff] [blame] | 87 | // test if libsystem is linked to the stub | 
|  | 88 | ld = ctx.ModuleForTests("libproduct", productVariant).Rule("ld") | 
|  | 89 | libflags = ld.Args["libFlags"] | 
| Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 90 | stubPaths = GetOutputPaths(ctx, productVariant, []string{"libvendorpublic"}) | 
| Colin Cross | b719c01 | 2021-04-26 14:35:38 -0700 | [diff] [blame] | 91 | if !strings.Contains(libflags, stubPaths[0].String()) { | 
|  | 92 | t.Errorf("libflags for libproduct must contain %#v, but was %#v", stubPaths[0], libflags) | 
|  | 93 | } | 
|  | 94 |  | 
| Colin Cross | f12db53 | 2021-04-23 14:04:33 -0700 | [diff] [blame] | 95 | // test if libvendor is linked to the real shared lib | 
|  | 96 | ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld") | 
|  | 97 | libflags = ld.Args["libFlags"] | 
| Ivan Lozano | d67a6b0 | 2021-05-20 13:01:32 -0400 | [diff] [blame] | 98 | stubPaths = GetOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"}) | 
|  | 99 |  | 
| Colin Cross | f12db53 | 2021-04-23 14:04:33 -0700 | [diff] [blame] | 100 | if !strings.Contains(libflags, stubPaths[0].String()) { | 
|  | 101 | t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags) | 
|  | 102 | } | 
| Colin Cross | f12db53 | 2021-04-23 14:04:33 -0700 | [diff] [blame] | 103 | } |