blob: ed65aa657163939c08d479da1ce6508ab71ab40b [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -07001// Copyright 2015 Google Inc. All rights reserved.
Colin Cross3f40fa42015-01-30 17:27:36 -08002//
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
17// This file contains the module types for compiling C/C++ for Android, and converts the properties
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
Dan Albert9e10cd42016-08-03 14:12:14 -070022 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080023 "strings"
24
Colin Cross97ba0732015-03-23 17:50:24 -070025 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070026 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070027
Colin Cross635c3b02016-05-18 15:37:25 -070028 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070029 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070030 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080031)
32
Colin Cross463a90e2015-06-17 14:20:06 -070033func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070034 android.RegisterModuleType("cc_defaults", defaultsFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070035
Colin Cross1e676be2016-10-12 14:38:15 -070036 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkf9332f12018-02-01 00:54:12 +090037 ctx.BottomUp("image", imageMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070038 ctx.BottomUp("link", LinkageMutator).Parallel()
Jiyong Parkd5b18a52017-08-03 21:22:50 +090039 ctx.BottomUp("vndk", vndkMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070040 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
41 ctx.BottomUp("test_per_src", testPerSrcMutator).Parallel()
Jiyong Park7ed9de32018-10-15 22:25:07 +090042 ctx.BottomUp("version", versionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070043 ctx.BottomUp("begin", BeginMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070044 })
Colin Cross16b23492016-01-06 14:41:07 -080045
Colin Cross1e676be2016-10-12 14:38:15 -070046 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
47 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
48 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080049
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070050 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
51 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
52
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000053 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
54 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
55
Colin Cross1e676be2016-10-12 14:38:15 -070056 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
57 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080058
Colin Cross6b753602018-06-21 13:03:07 -070059 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator)
Ivan Lozano30c5db22018-02-21 15:49:20 -080060
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +000061 ctx.BottomUp("coverage", coverageLinkingMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080062 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070063
64 ctx.TopDown("lto_deps", ltoDepsMutator)
65 ctx.BottomUp("lto", ltoMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070066 })
Colin Crossb98c8b02016-07-29 13:44:28 -070067
68 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070069}
70
Colin Crossca860ac2016-01-04 14:34:37 -080071type Deps struct {
72 SharedLibs, LateSharedLibs []string
73 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080074 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080075 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070076
Colin Cross5950f382016-12-13 12:50:57 -080077 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070078
Colin Cross81413472016-04-11 14:37:39 -070079 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070080
Dan Willemsenb40aab62016-04-20 14:21:14 -070081 GeneratedSources []string
82 GeneratedHeaders []string
83
Dan Willemsenb3454ab2016-09-28 17:34:58 -070084 ReexportGeneratedHeaders []string
85
Colin Cross97ba0732015-03-23 17:50:24 -070086 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -070087
88 // Used for host bionic
89 LinkerFlagsFile string
90 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -070091}
92
Colin Crossca860ac2016-01-04 14:34:37 -080093type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -070094 // Paths to .so files
95 SharedLibs, LateSharedLibs android.Paths
96 // Paths to the dependencies to use for .so files (.so.toc files)
97 SharedLibsDeps, LateSharedLibsDeps android.Paths
98 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -070099 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700100
Colin Cross26c34ed2016-09-30 17:10:16 -0700101 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700102 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800103 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700104 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700105
Colin Cross26c34ed2016-09-30 17:10:16 -0700106 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700107 GeneratedSources android.Paths
108 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700109
Dan Willemsen76f08272016-07-09 00:14:08 -0700110 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700111 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700112
Colin Cross26c34ed2016-09-30 17:10:16 -0700113 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700114 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700115
116 // Path to the file container flags to use with the linker
117 LinkerFlagsFile android.OptionalPath
118
119 // Path to the dynamic linker binary
120 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700121}
122
Colin Crossca860ac2016-01-04 14:34:37 -0800123type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700124 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
125 ArFlags []string // Flags that apply to ar
126 AsFlags []string // Flags that apply to assembly source files
127 CFlags []string // Flags that apply to C and C++ source files
128 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
129 ConlyFlags []string // Flags that apply to C source files
130 CppFlags []string // Flags that apply to C++ source files
131 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
132 YaccFlags []string // Flags that apply to Yacc source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700133 aidlFlags []string // Flags that apply to aidl source files
134 rsFlags []string // Flags that apply to renderscript source files
135 LdFlags []string // Flags that apply to linker command lines
136 libFlags []string // Flags to add libraries early to the link order
137 TidyFlags []string // Flags that apply to clang-tidy
138 SAbiFlags []string // Flags that apply to header-abi-dumper
139 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700140
Colin Crossc3199482017-03-30 15:03:04 -0700141 // Global include flags that apply to C, C++, and assembly source files
142 // These must be after any module include flags, which will be in GlobalFlags.
143 SystemIncludeFlags []string
144
Colin Crossb98c8b02016-07-29 13:44:28 -0700145 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700146 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800147 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800148 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800149
150 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800151 DynamicLinker string
152
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700153 CFlagsDeps android.Paths // Files depended on by compiler flags
154 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800155
156 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800157
158 protoDeps android.Paths
159 protoFlags []string // Flags that apply to proto source files
160 protoOutTypeFlag string // The output type, --cpp_out for example
161 protoOutParams []string // Flags that modify the output of proto generated files
162 protoC bool // Whether to use C instead of C++
163 protoOptionsFile bool // Whether to look for a .options file next to the .proto
164 ProtoRoot bool
Colin Crossc472d572015-03-17 15:06:21 -0700165}
166
Colin Cross81413472016-04-11 14:37:39 -0700167type ObjectLinkerProperties struct {
168 // names of other cc_object modules to link into this module using partial linking
169 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700170
171 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800172 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700173}
174
Colin Crossca860ac2016-01-04 14:34:37 -0800175// Properties used to compile all C or C++ modules
176type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700177 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800178 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700179
180 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800181 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700182
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +0000183 AndroidMkSharedLibs []string `blueprint:"mutated"`
184 AndroidMkStaticLibs []string `blueprint:"mutated"`
185 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
186 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
187 HideFromMake bool `blueprint:"mutated"`
188 PreventInstall bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700189
190 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800191
192 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
193 // file
194 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900195
196 // Make this module available when building for recovery
197 Recovery_available *bool
198
199 InRecovery bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700200}
201
202type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900203 // whether this module should be allowed to be directly depended by other
204 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
205 // If set to true, two variants will be built separately, one like
206 // normal, and the other limited to the set of libraries and headers
207 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700208 //
209 // The vendor variant may be used with a different (newer) /system,
210 // so it shouldn't have any unversioned runtime dependencies, or
211 // make assumptions about the system that may not be true in the
212 // future.
213 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900214 // If set to false, this module becomes inaccessible from /vendor modules.
215 //
216 // Default value is true when vndk: {enabled: true} or vendor: true.
217 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700218 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
219 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900220
221 // whether this module is capable of being loaded with other instance
222 // (possibly an older version) of the same module in the same process.
223 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
224 // can be double loaded in a vendor process if the library is also a
225 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
226 // explicitly marked as `double_loadable: true` by the owner, or the dependency
227 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
228 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800229}
230
Colin Crossca860ac2016-01-04 14:34:37 -0800231type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800232 static() bool
233 staticBinary() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700234 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700235 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800236 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700237 useVndk() bool
Justin Yun8effde42017-06-23 19:24:43 +0900238 isVndk() bool
239 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800240 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900241 inRecovery() bool
Logan Chien2f2b8902018-07-10 15:01:19 +0800242 shouldCreateVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700243 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700244 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800245 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800246 isPgoCompile() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800247}
248
249type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700250 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800251 ModuleContextIntf
252}
253
254type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700255 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800256 ModuleContextIntf
257}
258
Colin Cross37047f12016-12-13 17:06:13 -0800259type DepsContext interface {
260 android.BottomUpMutatorContext
261 ModuleContextIntf
262}
263
Colin Crossca860ac2016-01-04 14:34:37 -0800264type feature interface {
265 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800266 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800267 flags(ctx ModuleContext, flags Flags) Flags
268 props() []interface{}
269}
270
271type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700272 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800273 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800274 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700275 compilerProps() []interface{}
276
Colin Cross76fada02016-07-27 10:31:13 -0700277 appendCflags([]string)
278 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700279 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800280}
281
282type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700283 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800284 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700285 linkerFlags(ctx ModuleContext, flags Flags) Flags
286 linkerProps() []interface{}
287
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700288 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700289 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800290}
291
292type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700293 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700294 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800295 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700296 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700297 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800298}
299
Colin Crossc99deeb2016-04-11 15:06:20 -0700300type dependencyTag struct {
301 blueprint.BaseDependencyTag
302 name string
303 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700304
305 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700306}
307
308var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700309 sharedDepTag = dependencyTag{name: "shared", library: true}
310 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
311 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
312 staticDepTag = dependencyTag{name: "static", library: true}
313 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
314 lateStaticDepTag = dependencyTag{name: "late static", library: true}
315 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800316 headerDepTag = dependencyTag{name: "header", library: true}
317 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700318 genSourceDepTag = dependencyTag{name: "gen source"}
319 genHeaderDepTag = dependencyTag{name: "gen header"}
320 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
321 objDepTag = dependencyTag{name: "obj"}
322 crtBeginDepTag = dependencyTag{name: "crtbegin"}
323 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700324 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
325 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700326 reuseObjTag = dependencyTag{name: "reuse objects"}
327 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
328 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800329 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800330 runtimeDepTag = dependencyTag{name: "runtime lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700331)
332
Colin Crossca860ac2016-01-04 14:34:37 -0800333// Module contains the properties and members used by all C/C++ module types, and implements
334// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
335// to construct the output file. Behavior can be customized with a Customizer interface
336type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700337 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700338 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900339 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700340
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700341 Properties BaseProperties
342 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700343
Colin Crossca860ac2016-01-04 14:34:37 -0800344 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700345 hod android.HostOrDeviceSupported
346 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700347
Colin Crossca860ac2016-01-04 14:34:37 -0800348 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700349 features []feature
350 compiler compiler
351 linker linker
352 installer installer
353 stl *stl
354 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800355 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800356 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900357 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700358 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700359 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800360
361 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700362
Colin Cross635c3b02016-05-18 15:37:25 -0700363 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800364
Colin Crossb98c8b02016-07-29 13:44:28 -0700365 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700366
367 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800368
369 // Flags used to compile this module
370 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700371
372 // When calling a linker, if module A depends on module B, then A must precede B in its command
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800373 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700374 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800375 depsInLinkOrder android.Paths
376
377 // only non-nil when this is a shared library that reuses the objects of a static library
378 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700379}
380
Jiyong Parkc20eee32018-09-05 22:36:17 +0900381func (c *Module) OutputFile() android.OptionalPath {
382 return c.outputFile
383}
384
Colin Cross36242852017-06-23 15:06:31 -0700385func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700386 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800387 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700388 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800389 }
390 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700391 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800392 }
393 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700394 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800395 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700396 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700397 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700398 }
Colin Cross16b23492016-01-06 14:41:07 -0800399 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700400 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800401 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800402 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700403 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800404 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800405 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700406 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800407 }
Justin Yun8effde42017-06-23 19:24:43 +0900408 if c.vndkdep != nil {
409 c.AddProperties(c.vndkdep.props()...)
410 }
Stephen Craneba090d12017-05-09 15:44:35 -0700411 if c.lto != nil {
412 c.AddProperties(c.lto.props()...)
413 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700414 if c.pgo != nil {
415 c.AddProperties(c.pgo.props()...)
416 }
Colin Crossca860ac2016-01-04 14:34:37 -0800417 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700418 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800419 }
Colin Crossc472d572015-03-17 15:06:21 -0700420
Colin Crossa9d8bee2018-10-02 13:59:46 -0700421 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
422 switch class {
423 case android.Device:
424 return ctx.Config().DevicePrefer32BitExecutables()
425 case android.HostCross:
426 // Windows builds always prefer 32-bit
427 return true
428 default:
429 return false
430 }
431 })
Colin Cross36242852017-06-23 15:06:31 -0700432 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700433
Colin Cross1f44a3a2017-07-07 14:33:33 -0700434 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700435
Jiyong Park9d452992018-10-03 00:38:19 +0900436 android.InitApexModule(c)
437
Colin Cross36242852017-06-23 15:06:31 -0700438 return c
Colin Crossc472d572015-03-17 15:06:21 -0700439}
440
Colin Crossb916a382016-07-29 17:28:03 -0700441// Returns true for dependency roots (binaries)
442// TODO(ccross): also handle dlopenable libraries
443func (c *Module) isDependencyRoot() bool {
444 if root, ok := c.linker.(interface {
445 isDependencyRoot() bool
446 }); ok {
447 return root.isDependencyRoot()
448 }
449 return false
450}
451
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700452func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700453 return c.Properties.UseVndk
454}
455
Justin Yun8effde42017-06-23 19:24:43 +0900456func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800457 if vndkdep := c.vndkdep; vndkdep != nil {
458 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900459 }
460 return false
461}
462
Yi Kong7e53c572018-02-14 18:16:12 +0800463func (c *Module) isPgoCompile() bool {
464 if pgo := c.pgo; pgo != nil {
465 return pgo.Properties.PgoCompile
466 }
467 return false
468}
469
Logan Chienf3511742017-10-31 18:04:35 +0800470func (c *Module) isVndkSp() bool {
471 if vndkdep := c.vndkdep; vndkdep != nil {
472 return vndkdep.isVndkSp()
473 }
474 return false
475}
476
477func (c *Module) isVndkExt() bool {
478 if vndkdep := c.vndkdep; vndkdep != nil {
479 return vndkdep.isVndkExt()
480 }
481 return false
482}
483
484func (c *Module) getVndkExtendsModuleName() string {
485 if vndkdep := c.vndkdep; vndkdep != nil {
486 return vndkdep.getVndkExtendsModuleName()
487 }
488 return ""
489}
490
Jiyong Park82e2bf32017-08-16 14:05:54 +0900491// Returns true only when this module is configured to have core and vendor
492// variants.
493func (c *Module) hasVendorVariant() bool {
494 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
495}
496
Jiyong Parkf9332f12018-02-01 00:54:12 +0900497func (c *Module) inRecovery() bool {
498 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
499}
500
501func (c *Module) onlyInRecovery() bool {
502 return c.ModuleBase.InstallInRecovery()
503}
504
Colin Crossca860ac2016-01-04 14:34:37 -0800505type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700506 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800507 moduleContextImpl
508}
509
Colin Cross37047f12016-12-13 17:06:13 -0800510type depsContext struct {
511 android.BottomUpMutatorContext
512 moduleContextImpl
513}
514
Colin Crossca860ac2016-01-04 14:34:37 -0800515type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700516 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800517 moduleContextImpl
518}
519
Jiyong Park2db76922017-11-08 16:03:48 +0900520func (ctx *moduleContext) SocSpecific() bool {
521 return ctx.ModuleContext.SocSpecific() ||
522 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700523}
524
Colin Crossca860ac2016-01-04 14:34:37 -0800525type moduleContextImpl struct {
526 mod *Module
527 ctx BaseModuleContext
528}
529
Colin Crossb98c8b02016-07-29 13:44:28 -0700530func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800531 return ctx.mod.toolchain(ctx.ctx)
532}
533
534func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000535 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800536}
537
538func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700539 if static, ok := ctx.mod.linker.(interface {
540 staticBinary() bool
541 }); ok {
542 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800543 }
Colin Crossb916a382016-07-29 17:28:03 -0700544 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800545}
546
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700547func (ctx *moduleContextImpl) useSdk() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900548 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() {
Nan Zhang0007d812017-11-07 10:57:05 -0800549 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700550 }
551 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800552}
553
554func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700555 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700556 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900557 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700558 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900559 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
560 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
561 return "current"
562 }
563 return platform_vndk_ver
564 }
565 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800566 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900567 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700568 }
569 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800570}
571
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700572func (ctx *moduleContextImpl) useVndk() bool {
573 return ctx.mod.useVndk()
574}
Justin Yun8effde42017-06-23 19:24:43 +0900575
Logan Chienf3511742017-10-31 18:04:35 +0800576func (ctx *moduleContextImpl) isVndk() bool {
577 return ctx.mod.isVndk()
578}
579
Yi Kong7e53c572018-02-14 18:16:12 +0800580func (ctx *moduleContextImpl) isPgoCompile() bool {
581 return ctx.mod.isPgoCompile()
582}
583
Justin Yun8effde42017-06-23 19:24:43 +0900584func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800585 return ctx.mod.isVndkSp()
586}
587
588func (ctx *moduleContextImpl) isVndkExt() bool {
589 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900590}
591
Jiyong Parkf9332f12018-02-01 00:54:12 +0900592func (ctx *moduleContextImpl) inRecovery() bool {
593 return ctx.mod.inRecovery()
594}
595
Logan Chien2f2b8902018-07-10 15:01:19 +0800596// Check whether ABI dumps should be created for this module.
597func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump() bool {
598 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
599 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800600 }
Logan Chien2f2b8902018-07-10 15:01:19 +0800601 if sanitize := ctx.mod.sanitize; sanitize != nil {
602 if !sanitize.isVariantOnProductionDevice() {
603 return false
604 }
605 }
606 if !ctx.ctx.Device() {
607 // Host modules do not need ABI dumps.
608 return false
609 }
610 if inList(ctx.baseModuleName(), llndkLibraries) {
611 return true
612 }
Logan Chienf4b79c62018-08-02 02:27:02 +0800613 if inList(ctx.baseModuleName(), ndkMigratedLibs) {
614 return true
615 }
Logan Chien2f2b8902018-07-10 15:01:19 +0800616 if ctx.useVndk() && ctx.isVndk() {
617 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
618 // VNDK-private.
619 return Bool(ctx.mod.VendorProperties.Vendor_available) || ctx.isVndkExt()
620 }
621 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800622}
623
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700624func (ctx *moduleContextImpl) selectedStl() string {
625 if stl := ctx.mod.stl; stl != nil {
626 return stl.Properties.SelectedStl
627 }
628 return ""
629}
630
Colin Crossce75d2c2016-10-06 16:12:58 -0700631func (ctx *moduleContextImpl) baseModuleName() string {
632 return ctx.mod.ModuleBase.BaseModuleName()
633}
634
Logan Chienf3511742017-10-31 18:04:35 +0800635func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
636 return ctx.mod.getVndkExtendsModuleName()
637}
638
Colin Cross635c3b02016-05-18 15:37:25 -0700639func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800640 return &Module{
641 hod: hod,
642 multilib: multilib,
643 }
644}
645
Colin Cross635c3b02016-05-18 15:37:25 -0700646func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800647 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700648 module.features = []feature{
649 &tidyFeature{},
650 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700651 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800652 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800653 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800654 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900655 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700656 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700657 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -0800658 return module
659}
660
Colin Crossce75d2c2016-10-06 16:12:58 -0700661func (c *Module) Prebuilt() *android.Prebuilt {
662 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
663 return p.prebuilt()
664 }
665 return nil
666}
667
668func (c *Module) Name() string {
669 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700670 if p, ok := c.linker.(interface {
671 Name(string) string
672 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700673 name = p.Name(name)
674 }
675 return name
676}
677
Jeff Gaston294356f2017-09-27 17:05:30 -0700678// orderDeps reorders dependencies into a list such that if module A depends on B, then
679// A will precede B in the resultant list.
680// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800681// Note that directSharedDeps should be the analogous static library for each shared lib dep
682func orderDeps(directStaticDeps []android.Path, directSharedDeps []android.Path, allTransitiveDeps map[android.Path][]android.Path) (orderedAllDeps []android.Path, orderedDeclaredDeps []android.Path) {
Jeff Gaston294356f2017-09-27 17:05:30 -0700683 // If A depends on B, then
684 // Every list containing A will also contain B later in the list
685 // So, after concatenating all lists, the final instance of B will have come from the same
686 // original list as the final instance of A
687 // So, the final instance of B will be later in the concatenation than the final A
688 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
689 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800690 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700691 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800692 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
693 }
694 for _, dep := range directSharedDeps {
695 orderedAllDeps = append(orderedAllDeps, dep)
696 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700697 }
698
Colin Crossb6715442017-10-24 11:13:31 -0700699 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700700
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800701 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700702 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800703 // resultant list to only what the caller has chosen to include in directStaticDeps
704 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700705
706 return orderedAllDeps, orderedDeclaredDeps
707}
708
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800709func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
710 // convert Module to Path
711 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
712 staticDepFiles := []android.Path{}
713 for _, dep := range staticDeps {
714 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
715 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700716 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800717 sharedDepFiles := []android.Path{}
718 for _, sharedDep := range sharedDeps {
719 staticAnalogue := sharedDep.staticVariant
720 if staticAnalogue != nil {
721 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
722 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
723 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700724 }
725
726 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800727 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700728
729 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700730}
731
Colin Cross635c3b02016-05-18 15:37:25 -0700732func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800733 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700734 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800735 moduleContextImpl: moduleContextImpl{
736 mod: c,
737 },
738 }
739 ctx.ctx = ctx
740
Colin Crossf18e1102017-11-16 14:33:08 -0800741 deps := c.depsToPaths(ctx)
742 if ctx.Failed() {
743 return
744 }
745
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700746 if c.Properties.Clang != nil && *c.Properties.Clang == false {
747 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
748 }
749
Colin Crossca860ac2016-01-04 14:34:37 -0800750 flags := Flags{
751 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800752 }
Colin Crossca860ac2016-01-04 14:34:37 -0800753 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800754 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800755 }
756 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700757 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800758 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700759 if c.stl != nil {
760 flags = c.stl.flags(ctx, flags)
761 }
Colin Cross16b23492016-01-06 14:41:07 -0800762 if c.sanitize != nil {
763 flags = c.sanitize.flags(ctx, flags)
764 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800765 if c.coverage != nil {
766 flags = c.coverage.flags(ctx, flags)
767 }
Stephen Craneba090d12017-05-09 15:44:35 -0700768 if c.lto != nil {
769 flags = c.lto.flags(ctx, flags)
770 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700771 if c.pgo != nil {
772 flags = c.pgo.flags(ctx, flags)
773 }
Colin Crossca860ac2016-01-04 14:34:37 -0800774 for _, feature := range c.features {
775 flags = feature.flags(ctx, flags)
776 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800777 if ctx.Failed() {
778 return
779 }
780
Colin Crossb98c8b02016-07-29 13:44:28 -0700781 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
782 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
783 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800784
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800785 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
786 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700787 // We need access to all the flags seen by a source file.
788 if c.sabi != nil {
789 flags = c.sabi.flags(ctx, flags)
790 }
Colin Crossca860ac2016-01-04 14:34:37 -0800791 // Optimization to reduce size of build.ninja
792 // Replace the long list of flags for each file with a module-local variable
793 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
794 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
795 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
796 flags.CFlags = []string{"$cflags"}
797 flags.CppFlags = []string{"$cppflags"}
798 flags.AsFlags = []string{"$asflags"}
799
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700800 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800801 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700802 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800803 if ctx.Failed() {
804 return
805 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800806 }
807
Colin Crossca860ac2016-01-04 14:34:37 -0800808 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700809 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800810 if ctx.Failed() {
811 return
812 }
Colin Cross635c3b02016-05-18 15:37:25 -0700813 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700814 }
Colin Cross5049f022015-03-18 13:28:46 -0700815
Jiyong Park9d452992018-10-03 00:38:19 +0900816 if c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() {
Colin Crossce75d2c2016-10-06 16:12:58 -0700817 c.installer.install(ctx, c.outputFile.Path())
818 if ctx.Failed() {
819 return
Colin Crossca860ac2016-01-04 14:34:37 -0800820 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700821 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800822}
823
Colin Crossb98c8b02016-07-29 13:44:28 -0700824func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800825 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700826 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800827 }
Colin Crossca860ac2016-01-04 14:34:37 -0800828 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800829}
830
Colin Crossca860ac2016-01-04 14:34:37 -0800831func (c *Module) begin(ctx BaseModuleContext) {
832 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700833 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700834 }
Colin Crossca860ac2016-01-04 14:34:37 -0800835 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700836 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800837 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700838 if c.stl != nil {
839 c.stl.begin(ctx)
840 }
Colin Cross16b23492016-01-06 14:41:07 -0800841 if c.sanitize != nil {
842 c.sanitize.begin(ctx)
843 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800844 if c.coverage != nil {
845 c.coverage.begin(ctx)
846 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800847 if c.sabi != nil {
848 c.sabi.begin(ctx)
849 }
Justin Yun8effde42017-06-23 19:24:43 +0900850 if c.vndkdep != nil {
851 c.vndkdep.begin(ctx)
852 }
Stephen Craneba090d12017-05-09 15:44:35 -0700853 if c.lto != nil {
854 c.lto.begin(ctx)
855 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700856 if c.pgo != nil {
857 c.pgo.begin(ctx)
858 }
Colin Crossca860ac2016-01-04 14:34:37 -0800859 for _, feature := range c.features {
860 feature.begin(ctx)
861 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700862 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700863 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700864 if err != nil {
865 ctx.PropertyErrorf("sdk_version", err.Error())
866 }
Nan Zhang0007d812017-11-07 10:57:05 -0800867 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700868 }
Colin Crossca860ac2016-01-04 14:34:37 -0800869}
870
Colin Cross37047f12016-12-13 17:06:13 -0800871func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700872 deps := Deps{}
873
874 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700875 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700876 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +0000877 // Add the PGO dependency (the clang_rt.profile runtime library), which
878 // sometimes depends on symbols from libgcc, before libgcc gets added
879 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700880 if c.pgo != nil {
881 deps = c.pgo.deps(ctx, deps)
882 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700883 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700884 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700885 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700886 if c.stl != nil {
887 deps = c.stl.deps(ctx, deps)
888 }
Colin Cross16b23492016-01-06 14:41:07 -0800889 if c.sanitize != nil {
890 deps = c.sanitize.deps(ctx, deps)
891 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +0000892 if c.coverage != nil {
893 deps = c.coverage.deps(ctx, deps)
894 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800895 if c.sabi != nil {
896 deps = c.sabi.deps(ctx, deps)
897 }
Justin Yun8effde42017-06-23 19:24:43 +0900898 if c.vndkdep != nil {
899 deps = c.vndkdep.deps(ctx, deps)
900 }
Stephen Craneba090d12017-05-09 15:44:35 -0700901 if c.lto != nil {
902 deps = c.lto.deps(ctx, deps)
903 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700904 for _, feature := range c.features {
905 deps = feature.deps(ctx, deps)
906 }
907
Colin Crossb6715442017-10-24 11:13:31 -0700908 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
909 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
910 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
911 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
912 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
913 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +0800914 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700915
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700916 for _, lib := range deps.ReexportSharedLibHeaders {
917 if !inList(lib, deps.SharedLibs) {
918 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
919 }
920 }
921
922 for _, lib := range deps.ReexportStaticLibHeaders {
923 if !inList(lib, deps.StaticLibs) {
924 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
925 }
926 }
927
Colin Cross5950f382016-12-13 12:50:57 -0800928 for _, lib := range deps.ReexportHeaderLibHeaders {
929 if !inList(lib, deps.HeaderLibs) {
930 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
931 }
932 }
933
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700934 for _, gen := range deps.ReexportGeneratedHeaders {
935 if !inList(gen, deps.GeneratedHeaders) {
936 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
937 }
938 }
939
Colin Crossc99deeb2016-04-11 15:06:20 -0700940 return deps
941}
942
Dan Albert7e9d2952016-08-04 13:02:36 -0700943func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800944 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700945 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800946 moduleContextImpl: moduleContextImpl{
947 mod: c,
948 },
949 }
950 ctx.ctx = ctx
951
Colin Crossca860ac2016-01-04 14:34:37 -0800952 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700953}
954
Jiyong Park7ed9de32018-10-15 22:25:07 +0900955// Split name#version into name and version
956func stubsLibNameAndVersion(name string) (string, string) {
957 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
958 version := name[sharp+1:]
959 libname := name[:sharp]
960 return libname, version
961 }
962 return name, ""
963}
964
Colin Cross1e676be2016-10-12 14:38:15 -0700965func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -0800966 ctx := &depsContext{
967 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700968 moduleContextImpl: moduleContextImpl{
969 mod: c,
970 },
971 }
972 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800973
Colin Crossc99deeb2016-04-11 15:06:20 -0700974 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800975
Dan Albert914449f2016-06-17 16:45:24 -0700976 variantNdkLibs := []string{}
977 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700978 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700979 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700980
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700981 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
982 // of names:
Dan Albert914449f2016-06-17 16:45:24 -0700983 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700984 // 1. Name of an NDK library that refers to a prebuilt module.
985 // For each of these, it adds the name of the prebuilt module (which will be in
986 // prebuilts/ndk) to the list of nonvariant libs.
987 // 2. Name of an NDK library that refers to an ndk_library module.
988 // For each of these, it adds the name of the ndk_library module to the list of
989 // variant libs.
990 // 3. Anything else (so anything that isn't an NDK library).
991 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -0700992 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700993 // The caller can then know to add the variantLibs dependencies differently from the
994 // nonvariantLibs
995 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
996 variantLibs = []string{}
997 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -0700998 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +0900999 // strip #version suffix out
1000 name, _ := stubsLibNameAndVersion(entry)
1001 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1002 if !inList(name, ndkMigratedLibs) {
1003 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001004 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001005 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001006 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001007 } else if ctx.useVndk() && inList(name, llndkLibraries) {
1008 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
1009 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, vendorPublicLibraries) {
1010 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001011 if actx.OtherModuleExists(vendorPublicLib) {
1012 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1013 } else {
1014 // This can happen if vendor_public_library module is defined in a
1015 // namespace that isn't visible to the current module. In that case,
1016 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001017 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001018 }
Dan Albert914449f2016-06-17 16:45:24 -07001019 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001020 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001021 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001022 }
1023 }
Dan Albert914449f2016-06-17 16:45:24 -07001024 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001025 }
1026
Dan Albert914449f2016-06-17 16:45:24 -07001027 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1028 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001029 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001030 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001031
Jiyong Park7ed9de32018-10-15 22:25:07 +09001032 if c.linker != nil {
1033 if library, ok := c.linker.(*libraryDecorator); ok {
1034 if library.buildStubs() {
1035 // Stubs lib does not have dependency to other libraries. Don't proceed.
1036 return
1037 }
1038 }
1039 }
1040
Colin Cross32ec36c2016-12-15 07:39:51 -08001041 for _, lib := range deps.HeaderLibs {
1042 depTag := headerDepTag
1043 if inList(lib, deps.ReexportHeaderLibHeaders) {
1044 depTag = headerExportDepTag
1045 }
1046 actx.AddVariationDependencies(nil, depTag, lib)
1047 }
Colin Cross5950f382016-12-13 12:50:57 -08001048
Dan Willemsen59339a22018-07-22 21:18:45 -07001049 actx.AddVariationDependencies([]blueprint.Variation{
1050 {Mutator: "link", Variation: "static"},
1051 }, wholeStaticDepTag, deps.WholeStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001052
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001053 for _, lib := range deps.StaticLibs {
1054 depTag := staticDepTag
1055 if inList(lib, deps.ReexportStaticLibHeaders) {
1056 depTag = staticExportDepTag
1057 }
Dan Willemsen59339a22018-07-22 21:18:45 -07001058 actx.AddVariationDependencies([]blueprint.Variation{
1059 {Mutator: "link", Variation: "static"},
1060 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001061 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001062
Dan Willemsen59339a22018-07-22 21:18:45 -07001063 actx.AddVariationDependencies([]blueprint.Variation{
1064 {Mutator: "link", Variation: "static"},
1065 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001066
Jiyong Park7ed9de32018-10-15 22:25:07 +09001067 // shared lib names without the #version suffix
1068 var sharedLibNames []string
1069
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001070 for _, lib := range deps.SharedLibs {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001071 name, version := stubsLibNameAndVersion(lib)
1072 sharedLibNames = append(sharedLibNames, name)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001073 depTag := sharedDepTag
1074 if inList(lib, deps.ReexportSharedLibHeaders) {
1075 depTag = sharedExportDepTag
1076 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001077 var variations []blueprint.Variation
1078 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
1079 if version != "" && ctx.Os() == android.Android && !ctx.useVndk() && !c.inRecovery() {
1080 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1081 }
1082 actx.AddVariationDependencies(variations, depTag, name)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001083 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001084
Jiyong Park7ed9de32018-10-15 22:25:07 +09001085 for _, lib := range deps.LateSharedLibs {
1086 name, version := stubsLibNameAndVersion(lib)
1087 if inList(name, sharedLibNames) {
1088 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1089 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1090 // linking against both the stubs lib and the non-stubs lib at the same time.
1091 continue
1092 }
1093 depTag := lateSharedDepTag
1094 var variations []blueprint.Variation
1095 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
1096 if version != "" && ctx.Os() == android.Android && !ctx.useVndk() && !c.inRecovery() {
1097 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1098 }
1099 actx.AddVariationDependencies(variations, depTag, name)
1100 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001101
Dan Willemsen59339a22018-07-22 21:18:45 -07001102 actx.AddVariationDependencies([]blueprint.Variation{
1103 {Mutator: "link", Variation: "shared"},
1104 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001105
Colin Cross68861832016-07-08 10:41:41 -07001106 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001107
1108 for _, gen := range deps.GeneratedHeaders {
1109 depTag := genHeaderDepTag
1110 if inList(gen, deps.ReexportGeneratedHeaders) {
1111 depTag = genHeaderExportDepTag
1112 }
1113 actx.AddDependency(c, depTag, gen)
1114 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001115
Colin Cross42d48b72018-08-29 14:10:52 -07001116 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001117
1118 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001119 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001120 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001121 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001122 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001123 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001124 if deps.LinkerFlagsFile != "" {
1125 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1126 }
1127 if deps.DynamicLinker != "" {
1128 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001129 }
Dan Albert914449f2016-06-17 16:45:24 -07001130
1131 version := ctx.sdkVersion()
1132 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001133 {Mutator: "ndk_api", Variation: version},
1134 {Mutator: "link", Variation: "shared"},
1135 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001136 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001137 {Mutator: "ndk_api", Variation: version},
1138 {Mutator: "link", Variation: "shared"},
1139 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001140
1141 if vndkdep := c.vndkdep; vndkdep != nil {
1142 if vndkdep.isVndkExt() {
1143 baseModuleMode := vendorMode
1144 if actx.DeviceConfig().VndkVersion() == "" {
1145 baseModuleMode = coreMode
1146 }
1147 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001148 {Mutator: "image", Variation: baseModuleMode},
1149 {Mutator: "link", Variation: "shared"},
1150 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001151 }
1152 }
Colin Cross6362e272015-10-29 15:25:03 -07001153}
Colin Cross21b9a242015-03-24 14:15:58 -07001154
Colin Crosse40b4ea2018-10-02 22:25:58 -07001155func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001156 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1157 c.beginMutator(ctx)
1158 }
1159}
1160
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001161// Whether a module can link to another module, taking into
1162// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001163func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001164 if from.Target().Os != android.Android {
1165 // Host code is not restricted
1166 return
1167 }
1168 if from.Properties.UseVndk {
1169 // Though vendor code is limited by the vendor mutator,
1170 // each vendor-available module needs to check
1171 // link-type for VNDK.
1172 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001173 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001174 }
1175 return
1176 }
Nan Zhang0007d812017-11-07 10:57:05 -08001177 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001178 // Platform code can link to anything
1179 return
1180 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001181 if from.inRecovery() {
1182 // Recovery code is not NDK
1183 return
1184 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001185 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1186 // These are always allowed
1187 return
1188 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001189 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1190 // These are allowed, but they don't set sdk_version
1191 return
1192 }
1193 if _, ok := to.linker.(*stubDecorator); ok {
1194 // These aren't real libraries, but are the stub shared libraries that are included in
1195 // the NDK.
1196 return
1197 }
Nan Zhang0007d812017-11-07 10:57:05 -08001198 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001199 // NDK code linking to platform code is never okay.
1200 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1201 ctx.OtherModuleName(to))
1202 }
1203
1204 // At this point we know we have two NDK libraries, but we need to
1205 // check that we're not linking against anything built against a higher
1206 // API level, as it is only valid to link against older or equivalent
1207 // APIs.
1208
Inseob Kim01a28722018-04-11 09:48:45 +09001209 // Current can link against anything.
1210 if String(from.Properties.Sdk_version) != "current" {
1211 // Otherwise we need to check.
1212 if String(to.Properties.Sdk_version) == "current" {
1213 // Current can't be linked against by anything else.
1214 ctx.ModuleErrorf("links %q built against newer API version %q",
1215 ctx.OtherModuleName(to), "current")
1216 } else {
1217 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1218 if err != nil {
1219 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001220 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001221 String(from.Properties.Sdk_version))
1222 }
1223 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1224 if err != nil {
1225 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001226 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001227 String(to.Properties.Sdk_version))
1228 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001229
Inseob Kim01a28722018-04-11 09:48:45 +09001230 if toApi > fromApi {
1231 ctx.ModuleErrorf("links %q built against newer API version %q",
1232 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1233 }
1234 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001235 }
Dan Albert202fe492017-12-15 13:56:59 -08001236
1237 // Also check that the two STL choices are compatible.
1238 fromStl := from.stl.Properties.SelectedStl
1239 toStl := to.stl.Properties.SelectedStl
1240 if fromStl == "" || toStl == "" {
1241 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001242 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001243 // We can be permissive with the system "STL" since it is only the C++
1244 // ABI layer, but in the future we should make sure that everyone is
1245 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001246 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001247 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1248 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1249 to.stl.Properties.SelectedStl)
1250 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001251}
1252
Jiyong Park5fb8c102018-04-09 12:03:06 +09001253// Tests whether the dependent library is okay to be double loaded inside a single process.
1254// If a library is a member of VNDK and at the same time dependencies of an LLNDK library,
1255// it is subject to be double loaded. Such lib should be explicitly marked as double_loaded: true
1256// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
1257func checkDoubleLoadableLibries(ctx android.ModuleContext, from *Module, to *Module) {
1258 if _, ok := from.linker.(*libraryDecorator); !ok {
1259 return
1260 }
1261
1262 if inList(ctx.ModuleName(), llndkLibraries) ||
1263 (from.useVndk() && Bool(from.VendorProperties.Double_loadable)) {
1264 _, depIsLlndk := to.linker.(*llndkStubDecorator)
1265 depIsVndkSp := false
1266 if to.vndkdep != nil && to.vndkdep.isVndkSp() {
1267 depIsVndkSp = true
1268 }
1269 depIsVndk := false
1270 if to.vndkdep != nil && to.vndkdep.isVndk() {
1271 depIsVndk = true
1272 }
1273 depIsDoubleLoadable := Bool(to.VendorProperties.Double_loadable)
1274 if !depIsLlndk && !depIsVndkSp && !depIsDoubleLoadable && depIsVndk {
1275 ctx.ModuleErrorf("links VNDK library %q that isn't double_loadable.",
1276 ctx.OtherModuleName(to))
1277 }
1278 }
1279}
1280
Colin Crossc99deeb2016-04-11 15:06:20 -07001281// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001282func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001283 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001284
Jeff Gaston294356f2017-09-27 17:05:30 -07001285 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001286 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001287
Colin Crossd11fcda2017-10-23 17:59:01 -07001288 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001289 depName := ctx.OtherModuleName(dep)
1290 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001291
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001292 ccDep, _ := dep.(*Module)
1293 if ccDep == nil {
1294 // handling for a few module types that aren't cc Module but that are also supported
1295 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001296 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001297 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001298 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1299 genRule.GeneratedSourceFiles()...)
1300 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001301 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001302 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001303 // Support exported headers from a generated_sources dependency
1304 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001305 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001306 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001307 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001308 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001309 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001310 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001311 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001312 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001313 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001314 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001315 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1316 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1317
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001318 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001319 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001320 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001321 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001322 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001323 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001324 files := genRule.GeneratedSourceFiles()
1325 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001326 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001327 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001328 ctx.ModuleErrorf("module %q can only generate a single file if used for a linker flag file", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001329 }
1330 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001331 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001332 }
Colin Crossca860ac2016-01-04 14:34:37 -08001333 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001334 return
1335 }
1336
Colin Crossd11fcda2017-10-23 17:59:01 -07001337 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001338 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1339 return
1340 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001341 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001342 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001343 return
1344 }
1345
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001346 // re-exporting flags
1347 if depTag == reuseObjTag {
1348 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001349 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001350 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001351 depPaths.Objs = depPaths.Objs.Append(objs)
1352 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001353 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001354 return
1355 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001356 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001357 if t, ok := depTag.(dependencyTag); ok && t.library {
1358 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001359 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001360 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001361 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001362 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001363
1364 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001365 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001366 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001367 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
Jayant Chowdharyaf6eb712017-08-23 16:08:29 -07001368 // Re-exported shared library headers must be included as well since they can help us with type information
1369 // about template instantiations (instantiated from their headers).
1370 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001371 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001372 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001373
Logan Chienf3511742017-10-31 18:04:35 +08001374 checkLinkType(ctx, c, ccDep, t)
Jiyong Park5fb8c102018-04-09 12:03:06 +09001375 checkDoubleLoadableLibries(ctx, c, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001376 }
1377
Colin Cross26c34ed2016-09-30 17:10:16 -07001378 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001379 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001380
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001381 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001382 depFile := android.OptionalPath{}
1383
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001384 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001385 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001386 ptr = &depPaths.SharedLibs
1387 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001388 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001389 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001390 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001391 ptr = &depPaths.LateSharedLibs
1392 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001393 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001394 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001395 ptr = nil
1396 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001397 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001398 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001399 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001400 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001401 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001402 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001403 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001404 return
1405 }
1406
1407 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001408 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001409 for i := range missingDeps {
1410 missingDeps[i] += postfix
1411 }
1412 ctx.AddMissingDependencies(missingDeps)
1413 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001414 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001415 case headerDepTag:
1416 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001417 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001418 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001419 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001420 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001421 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001422 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001423 case dynamicLinkerDepTag:
1424 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001425 }
1426
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001427 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001428 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001429 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001430 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001431 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001432 return
1433 }
1434
1435 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001436 // in static libraries act as if they were whole static libraries. The same goes for
1437 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001438 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1439 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001440 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1441 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001442
Dan Willemsen581341d2017-02-09 16:16:31 -08001443 }
1444
Colin Cross26c34ed2016-09-30 17:10:16 -07001445 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001446 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001447 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001448 return
1449 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001450 *ptr = append(*ptr, linkFile.Path())
1451 }
1452
Colin Crossc99deeb2016-04-11 15:06:20 -07001453 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001454 dep := depFile
1455 if !dep.Valid() {
1456 dep = linkFile
1457 }
1458 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001459 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001460
Logan Chien43d34c32017-12-20 01:17:32 +08001461 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001462 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001463 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001464 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001465 isLLndk := inList(libName, llndkLibraries)
Jiyong Park374510b2018-03-19 18:23:01 +09001466 isVendorPublicLib := inList(libName, vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001467 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1468 if c.useVndk() && bothVendorAndCoreVariantsExist {
1469 // The vendor module in Make will have been renamed to not conflict with the core
1470 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001471 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001472 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001473 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001474 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1475 return libName + recoverySuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001476 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001477 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001478 }
Logan Chien43d34c32017-12-20 01:17:32 +08001479 }
1480
1481 // Export the shared libs to Make.
1482 switch depTag {
1483 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jiyong Park27b188b2017-07-18 13:23:39 +09001484 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001485 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001486 c.Properties.AndroidMkSharedLibs = append(
1487 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001488 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1489 c.Properties.AndroidMkStaticLibs = append(
1490 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001491 case runtimeDepTag:
1492 c.Properties.AndroidMkRuntimeLibs = append(
1493 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001494 case wholeStaticDepTag:
1495 c.Properties.AndroidMkWholeStaticLibs = append(
1496 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001497 }
Colin Crossca860ac2016-01-04 14:34:37 -08001498 })
1499
Jeff Gaston294356f2017-09-27 17:05:30 -07001500 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001501 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001502
Colin Crossdd84e052017-05-17 13:44:16 -07001503 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001504 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001505 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001506 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001507 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1508
1509 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001510 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001511 }
Colin Crossdd84e052017-05-17 13:44:16 -07001512
Colin Crossca860ac2016-01-04 14:34:37 -08001513 return depPaths
1514}
1515
1516func (c *Module) InstallInData() bool {
1517 if c.installer == nil {
1518 return false
1519 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001520 return c.installer.inData()
1521}
1522
1523func (c *Module) InstallInSanitizerDir() bool {
1524 if c.installer == nil {
1525 return false
1526 }
1527 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001528 return true
1529 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001530 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001531}
1532
Jiyong Parkf9332f12018-02-01 00:54:12 +09001533func (c *Module) InstallInRecovery() bool {
1534 return c.inRecovery()
1535}
1536
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001537func (c *Module) HostToolPath() android.OptionalPath {
1538 if c.installer == nil {
1539 return android.OptionalPath{}
1540 }
1541 return c.installer.hostToolPath()
1542}
1543
Nan Zhangd4e641b2017-07-12 12:55:28 -07001544func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1545 return c.outputFile
1546}
1547
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001548func (c *Module) Srcs() android.Paths {
1549 if c.outputFile.Valid() {
1550 return android.Paths{c.outputFile.Path()}
1551 }
1552 return android.Paths{}
1553}
1554
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001555func (c *Module) static() bool {
1556 if static, ok := c.linker.(interface {
1557 static() bool
1558 }); ok {
1559 return static.static()
1560 }
1561 return false
1562}
1563
Colin Crossb60190a2018-09-04 16:28:17 -07001564func (c *Module) getMakeLinkType() string {
1565 if c.useVndk() {
1566 if inList(c.Name(), vndkCoreLibraries) || inList(c.Name(), vndkSpLibraries) || inList(c.Name(), llndkLibraries) {
1567 if inList(c.Name(), vndkPrivateLibraries) {
1568 return "native:vndk_private"
1569 } else {
1570 return "native:vndk"
1571 }
1572 } else {
1573 return "native:vendor"
1574 }
1575 } else if c.inRecovery() {
1576 return "native:recovery"
1577 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
1578 return "native:ndk:none:none"
1579 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
1580 //family, link := getNdkStlFamilyAndLinkType(c)
1581 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
1582 } else {
1583 return "native:platform"
1584 }
1585}
1586
Jiyong Park9d452992018-10-03 00:38:19 +09001587// Overrides ApexModule.IsInstallabeToApex()
1588// Only shared libraries are installable to APEX.
1589func (c *Module) IsInstallableToApex() bool {
1590 if shared, ok := c.linker.(interface {
1591 shared() bool
1592 }); ok {
1593 return shared.shared()
1594 }
1595 return false
1596}
1597
Colin Cross2ba19d92015-05-07 15:44:20 -07001598//
Colin Crosscfad1192015-11-02 16:43:11 -08001599// Defaults
1600//
Colin Crossca860ac2016-01-04 14:34:37 -08001601type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001602 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001603 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09001604 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001605}
1606
Colin Cross635c3b02016-05-18 15:37:25 -07001607func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001608}
1609
Colin Cross1e676be2016-10-12 14:38:15 -07001610func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1611}
1612
Colin Cross36242852017-06-23 15:06:31 -07001613func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001614 return DefaultsFactory()
1615}
1616
Colin Cross36242852017-06-23 15:06:31 -07001617func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001618 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001619
Colin Cross36242852017-06-23 15:06:31 -07001620 module.AddProperties(props...)
1621 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001622 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001623 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001624 &BaseCompilerProperties{},
1625 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001626 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001627 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001628 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001629 &TestProperties{},
1630 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001631 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001632 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001633 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001634 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001635 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001636 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001637 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001638 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001639 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001640 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001641 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001642 )
Colin Crosscfad1192015-11-02 16:43:11 -08001643
Colin Cross1f44a3a2017-07-07 14:33:33 -07001644 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09001645 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001646
1647 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001648}
1649
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001650const (
1651 // coreMode is the variant used for framework-private libraries, or
1652 // SDK libraries. (which framework-private libraries can use)
1653 coreMode = "core"
1654
1655 // vendorMode is the variant used for /vendor code that compiles
1656 // against the VNDK.
1657 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09001658
1659 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001660)
1661
Jiyong Park6a43f042017-10-12 23:05:00 +09001662func squashVendorSrcs(m *Module) {
1663 if lib, ok := m.compiler.(*libraryDecorator); ok {
1664 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1665 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1666
1667 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1668 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1669 }
1670}
1671
Jiyong Parkf9332f12018-02-01 00:54:12 +09001672func squashRecoverySrcs(m *Module) {
1673 if lib, ok := m.compiler.(*libraryDecorator); ok {
1674 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1675 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
1676
1677 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1678 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
1679 }
1680}
1681
1682func imageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001683 if mctx.Os() != android.Android {
1684 return
1685 }
1686
Jiyong Park7ed9de32018-10-15 22:25:07 +09001687 if g, ok := mctx.Module().(*genrule.Module); ok {
1688 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09001689 var coreVariantNeeded bool = false
1690 var vendorVariantNeeded bool = false
1691 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09001692 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09001693 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001694 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09001695 coreVariantNeeded = true
1696 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09001697 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09001698 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001699 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09001700 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001701 }
Jiyong Park3f736c92018-05-24 13:36:56 +09001702 if Bool(props.Recovery_available) {
1703 recoveryVariantNeeded = true
1704 }
1705
Jiyong Park413cc742018-06-19 01:46:06 +09001706 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09001707 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09001708 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09001709 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09001710 recoveryVariantNeeded = false
1711 }
1712 }
1713
Jiyong Park3f736c92018-05-24 13:36:56 +09001714 var variants []string
1715 if coreVariantNeeded {
1716 variants = append(variants, coreMode)
1717 }
1718 if vendorVariantNeeded {
1719 variants = append(variants, vendorMode)
1720 }
1721 if recoveryVariantNeeded {
1722 variants = append(variants, recoveryMode)
1723 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001724 mod := mctx.CreateVariations(variants...)
1725 for i, v := range variants {
1726 if v == recoveryMode {
1727 m := mod[i].(*genrule.Module)
1728 m.Extra.(*GenruleExtraProperties).InRecovery = true
1729 }
1730 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001731 }
1732 }
1733
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001734 m, ok := mctx.Module().(*Module)
1735 if !ok {
1736 return
1737 }
1738
1739 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08001740 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
1741
1742 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001743 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09001744 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001745 return
1746 }
Logan Chienf3511742017-10-31 18:04:35 +08001747
1748 if vndkdep := m.vndkdep; vndkdep != nil {
1749 if vndkdep.isVndk() {
1750 if vendorSpecific {
1751 if !vndkdep.isVndkExt() {
1752 mctx.PropertyErrorf("vndk",
1753 "must set `extends: \"...\"` to vndk extension")
1754 return
1755 }
1756 } else {
1757 if vndkdep.isVndkExt() {
1758 mctx.PropertyErrorf("vndk",
1759 "must set `vendor: true` to set `extends: %q`",
1760 m.getVndkExtendsModuleName())
1761 return
1762 }
1763 if m.VendorProperties.Vendor_available == nil {
1764 mctx.PropertyErrorf("vndk",
1765 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
1766 return
1767 }
1768 }
1769 } else {
1770 if vndkdep.isVndkSp() {
1771 mctx.PropertyErrorf("vndk",
1772 "must set `enabled: true` to set `support_system_process: true`")
1773 return
1774 }
1775 if vndkdep.isVndkExt() {
1776 mctx.PropertyErrorf("vndk",
1777 "must set `enabled: true` to set `extends: %q`",
1778 m.getVndkExtendsModuleName())
1779 return
1780 }
Justin Yun8effde42017-06-23 19:24:43 +09001781 }
1782 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001783
Jiyong Parkf9332f12018-02-01 00:54:12 +09001784 var coreVariantNeeded bool = false
1785 var vendorVariantNeeded bool = false
1786 var recoveryVariantNeeded bool = false
1787
Justin Yun71549282017-11-17 12:10:28 +09001788 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001789 // If the device isn't compiling against the VNDK, we always
1790 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001791 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001792 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1793 // LL-NDK stubs only exist in the vendor variant, since the
1794 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001795 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09001796 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1797 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09001798 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09001799 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09001800 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
1801 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001802 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08001803 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001804 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001805 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001806 coreVariantNeeded = true
1807 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08001808 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09001809 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09001810 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001811 } else {
1812 // This is either in /system (or similar: /data), or is a
1813 // modules built with the NDK. Modules built with the NDK
1814 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001815 coreVariantNeeded = true
1816 }
1817
1818 if Bool(m.Properties.Recovery_available) {
1819 recoveryVariantNeeded = true
1820 }
1821
1822 if m.ModuleBase.InstallInRecovery() {
1823 recoveryVariantNeeded = true
1824 coreVariantNeeded = false
1825 }
1826
Jiyong Park413cc742018-06-19 01:46:06 +09001827 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09001828 primaryArch := mctx.Config().DevicePrimaryArchType()
1829 moduleArch := m.Target().Arch.ArchType
1830 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09001831 recoveryVariantNeeded = false
1832 }
1833 }
1834
Jiyong Parkf9332f12018-02-01 00:54:12 +09001835 var variants []string
1836 if coreVariantNeeded {
1837 variants = append(variants, coreMode)
1838 }
1839 if vendorVariantNeeded {
1840 variants = append(variants, vendorMode)
1841 }
1842 if recoveryVariantNeeded {
1843 variants = append(variants, recoveryMode)
1844 }
1845 mod := mctx.CreateVariations(variants...)
1846 for i, v := range variants {
1847 if v == vendorMode {
1848 m := mod[i].(*Module)
1849 m.Properties.UseVndk = true
1850 squashVendorSrcs(m)
1851 } else if v == recoveryMode {
1852 m := mod[i].(*Module)
1853 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09001854 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001855 squashRecoverySrcs(m)
1856 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001857 }
1858}
1859
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001860func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08001861 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001862 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1863 }
Colin Cross6510f912017-11-29 00:27:14 -08001864 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001865}
1866
Colin Cross06a931b2015-10-28 17:23:31 -07001867var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07001868var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08001869var BoolPtr = proptools.BoolPtr
1870var String = proptools.String
1871var StringPtr = proptools.StringPtr