blob: 3aaaf39d96f822ebb75ff98c2f884e84b62ad48f [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
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080056 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
57 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
58
Colin Cross1e676be2016-10-12 14:38:15 -070059 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
60 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080061
Colin Cross6b753602018-06-21 13:03:07 -070062 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator)
Ivan Lozano30c5db22018-02-21 15:49:20 -080063
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +000064 ctx.BottomUp("coverage", coverageLinkingMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080065 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070066
67 ctx.TopDown("lto_deps", ltoDepsMutator)
68 ctx.BottomUp("lto", ltoMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070069 })
Colin Crossb98c8b02016-07-29 13:44:28 -070070
71 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070072}
73
Colin Crossca860ac2016-01-04 14:34:37 -080074type Deps struct {
75 SharedLibs, LateSharedLibs []string
76 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080077 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080078 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070079
Colin Cross5950f382016-12-13 12:50:57 -080080 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070081
Colin Cross81413472016-04-11 14:37:39 -070082 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070083
Dan Willemsenb40aab62016-04-20 14:21:14 -070084 GeneratedSources []string
85 GeneratedHeaders []string
86
Dan Willemsenb3454ab2016-09-28 17:34:58 -070087 ReexportGeneratedHeaders []string
88
Colin Cross97ba0732015-03-23 17:50:24 -070089 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -070090
91 // Used for host bionic
92 LinkerFlagsFile string
93 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -070094}
95
Colin Crossca860ac2016-01-04 14:34:37 -080096type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -070097 // Paths to .so files
98 SharedLibs, LateSharedLibs android.Paths
99 // Paths to the dependencies to use for .so files (.so.toc files)
100 SharedLibsDeps, LateSharedLibsDeps android.Paths
101 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700102 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700103
Colin Cross26c34ed2016-09-30 17:10:16 -0700104 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700105 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800106 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700107 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700108
Colin Cross26c34ed2016-09-30 17:10:16 -0700109 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700110 GeneratedSources android.Paths
111 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700112
Dan Willemsen76f08272016-07-09 00:14:08 -0700113 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700114 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700115
Colin Cross26c34ed2016-09-30 17:10:16 -0700116 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700117 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700118
119 // Path to the file container flags to use with the linker
120 LinkerFlagsFile android.OptionalPath
121
122 // Path to the dynamic linker binary
123 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700124}
125
Colin Crossca860ac2016-01-04 14:34:37 -0800126type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700127 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
128 ArFlags []string // Flags that apply to ar
129 AsFlags []string // Flags that apply to assembly source files
130 CFlags []string // Flags that apply to C and C++ source files
131 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
132 ConlyFlags []string // Flags that apply to C source files
133 CppFlags []string // Flags that apply to C++ source files
134 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
135 YaccFlags []string // Flags that apply to Yacc source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700136 aidlFlags []string // Flags that apply to aidl source files
137 rsFlags []string // Flags that apply to renderscript source files
138 LdFlags []string // Flags that apply to linker command lines
139 libFlags []string // Flags to add libraries early to the link order
140 TidyFlags []string // Flags that apply to clang-tidy
141 SAbiFlags []string // Flags that apply to header-abi-dumper
142 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700143
Colin Crossc3199482017-03-30 15:03:04 -0700144 // Global include flags that apply to C, C++, and assembly source files
145 // These must be after any module include flags, which will be in GlobalFlags.
146 SystemIncludeFlags []string
147
Colin Crossb98c8b02016-07-29 13:44:28 -0700148 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700149 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800150 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800151 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800152
153 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800154 DynamicLinker string
155
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700156 CFlagsDeps android.Paths // Files depended on by compiler flags
157 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800158
159 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800160
161 protoDeps android.Paths
162 protoFlags []string // Flags that apply to proto source files
163 protoOutTypeFlag string // The output type, --cpp_out for example
164 protoOutParams []string // Flags that modify the output of proto generated files
165 protoC bool // Whether to use C instead of C++
166 protoOptionsFile bool // Whether to look for a .options file next to the .proto
167 ProtoRoot bool
Colin Crossc472d572015-03-17 15:06:21 -0700168}
169
Colin Cross81413472016-04-11 14:37:39 -0700170type ObjectLinkerProperties struct {
171 // names of other cc_object modules to link into this module using partial linking
172 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700173
174 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800175 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700176}
177
Colin Crossca860ac2016-01-04 14:34:37 -0800178// Properties used to compile all C or C++ modules
179type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700180 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800181 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700182
183 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800184 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700185
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +0000186 AndroidMkSharedLibs []string `blueprint:"mutated"`
187 AndroidMkStaticLibs []string `blueprint:"mutated"`
188 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
189 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
190 HideFromMake bool `blueprint:"mutated"`
191 PreventInstall bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700192
193 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800194
195 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
196 // file
197 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900198
199 // Make this module available when building for recovery
200 Recovery_available *bool
201
202 InRecovery bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700203}
204
205type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900206 // whether this module should be allowed to be directly depended by other
207 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
208 // If set to true, two variants will be built separately, one like
209 // normal, and the other limited to the set of libraries and headers
210 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700211 //
212 // The vendor variant may be used with a different (newer) /system,
213 // so it shouldn't have any unversioned runtime dependencies, or
214 // make assumptions about the system that may not be true in the
215 // future.
216 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900217 // If set to false, this module becomes inaccessible from /vendor modules.
218 //
219 // Default value is true when vndk: {enabled: true} or vendor: true.
220 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700221 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
222 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900223
224 // whether this module is capable of being loaded with other instance
225 // (possibly an older version) of the same module in the same process.
226 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
227 // can be double loaded in a vendor process if the library is also a
228 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
229 // explicitly marked as `double_loadable: true` by the owner, or the dependency
230 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
231 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800232}
233
Colin Crossca860ac2016-01-04 14:34:37 -0800234type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800235 static() bool
236 staticBinary() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700237 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700238 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800239 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700240 useVndk() bool
Justin Yun8effde42017-06-23 19:24:43 +0900241 isVndk() bool
242 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800243 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900244 inRecovery() bool
Logan Chien2f2b8902018-07-10 15:01:19 +0800245 shouldCreateVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700246 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700247 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800248 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800249 isPgoCompile() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800250}
251
252type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700253 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800254 ModuleContextIntf
255}
256
257type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700258 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800259 ModuleContextIntf
260}
261
Colin Cross37047f12016-12-13 17:06:13 -0800262type DepsContext interface {
263 android.BottomUpMutatorContext
264 ModuleContextIntf
265}
266
Colin Crossca860ac2016-01-04 14:34:37 -0800267type feature interface {
268 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800269 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800270 flags(ctx ModuleContext, flags Flags) Flags
271 props() []interface{}
272}
273
274type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700275 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800276 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800277 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700278 compilerProps() []interface{}
279
Colin Cross76fada02016-07-27 10:31:13 -0700280 appendCflags([]string)
281 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700282 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800283}
284
285type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700286 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800287 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700288 linkerFlags(ctx ModuleContext, flags Flags) Flags
289 linkerProps() []interface{}
290
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700291 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700292 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800293}
294
295type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700296 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700297 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800298 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700299 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700300 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800301}
302
Colin Crossc99deeb2016-04-11 15:06:20 -0700303type dependencyTag struct {
304 blueprint.BaseDependencyTag
305 name string
306 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700307
308 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700309}
310
311var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700312 sharedDepTag = dependencyTag{name: "shared", library: true}
313 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
314 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
315 staticDepTag = dependencyTag{name: "static", library: true}
316 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
317 lateStaticDepTag = dependencyTag{name: "late static", library: true}
318 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800319 headerDepTag = dependencyTag{name: "header", library: true}
320 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700321 genSourceDepTag = dependencyTag{name: "gen source"}
322 genHeaderDepTag = dependencyTag{name: "gen header"}
323 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
324 objDepTag = dependencyTag{name: "obj"}
325 crtBeginDepTag = dependencyTag{name: "crtbegin"}
326 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700327 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
328 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700329 reuseObjTag = dependencyTag{name: "reuse objects"}
330 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
331 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800332 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800333 runtimeDepTag = dependencyTag{name: "runtime lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700334)
335
Colin Crossca860ac2016-01-04 14:34:37 -0800336// Module contains the properties and members used by all C/C++ module types, and implements
337// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
338// to construct the output file. Behavior can be customized with a Customizer interface
339type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700340 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700341 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900342 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700343
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700344 Properties BaseProperties
345 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700346
Colin Crossca860ac2016-01-04 14:34:37 -0800347 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700348 hod android.HostOrDeviceSupported
349 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700350
Colin Crossca860ac2016-01-04 14:34:37 -0800351 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700352 features []feature
353 compiler compiler
354 linker linker
355 installer installer
356 stl *stl
357 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800358 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800359 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900360 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700361 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700362 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800363 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800364
365 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700366
Colin Cross635c3b02016-05-18 15:37:25 -0700367 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800368
Colin Crossb98c8b02016-07-29 13:44:28 -0700369 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700370
371 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800372
373 // Flags used to compile this module
374 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700375
376 // 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 -0800377 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700378 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800379 depsInLinkOrder android.Paths
380
381 // only non-nil when this is a shared library that reuses the objects of a static library
382 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700383}
384
Jiyong Parkc20eee32018-09-05 22:36:17 +0900385func (c *Module) OutputFile() android.OptionalPath {
386 return c.outputFile
387}
388
Colin Cross36242852017-06-23 15:06:31 -0700389func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700390 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800391 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700392 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800393 }
394 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700395 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800396 }
397 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700398 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800399 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700400 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700401 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700402 }
Colin Cross16b23492016-01-06 14:41:07 -0800403 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700404 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800405 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800406 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700407 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800408 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800409 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700410 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800411 }
Justin Yun8effde42017-06-23 19:24:43 +0900412 if c.vndkdep != nil {
413 c.AddProperties(c.vndkdep.props()...)
414 }
Stephen Craneba090d12017-05-09 15:44:35 -0700415 if c.lto != nil {
416 c.AddProperties(c.lto.props()...)
417 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700418 if c.pgo != nil {
419 c.AddProperties(c.pgo.props()...)
420 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800421 if c.xom != nil {
422 c.AddProperties(c.xom.props()...)
423 }
Colin Crossca860ac2016-01-04 14:34:37 -0800424 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700425 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800426 }
Colin Crossc472d572015-03-17 15:06:21 -0700427
Colin Crossa9d8bee2018-10-02 13:59:46 -0700428 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
429 switch class {
430 case android.Device:
431 return ctx.Config().DevicePrefer32BitExecutables()
432 case android.HostCross:
433 // Windows builds always prefer 32-bit
434 return true
435 default:
436 return false
437 }
438 })
Colin Cross36242852017-06-23 15:06:31 -0700439 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700440
Colin Cross1f44a3a2017-07-07 14:33:33 -0700441 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700442
Jiyong Park9d452992018-10-03 00:38:19 +0900443 android.InitApexModule(c)
444
Colin Cross36242852017-06-23 15:06:31 -0700445 return c
Colin Crossc472d572015-03-17 15:06:21 -0700446}
447
Colin Crossb916a382016-07-29 17:28:03 -0700448// Returns true for dependency roots (binaries)
449// TODO(ccross): also handle dlopenable libraries
450func (c *Module) isDependencyRoot() bool {
451 if root, ok := c.linker.(interface {
452 isDependencyRoot() bool
453 }); ok {
454 return root.isDependencyRoot()
455 }
456 return false
457}
458
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700459func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700460 return c.Properties.UseVndk
461}
462
Justin Yun8effde42017-06-23 19:24:43 +0900463func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800464 if vndkdep := c.vndkdep; vndkdep != nil {
465 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900466 }
467 return false
468}
469
Yi Kong7e53c572018-02-14 18:16:12 +0800470func (c *Module) isPgoCompile() bool {
471 if pgo := c.pgo; pgo != nil {
472 return pgo.Properties.PgoCompile
473 }
474 return false
475}
476
Logan Chienf3511742017-10-31 18:04:35 +0800477func (c *Module) isVndkSp() bool {
478 if vndkdep := c.vndkdep; vndkdep != nil {
479 return vndkdep.isVndkSp()
480 }
481 return false
482}
483
484func (c *Module) isVndkExt() bool {
485 if vndkdep := c.vndkdep; vndkdep != nil {
486 return vndkdep.isVndkExt()
487 }
488 return false
489}
490
491func (c *Module) getVndkExtendsModuleName() string {
492 if vndkdep := c.vndkdep; vndkdep != nil {
493 return vndkdep.getVndkExtendsModuleName()
494 }
495 return ""
496}
497
Jiyong Park82e2bf32017-08-16 14:05:54 +0900498// Returns true only when this module is configured to have core and vendor
499// variants.
500func (c *Module) hasVendorVariant() bool {
501 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
502}
503
Jiyong Parkf9332f12018-02-01 00:54:12 +0900504func (c *Module) inRecovery() bool {
505 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
506}
507
508func (c *Module) onlyInRecovery() bool {
509 return c.ModuleBase.InstallInRecovery()
510}
511
Colin Crossca860ac2016-01-04 14:34:37 -0800512type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700513 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800514 moduleContextImpl
515}
516
Colin Cross37047f12016-12-13 17:06:13 -0800517type depsContext struct {
518 android.BottomUpMutatorContext
519 moduleContextImpl
520}
521
Colin Crossca860ac2016-01-04 14:34:37 -0800522type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700523 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800524 moduleContextImpl
525}
526
Jiyong Park2db76922017-11-08 16:03:48 +0900527func (ctx *moduleContext) SocSpecific() bool {
528 return ctx.ModuleContext.SocSpecific() ||
529 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700530}
531
Colin Crossca860ac2016-01-04 14:34:37 -0800532type moduleContextImpl struct {
533 mod *Module
534 ctx BaseModuleContext
535}
536
Colin Crossb98c8b02016-07-29 13:44:28 -0700537func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800538 return ctx.mod.toolchain(ctx.ctx)
539}
540
541func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000542 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800543}
544
545func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700546 if static, ok := ctx.mod.linker.(interface {
547 staticBinary() bool
548 }); ok {
549 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800550 }
Colin Crossb916a382016-07-29 17:28:03 -0700551 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800552}
553
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700554func (ctx *moduleContextImpl) useSdk() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900555 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() {
Nan Zhang0007d812017-11-07 10:57:05 -0800556 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700557 }
558 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800559}
560
561func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700562 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700563 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900564 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700565 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900566 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
567 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
568 return "current"
569 }
570 return platform_vndk_ver
571 }
572 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800573 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900574 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700575 }
576 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800577}
578
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700579func (ctx *moduleContextImpl) useVndk() bool {
580 return ctx.mod.useVndk()
581}
Justin Yun8effde42017-06-23 19:24:43 +0900582
Logan Chienf3511742017-10-31 18:04:35 +0800583func (ctx *moduleContextImpl) isVndk() bool {
584 return ctx.mod.isVndk()
585}
586
Yi Kong7e53c572018-02-14 18:16:12 +0800587func (ctx *moduleContextImpl) isPgoCompile() bool {
588 return ctx.mod.isPgoCompile()
589}
590
Justin Yun8effde42017-06-23 19:24:43 +0900591func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800592 return ctx.mod.isVndkSp()
593}
594
595func (ctx *moduleContextImpl) isVndkExt() bool {
596 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900597}
598
Jiyong Parkf9332f12018-02-01 00:54:12 +0900599func (ctx *moduleContextImpl) inRecovery() bool {
600 return ctx.mod.inRecovery()
601}
602
Logan Chien2f2b8902018-07-10 15:01:19 +0800603// Check whether ABI dumps should be created for this module.
604func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump() bool {
605 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
606 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800607 }
Logan Chien2f2b8902018-07-10 15:01:19 +0800608 if sanitize := ctx.mod.sanitize; sanitize != nil {
609 if !sanitize.isVariantOnProductionDevice() {
610 return false
611 }
612 }
613 if !ctx.ctx.Device() {
614 // Host modules do not need ABI dumps.
615 return false
616 }
617 if inList(ctx.baseModuleName(), llndkLibraries) {
618 return true
619 }
Logan Chienf4b79c62018-08-02 02:27:02 +0800620 if inList(ctx.baseModuleName(), ndkMigratedLibs) {
621 return true
622 }
Logan Chien2f2b8902018-07-10 15:01:19 +0800623 if ctx.useVndk() && ctx.isVndk() {
624 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
625 // VNDK-private.
626 return Bool(ctx.mod.VendorProperties.Vendor_available) || ctx.isVndkExt()
627 }
628 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800629}
630
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700631func (ctx *moduleContextImpl) selectedStl() string {
632 if stl := ctx.mod.stl; stl != nil {
633 return stl.Properties.SelectedStl
634 }
635 return ""
636}
637
Colin Crossce75d2c2016-10-06 16:12:58 -0700638func (ctx *moduleContextImpl) baseModuleName() string {
639 return ctx.mod.ModuleBase.BaseModuleName()
640}
641
Logan Chienf3511742017-10-31 18:04:35 +0800642func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
643 return ctx.mod.getVndkExtendsModuleName()
644}
645
Colin Cross635c3b02016-05-18 15:37:25 -0700646func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800647 return &Module{
648 hod: hod,
649 multilib: multilib,
650 }
651}
652
Colin Cross635c3b02016-05-18 15:37:25 -0700653func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800654 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700655 module.features = []feature{
656 &tidyFeature{},
657 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700658 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800659 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800660 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800661 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900662 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700663 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700664 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800665 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800666 return module
667}
668
Colin Crossce75d2c2016-10-06 16:12:58 -0700669func (c *Module) Prebuilt() *android.Prebuilt {
670 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
671 return p.prebuilt()
672 }
673 return nil
674}
675
676func (c *Module) Name() string {
677 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700678 if p, ok := c.linker.(interface {
679 Name(string) string
680 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700681 name = p.Name(name)
682 }
683 return name
684}
685
Jeff Gaston294356f2017-09-27 17:05:30 -0700686// orderDeps reorders dependencies into a list such that if module A depends on B, then
687// A will precede B in the resultant list.
688// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800689// Note that directSharedDeps should be the analogous static library for each shared lib dep
690func 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 -0700691 // If A depends on B, then
692 // Every list containing A will also contain B later in the list
693 // So, after concatenating all lists, the final instance of B will have come from the same
694 // original list as the final instance of A
695 // So, the final instance of B will be later in the concatenation than the final A
696 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
697 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800698 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700699 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800700 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
701 }
702 for _, dep := range directSharedDeps {
703 orderedAllDeps = append(orderedAllDeps, dep)
704 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700705 }
706
Colin Crossb6715442017-10-24 11:13:31 -0700707 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700708
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800709 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700710 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800711 // resultant list to only what the caller has chosen to include in directStaticDeps
712 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700713
714 return orderedAllDeps, orderedDeclaredDeps
715}
716
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800717func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
718 // convert Module to Path
719 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
720 staticDepFiles := []android.Path{}
721 for _, dep := range staticDeps {
722 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
723 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700724 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800725 sharedDepFiles := []android.Path{}
726 for _, sharedDep := range sharedDeps {
727 staticAnalogue := sharedDep.staticVariant
728 if staticAnalogue != nil {
729 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
730 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
731 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700732 }
733
734 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800735 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700736
737 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700738}
739
Colin Cross635c3b02016-05-18 15:37:25 -0700740func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800741 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700742 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800743 moduleContextImpl: moduleContextImpl{
744 mod: c,
745 },
746 }
747 ctx.ctx = ctx
748
Colin Crossf18e1102017-11-16 14:33:08 -0800749 deps := c.depsToPaths(ctx)
750 if ctx.Failed() {
751 return
752 }
753
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700754 if c.Properties.Clang != nil && *c.Properties.Clang == false {
755 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
756 }
757
Colin Crossca860ac2016-01-04 14:34:37 -0800758 flags := Flags{
759 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800760 }
Colin Crossca860ac2016-01-04 14:34:37 -0800761 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800762 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800763 }
764 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700765 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800766 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700767 if c.stl != nil {
768 flags = c.stl.flags(ctx, flags)
769 }
Colin Cross16b23492016-01-06 14:41:07 -0800770 if c.sanitize != nil {
771 flags = c.sanitize.flags(ctx, flags)
772 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800773 if c.coverage != nil {
774 flags = c.coverage.flags(ctx, flags)
775 }
Stephen Craneba090d12017-05-09 15:44:35 -0700776 if c.lto != nil {
777 flags = c.lto.flags(ctx, flags)
778 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700779 if c.pgo != nil {
780 flags = c.pgo.flags(ctx, flags)
781 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800782 if c.xom != nil {
783 flags = c.xom.flags(ctx, flags)
784 }
Colin Crossca860ac2016-01-04 14:34:37 -0800785 for _, feature := range c.features {
786 flags = feature.flags(ctx, flags)
787 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800788 if ctx.Failed() {
789 return
790 }
791
Colin Crossb98c8b02016-07-29 13:44:28 -0700792 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
793 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
794 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800795
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800796 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
797 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700798 // We need access to all the flags seen by a source file.
799 if c.sabi != nil {
800 flags = c.sabi.flags(ctx, flags)
801 }
Colin Crossca860ac2016-01-04 14:34:37 -0800802 // Optimization to reduce size of build.ninja
803 // Replace the long list of flags for each file with a module-local variable
804 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
805 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
806 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
807 flags.CFlags = []string{"$cflags"}
808 flags.CppFlags = []string{"$cppflags"}
809 flags.AsFlags = []string{"$asflags"}
810
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700811 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800812 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700813 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800814 if ctx.Failed() {
815 return
816 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800817 }
818
Colin Crossca860ac2016-01-04 14:34:37 -0800819 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700820 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800821 if ctx.Failed() {
822 return
823 }
Colin Cross635c3b02016-05-18 15:37:25 -0700824 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700825 }
Colin Cross5049f022015-03-18 13:28:46 -0700826
Jiyong Park9d452992018-10-03 00:38:19 +0900827 if c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() {
Colin Crossce75d2c2016-10-06 16:12:58 -0700828 c.installer.install(ctx, c.outputFile.Path())
829 if ctx.Failed() {
830 return
Colin Crossca860ac2016-01-04 14:34:37 -0800831 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700832 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800833}
834
Colin Crossb98c8b02016-07-29 13:44:28 -0700835func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800836 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700837 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800838 }
Colin Crossca860ac2016-01-04 14:34:37 -0800839 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800840}
841
Colin Crossca860ac2016-01-04 14:34:37 -0800842func (c *Module) begin(ctx BaseModuleContext) {
843 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700844 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700845 }
Colin Crossca860ac2016-01-04 14:34:37 -0800846 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700847 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800848 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700849 if c.stl != nil {
850 c.stl.begin(ctx)
851 }
Colin Cross16b23492016-01-06 14:41:07 -0800852 if c.sanitize != nil {
853 c.sanitize.begin(ctx)
854 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800855 if c.coverage != nil {
856 c.coverage.begin(ctx)
857 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800858 if c.sabi != nil {
859 c.sabi.begin(ctx)
860 }
Justin Yun8effde42017-06-23 19:24:43 +0900861 if c.vndkdep != nil {
862 c.vndkdep.begin(ctx)
863 }
Stephen Craneba090d12017-05-09 15:44:35 -0700864 if c.lto != nil {
865 c.lto.begin(ctx)
866 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700867 if c.pgo != nil {
868 c.pgo.begin(ctx)
869 }
Colin Crossca860ac2016-01-04 14:34:37 -0800870 for _, feature := range c.features {
871 feature.begin(ctx)
872 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700873 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700874 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700875 if err != nil {
876 ctx.PropertyErrorf("sdk_version", err.Error())
877 }
Nan Zhang0007d812017-11-07 10:57:05 -0800878 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700879 }
Colin Crossca860ac2016-01-04 14:34:37 -0800880}
881
Colin Cross37047f12016-12-13 17:06:13 -0800882func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700883 deps := Deps{}
884
885 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700886 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700887 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +0000888 // Add the PGO dependency (the clang_rt.profile runtime library), which
889 // sometimes depends on symbols from libgcc, before libgcc gets added
890 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700891 if c.pgo != nil {
892 deps = c.pgo.deps(ctx, deps)
893 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700894 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700895 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700896 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700897 if c.stl != nil {
898 deps = c.stl.deps(ctx, deps)
899 }
Colin Cross16b23492016-01-06 14:41:07 -0800900 if c.sanitize != nil {
901 deps = c.sanitize.deps(ctx, deps)
902 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +0000903 if c.coverage != nil {
904 deps = c.coverage.deps(ctx, deps)
905 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800906 if c.sabi != nil {
907 deps = c.sabi.deps(ctx, deps)
908 }
Justin Yun8effde42017-06-23 19:24:43 +0900909 if c.vndkdep != nil {
910 deps = c.vndkdep.deps(ctx, deps)
911 }
Stephen Craneba090d12017-05-09 15:44:35 -0700912 if c.lto != nil {
913 deps = c.lto.deps(ctx, deps)
914 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700915 for _, feature := range c.features {
916 deps = feature.deps(ctx, deps)
917 }
918
Colin Crossb6715442017-10-24 11:13:31 -0700919 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
920 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
921 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
922 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
923 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
924 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +0800925 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700926
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700927 for _, lib := range deps.ReexportSharedLibHeaders {
928 if !inList(lib, deps.SharedLibs) {
929 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
930 }
931 }
932
933 for _, lib := range deps.ReexportStaticLibHeaders {
934 if !inList(lib, deps.StaticLibs) {
935 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
936 }
937 }
938
Colin Cross5950f382016-12-13 12:50:57 -0800939 for _, lib := range deps.ReexportHeaderLibHeaders {
940 if !inList(lib, deps.HeaderLibs) {
941 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
942 }
943 }
944
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700945 for _, gen := range deps.ReexportGeneratedHeaders {
946 if !inList(gen, deps.GeneratedHeaders) {
947 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
948 }
949 }
950
Colin Crossc99deeb2016-04-11 15:06:20 -0700951 return deps
952}
953
Dan Albert7e9d2952016-08-04 13:02:36 -0700954func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800955 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700956 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800957 moduleContextImpl: moduleContextImpl{
958 mod: c,
959 },
960 }
961 ctx.ctx = ctx
962
Colin Crossca860ac2016-01-04 14:34:37 -0800963 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700964}
965
Jiyong Park7ed9de32018-10-15 22:25:07 +0900966// Split name#version into name and version
967func stubsLibNameAndVersion(name string) (string, string) {
968 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
969 version := name[sharp+1:]
970 libname := name[:sharp]
971 return libname, version
972 }
973 return name, ""
974}
975
Colin Cross1e676be2016-10-12 14:38:15 -0700976func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -0800977 ctx := &depsContext{
978 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700979 moduleContextImpl: moduleContextImpl{
980 mod: c,
981 },
982 }
983 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800984
Colin Crossc99deeb2016-04-11 15:06:20 -0700985 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800986
Dan Albert914449f2016-06-17 16:45:24 -0700987 variantNdkLibs := []string{}
988 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700989 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700990 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700991
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700992 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
993 // of names:
Dan Albert914449f2016-06-17 16:45:24 -0700994 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700995 // 1. Name of an NDK library that refers to a prebuilt module.
996 // For each of these, it adds the name of the prebuilt module (which will be in
997 // prebuilts/ndk) to the list of nonvariant libs.
998 // 2. Name of an NDK library that refers to an ndk_library module.
999 // For each of these, it adds the name of the ndk_library module to the list of
1000 // variant libs.
1001 // 3. Anything else (so anything that isn't an NDK library).
1002 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001003 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001004 // The caller can then know to add the variantLibs dependencies differently from the
1005 // nonvariantLibs
1006 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1007 variantLibs = []string{}
1008 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001009 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001010 // strip #version suffix out
1011 name, _ := stubsLibNameAndVersion(entry)
1012 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1013 if !inList(name, ndkMigratedLibs) {
1014 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001015 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001016 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001017 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001018 } else if ctx.useVndk() && inList(name, llndkLibraries) {
1019 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
1020 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, vendorPublicLibraries) {
1021 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001022 if actx.OtherModuleExists(vendorPublicLib) {
1023 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1024 } else {
1025 // This can happen if vendor_public_library module is defined in a
1026 // namespace that isn't visible to the current module. In that case,
1027 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001028 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001029 }
Dan Albert914449f2016-06-17 16:45:24 -07001030 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001031 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001032 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001033 }
1034 }
Dan Albert914449f2016-06-17 16:45:24 -07001035 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001036 }
1037
Dan Albert914449f2016-06-17 16:45:24 -07001038 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1039 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001040 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001041 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001042
Jiyong Park7ed9de32018-10-15 22:25:07 +09001043 if c.linker != nil {
1044 if library, ok := c.linker.(*libraryDecorator); ok {
1045 if library.buildStubs() {
1046 // Stubs lib does not have dependency to other libraries. Don't proceed.
1047 return
1048 }
1049 }
1050 }
1051
Colin Cross32ec36c2016-12-15 07:39:51 -08001052 for _, lib := range deps.HeaderLibs {
1053 depTag := headerDepTag
1054 if inList(lib, deps.ReexportHeaderLibHeaders) {
1055 depTag = headerExportDepTag
1056 }
1057 actx.AddVariationDependencies(nil, depTag, lib)
1058 }
Colin Cross5950f382016-12-13 12:50:57 -08001059
Dan Willemsen59339a22018-07-22 21:18:45 -07001060 actx.AddVariationDependencies([]blueprint.Variation{
1061 {Mutator: "link", Variation: "static"},
1062 }, wholeStaticDepTag, deps.WholeStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001063
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001064 for _, lib := range deps.StaticLibs {
1065 depTag := staticDepTag
1066 if inList(lib, deps.ReexportStaticLibHeaders) {
1067 depTag = staticExportDepTag
1068 }
Dan Willemsen59339a22018-07-22 21:18:45 -07001069 actx.AddVariationDependencies([]blueprint.Variation{
1070 {Mutator: "link", Variation: "static"},
1071 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001072 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001073
Dan Willemsen59339a22018-07-22 21:18:45 -07001074 actx.AddVariationDependencies([]blueprint.Variation{
1075 {Mutator: "link", Variation: "static"},
1076 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001077
Jiyong Park7ed9de32018-10-15 22:25:07 +09001078 // shared lib names without the #version suffix
1079 var sharedLibNames []string
1080
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001081 for _, lib := range deps.SharedLibs {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001082 name, version := stubsLibNameAndVersion(lib)
1083 sharedLibNames = append(sharedLibNames, name)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001084 depTag := sharedDepTag
1085 if inList(lib, deps.ReexportSharedLibHeaders) {
1086 depTag = sharedExportDepTag
1087 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001088 var variations []blueprint.Variation
1089 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
1090 if version != "" && ctx.Os() == android.Android && !ctx.useVndk() && !c.inRecovery() {
1091 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1092 }
1093 actx.AddVariationDependencies(variations, depTag, name)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001094 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001095
Jiyong Park7ed9de32018-10-15 22:25:07 +09001096 for _, lib := range deps.LateSharedLibs {
1097 name, version := stubsLibNameAndVersion(lib)
1098 if inList(name, sharedLibNames) {
1099 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1100 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1101 // linking against both the stubs lib and the non-stubs lib at the same time.
1102 continue
1103 }
1104 depTag := lateSharedDepTag
1105 var variations []blueprint.Variation
1106 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
1107 if version != "" && ctx.Os() == android.Android && !ctx.useVndk() && !c.inRecovery() {
1108 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1109 }
1110 actx.AddVariationDependencies(variations, depTag, name)
1111 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001112
Dan Willemsen59339a22018-07-22 21:18:45 -07001113 actx.AddVariationDependencies([]blueprint.Variation{
1114 {Mutator: "link", Variation: "shared"},
1115 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001116
Colin Cross68861832016-07-08 10:41:41 -07001117 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001118
1119 for _, gen := range deps.GeneratedHeaders {
1120 depTag := genHeaderDepTag
1121 if inList(gen, deps.ReexportGeneratedHeaders) {
1122 depTag = genHeaderExportDepTag
1123 }
1124 actx.AddDependency(c, depTag, gen)
1125 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001126
Colin Cross42d48b72018-08-29 14:10:52 -07001127 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001128
1129 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001130 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001131 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001132 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001133 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001134 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001135 if deps.LinkerFlagsFile != "" {
1136 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1137 }
1138 if deps.DynamicLinker != "" {
1139 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001140 }
Dan Albert914449f2016-06-17 16:45:24 -07001141
1142 version := ctx.sdkVersion()
1143 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001144 {Mutator: "ndk_api", Variation: version},
1145 {Mutator: "link", Variation: "shared"},
1146 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001147 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001148 {Mutator: "ndk_api", Variation: version},
1149 {Mutator: "link", Variation: "shared"},
1150 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001151
1152 if vndkdep := c.vndkdep; vndkdep != nil {
1153 if vndkdep.isVndkExt() {
1154 baseModuleMode := vendorMode
1155 if actx.DeviceConfig().VndkVersion() == "" {
1156 baseModuleMode = coreMode
1157 }
1158 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001159 {Mutator: "image", Variation: baseModuleMode},
1160 {Mutator: "link", Variation: "shared"},
1161 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001162 }
1163 }
Colin Cross6362e272015-10-29 15:25:03 -07001164}
Colin Cross21b9a242015-03-24 14:15:58 -07001165
Colin Crosse40b4ea2018-10-02 22:25:58 -07001166func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001167 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1168 c.beginMutator(ctx)
1169 }
1170}
1171
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001172// Whether a module can link to another module, taking into
1173// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001174func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001175 if from.Target().Os != android.Android {
1176 // Host code is not restricted
1177 return
1178 }
1179 if from.Properties.UseVndk {
1180 // Though vendor code is limited by the vendor mutator,
1181 // each vendor-available module needs to check
1182 // link-type for VNDK.
1183 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001184 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001185 }
1186 return
1187 }
Nan Zhang0007d812017-11-07 10:57:05 -08001188 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001189 // Platform code can link to anything
1190 return
1191 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001192 if from.inRecovery() {
1193 // Recovery code is not NDK
1194 return
1195 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001196 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1197 // These are always allowed
1198 return
1199 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001200 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1201 // These are allowed, but they don't set sdk_version
1202 return
1203 }
1204 if _, ok := to.linker.(*stubDecorator); ok {
1205 // These aren't real libraries, but are the stub shared libraries that are included in
1206 // the NDK.
1207 return
1208 }
Nan Zhang0007d812017-11-07 10:57:05 -08001209 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001210 // NDK code linking to platform code is never okay.
1211 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1212 ctx.OtherModuleName(to))
1213 }
1214
1215 // At this point we know we have two NDK libraries, but we need to
1216 // check that we're not linking against anything built against a higher
1217 // API level, as it is only valid to link against older or equivalent
1218 // APIs.
1219
Inseob Kim01a28722018-04-11 09:48:45 +09001220 // Current can link against anything.
1221 if String(from.Properties.Sdk_version) != "current" {
1222 // Otherwise we need to check.
1223 if String(to.Properties.Sdk_version) == "current" {
1224 // Current can't be linked against by anything else.
1225 ctx.ModuleErrorf("links %q built against newer API version %q",
1226 ctx.OtherModuleName(to), "current")
1227 } else {
1228 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1229 if err != nil {
1230 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001231 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001232 String(from.Properties.Sdk_version))
1233 }
1234 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1235 if err != nil {
1236 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001237 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001238 String(to.Properties.Sdk_version))
1239 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001240
Inseob Kim01a28722018-04-11 09:48:45 +09001241 if toApi > fromApi {
1242 ctx.ModuleErrorf("links %q built against newer API version %q",
1243 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1244 }
1245 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001246 }
Dan Albert202fe492017-12-15 13:56:59 -08001247
1248 // Also check that the two STL choices are compatible.
1249 fromStl := from.stl.Properties.SelectedStl
1250 toStl := to.stl.Properties.SelectedStl
1251 if fromStl == "" || toStl == "" {
1252 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001253 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001254 // We can be permissive with the system "STL" since it is only the C++
1255 // ABI layer, but in the future we should make sure that everyone is
1256 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001257 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001258 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1259 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1260 to.stl.Properties.SelectedStl)
1261 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001262}
1263
Jiyong Park5fb8c102018-04-09 12:03:06 +09001264// Tests whether the dependent library is okay to be double loaded inside a single process.
1265// If a library is a member of VNDK and at the same time dependencies of an LLNDK library,
1266// it is subject to be double loaded. Such lib should be explicitly marked as double_loaded: true
1267// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
1268func checkDoubleLoadableLibries(ctx android.ModuleContext, from *Module, to *Module) {
1269 if _, ok := from.linker.(*libraryDecorator); !ok {
1270 return
1271 }
1272
1273 if inList(ctx.ModuleName(), llndkLibraries) ||
1274 (from.useVndk() && Bool(from.VendorProperties.Double_loadable)) {
1275 _, depIsLlndk := to.linker.(*llndkStubDecorator)
1276 depIsVndkSp := false
1277 if to.vndkdep != nil && to.vndkdep.isVndkSp() {
1278 depIsVndkSp = true
1279 }
1280 depIsVndk := false
1281 if to.vndkdep != nil && to.vndkdep.isVndk() {
1282 depIsVndk = true
1283 }
1284 depIsDoubleLoadable := Bool(to.VendorProperties.Double_loadable)
1285 if !depIsLlndk && !depIsVndkSp && !depIsDoubleLoadable && depIsVndk {
1286 ctx.ModuleErrorf("links VNDK library %q that isn't double_loadable.",
1287 ctx.OtherModuleName(to))
1288 }
1289 }
1290}
1291
Colin Crossc99deeb2016-04-11 15:06:20 -07001292// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001293func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001294 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001295
Jeff Gaston294356f2017-09-27 17:05:30 -07001296 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001297 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001298
Colin Crossd11fcda2017-10-23 17:59:01 -07001299 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001300 depName := ctx.OtherModuleName(dep)
1301 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001302
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001303 ccDep, _ := dep.(*Module)
1304 if ccDep == nil {
1305 // handling for a few module types that aren't cc Module but that are also supported
1306 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001307 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001308 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001309 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1310 genRule.GeneratedSourceFiles()...)
1311 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001312 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001313 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001314 // Support exported headers from a generated_sources dependency
1315 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001316 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001317 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001318 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001319 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001320 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001321 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001322 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001323 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001324 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001325 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001326 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1327 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1328
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001329 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001330 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001331 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001332 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001333 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001334 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001335 files := genRule.GeneratedSourceFiles()
1336 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001337 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001338 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001339 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 -07001340 }
1341 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001342 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001343 }
Colin Crossca860ac2016-01-04 14:34:37 -08001344 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001345 return
1346 }
1347
Colin Crossd11fcda2017-10-23 17:59:01 -07001348 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001349 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1350 return
1351 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001352 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001353 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001354 return
1355 }
1356
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001357 // re-exporting flags
1358 if depTag == reuseObjTag {
1359 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001360 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001361 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001362 depPaths.Objs = depPaths.Objs.Append(objs)
1363 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001364 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001365 return
1366 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001367 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001368 if t, ok := depTag.(dependencyTag); ok && t.library {
1369 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001370 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001371 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001372 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001373 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001374
1375 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001376 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001377 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001378 // 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 -07001379 // Re-exported shared library headers must be included as well since they can help us with type information
1380 // about template instantiations (instantiated from their headers).
1381 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001382 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001383 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001384
Logan Chienf3511742017-10-31 18:04:35 +08001385 checkLinkType(ctx, c, ccDep, t)
Jiyong Park5fb8c102018-04-09 12:03:06 +09001386 checkDoubleLoadableLibries(ctx, c, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001387 }
1388
Colin Cross26c34ed2016-09-30 17:10:16 -07001389 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001390 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001391
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001392 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001393 depFile := android.OptionalPath{}
1394
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001395 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001396 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001397 ptr = &depPaths.SharedLibs
1398 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001399 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001400 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001401 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001402 ptr = &depPaths.LateSharedLibs
1403 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001404 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001405 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001406 ptr = nil
1407 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001408 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001409 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001410 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001411 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001412 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001413 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001414 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001415 return
1416 }
1417
1418 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001419 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001420 for i := range missingDeps {
1421 missingDeps[i] += postfix
1422 }
1423 ctx.AddMissingDependencies(missingDeps)
1424 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001425 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001426 case headerDepTag:
1427 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001428 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001429 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001430 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001431 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001432 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001433 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001434 case dynamicLinkerDepTag:
1435 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001436 }
1437
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001438 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001439 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001440 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001441 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001442 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001443 return
1444 }
1445
1446 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001447 // in static libraries act as if they were whole static libraries. The same goes for
1448 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001449 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1450 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001451 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1452 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001453
Dan Willemsen581341d2017-02-09 16:16:31 -08001454 }
1455
Colin Cross26c34ed2016-09-30 17:10:16 -07001456 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001457 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001458 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001459 return
1460 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001461 *ptr = append(*ptr, linkFile.Path())
1462 }
1463
Colin Crossc99deeb2016-04-11 15:06:20 -07001464 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001465 dep := depFile
1466 if !dep.Valid() {
1467 dep = linkFile
1468 }
1469 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001470 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001471
Logan Chien43d34c32017-12-20 01:17:32 +08001472 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001473 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001474 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001475 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001476 isLLndk := inList(libName, llndkLibraries)
Jiyong Park374510b2018-03-19 18:23:01 +09001477 isVendorPublicLib := inList(libName, vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001478 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1479 if c.useVndk() && bothVendorAndCoreVariantsExist {
1480 // The vendor module in Make will have been renamed to not conflict with the core
1481 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001482 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001483 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001484 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001485 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1486 return libName + recoverySuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001487 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001488 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001489 }
Logan Chien43d34c32017-12-20 01:17:32 +08001490 }
1491
1492 // Export the shared libs to Make.
1493 switch depTag {
1494 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jiyong Park27b188b2017-07-18 13:23:39 +09001495 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001496 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001497 c.Properties.AndroidMkSharedLibs = append(
1498 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001499 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1500 c.Properties.AndroidMkStaticLibs = append(
1501 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001502 case runtimeDepTag:
1503 c.Properties.AndroidMkRuntimeLibs = append(
1504 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001505 case wholeStaticDepTag:
1506 c.Properties.AndroidMkWholeStaticLibs = append(
1507 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001508 }
Colin Crossca860ac2016-01-04 14:34:37 -08001509 })
1510
Jeff Gaston294356f2017-09-27 17:05:30 -07001511 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001512 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001513
Colin Crossdd84e052017-05-17 13:44:16 -07001514 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001515 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001516 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001517 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001518 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1519
1520 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001521 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001522 }
Colin Crossdd84e052017-05-17 13:44:16 -07001523
Colin Crossca860ac2016-01-04 14:34:37 -08001524 return depPaths
1525}
1526
1527func (c *Module) InstallInData() bool {
1528 if c.installer == nil {
1529 return false
1530 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001531 return c.installer.inData()
1532}
1533
1534func (c *Module) InstallInSanitizerDir() bool {
1535 if c.installer == nil {
1536 return false
1537 }
1538 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001539 return true
1540 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001541 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001542}
1543
Jiyong Parkf9332f12018-02-01 00:54:12 +09001544func (c *Module) InstallInRecovery() bool {
1545 return c.inRecovery()
1546}
1547
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001548func (c *Module) HostToolPath() android.OptionalPath {
1549 if c.installer == nil {
1550 return android.OptionalPath{}
1551 }
1552 return c.installer.hostToolPath()
1553}
1554
Nan Zhangd4e641b2017-07-12 12:55:28 -07001555func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1556 return c.outputFile
1557}
1558
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001559func (c *Module) Srcs() android.Paths {
1560 if c.outputFile.Valid() {
1561 return android.Paths{c.outputFile.Path()}
1562 }
1563 return android.Paths{}
1564}
1565
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001566func (c *Module) static() bool {
1567 if static, ok := c.linker.(interface {
1568 static() bool
1569 }); ok {
1570 return static.static()
1571 }
1572 return false
1573}
1574
Colin Crossb60190a2018-09-04 16:28:17 -07001575func (c *Module) getMakeLinkType() string {
1576 if c.useVndk() {
1577 if inList(c.Name(), vndkCoreLibraries) || inList(c.Name(), vndkSpLibraries) || inList(c.Name(), llndkLibraries) {
1578 if inList(c.Name(), vndkPrivateLibraries) {
1579 return "native:vndk_private"
1580 } else {
1581 return "native:vndk"
1582 }
1583 } else {
1584 return "native:vendor"
1585 }
1586 } else if c.inRecovery() {
1587 return "native:recovery"
1588 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
1589 return "native:ndk:none:none"
1590 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
1591 //family, link := getNdkStlFamilyAndLinkType(c)
1592 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
1593 } else {
1594 return "native:platform"
1595 }
1596}
1597
Jiyong Park9d452992018-10-03 00:38:19 +09001598// Overrides ApexModule.IsInstallabeToApex()
1599// Only shared libraries are installable to APEX.
1600func (c *Module) IsInstallableToApex() bool {
1601 if shared, ok := c.linker.(interface {
1602 shared() bool
1603 }); ok {
1604 return shared.shared()
1605 }
1606 return false
1607}
1608
Colin Cross2ba19d92015-05-07 15:44:20 -07001609//
Colin Crosscfad1192015-11-02 16:43:11 -08001610// Defaults
1611//
Colin Crossca860ac2016-01-04 14:34:37 -08001612type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001613 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001614 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09001615 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001616}
1617
Colin Cross635c3b02016-05-18 15:37:25 -07001618func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001619}
1620
Colin Cross1e676be2016-10-12 14:38:15 -07001621func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1622}
1623
Colin Cross36242852017-06-23 15:06:31 -07001624func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001625 return DefaultsFactory()
1626}
1627
Colin Cross36242852017-06-23 15:06:31 -07001628func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001629 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001630
Colin Cross36242852017-06-23 15:06:31 -07001631 module.AddProperties(props...)
1632 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001633 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001634 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001635 &BaseCompilerProperties{},
1636 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001637 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001638 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001639 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001640 &TestProperties{},
1641 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001642 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001643 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001644 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001645 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001646 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001647 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001648 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001649 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001650 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001651 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08001652 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001653 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001654 )
Colin Crosscfad1192015-11-02 16:43:11 -08001655
Colin Cross1f44a3a2017-07-07 14:33:33 -07001656 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09001657 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001658
1659 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001660}
1661
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001662const (
1663 // coreMode is the variant used for framework-private libraries, or
1664 // SDK libraries. (which framework-private libraries can use)
1665 coreMode = "core"
1666
1667 // vendorMode is the variant used for /vendor code that compiles
1668 // against the VNDK.
1669 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09001670
1671 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001672)
1673
Jiyong Park6a43f042017-10-12 23:05:00 +09001674func squashVendorSrcs(m *Module) {
1675 if lib, ok := m.compiler.(*libraryDecorator); ok {
1676 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1677 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1678
1679 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1680 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1681 }
1682}
1683
Jiyong Parkf9332f12018-02-01 00:54:12 +09001684func squashRecoverySrcs(m *Module) {
1685 if lib, ok := m.compiler.(*libraryDecorator); ok {
1686 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1687 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
1688
1689 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1690 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
1691 }
1692}
1693
1694func imageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001695 if mctx.Os() != android.Android {
1696 return
1697 }
1698
Jiyong Park7ed9de32018-10-15 22:25:07 +09001699 if g, ok := mctx.Module().(*genrule.Module); ok {
1700 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09001701 var coreVariantNeeded bool = false
1702 var vendorVariantNeeded bool = false
1703 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09001704 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09001705 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001706 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09001707 coreVariantNeeded = true
1708 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09001709 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09001710 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001711 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09001712 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001713 }
Jiyong Park3f736c92018-05-24 13:36:56 +09001714 if Bool(props.Recovery_available) {
1715 recoveryVariantNeeded = true
1716 }
1717
Jiyong Park413cc742018-06-19 01:46:06 +09001718 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09001719 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09001720 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09001721 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09001722 recoveryVariantNeeded = false
1723 }
1724 }
1725
Jiyong Park3f736c92018-05-24 13:36:56 +09001726 var variants []string
1727 if coreVariantNeeded {
1728 variants = append(variants, coreMode)
1729 }
1730 if vendorVariantNeeded {
1731 variants = append(variants, vendorMode)
1732 }
1733 if recoveryVariantNeeded {
1734 variants = append(variants, recoveryMode)
1735 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001736 mod := mctx.CreateVariations(variants...)
1737 for i, v := range variants {
1738 if v == recoveryMode {
1739 m := mod[i].(*genrule.Module)
1740 m.Extra.(*GenruleExtraProperties).InRecovery = true
1741 }
1742 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001743 }
1744 }
1745
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001746 m, ok := mctx.Module().(*Module)
1747 if !ok {
1748 return
1749 }
1750
1751 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08001752 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
1753
1754 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001755 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09001756 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001757 return
1758 }
Logan Chienf3511742017-10-31 18:04:35 +08001759
1760 if vndkdep := m.vndkdep; vndkdep != nil {
1761 if vndkdep.isVndk() {
1762 if vendorSpecific {
1763 if !vndkdep.isVndkExt() {
1764 mctx.PropertyErrorf("vndk",
1765 "must set `extends: \"...\"` to vndk extension")
1766 return
1767 }
1768 } else {
1769 if vndkdep.isVndkExt() {
1770 mctx.PropertyErrorf("vndk",
1771 "must set `vendor: true` to set `extends: %q`",
1772 m.getVndkExtendsModuleName())
1773 return
1774 }
1775 if m.VendorProperties.Vendor_available == nil {
1776 mctx.PropertyErrorf("vndk",
1777 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
1778 return
1779 }
1780 }
1781 } else {
1782 if vndkdep.isVndkSp() {
1783 mctx.PropertyErrorf("vndk",
1784 "must set `enabled: true` to set `support_system_process: true`")
1785 return
1786 }
1787 if vndkdep.isVndkExt() {
1788 mctx.PropertyErrorf("vndk",
1789 "must set `enabled: true` to set `extends: %q`",
1790 m.getVndkExtendsModuleName())
1791 return
1792 }
Justin Yun8effde42017-06-23 19:24:43 +09001793 }
1794 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001795
Jiyong Parkf9332f12018-02-01 00:54:12 +09001796 var coreVariantNeeded bool = false
1797 var vendorVariantNeeded bool = false
1798 var recoveryVariantNeeded bool = false
1799
Justin Yun71549282017-11-17 12:10:28 +09001800 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001801 // If the device isn't compiling against the VNDK, we always
1802 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001803 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001804 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1805 // LL-NDK stubs only exist in the vendor variant, since the
1806 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001807 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09001808 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1809 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09001810 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09001811 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09001812 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
1813 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001814 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08001815 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001816 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001817 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001818 coreVariantNeeded = true
1819 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08001820 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09001821 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09001822 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001823 } else {
1824 // This is either in /system (or similar: /data), or is a
1825 // modules built with the NDK. Modules built with the NDK
1826 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001827 coreVariantNeeded = true
1828 }
1829
1830 if Bool(m.Properties.Recovery_available) {
1831 recoveryVariantNeeded = true
1832 }
1833
1834 if m.ModuleBase.InstallInRecovery() {
1835 recoveryVariantNeeded = true
1836 coreVariantNeeded = false
1837 }
1838
Jiyong Park413cc742018-06-19 01:46:06 +09001839 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09001840 primaryArch := mctx.Config().DevicePrimaryArchType()
1841 moduleArch := m.Target().Arch.ArchType
1842 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09001843 recoveryVariantNeeded = false
1844 }
1845 }
1846
Jiyong Parkf9332f12018-02-01 00:54:12 +09001847 var variants []string
1848 if coreVariantNeeded {
1849 variants = append(variants, coreMode)
1850 }
1851 if vendorVariantNeeded {
1852 variants = append(variants, vendorMode)
1853 }
1854 if recoveryVariantNeeded {
1855 variants = append(variants, recoveryMode)
1856 }
1857 mod := mctx.CreateVariations(variants...)
1858 for i, v := range variants {
1859 if v == vendorMode {
1860 m := mod[i].(*Module)
1861 m.Properties.UseVndk = true
1862 squashVendorSrcs(m)
1863 } else if v == recoveryMode {
1864 m := mod[i].(*Module)
1865 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09001866 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001867 squashRecoverySrcs(m)
1868 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001869 }
1870}
1871
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001872func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08001873 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001874 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1875 }
Colin Cross6510f912017-11-29 00:27:14 -08001876 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001877}
1878
Colin Cross06a931b2015-10-28 17:23:31 -07001879var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07001880var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08001881var BoolPtr = proptools.BoolPtr
1882var String = proptools.String
1883var StringPtr = proptools.StringPtr