blob: 0c4bcfdbc39df9c0c69a40369bb5093f7955e64f [file] [log] [blame]
Dan Willemsenb916b802017-03-19 13:44:32 -07001// Copyright 2017 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 (
Dan Willemsenb916b802017-03-19 13:44:32 -070018 "strings"
19
Dan Willemsenb916b802017-03-19 13:44:32 -070020 "android/soong/android"
21)
22
23var (
24 llndkLibrarySuffix = ".llndk"
Jiyong Park2a454122017-10-19 15:59:33 +090025 llndkHeadersSuffix = ".llndk"
Dan Willemsenb916b802017-03-19 13:44:32 -070026)
27
Colin Cross127bb8b2020-12-16 16:46:01 -080028// Holds properties to describe a stub shared library based on the provided version file.
29// The stub library will actually be built by the cc_library module that points to this
30// module with the llndk_stubs property.
31// TODO(ccross): move the properties from llndk_library modules directly into the cc_library
32// modules and remove the llndk_library modules.
Dan Willemsenb916b802017-03-19 13:44:32 -070033//
Dan Willemsenb916b802017-03-19 13:44:32 -070034// Example:
35//
36// llndk_library {
Dan Willemsen01a90592017-04-07 15:21:13 -070037// name: "libfoo",
Dan Willemsenb916b802017-03-19 13:44:32 -070038// symbol_file: "libfoo.map.txt",
39// export_include_dirs: ["include_vndk"],
40// }
41//
42type llndkLibraryProperties struct {
43 // Relative path to the symbol map.
44 // An example file can be seen here: TODO(danalbert): Make an example.
Nan Zhang0007d812017-11-07 10:57:05 -080045 Symbol_file *string
Dan Willemsenb916b802017-03-19 13:44:32 -070046
47 // Whether to export any headers as -isystem instead of -I. Mainly for use by
48 // bionic/libc.
Nan Zhang0007d812017-11-07 10:57:05 -080049 Export_headers_as_system *bool
Dan Willemsenb916b802017-03-19 13:44:32 -070050
51 // Which headers to process with versioner. This really only handles
52 // bionic/libc/include right now.
53 Export_preprocessed_headers []string
54
55 // Whether the system library uses symbol versions.
Nan Zhang0007d812017-11-07 10:57:05 -080056 Unversioned *bool
Jiyong Park82e2bf32017-08-16 14:05:54 +090057
Justin Yun63e9ec72020-10-29 16:49:43 +090058 // whether this module can be directly depended upon by libs that are installed
59 // to /vendor and /product.
60 // When set to false, this module can only be depended on by VNDK libraries, not
61 // vendor nor product libraries. This effectively hides this module from
62 // non-system modules. Default value is true.
Nan Zhang0007d812017-11-07 10:57:05 -080063 Vendor_available *bool
Jiyong Park2a454122017-10-19 15:59:33 +090064
65 // list of llndk headers to re-export include directories from.
66 Export_llndk_headers []string `android:"arch_variant"`
Colin Cross127bb8b2020-12-16 16:46:01 -080067
68 // whether this module can be directly depended upon by libs that are installed
69 // to /vendor and /product.
70 // When set to true, this module can only be depended on by VNDK libraries, not
71 // vendor nor product libraries. This effectively hides this module from
72 // non-system modules. Default value is false.
73 Private *bool
Dan Willemsenb916b802017-03-19 13:44:32 -070074}
75
76type llndkStubDecorator struct {
77 *libraryDecorator
78
79 Properties llndkLibraryProperties
Dan Willemsenb916b802017-03-19 13:44:32 -070080}
81
Colin Cross0477b422020-10-13 18:43:54 -070082var _ versionedInterface = (*llndkStubDecorator)(nil)
83
Colin Crossf18e1102017-11-16 14:33:08 -080084func (stub *llndkStubDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags {
Colin Cross127bb8b2020-12-16 16:46:01 -080085 return flags
George Burgess IVf5310e32017-07-19 11:39:53 -070086}
87
Dan Willemsenb916b802017-03-19 13:44:32 -070088func (stub *llndkStubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
Colin Cross127bb8b2020-12-16 16:46:01 -080089 return Objects{}
Dan Willemsenb916b802017-03-19 13:44:32 -070090}
91
92func (stub *llndkStubDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
Jiyong Park2a454122017-10-19 15:59:33 +090093 return deps
Dan Willemsenb916b802017-03-19 13:44:32 -070094}
95
Dan Willemsen01a90592017-04-07 15:21:13 -070096func (stub *llndkStubDecorator) Name(name string) string {
Colin Cross0477b422020-10-13 18:43:54 -070097 if strings.HasSuffix(name, llndkLibrarySuffix) {
98 return name
99 }
Dan Willemsen01a90592017-04-07 15:21:13 -0700100 return name + llndkLibrarySuffix
101}
102
Colin Cross4f4f8eb2021-01-06 14:07:27 -0800103func (stub *llndkStubDecorator) linkerProps() []interface{} {
104 props := stub.libraryDecorator.linkerProps()
105 return append(props, &stub.Properties)
106}
107
Dan Willemsenb916b802017-03-19 13:44:32 -0700108func (stub *llndkStubDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
Colin Cross0477b422020-10-13 18:43:54 -0700109 stub.libraryDecorator.libName = stub.implementationModuleName(ctx.ModuleName())
Dan Willemsenb916b802017-03-19 13:44:32 -0700110 return stub.libraryDecorator.linkerFlags(ctx, flags)
111}
112
Dan Willemsenb916b802017-03-19 13:44:32 -0700113func (stub *llndkStubDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps,
114 objs Objects) android.Path {
Colin Cross127bb8b2020-12-16 16:46:01 -0800115 return nil
Dan Willemsenb916b802017-03-19 13:44:32 -0700116}
117
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700118func (stub *llndkStubDecorator) nativeCoverage() bool {
119 return false
120}
121
Colin Cross0477b422020-10-13 18:43:54 -0700122func (stub *llndkStubDecorator) implementationModuleName(name string) string {
123 return strings.TrimSuffix(name, llndkLibrarySuffix)
124}
125
Colin Crossc88c2722020-09-28 17:32:47 -0700126func (stub *llndkStubDecorator) buildStubs() bool {
127 return true
128}
129
Jiyong Park64ca4b72017-11-14 20:53:00 +0900130func NewLLndkStubLibrary() *Module {
Dan Willemsenb916b802017-03-19 13:44:32 -0700131 module, library := NewLibrary(android.DeviceSupported)
Dan Willemsenb916b802017-03-19 13:44:32 -0700132 module.stl = nil
133 module.sanitize = nil
ThiƩbaud Weksteend4587452020-08-19 14:53:01 +0200134 library.disableStripping()
Dan Willemsenb916b802017-03-19 13:44:32 -0700135
136 stub := &llndkStubDecorator{
137 libraryDecorator: library,
138 }
Nan Zhang0007d812017-11-07 10:57:05 -0800139 stub.Properties.Vendor_available = BoolPtr(true)
Dan Willemsenb916b802017-03-19 13:44:32 -0700140 module.compiler = stub
141 module.linker = stub
142 module.installer = nil
Colin Cross31076b32020-10-23 17:22:06 -0700143 module.library = stub
Dan Willemsenb916b802017-03-19 13:44:32 -0700144
Colin Cross36242852017-06-23 15:06:31 -0700145 return module
Dan Willemsenb916b802017-03-19 13:44:32 -0700146}
147
Patrice Arrudaea3fcdf2019-04-03 14:37:46 -0700148// llndk_library creates a stub llndk shared library based on the provided
149// version file. Example:
150//
151// llndk_library {
152// name: "libfoo",
153// symbol_file: "libfoo.map.txt",
154// export_include_dirs: ["include_vndk"],
155// }
Jiyong Parkda6eb592018-12-19 17:12:36 +0900156func LlndkLibraryFactory() android.Module {
Jiyong Park64ca4b72017-11-14 20:53:00 +0900157 module := NewLLndkStubLibrary()
Colin Cross4f4f8eb2021-01-06 14:07:27 -0800158 return module.Init()
159}
160
161// isVestigialLLNDKModule returns true if m is a vestigial llndk_library module used to provide
162// properties to the LLNDK variant of a cc_library.
163func isVestigialLLNDKModule(m *Module) bool {
164 _, ok := m.linker.(*llndkStubDecorator)
165 return ok
Dan Willemsenb916b802017-03-19 13:44:32 -0700166}
167
Jiyong Park2a454122017-10-19 15:59:33 +0900168type llndkHeadersDecorator struct {
169 *libraryDecorator
170}
171
Patrice Arrudaea3fcdf2019-04-03 14:37:46 -0700172// llndk_headers contains a set of c/c++ llndk headers files which are imported
173// by other soongs cc modules.
Jiyong Park2a454122017-10-19 15:59:33 +0900174func llndkHeadersFactory() android.Module {
175 module, library := NewLibrary(android.DeviceSupported)
176 library.HeaderOnly()
Inseob Kimc7c69102020-07-08 07:56:02 +0900177 module.stl = nil
178 module.sanitize = nil
Jiyong Park2a454122017-10-19 15:59:33 +0900179
180 decorator := &llndkHeadersDecorator{
181 libraryDecorator: library,
182 }
183
184 module.compiler = nil
185 module.linker = decorator
186 module.installer = nil
Colin Cross31076b32020-10-23 17:22:06 -0700187 module.library = decorator
Jiyong Park2a454122017-10-19 15:59:33 +0900188
Jiyong Park5e676fe2019-04-17 13:12:10 +0900189 module.AddProperties(
190 &module.Properties,
191 &library.MutatedProperties,
192 &library.flagExporter.Properties)
Jiyong Park2a454122017-10-19 15:59:33 +0900193
Jiyong Park1d1119f2019-07-29 21:27:18 +0900194 module.Init()
Jiyong Park2a454122017-10-19 15:59:33 +0900195
196 return module
197}
198
Dan Willemsenb916b802017-03-19 13:44:32 -0700199func init() {
Jiyong Parkda6eb592018-12-19 17:12:36 +0900200 android.RegisterModuleType("llndk_library", LlndkLibraryFactory)
Jiyong Park2a454122017-10-19 15:59:33 +0900201 android.RegisterModuleType("llndk_headers", llndkHeadersFactory)
Dan Willemsenb916b802017-03-19 13:44:32 -0700202}