blob: 6320b9c36619d2b563cc243b956042b465bb0016 [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()
Colin Crosse40b4ea2018-10-02 22:25:58 -070042 ctx.BottomUp("begin", BeginMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070043 })
Colin Cross16b23492016-01-06 14:41:07 -080044
Colin Cross1e676be2016-10-12 14:38:15 -070045 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
46 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
47 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080048
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070049 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
50 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
51
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000052 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
53 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
54
Colin Cross1e676be2016-10-12 14:38:15 -070055 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
56 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080057
Colin Cross6b753602018-06-21 13:03:07 -070058 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator)
Ivan Lozano30c5db22018-02-21 15:49:20 -080059
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +000060 ctx.BottomUp("coverage", coverageLinkingMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080061 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070062
63 ctx.TopDown("lto_deps", ltoDepsMutator)
64 ctx.BottomUp("lto", ltoMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070065 })
Colin Crossb98c8b02016-07-29 13:44:28 -070066
67 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070068}
69
Colin Crossca860ac2016-01-04 14:34:37 -080070type Deps struct {
71 SharedLibs, LateSharedLibs []string
72 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080073 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080074 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070075
Colin Cross5950f382016-12-13 12:50:57 -080076 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070077
Colin Cross81413472016-04-11 14:37:39 -070078 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070079
Dan Willemsenb40aab62016-04-20 14:21:14 -070080 GeneratedSources []string
81 GeneratedHeaders []string
82
Dan Willemsenb3454ab2016-09-28 17:34:58 -070083 ReexportGeneratedHeaders []string
84
Colin Cross97ba0732015-03-23 17:50:24 -070085 CrtBegin, CrtEnd string
Dan Willemsenc77a0b32017-09-18 23:19:12 -070086 LinkerScript string
Colin Crossc472d572015-03-17 15:06:21 -070087}
88
Colin Crossca860ac2016-01-04 14:34:37 -080089type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -070090 // Paths to .so files
91 SharedLibs, LateSharedLibs android.Paths
92 // Paths to the dependencies to use for .so files (.so.toc files)
93 SharedLibsDeps, LateSharedLibsDeps android.Paths
94 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -070095 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -070096
Colin Cross26c34ed2016-09-30 17:10:16 -070097 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -070098 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -080099 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700100 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700101
Colin Cross26c34ed2016-09-30 17:10:16 -0700102 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700103 GeneratedSources android.Paths
104 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700105
Dan Willemsen76f08272016-07-09 00:14:08 -0700106 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700107 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700108
Colin Cross26c34ed2016-09-30 17:10:16 -0700109 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700110 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700111 LinkerScript android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700112}
113
Colin Crossca860ac2016-01-04 14:34:37 -0800114type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700115 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
116 ArFlags []string // Flags that apply to ar
117 AsFlags []string // Flags that apply to assembly source files
118 CFlags []string // Flags that apply to C and C++ source files
119 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
120 ConlyFlags []string // Flags that apply to C source files
121 CppFlags []string // Flags that apply to C++ source files
122 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
123 YaccFlags []string // Flags that apply to Yacc source files
124 protoFlags []string // Flags that apply to proto source files
Joe Onorato09e94ab2017-11-18 18:23:14 -0800125 protoOutParams []string // Flags that modify the output of proto generated files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700126 aidlFlags []string // Flags that apply to aidl source files
127 rsFlags []string // Flags that apply to renderscript source files
128 LdFlags []string // Flags that apply to linker command lines
129 libFlags []string // Flags to add libraries early to the link order
130 TidyFlags []string // Flags that apply to clang-tidy
131 SAbiFlags []string // Flags that apply to header-abi-dumper
132 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700133
Colin Crossc3199482017-03-30 15:03:04 -0700134 // Global include flags that apply to C, C++, and assembly source files
135 // These must be after any module include flags, which will be in GlobalFlags.
136 SystemIncludeFlags []string
137
Colin Crossb98c8b02016-07-29 13:44:28 -0700138 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700139 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800140 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800141 SAbiDump bool
Dan Willemsenab9f4262018-02-14 13:58:34 -0800142 ProtoRoot bool
Colin Crossca860ac2016-01-04 14:34:37 -0800143
144 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800145 DynamicLinker string
146
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700147 CFlagsDeps android.Paths // Files depended on by compiler flags
148 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800149
150 GroupStaticLibs bool
Zhizhou Yang51be6322018-02-08 18:32:11 -0800151 ArGoldPlugin bool // Whether LLVM gold plugin option is passed to llvm-ar
Colin Crossc472d572015-03-17 15:06:21 -0700152}
153
Colin Cross81413472016-04-11 14:37:39 -0700154type ObjectLinkerProperties struct {
155 // names of other cc_object modules to link into this module using partial linking
156 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700157
158 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800159 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700160}
161
Colin Crossca860ac2016-01-04 14:34:37 -0800162// Properties used to compile all C or C++ modules
163type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700164 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800165 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700166
167 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800168 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700169
Logan Chien43d34c32017-12-20 01:17:32 +0800170 AndroidMkSharedLibs []string `blueprint:"mutated"`
171 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
172 HideFromMake bool `blueprint:"mutated"`
173 PreventInstall bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700174
175 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800176
177 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
178 // file
179 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900180
181 // Make this module available when building for recovery
182 Recovery_available *bool
183
184 InRecovery bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700185}
186
187type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900188 // whether this module should be allowed to be directly depended by other
189 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
190 // If set to true, two variants will be built separately, one like
191 // normal, and the other limited to the set of libraries and headers
192 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700193 //
194 // The vendor variant may be used with a different (newer) /system,
195 // so it shouldn't have any unversioned runtime dependencies, or
196 // make assumptions about the system that may not be true in the
197 // future.
198 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900199 // If set to false, this module becomes inaccessible from /vendor modules.
200 //
201 // Default value is true when vndk: {enabled: true} or vendor: true.
202 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700203 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
204 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900205
206 // whether this module is capable of being loaded with other instance
207 // (possibly an older version) of the same module in the same process.
208 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
209 // can be double loaded in a vendor process if the library is also a
210 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
211 // explicitly marked as `double_loadable: true` by the owner, or the dependency
212 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
213 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800214}
215
Colin Crossca860ac2016-01-04 14:34:37 -0800216type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800217 static() bool
218 staticBinary() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700219 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700220 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800221 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700222 useVndk() bool
Justin Yun8effde42017-06-23 19:24:43 +0900223 isVndk() bool
224 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800225 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900226 inRecovery() bool
Logan Chien2f2b8902018-07-10 15:01:19 +0800227 shouldCreateVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700228 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700229 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800230 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800231 isPgoCompile() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800232}
233
234type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700235 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800236 ModuleContextIntf
237}
238
239type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700240 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800241 ModuleContextIntf
242}
243
Colin Cross37047f12016-12-13 17:06:13 -0800244type DepsContext interface {
245 android.BottomUpMutatorContext
246 ModuleContextIntf
247}
248
Colin Crossca860ac2016-01-04 14:34:37 -0800249type feature interface {
250 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800251 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800252 flags(ctx ModuleContext, flags Flags) Flags
253 props() []interface{}
254}
255
256type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700257 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800258 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800259 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700260 compilerProps() []interface{}
261
Colin Cross76fada02016-07-27 10:31:13 -0700262 appendCflags([]string)
263 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700264 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800265}
266
267type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700268 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800269 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700270 linkerFlags(ctx ModuleContext, flags Flags) Flags
271 linkerProps() []interface{}
272
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700273 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700274 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800275}
276
277type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700278 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700279 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800280 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700281 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700282 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800283}
284
Colin Crossc99deeb2016-04-11 15:06:20 -0700285type dependencyTag struct {
286 blueprint.BaseDependencyTag
287 name string
288 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700289
290 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700291}
292
293var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700294 sharedDepTag = dependencyTag{name: "shared", library: true}
295 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
296 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
297 staticDepTag = dependencyTag{name: "static", library: true}
298 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
299 lateStaticDepTag = dependencyTag{name: "late static", library: true}
300 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800301 headerDepTag = dependencyTag{name: "header", library: true}
302 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700303 genSourceDepTag = dependencyTag{name: "gen source"}
304 genHeaderDepTag = dependencyTag{name: "gen header"}
305 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
306 objDepTag = dependencyTag{name: "obj"}
307 crtBeginDepTag = dependencyTag{name: "crtbegin"}
308 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700309 linkerScriptDepTag = dependencyTag{name: "linker script"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700310 reuseObjTag = dependencyTag{name: "reuse objects"}
311 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
312 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800313 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800314 runtimeDepTag = dependencyTag{name: "runtime lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700315)
316
Colin Crossca860ac2016-01-04 14:34:37 -0800317// Module contains the properties and members used by all C/C++ module types, and implements
318// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
319// to construct the output file. Behavior can be customized with a Customizer interface
320type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700321 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700322 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900323 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700324
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700325 Properties BaseProperties
326 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700327
Colin Crossca860ac2016-01-04 14:34:37 -0800328 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700329 hod android.HostOrDeviceSupported
330 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700331
Colin Crossca860ac2016-01-04 14:34:37 -0800332 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700333 features []feature
334 compiler compiler
335 linker linker
336 installer installer
337 stl *stl
338 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800339 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800340 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900341 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700342 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700343 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800344
345 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700346
Colin Cross635c3b02016-05-18 15:37:25 -0700347 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800348
Colin Crossb98c8b02016-07-29 13:44:28 -0700349 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700350
351 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800352
353 // Flags used to compile this module
354 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700355
356 // 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 -0800357 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700358 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800359 depsInLinkOrder android.Paths
360
361 // only non-nil when this is a shared library that reuses the objects of a static library
362 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700363}
364
Jiyong Parkc20eee32018-09-05 22:36:17 +0900365func (c *Module) OutputFile() android.OptionalPath {
366 return c.outputFile
367}
368
Colin Cross36242852017-06-23 15:06:31 -0700369func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700370 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800371 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700372 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800373 }
374 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700375 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800376 }
377 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700378 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800379 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700380 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700381 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700382 }
Colin Cross16b23492016-01-06 14:41:07 -0800383 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700384 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800385 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800386 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700387 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800388 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800389 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700390 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800391 }
Justin Yun8effde42017-06-23 19:24:43 +0900392 if c.vndkdep != nil {
393 c.AddProperties(c.vndkdep.props()...)
394 }
Stephen Craneba090d12017-05-09 15:44:35 -0700395 if c.lto != nil {
396 c.AddProperties(c.lto.props()...)
397 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700398 if c.pgo != nil {
399 c.AddProperties(c.pgo.props()...)
400 }
Colin Crossca860ac2016-01-04 14:34:37 -0800401 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700402 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800403 }
Colin Crossc472d572015-03-17 15:06:21 -0700404
Colin Crossa9d8bee2018-10-02 13:59:46 -0700405 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
406 switch class {
407 case android.Device:
408 return ctx.Config().DevicePrefer32BitExecutables()
409 case android.HostCross:
410 // Windows builds always prefer 32-bit
411 return true
412 default:
413 return false
414 }
415 })
Colin Cross36242852017-06-23 15:06:31 -0700416 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700417
Colin Cross1f44a3a2017-07-07 14:33:33 -0700418 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700419
Jiyong Park9d452992018-10-03 00:38:19 +0900420 android.InitApexModule(c)
421
Colin Cross36242852017-06-23 15:06:31 -0700422 return c
Colin Crossc472d572015-03-17 15:06:21 -0700423}
424
Colin Crossb916a382016-07-29 17:28:03 -0700425// Returns true for dependency roots (binaries)
426// TODO(ccross): also handle dlopenable libraries
427func (c *Module) isDependencyRoot() bool {
428 if root, ok := c.linker.(interface {
429 isDependencyRoot() bool
430 }); ok {
431 return root.isDependencyRoot()
432 }
433 return false
434}
435
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700436func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700437 return c.Properties.UseVndk
438}
439
Justin Yun8effde42017-06-23 19:24:43 +0900440func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800441 if vndkdep := c.vndkdep; vndkdep != nil {
442 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900443 }
444 return false
445}
446
Yi Kong7e53c572018-02-14 18:16:12 +0800447func (c *Module) isPgoCompile() bool {
448 if pgo := c.pgo; pgo != nil {
449 return pgo.Properties.PgoCompile
450 }
451 return false
452}
453
Logan Chienf3511742017-10-31 18:04:35 +0800454func (c *Module) isVndkSp() bool {
455 if vndkdep := c.vndkdep; vndkdep != nil {
456 return vndkdep.isVndkSp()
457 }
458 return false
459}
460
461func (c *Module) isVndkExt() bool {
462 if vndkdep := c.vndkdep; vndkdep != nil {
463 return vndkdep.isVndkExt()
464 }
465 return false
466}
467
468func (c *Module) getVndkExtendsModuleName() string {
469 if vndkdep := c.vndkdep; vndkdep != nil {
470 return vndkdep.getVndkExtendsModuleName()
471 }
472 return ""
473}
474
Jiyong Park82e2bf32017-08-16 14:05:54 +0900475// Returns true only when this module is configured to have core and vendor
476// variants.
477func (c *Module) hasVendorVariant() bool {
478 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
479}
480
Jiyong Parkf9332f12018-02-01 00:54:12 +0900481func (c *Module) inRecovery() bool {
482 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
483}
484
485func (c *Module) onlyInRecovery() bool {
486 return c.ModuleBase.InstallInRecovery()
487}
488
Colin Crossca860ac2016-01-04 14:34:37 -0800489type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700490 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800491 moduleContextImpl
492}
493
Colin Cross37047f12016-12-13 17:06:13 -0800494type depsContext struct {
495 android.BottomUpMutatorContext
496 moduleContextImpl
497}
498
Colin Crossca860ac2016-01-04 14:34:37 -0800499type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700500 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800501 moduleContextImpl
502}
503
Jiyong Park2db76922017-11-08 16:03:48 +0900504func (ctx *moduleContext) SocSpecific() bool {
505 return ctx.ModuleContext.SocSpecific() ||
506 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700507}
508
Colin Crossca860ac2016-01-04 14:34:37 -0800509type moduleContextImpl struct {
510 mod *Module
511 ctx BaseModuleContext
512}
513
Colin Crossb98c8b02016-07-29 13:44:28 -0700514func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800515 return ctx.mod.toolchain(ctx.ctx)
516}
517
518func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000519 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800520}
521
522func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700523 if static, ok := ctx.mod.linker.(interface {
524 staticBinary() bool
525 }); ok {
526 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800527 }
Colin Crossb916a382016-07-29 17:28:03 -0700528 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800529}
530
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700531func (ctx *moduleContextImpl) useSdk() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900532 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() {
Nan Zhang0007d812017-11-07 10:57:05 -0800533 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700534 }
535 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800536}
537
538func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700539 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700540 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900541 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700542 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900543 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
544 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
545 return "current"
546 }
547 return platform_vndk_ver
548 }
549 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800550 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900551 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700552 }
553 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800554}
555
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700556func (ctx *moduleContextImpl) useVndk() bool {
557 return ctx.mod.useVndk()
558}
Justin Yun8effde42017-06-23 19:24:43 +0900559
Logan Chienf3511742017-10-31 18:04:35 +0800560func (ctx *moduleContextImpl) isVndk() bool {
561 return ctx.mod.isVndk()
562}
563
Yi Kong7e53c572018-02-14 18:16:12 +0800564func (ctx *moduleContextImpl) isPgoCompile() bool {
565 return ctx.mod.isPgoCompile()
566}
567
Justin Yun8effde42017-06-23 19:24:43 +0900568func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800569 return ctx.mod.isVndkSp()
570}
571
572func (ctx *moduleContextImpl) isVndkExt() bool {
573 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900574}
575
Jiyong Parkf9332f12018-02-01 00:54:12 +0900576func (ctx *moduleContextImpl) inRecovery() bool {
577 return ctx.mod.inRecovery()
578}
579
Logan Chien2f2b8902018-07-10 15:01:19 +0800580// Check whether ABI dumps should be created for this module.
581func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump() bool {
582 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
583 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800584 }
Logan Chien2f2b8902018-07-10 15:01:19 +0800585 if sanitize := ctx.mod.sanitize; sanitize != nil {
586 if !sanitize.isVariantOnProductionDevice() {
587 return false
588 }
589 }
590 if !ctx.ctx.Device() {
591 // Host modules do not need ABI dumps.
592 return false
593 }
594 if inList(ctx.baseModuleName(), llndkLibraries) {
595 return true
596 }
Logan Chienf4b79c62018-08-02 02:27:02 +0800597 if inList(ctx.baseModuleName(), ndkMigratedLibs) {
598 return true
599 }
Logan Chien2f2b8902018-07-10 15:01:19 +0800600 if ctx.useVndk() && ctx.isVndk() {
601 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
602 // VNDK-private.
603 return Bool(ctx.mod.VendorProperties.Vendor_available) || ctx.isVndkExt()
604 }
605 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800606}
607
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700608func (ctx *moduleContextImpl) selectedStl() string {
609 if stl := ctx.mod.stl; stl != nil {
610 return stl.Properties.SelectedStl
611 }
612 return ""
613}
614
Colin Crossce75d2c2016-10-06 16:12:58 -0700615func (ctx *moduleContextImpl) baseModuleName() string {
616 return ctx.mod.ModuleBase.BaseModuleName()
617}
618
Logan Chienf3511742017-10-31 18:04:35 +0800619func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
620 return ctx.mod.getVndkExtendsModuleName()
621}
622
Colin Cross635c3b02016-05-18 15:37:25 -0700623func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800624 return &Module{
625 hod: hod,
626 multilib: multilib,
627 }
628}
629
Colin Cross635c3b02016-05-18 15:37:25 -0700630func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800631 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700632 module.features = []feature{
633 &tidyFeature{},
634 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700635 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800636 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800637 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800638 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900639 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700640 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700641 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -0800642 return module
643}
644
Colin Crossce75d2c2016-10-06 16:12:58 -0700645func (c *Module) Prebuilt() *android.Prebuilt {
646 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
647 return p.prebuilt()
648 }
649 return nil
650}
651
652func (c *Module) Name() string {
653 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700654 if p, ok := c.linker.(interface {
655 Name(string) string
656 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700657 name = p.Name(name)
658 }
659 return name
660}
661
Jeff Gaston294356f2017-09-27 17:05:30 -0700662// orderDeps reorders dependencies into a list such that if module A depends on B, then
663// A will precede B in the resultant list.
664// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800665// Note that directSharedDeps should be the analogous static library for each shared lib dep
666func 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 -0700667 // If A depends on B, then
668 // Every list containing A will also contain B later in the list
669 // So, after concatenating all lists, the final instance of B will have come from the same
670 // original list as the final instance of A
671 // So, the final instance of B will be later in the concatenation than the final A
672 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
673 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800674 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700675 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800676 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
677 }
678 for _, dep := range directSharedDeps {
679 orderedAllDeps = append(orderedAllDeps, dep)
680 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700681 }
682
Colin Crossb6715442017-10-24 11:13:31 -0700683 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700684
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800685 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700686 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800687 // resultant list to only what the caller has chosen to include in directStaticDeps
688 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700689
690 return orderedAllDeps, orderedDeclaredDeps
691}
692
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800693func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
694 // convert Module to Path
695 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
696 staticDepFiles := []android.Path{}
697 for _, dep := range staticDeps {
698 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
699 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700700 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800701 sharedDepFiles := []android.Path{}
702 for _, sharedDep := range sharedDeps {
703 staticAnalogue := sharedDep.staticVariant
704 if staticAnalogue != nil {
705 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
706 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
707 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700708 }
709
710 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800711 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700712
713 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700714}
715
Colin Cross635c3b02016-05-18 15:37:25 -0700716func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800717 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700718 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800719 moduleContextImpl: moduleContextImpl{
720 mod: c,
721 },
722 }
723 ctx.ctx = ctx
724
Colin Crossf18e1102017-11-16 14:33:08 -0800725 deps := c.depsToPaths(ctx)
726 if ctx.Failed() {
727 return
728 }
729
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700730 if c.Properties.Clang != nil && *c.Properties.Clang == false {
731 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
732 }
733
Colin Crossca860ac2016-01-04 14:34:37 -0800734 flags := Flags{
735 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800736 }
Colin Crossca860ac2016-01-04 14:34:37 -0800737 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800738 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800739 }
740 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700741 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800742 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700743 if c.stl != nil {
744 flags = c.stl.flags(ctx, flags)
745 }
Colin Cross16b23492016-01-06 14:41:07 -0800746 if c.sanitize != nil {
747 flags = c.sanitize.flags(ctx, flags)
748 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800749 if c.coverage != nil {
750 flags = c.coverage.flags(ctx, flags)
751 }
Stephen Craneba090d12017-05-09 15:44:35 -0700752 if c.lto != nil {
753 flags = c.lto.flags(ctx, flags)
754 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700755 if c.pgo != nil {
756 flags = c.pgo.flags(ctx, flags)
757 }
Colin Crossca860ac2016-01-04 14:34:37 -0800758 for _, feature := range c.features {
759 flags = feature.flags(ctx, flags)
760 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800761 if ctx.Failed() {
762 return
763 }
764
Colin Crossb98c8b02016-07-29 13:44:28 -0700765 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
766 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
767 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800768
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800769 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
770 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700771 // We need access to all the flags seen by a source file.
772 if c.sabi != nil {
773 flags = c.sabi.flags(ctx, flags)
774 }
Colin Crossca860ac2016-01-04 14:34:37 -0800775 // Optimization to reduce size of build.ninja
776 // Replace the long list of flags for each file with a module-local variable
777 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
778 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
779 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
780 flags.CFlags = []string{"$cflags"}
781 flags.CppFlags = []string{"$cppflags"}
782 flags.AsFlags = []string{"$asflags"}
783
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700784 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800785 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700786 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800787 if ctx.Failed() {
788 return
789 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800790 }
791
Colin Crossca860ac2016-01-04 14:34:37 -0800792 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700793 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800794 if ctx.Failed() {
795 return
796 }
Colin Cross635c3b02016-05-18 15:37:25 -0700797 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700798 }
Colin Cross5049f022015-03-18 13:28:46 -0700799
Jiyong Park9d452992018-10-03 00:38:19 +0900800 if c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() {
Colin Crossce75d2c2016-10-06 16:12:58 -0700801 c.installer.install(ctx, c.outputFile.Path())
802 if ctx.Failed() {
803 return
Colin Crossca860ac2016-01-04 14:34:37 -0800804 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700805 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800806}
807
Colin Crossb98c8b02016-07-29 13:44:28 -0700808func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800809 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700810 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800811 }
Colin Crossca860ac2016-01-04 14:34:37 -0800812 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800813}
814
Colin Crossca860ac2016-01-04 14:34:37 -0800815func (c *Module) begin(ctx BaseModuleContext) {
816 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700817 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700818 }
Colin Crossca860ac2016-01-04 14:34:37 -0800819 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700820 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800821 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700822 if c.stl != nil {
823 c.stl.begin(ctx)
824 }
Colin Cross16b23492016-01-06 14:41:07 -0800825 if c.sanitize != nil {
826 c.sanitize.begin(ctx)
827 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800828 if c.coverage != nil {
829 c.coverage.begin(ctx)
830 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800831 if c.sabi != nil {
832 c.sabi.begin(ctx)
833 }
Justin Yun8effde42017-06-23 19:24:43 +0900834 if c.vndkdep != nil {
835 c.vndkdep.begin(ctx)
836 }
Stephen Craneba090d12017-05-09 15:44:35 -0700837 if c.lto != nil {
838 c.lto.begin(ctx)
839 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700840 if c.pgo != nil {
841 c.pgo.begin(ctx)
842 }
Colin Crossca860ac2016-01-04 14:34:37 -0800843 for _, feature := range c.features {
844 feature.begin(ctx)
845 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700846 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700847 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700848 if err != nil {
849 ctx.PropertyErrorf("sdk_version", err.Error())
850 }
Nan Zhang0007d812017-11-07 10:57:05 -0800851 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700852 }
Colin Crossca860ac2016-01-04 14:34:37 -0800853}
854
Colin Cross37047f12016-12-13 17:06:13 -0800855func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700856 deps := Deps{}
857
858 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700859 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700860 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +0000861 // Add the PGO dependency (the clang_rt.profile runtime library), which
862 // sometimes depends on symbols from libgcc, before libgcc gets added
863 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700864 if c.pgo != nil {
865 deps = c.pgo.deps(ctx, deps)
866 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700867 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700868 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700869 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700870 if c.stl != nil {
871 deps = c.stl.deps(ctx, deps)
872 }
Colin Cross16b23492016-01-06 14:41:07 -0800873 if c.sanitize != nil {
874 deps = c.sanitize.deps(ctx, deps)
875 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +0000876 if c.coverage != nil {
877 deps = c.coverage.deps(ctx, deps)
878 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800879 if c.sabi != nil {
880 deps = c.sabi.deps(ctx, deps)
881 }
Justin Yun8effde42017-06-23 19:24:43 +0900882 if c.vndkdep != nil {
883 deps = c.vndkdep.deps(ctx, deps)
884 }
Stephen Craneba090d12017-05-09 15:44:35 -0700885 if c.lto != nil {
886 deps = c.lto.deps(ctx, deps)
887 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700888 for _, feature := range c.features {
889 deps = feature.deps(ctx, deps)
890 }
891
Colin Crossb6715442017-10-24 11:13:31 -0700892 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
893 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
894 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
895 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
896 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
897 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +0800898 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700899
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700900 for _, lib := range deps.ReexportSharedLibHeaders {
901 if !inList(lib, deps.SharedLibs) {
902 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
903 }
904 }
905
906 for _, lib := range deps.ReexportStaticLibHeaders {
907 if !inList(lib, deps.StaticLibs) {
908 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
909 }
910 }
911
Colin Cross5950f382016-12-13 12:50:57 -0800912 for _, lib := range deps.ReexportHeaderLibHeaders {
913 if !inList(lib, deps.HeaderLibs) {
914 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
915 }
916 }
917
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700918 for _, gen := range deps.ReexportGeneratedHeaders {
919 if !inList(gen, deps.GeneratedHeaders) {
920 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
921 }
922 }
923
Colin Crossc99deeb2016-04-11 15:06:20 -0700924 return deps
925}
926
Dan Albert7e9d2952016-08-04 13:02:36 -0700927func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800928 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700929 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800930 moduleContextImpl: moduleContextImpl{
931 mod: c,
932 },
933 }
934 ctx.ctx = ctx
935
Colin Crossca860ac2016-01-04 14:34:37 -0800936 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700937}
938
Colin Cross1e676be2016-10-12 14:38:15 -0700939func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -0800940 ctx := &depsContext{
941 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700942 moduleContextImpl: moduleContextImpl{
943 mod: c,
944 },
945 }
946 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800947
Colin Crossc99deeb2016-04-11 15:06:20 -0700948 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800949
Dan Albert914449f2016-06-17 16:45:24 -0700950 variantNdkLibs := []string{}
951 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700952 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700953 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700954
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700955 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
956 // of names:
Dan Albert914449f2016-06-17 16:45:24 -0700957 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700958 // 1. Name of an NDK library that refers to a prebuilt module.
959 // For each of these, it adds the name of the prebuilt module (which will be in
960 // prebuilts/ndk) to the list of nonvariant libs.
961 // 2. Name of an NDK library that refers to an ndk_library module.
962 // For each of these, it adds the name of the ndk_library module to the list of
963 // variant libs.
964 // 3. Anything else (so anything that isn't an NDK library).
965 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -0700966 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700967 // The caller can then know to add the variantLibs dependencies differently from the
968 // nonvariantLibs
969 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
970 variantLibs = []string{}
971 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -0700972 for _, entry := range list {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700973 if ctx.useSdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700974 if !inList(entry, ndkMigratedLibs) {
975 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
976 } else {
977 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
978 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700979 } else if ctx.useVndk() && inList(entry, llndkLibraries) {
Dan Willemsenb916b802017-03-19 13:44:32 -0700980 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +0900981 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(entry, vendorPublicLibraries) {
982 vendorPublicLib := entry + vendorPublicLibrarySuffix
983 if actx.OtherModuleExists(vendorPublicLib) {
984 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
985 } else {
986 // This can happen if vendor_public_library module is defined in a
987 // namespace that isn't visible to the current module. In that case,
988 // link to the original library.
989 nonvariantLibs = append(nonvariantLibs, entry)
990 }
Dan Albert914449f2016-06-17 16:45:24 -0700991 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700992 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700993 }
994 }
Dan Albert914449f2016-06-17 16:45:24 -0700995 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700996 }
997
Dan Albert914449f2016-06-17 16:45:24 -0700998 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
999 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001000 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001001 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001002
Colin Cross32ec36c2016-12-15 07:39:51 -08001003 for _, lib := range deps.HeaderLibs {
1004 depTag := headerDepTag
1005 if inList(lib, deps.ReexportHeaderLibHeaders) {
1006 depTag = headerExportDepTag
1007 }
1008 actx.AddVariationDependencies(nil, depTag, lib)
1009 }
Colin Cross5950f382016-12-13 12:50:57 -08001010
Dan Willemsen59339a22018-07-22 21:18:45 -07001011 actx.AddVariationDependencies([]blueprint.Variation{
1012 {Mutator: "link", Variation: "static"},
1013 }, wholeStaticDepTag, deps.WholeStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001014
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001015 for _, lib := range deps.StaticLibs {
1016 depTag := staticDepTag
1017 if inList(lib, deps.ReexportStaticLibHeaders) {
1018 depTag = staticExportDepTag
1019 }
Dan Willemsen59339a22018-07-22 21:18:45 -07001020 actx.AddVariationDependencies([]blueprint.Variation{
1021 {Mutator: "link", Variation: "static"},
1022 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001023 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001024
Dan Willemsen59339a22018-07-22 21:18:45 -07001025 actx.AddVariationDependencies([]blueprint.Variation{
1026 {Mutator: "link", Variation: "static"},
1027 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001028
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001029 for _, lib := range deps.SharedLibs {
1030 depTag := sharedDepTag
1031 if inList(lib, deps.ReexportSharedLibHeaders) {
1032 depTag = sharedExportDepTag
1033 }
Dan Willemsen59339a22018-07-22 21:18:45 -07001034 actx.AddVariationDependencies([]blueprint.Variation{
1035 {Mutator: "link", Variation: "shared"},
1036 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001037 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001038
Dan Willemsen59339a22018-07-22 21:18:45 -07001039 actx.AddVariationDependencies([]blueprint.Variation{
1040 {Mutator: "link", Variation: "shared"},
1041 }, lateSharedDepTag, deps.LateSharedLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001042
Dan Willemsen59339a22018-07-22 21:18:45 -07001043 actx.AddVariationDependencies([]blueprint.Variation{
1044 {Mutator: "link", Variation: "shared"},
1045 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001046
Colin Cross68861832016-07-08 10:41:41 -07001047 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001048
1049 for _, gen := range deps.GeneratedHeaders {
1050 depTag := genHeaderDepTag
1051 if inList(gen, deps.ReexportGeneratedHeaders) {
1052 depTag = genHeaderExportDepTag
1053 }
1054 actx.AddDependency(c, depTag, gen)
1055 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001056
Colin Cross42d48b72018-08-29 14:10:52 -07001057 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001058
1059 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001060 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001061 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001062 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001063 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001064 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001065 if deps.LinkerScript != "" {
1066 actx.AddDependency(c, linkerScriptDepTag, deps.LinkerScript)
1067 }
Dan Albert914449f2016-06-17 16:45:24 -07001068
1069 version := ctx.sdkVersion()
1070 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001071 {Mutator: "ndk_api", Variation: version},
1072 {Mutator: "link", Variation: "shared"},
1073 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001074 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001075 {Mutator: "ndk_api", Variation: version},
1076 {Mutator: "link", Variation: "shared"},
1077 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001078
1079 if vndkdep := c.vndkdep; vndkdep != nil {
1080 if vndkdep.isVndkExt() {
1081 baseModuleMode := vendorMode
1082 if actx.DeviceConfig().VndkVersion() == "" {
1083 baseModuleMode = coreMode
1084 }
1085 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001086 {Mutator: "image", Variation: baseModuleMode},
1087 {Mutator: "link", Variation: "shared"},
1088 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001089 }
1090 }
Colin Cross6362e272015-10-29 15:25:03 -07001091}
Colin Cross21b9a242015-03-24 14:15:58 -07001092
Colin Crosse40b4ea2018-10-02 22:25:58 -07001093func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001094 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1095 c.beginMutator(ctx)
1096 }
1097}
1098
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001099// Whether a module can link to another module, taking into
1100// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001101func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001102 if from.Target().Os != android.Android {
1103 // Host code is not restricted
1104 return
1105 }
1106 if from.Properties.UseVndk {
1107 // Though vendor code is limited by the vendor mutator,
1108 // each vendor-available module needs to check
1109 // link-type for VNDK.
1110 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001111 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001112 }
1113 return
1114 }
Nan Zhang0007d812017-11-07 10:57:05 -08001115 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001116 // Platform code can link to anything
1117 return
1118 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001119 if from.inRecovery() {
1120 // Recovery code is not NDK
1121 return
1122 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001123 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1124 // These are always allowed
1125 return
1126 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001127 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1128 // These are allowed, but they don't set sdk_version
1129 return
1130 }
1131 if _, ok := to.linker.(*stubDecorator); ok {
1132 // These aren't real libraries, but are the stub shared libraries that are included in
1133 // the NDK.
1134 return
1135 }
Nan Zhang0007d812017-11-07 10:57:05 -08001136 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001137 // NDK code linking to platform code is never okay.
1138 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1139 ctx.OtherModuleName(to))
1140 }
1141
1142 // At this point we know we have two NDK libraries, but we need to
1143 // check that we're not linking against anything built against a higher
1144 // API level, as it is only valid to link against older or equivalent
1145 // APIs.
1146
Inseob Kim01a28722018-04-11 09:48:45 +09001147 // Current can link against anything.
1148 if String(from.Properties.Sdk_version) != "current" {
1149 // Otherwise we need to check.
1150 if String(to.Properties.Sdk_version) == "current" {
1151 // Current can't be linked against by anything else.
1152 ctx.ModuleErrorf("links %q built against newer API version %q",
1153 ctx.OtherModuleName(to), "current")
1154 } else {
1155 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1156 if err != nil {
1157 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001158 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001159 String(from.Properties.Sdk_version))
1160 }
1161 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1162 if err != nil {
1163 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001164 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001165 String(to.Properties.Sdk_version))
1166 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001167
Inseob Kim01a28722018-04-11 09:48:45 +09001168 if toApi > fromApi {
1169 ctx.ModuleErrorf("links %q built against newer API version %q",
1170 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1171 }
1172 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001173 }
Dan Albert202fe492017-12-15 13:56:59 -08001174
1175 // Also check that the two STL choices are compatible.
1176 fromStl := from.stl.Properties.SelectedStl
1177 toStl := to.stl.Properties.SelectedStl
1178 if fromStl == "" || toStl == "" {
1179 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001180 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001181 // We can be permissive with the system "STL" since it is only the C++
1182 // ABI layer, but in the future we should make sure that everyone is
1183 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001184 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001185 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1186 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1187 to.stl.Properties.SelectedStl)
1188 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001189}
1190
Jiyong Park5fb8c102018-04-09 12:03:06 +09001191// Tests whether the dependent library is okay to be double loaded inside a single process.
1192// If a library is a member of VNDK and at the same time dependencies of an LLNDK library,
1193// it is subject to be double loaded. Such lib should be explicitly marked as double_loaded: true
1194// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
1195func checkDoubleLoadableLibries(ctx android.ModuleContext, from *Module, to *Module) {
1196 if _, ok := from.linker.(*libraryDecorator); !ok {
1197 return
1198 }
1199
1200 if inList(ctx.ModuleName(), llndkLibraries) ||
1201 (from.useVndk() && Bool(from.VendorProperties.Double_loadable)) {
1202 _, depIsLlndk := to.linker.(*llndkStubDecorator)
1203 depIsVndkSp := false
1204 if to.vndkdep != nil && to.vndkdep.isVndkSp() {
1205 depIsVndkSp = true
1206 }
1207 depIsVndk := false
1208 if to.vndkdep != nil && to.vndkdep.isVndk() {
1209 depIsVndk = true
1210 }
1211 depIsDoubleLoadable := Bool(to.VendorProperties.Double_loadable)
1212 if !depIsLlndk && !depIsVndkSp && !depIsDoubleLoadable && depIsVndk {
1213 ctx.ModuleErrorf("links VNDK library %q that isn't double_loadable.",
1214 ctx.OtherModuleName(to))
1215 }
1216 }
1217}
1218
Colin Crossc99deeb2016-04-11 15:06:20 -07001219// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001220func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001221 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001222
Jeff Gaston294356f2017-09-27 17:05:30 -07001223 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001224 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001225
Colin Crossd11fcda2017-10-23 17:59:01 -07001226 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001227 depName := ctx.OtherModuleName(dep)
1228 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001229
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001230 ccDep, _ := dep.(*Module)
1231 if ccDep == nil {
1232 // handling for a few module types that aren't cc Module but that are also supported
1233 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001234 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001235 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001236 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1237 genRule.GeneratedSourceFiles()...)
1238 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001239 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001240 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001241 // Support exported headers from a generated_sources dependency
1242 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001243 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001244 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001245 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001246 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001247 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001248 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001249 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001250 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001251 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001252 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001253 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1254 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1255
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001256 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001257 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001258 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001259 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001260 case linkerScriptDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001261 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001262 files := genRule.GeneratedSourceFiles()
1263 if len(files) == 1 {
1264 depPaths.LinkerScript = android.OptionalPathForPath(files[0])
1265 } else if len(files) > 1 {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001266 ctx.ModuleErrorf("module %q can only generate a single file if used for a linker script", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001267 }
1268 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001269 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001270 }
Colin Crossca860ac2016-01-04 14:34:37 -08001271 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001272 return
1273 }
1274
Colin Crossd11fcda2017-10-23 17:59:01 -07001275 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001276 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1277 return
1278 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001279 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001280 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001281 return
1282 }
1283
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001284 // re-exporting flags
1285 if depTag == reuseObjTag {
1286 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001287 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001288 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001289 depPaths.Objs = depPaths.Objs.Append(objs)
1290 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001291 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001292 return
1293 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001294 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001295 if t, ok := depTag.(dependencyTag); ok && t.library {
1296 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001297 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001298 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001299 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001300 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001301
1302 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001303 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001304 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001305 // 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 -07001306 // Re-exported shared library headers must be included as well since they can help us with type information
1307 // about template instantiations (instantiated from their headers).
1308 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001309 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001310 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001311
Logan Chienf3511742017-10-31 18:04:35 +08001312 checkLinkType(ctx, c, ccDep, t)
Jiyong Park5fb8c102018-04-09 12:03:06 +09001313 checkDoubleLoadableLibries(ctx, c, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001314 }
1315
Colin Cross26c34ed2016-09-30 17:10:16 -07001316 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001317 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001318
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001319 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001320 depFile := android.OptionalPath{}
1321
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001322 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001323 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001324 ptr = &depPaths.SharedLibs
1325 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001326 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001327 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001328 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001329 ptr = &depPaths.LateSharedLibs
1330 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001331 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001332 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001333 ptr = nil
1334 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001335 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001336 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001337 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001338 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001339 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001340 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001341 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001342 return
1343 }
1344
1345 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001346 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001347 for i := range missingDeps {
1348 missingDeps[i] += postfix
1349 }
1350 ctx.AddMissingDependencies(missingDeps)
1351 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001352 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001353 case headerDepTag:
1354 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001355 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001356 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001357 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001358 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001359 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001360 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001361 }
1362
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001363 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001364 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001365 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001366 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001367 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001368 return
1369 }
1370
1371 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001372 // in static libraries act as if they were whole static libraries. The same goes for
1373 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001374 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1375 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001376 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1377 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001378
Dan Willemsen581341d2017-02-09 16:16:31 -08001379 }
1380
Colin Cross26c34ed2016-09-30 17:10:16 -07001381 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001382 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001383 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001384 return
1385 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001386 *ptr = append(*ptr, linkFile.Path())
1387 }
1388
Colin Crossc99deeb2016-04-11 15:06:20 -07001389 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001390 dep := depFile
1391 if !dep.Valid() {
1392 dep = linkFile
1393 }
1394 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001395 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001396
Logan Chien43d34c32017-12-20 01:17:32 +08001397 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001398 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001399 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001400 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001401 isLLndk := inList(libName, llndkLibraries)
Jiyong Park374510b2018-03-19 18:23:01 +09001402 isVendorPublicLib := inList(libName, vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001403 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1404 if c.useVndk() && bothVendorAndCoreVariantsExist {
1405 // The vendor module in Make will have been renamed to not conflict with the core
1406 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001407 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001408 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001409 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001410 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1411 return libName + recoverySuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001412 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001413 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001414 }
Logan Chien43d34c32017-12-20 01:17:32 +08001415 }
1416
1417 // Export the shared libs to Make.
1418 switch depTag {
1419 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jiyong Park27b188b2017-07-18 13:23:39 +09001420 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001421 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001422 c.Properties.AndroidMkSharedLibs = append(
1423 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
1424 case runtimeDepTag:
1425 c.Properties.AndroidMkRuntimeLibs = append(
1426 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001427 }
Colin Crossca860ac2016-01-04 14:34:37 -08001428 })
1429
Jeff Gaston294356f2017-09-27 17:05:30 -07001430 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001431 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001432
Colin Crossdd84e052017-05-17 13:44:16 -07001433 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001434 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001435 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001436 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001437 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1438
1439 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001440 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001441 }
Colin Crossdd84e052017-05-17 13:44:16 -07001442
Colin Crossca860ac2016-01-04 14:34:37 -08001443 return depPaths
1444}
1445
1446func (c *Module) InstallInData() bool {
1447 if c.installer == nil {
1448 return false
1449 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001450 return c.installer.inData()
1451}
1452
1453func (c *Module) InstallInSanitizerDir() bool {
1454 if c.installer == nil {
1455 return false
1456 }
1457 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001458 return true
1459 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001460 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001461}
1462
Jiyong Parkf9332f12018-02-01 00:54:12 +09001463func (c *Module) InstallInRecovery() bool {
1464 return c.inRecovery()
1465}
1466
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001467func (c *Module) HostToolPath() android.OptionalPath {
1468 if c.installer == nil {
1469 return android.OptionalPath{}
1470 }
1471 return c.installer.hostToolPath()
1472}
1473
Nan Zhangd4e641b2017-07-12 12:55:28 -07001474func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1475 return c.outputFile
1476}
1477
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001478func (c *Module) Srcs() android.Paths {
1479 if c.outputFile.Valid() {
1480 return android.Paths{c.outputFile.Path()}
1481 }
1482 return android.Paths{}
1483}
1484
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001485func (c *Module) static() bool {
1486 if static, ok := c.linker.(interface {
1487 static() bool
1488 }); ok {
1489 return static.static()
1490 }
1491 return false
1492}
1493
Colin Crossb60190a2018-09-04 16:28:17 -07001494func (c *Module) getMakeLinkType() string {
1495 if c.useVndk() {
1496 if inList(c.Name(), vndkCoreLibraries) || inList(c.Name(), vndkSpLibraries) || inList(c.Name(), llndkLibraries) {
1497 if inList(c.Name(), vndkPrivateLibraries) {
1498 return "native:vndk_private"
1499 } else {
1500 return "native:vndk"
1501 }
1502 } else {
1503 return "native:vendor"
1504 }
1505 } else if c.inRecovery() {
1506 return "native:recovery"
1507 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
1508 return "native:ndk:none:none"
1509 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
1510 //family, link := getNdkStlFamilyAndLinkType(c)
1511 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
1512 } else {
1513 return "native:platform"
1514 }
1515}
1516
Jiyong Park9d452992018-10-03 00:38:19 +09001517// Overrides ApexModule.IsInstallabeToApex()
1518// Only shared libraries are installable to APEX.
1519func (c *Module) IsInstallableToApex() bool {
1520 if shared, ok := c.linker.(interface {
1521 shared() bool
1522 }); ok {
1523 return shared.shared()
1524 }
1525 return false
1526}
1527
Colin Cross2ba19d92015-05-07 15:44:20 -07001528//
Colin Crosscfad1192015-11-02 16:43:11 -08001529// Defaults
1530//
Colin Crossca860ac2016-01-04 14:34:37 -08001531type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001532 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001533 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09001534 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001535}
1536
Colin Cross635c3b02016-05-18 15:37:25 -07001537func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001538}
1539
Colin Cross1e676be2016-10-12 14:38:15 -07001540func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1541}
1542
Colin Cross36242852017-06-23 15:06:31 -07001543func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001544 return DefaultsFactory()
1545}
1546
Colin Cross36242852017-06-23 15:06:31 -07001547func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001548 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001549
Colin Cross36242852017-06-23 15:06:31 -07001550 module.AddProperties(props...)
1551 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001552 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001553 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001554 &BaseCompilerProperties{},
1555 &BaseLinkerProperties{},
Chih-Hung Hsieh86814712018-05-23 18:30:46 -07001556 &MoreBaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001557 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001558 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001559 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001560 &TestProperties{},
1561 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001562 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001563 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001564 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001565 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001566 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001567 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001568 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001569 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001570 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001571 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001572 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001573 )
Colin Crosscfad1192015-11-02 16:43:11 -08001574
Colin Cross1f44a3a2017-07-07 14:33:33 -07001575 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09001576 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001577
1578 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001579}
1580
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001581const (
1582 // coreMode is the variant used for framework-private libraries, or
1583 // SDK libraries. (which framework-private libraries can use)
1584 coreMode = "core"
1585
1586 // vendorMode is the variant used for /vendor code that compiles
1587 // against the VNDK.
1588 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09001589
1590 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001591)
1592
Jiyong Park6a43f042017-10-12 23:05:00 +09001593func squashVendorSrcs(m *Module) {
1594 if lib, ok := m.compiler.(*libraryDecorator); ok {
1595 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1596 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1597
1598 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1599 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1600 }
1601}
1602
Jiyong Parkf9332f12018-02-01 00:54:12 +09001603func squashRecoverySrcs(m *Module) {
1604 if lib, ok := m.compiler.(*libraryDecorator); ok {
1605 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1606 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
1607
1608 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1609 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
1610 }
1611}
1612
1613func imageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001614 if mctx.Os() != android.Android {
1615 return
1616 }
1617
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001618 if genrule, ok := mctx.Module().(*genrule.Module); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09001619 if props, ok := genrule.Extra.(*GenruleExtraProperties); ok {
1620 var coreVariantNeeded bool = false
1621 var vendorVariantNeeded bool = false
1622 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09001623 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09001624 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001625 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09001626 coreVariantNeeded = true
1627 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09001628 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09001629 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001630 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09001631 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001632 }
Jiyong Park3f736c92018-05-24 13:36:56 +09001633 if Bool(props.Recovery_available) {
1634 recoveryVariantNeeded = true
1635 }
1636
Jiyong Park413cc742018-06-19 01:46:06 +09001637 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09001638 primaryArch := mctx.Config().DevicePrimaryArchType()
1639 moduleArch := genrule.Target().Arch.ArchType
1640 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09001641 recoveryVariantNeeded = false
1642 }
1643 }
1644
Jiyong Park3f736c92018-05-24 13:36:56 +09001645 var variants []string
1646 if coreVariantNeeded {
1647 variants = append(variants, coreMode)
1648 }
1649 if vendorVariantNeeded {
1650 variants = append(variants, vendorMode)
1651 }
1652 if recoveryVariantNeeded {
1653 variants = append(variants, recoveryMode)
1654 }
1655 mctx.CreateVariations(variants...)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001656 }
1657 }
1658
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001659 m, ok := mctx.Module().(*Module)
1660 if !ok {
1661 return
1662 }
1663
1664 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08001665 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
1666
1667 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001668 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09001669 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001670 return
1671 }
Logan Chienf3511742017-10-31 18:04:35 +08001672
1673 if vndkdep := m.vndkdep; vndkdep != nil {
1674 if vndkdep.isVndk() {
1675 if vendorSpecific {
1676 if !vndkdep.isVndkExt() {
1677 mctx.PropertyErrorf("vndk",
1678 "must set `extends: \"...\"` to vndk extension")
1679 return
1680 }
1681 } else {
1682 if vndkdep.isVndkExt() {
1683 mctx.PropertyErrorf("vndk",
1684 "must set `vendor: true` to set `extends: %q`",
1685 m.getVndkExtendsModuleName())
1686 return
1687 }
1688 if m.VendorProperties.Vendor_available == nil {
1689 mctx.PropertyErrorf("vndk",
1690 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
1691 return
1692 }
1693 }
1694 } else {
1695 if vndkdep.isVndkSp() {
1696 mctx.PropertyErrorf("vndk",
1697 "must set `enabled: true` to set `support_system_process: true`")
1698 return
1699 }
1700 if vndkdep.isVndkExt() {
1701 mctx.PropertyErrorf("vndk",
1702 "must set `enabled: true` to set `extends: %q`",
1703 m.getVndkExtendsModuleName())
1704 return
1705 }
Justin Yun8effde42017-06-23 19:24:43 +09001706 }
1707 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001708
Jiyong Parkf9332f12018-02-01 00:54:12 +09001709 var coreVariantNeeded bool = false
1710 var vendorVariantNeeded bool = false
1711 var recoveryVariantNeeded bool = false
1712
Justin Yun71549282017-11-17 12:10:28 +09001713 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001714 // If the device isn't compiling against the VNDK, we always
1715 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001716 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001717 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1718 // LL-NDK stubs only exist in the vendor variant, since the
1719 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001720 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09001721 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1722 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09001723 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09001724 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09001725 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
1726 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001727 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08001728 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001729 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001730 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001731 coreVariantNeeded = true
1732 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08001733 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09001734 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09001735 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001736 } else {
1737 // This is either in /system (or similar: /data), or is a
1738 // modules built with the NDK. Modules built with the NDK
1739 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001740 coreVariantNeeded = true
1741 }
1742
1743 if Bool(m.Properties.Recovery_available) {
1744 recoveryVariantNeeded = true
1745 }
1746
1747 if m.ModuleBase.InstallInRecovery() {
1748 recoveryVariantNeeded = true
1749 coreVariantNeeded = false
1750 }
1751
Jiyong Park413cc742018-06-19 01:46:06 +09001752 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09001753 primaryArch := mctx.Config().DevicePrimaryArchType()
1754 moduleArch := m.Target().Arch.ArchType
1755 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09001756 recoveryVariantNeeded = false
1757 }
1758 }
1759
Jiyong Parkf9332f12018-02-01 00:54:12 +09001760 var variants []string
1761 if coreVariantNeeded {
1762 variants = append(variants, coreMode)
1763 }
1764 if vendorVariantNeeded {
1765 variants = append(variants, vendorMode)
1766 }
1767 if recoveryVariantNeeded {
1768 variants = append(variants, recoveryMode)
1769 }
1770 mod := mctx.CreateVariations(variants...)
1771 for i, v := range variants {
1772 if v == vendorMode {
1773 m := mod[i].(*Module)
1774 m.Properties.UseVndk = true
1775 squashVendorSrcs(m)
1776 } else if v == recoveryMode {
1777 m := mod[i].(*Module)
1778 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09001779 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001780 squashRecoverySrcs(m)
1781 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001782 }
1783}
1784
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001785func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08001786 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001787 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1788 }
Colin Cross6510f912017-11-29 00:27:14 -08001789 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001790}
1791
Colin Cross06a931b2015-10-28 17:23:31 -07001792var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07001793var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08001794var BoolPtr = proptools.BoolPtr
1795var String = proptools.String
1796var StringPtr = proptools.StringPtr