blob: 7385f2b88af9407923658d3ca8ad8f8c5fc634b2 [file] [log] [blame]
Colin Crossf12db532021-04-23 14:04:33 -07001// 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
15package cc
16
17import (
18 "strings"
19 "testing"
20)
21
22func TestVendorPublicLibraries(t *testing.T) {
23 ctx := testCc(t, `
24 cc_library_headers {
25 name: "libvendorpublic_headers",
Colin Crossb719c012021-04-26 14:35:38 -070026 product_available: true,
Colin Crossf12db532021-04-23 14:04:33 -070027 export_include_dirs: ["my_include"],
28 }
Colin Crossf12db532021-04-23 14:04:33 -070029 cc_library {
30 name: "libvendorpublic",
31 srcs: ["foo.c"],
32 vendor: true,
33 no_libcrt: true,
34 nocrt: true,
Colin Cross5271fea2021-04-27 13:06:04 -070035 vendor_public_library: {
36 symbol_file: "libvendorpublic.map.txt",
37 export_public_headers: ["libvendorpublic_headers"],
38 },
Colin Crossf12db532021-04-23 14:04:33 -070039 }
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 Crossb719c012021-04-26 14:35:38 -070050 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 Crossf12db532021-04-23 14:04:33 -070058 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"
Kiyoung Kim0d1c1e62024-03-26 16:33:58 +090068 vendorVariant := "android_vendor_arm64_armv8-a_shared"
69 productVariant := "android_product_arm64_armv8-a_shared"
Colin Crossf12db532021-04-23 14:04:33 -070070
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 Lozanod67a6b02021-05-20 13:01:32 -040082 stubPaths := GetOutputPaths(ctx, coreVariant, []string{"libvendorpublic"})
Colin Crossf12db532021-04-23 14:04:33 -070083 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 Crossb719c012021-04-26 14:35:38 -070087 // test if libsystem is linked to the stub
88 ld = ctx.ModuleForTests("libproduct", productVariant).Rule("ld")
89 libflags = ld.Args["libFlags"]
Ivan Lozanod67a6b02021-05-20 13:01:32 -040090 stubPaths = GetOutputPaths(ctx, productVariant, []string{"libvendorpublic"})
Colin Crossb719c012021-04-26 14:35:38 -070091 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 Crossf12db532021-04-23 14:04:33 -070095 // test if libvendor is linked to the real shared lib
96 ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld")
97 libflags = ld.Args["libFlags"]
Ivan Lozanod67a6b02021-05-20 13:01:32 -040098 stubPaths = GetOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"})
99
Colin Crossf12db532021-04-23 14:04:33 -0700100 if !strings.Contains(libflags, stubPaths[0].String()) {
101 t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
102 }
Colin Crossf12db532021-04-23 14:04:33 -0700103}