blob: 9f2accf4bea28f0b0aae84274e922345e98daaed [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 }
29 vendor_public_library {
30 name: "libvendorpublic",
Colin Crossb719c012021-04-26 14:35:38 -070031 product_available: true,
Colin Crossf12db532021-04-23 14:04:33 -070032 symbol_file: "",
33 export_public_headers: ["libvendorpublic_headers"],
34 }
35 cc_library {
36 name: "libvendorpublic",
37 srcs: ["foo.c"],
38 vendor: true,
39 no_libcrt: true,
40 nocrt: true,
41 }
42
43 cc_library {
44 name: "libsystem",
45 shared_libs: ["libvendorpublic"],
46 vendor: false,
47 srcs: ["foo.c"],
48 no_libcrt: true,
49 nocrt: true,
50 }
51 cc_library {
Colin Crossb719c012021-04-26 14:35:38 -070052 name: "libproduct",
53 shared_libs: ["libvendorpublic"],
54 product_specific: true,
55 srcs: ["foo.c"],
56 no_libcrt: true,
57 nocrt: true,
58 }
59 cc_library {
Colin Crossf12db532021-04-23 14:04:33 -070060 name: "libvendor",
61 shared_libs: ["libvendorpublic"],
62 vendor: true,
63 srcs: ["foo.c"],
64 no_libcrt: true,
65 nocrt: true,
66 }
67 `)
68
69 coreVariant := "android_arm64_armv8-a_shared"
70 vendorVariant := "android_vendor.29_arm64_armv8-a_shared"
Colin Crossb719c012021-04-26 14:35:38 -070071 productVariant := "android_product.29_arm64_armv8-a_shared"
Colin Crossf12db532021-04-23 14:04:33 -070072
73 // test if header search paths are correctly added
74 // _static variant is used since _shared reuses *.o from the static variant
75 cc := ctx.ModuleForTests("libsystem", strings.Replace(coreVariant, "_shared", "_static", 1)).Rule("cc")
76 cflags := cc.Args["cFlags"]
77 if !strings.Contains(cflags, "-Imy_include") {
78 t.Errorf("cflags for libsystem must contain -Imy_include, but was %#v.", cflags)
79 }
80
81 // test if libsystem is linked to the stub
82 ld := ctx.ModuleForTests("libsystem", coreVariant).Rule("ld")
83 libflags := ld.Args["libFlags"]
84 stubPaths := getOutputPaths(ctx, coreVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
85 if !strings.Contains(libflags, stubPaths[0].String()) {
86 t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
87 }
88
Colin Crossb719c012021-04-26 14:35:38 -070089 // test if libsystem is linked to the stub
90 ld = ctx.ModuleForTests("libproduct", productVariant).Rule("ld")
91 libflags = ld.Args["libFlags"]
92 stubPaths = getOutputPaths(ctx, productVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
93 if !strings.Contains(libflags, stubPaths[0].String()) {
94 t.Errorf("libflags for libproduct must contain %#v, but was %#v", stubPaths[0], libflags)
95 }
96
Colin Crossf12db532021-04-23 14:04:33 -070097 // test if libvendor is linked to the real shared lib
98 ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld")
99 libflags = ld.Args["libFlags"]
100 stubPaths = getOutputPaths(ctx, vendorVariant, []string{"libvendorpublic"})
101 if !strings.Contains(libflags, stubPaths[0].String()) {
102 t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
103 }
Colin Crossf12db532021-04-23 14:04:33 -0700104}