blob: 02f36d5b269a78e999b7af621326497e450e65cf [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 Parkda6eb592018-12-19 17:12:36 +090037 ctx.BottomUp("image", ImageMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070038 ctx.BottomUp("link", LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +090039 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070040 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
41 ctx.BottomUp("test_per_src", testPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090042 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070043 ctx.BottomUp("begin", BeginMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070044 })
Colin Cross16b23492016-01-06 14:41:07 -080045
Colin Cross1e676be2016-10-12 14:38:15 -070046 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
47 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
48 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080049
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070050 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
51 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
52
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000053 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
54 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
55
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080056 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
57 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
58
Colin Cross1e676be2016-10-12 14:38:15 -070059 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
60 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080061
Colin Cross6b753602018-06-21 13:03:07 -070062 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator)
Jiyong Park379de2f2018-12-19 02:47:14 +090063 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080064
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +000065 ctx.BottomUp("coverage", coverageLinkingMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080066 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070067
68 ctx.TopDown("lto_deps", ltoDepsMutator)
69 ctx.BottomUp("lto", ltoMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070070 })
Colin Crossb98c8b02016-07-29 13:44:28 -070071
72 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070073}
74
Colin Crossca860ac2016-01-04 14:34:37 -080075type Deps struct {
76 SharedLibs, LateSharedLibs []string
77 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080078 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080079 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070080
Colin Cross5950f382016-12-13 12:50:57 -080081 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070082
Colin Cross81413472016-04-11 14:37:39 -070083 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070084
Dan Willemsenb40aab62016-04-20 14:21:14 -070085 GeneratedSources []string
86 GeneratedHeaders []string
87
Dan Willemsenb3454ab2016-09-28 17:34:58 -070088 ReexportGeneratedHeaders []string
89
Colin Cross97ba0732015-03-23 17:50:24 -070090 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -070091
92 // Used for host bionic
93 LinkerFlagsFile string
94 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -070095}
96
Colin Crossca860ac2016-01-04 14:34:37 -080097type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -070098 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +090099 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700100 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900101 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700102 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700103 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700104
Colin Cross26c34ed2016-09-30 17:10:16 -0700105 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700106 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800107 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700108 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700109
Colin Cross26c34ed2016-09-30 17:10:16 -0700110 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700111 GeneratedSources android.Paths
112 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700113
Dan Willemsen76f08272016-07-09 00:14:08 -0700114 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700115 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700116
Colin Cross26c34ed2016-09-30 17:10:16 -0700117 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700118 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700119
120 // Path to the file container flags to use with the linker
121 LinkerFlagsFile android.OptionalPath
122
123 // Path to the dynamic linker binary
124 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700125}
126
Colin Crossca860ac2016-01-04 14:34:37 -0800127type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700128 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
129 ArFlags []string // Flags that apply to ar
130 AsFlags []string // Flags that apply to assembly source files
131 CFlags []string // Flags that apply to C and C++ source files
132 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
133 ConlyFlags []string // Flags that apply to C source files
134 CppFlags []string // Flags that apply to C++ source files
135 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
136 YaccFlags []string // Flags that apply to Yacc source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700137 aidlFlags []string // Flags that apply to aidl source files
138 rsFlags []string // Flags that apply to renderscript source files
139 LdFlags []string // Flags that apply to linker command lines
140 libFlags []string // Flags to add libraries early to the link order
141 TidyFlags []string // Flags that apply to clang-tidy
142 SAbiFlags []string // Flags that apply to header-abi-dumper
143 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700144
Colin Crossc3199482017-03-30 15:03:04 -0700145 // Global include flags that apply to C, C++, and assembly source files
146 // These must be after any module include flags, which will be in GlobalFlags.
147 SystemIncludeFlags []string
148
Colin Crossb98c8b02016-07-29 13:44:28 -0700149 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700150 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800151 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800152 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800153
154 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800155 DynamicLinker string
156
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700157 CFlagsDeps android.Paths // Files depended on by compiler flags
158 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800159
160 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800161
162 protoDeps android.Paths
163 protoFlags []string // Flags that apply to proto source files
164 protoOutTypeFlag string // The output type, --cpp_out for example
165 protoOutParams []string // Flags that modify the output of proto generated files
166 protoC bool // Whether to use C instead of C++
167 protoOptionsFile bool // Whether to look for a .options file next to the .proto
168 ProtoRoot bool
Colin Crossc472d572015-03-17 15:06:21 -0700169}
170
Colin Cross81413472016-04-11 14:37:39 -0700171type ObjectLinkerProperties struct {
172 // names of other cc_object modules to link into this module using partial linking
173 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700174
175 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800176 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700177}
178
Colin Crossca860ac2016-01-04 14:34:37 -0800179// Properties used to compile all C or C++ modules
180type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700181 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800182 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700183
184 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800185 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700186
Jiyong Parkde866cb2018-12-07 23:08:36 +0900187 AndroidMkSharedLibs []string `blueprint:"mutated"`
188 AndroidMkStaticLibs []string `blueprint:"mutated"`
189 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
190 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
191 HideFromMake bool `blueprint:"mutated"`
192 PreventInstall bool `blueprint:"mutated"`
193 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700194
195 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800196
197 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
198 // file
199 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900200
201 // Make this module available when building for recovery
202 Recovery_available *bool
203
204 InRecovery bool `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900205
206 // Allows this module to use non-APEX version of libraries. Useful
207 // for building binaries that are started before APEXes are activated.
208 Bootstrap *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700209}
210
211type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900212 // whether this module should be allowed to be directly depended by other
213 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
214 // If set to true, two variants will be built separately, one like
215 // normal, and the other limited to the set of libraries and headers
216 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700217 //
218 // The vendor variant may be used with a different (newer) /system,
219 // so it shouldn't have any unversioned runtime dependencies, or
220 // make assumptions about the system that may not be true in the
221 // future.
222 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900223 // If set to false, this module becomes inaccessible from /vendor modules.
224 //
225 // Default value is true when vndk: {enabled: true} or vendor: true.
226 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700227 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
228 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900229
230 // whether this module is capable of being loaded with other instance
231 // (possibly an older version) of the same module in the same process.
232 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
233 // can be double loaded in a vendor process if the library is also a
234 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
235 // explicitly marked as `double_loadable: true` by the owner, or the dependency
236 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
237 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800238}
239
Colin Crossca860ac2016-01-04 14:34:37 -0800240type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800241 static() bool
242 staticBinary() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700243 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700244 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800245 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700246 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800247 isNdk() bool
248 isLlndk() bool
249 isLlndkPublic() bool
250 isVndkPrivate() bool
Justin Yun8effde42017-06-23 19:24:43 +0900251 isVndk() bool
252 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800253 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900254 inRecovery() bool
Logan Chien2f2b8902018-07-10 15:01:19 +0800255 shouldCreateVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700256 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700257 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800258 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800259 isPgoCompile() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800260 useClangLld(actx ModuleContext) bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900261 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900262 hasStubsVariants() bool
263 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900264 bootstrap() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800265}
266
267type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700268 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800269 ModuleContextIntf
270}
271
272type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700273 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800274 ModuleContextIntf
275}
276
Colin Cross37047f12016-12-13 17:06:13 -0800277type DepsContext interface {
278 android.BottomUpMutatorContext
279 ModuleContextIntf
280}
281
Colin Crossca860ac2016-01-04 14:34:37 -0800282type feature interface {
283 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800284 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800285 flags(ctx ModuleContext, flags Flags) Flags
286 props() []interface{}
287}
288
289type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700290 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800291 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800292 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700293 compilerProps() []interface{}
294
Colin Cross76fada02016-07-27 10:31:13 -0700295 appendCflags([]string)
296 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700297 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800298}
299
300type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700301 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800302 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700303 linkerFlags(ctx ModuleContext, flags Flags) Flags
304 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800305 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700306
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700307 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700308 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900309 unstrippedOutputFilePath() android.Path
Colin Crossca860ac2016-01-04 14:34:37 -0800310}
311
312type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700313 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700314 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800315 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700316 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700317 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900318 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800319}
320
Colin Crossc99deeb2016-04-11 15:06:20 -0700321type dependencyTag struct {
322 blueprint.BaseDependencyTag
323 name string
324 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700325
326 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900327
328 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700329}
330
331var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700332 sharedDepTag = dependencyTag{name: "shared", library: true}
333 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
Jiyong Park64a44f22019-01-18 14:37:08 +0900334 earlySharedDepTag = dependencyTag{name: "early_shared", library: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700335 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
336 staticDepTag = dependencyTag{name: "static", library: true}
337 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
338 lateStaticDepTag = dependencyTag{name: "late static", library: true}
339 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800340 headerDepTag = dependencyTag{name: "header", library: true}
341 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700342 genSourceDepTag = dependencyTag{name: "gen source"}
343 genHeaderDepTag = dependencyTag{name: "gen header"}
344 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
345 objDepTag = dependencyTag{name: "obj"}
346 crtBeginDepTag = dependencyTag{name: "crtbegin"}
347 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700348 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
349 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700350 reuseObjTag = dependencyTag{name: "reuse objects"}
351 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
352 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800353 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800354 runtimeDepTag = dependencyTag{name: "runtime lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700355)
356
Colin Crossca860ac2016-01-04 14:34:37 -0800357// Module contains the properties and members used by all C/C++ module types, and implements
358// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
359// to construct the output file. Behavior can be customized with a Customizer interface
360type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700361 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700362 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900363 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700364
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700365 Properties BaseProperties
366 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700367
Colin Crossca860ac2016-01-04 14:34:37 -0800368 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700369 hod android.HostOrDeviceSupported
370 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700371
Colin Crossca860ac2016-01-04 14:34:37 -0800372 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700373 features []feature
374 compiler compiler
375 linker linker
376 installer installer
377 stl *stl
378 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800379 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800380 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900381 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700382 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700383 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800384 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800385
386 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700387
Colin Cross635c3b02016-05-18 15:37:25 -0700388 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800389
Colin Crossb98c8b02016-07-29 13:44:28 -0700390 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700391
392 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800393
394 // Flags used to compile this module
395 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700396
397 // 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 -0800398 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700399 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800400 depsInLinkOrder android.Paths
401
402 // only non-nil when this is a shared library that reuses the objects of a static library
403 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700404}
405
Jiyong Parkc20eee32018-09-05 22:36:17 +0900406func (c *Module) OutputFile() android.OptionalPath {
407 return c.outputFile
408}
409
Jiyong Park719b4462019-01-13 00:39:51 +0900410func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900411 if c.linker != nil {
412 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900413 }
414 return nil
415}
416
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900417func (c *Module) RelativeInstallPath() string {
418 if c.installer != nil {
419 return c.installer.relativeInstallPath()
420 }
421 return ""
422}
423
Colin Cross36242852017-06-23 15:06:31 -0700424func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700425 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800426 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700427 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800428 }
429 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700430 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800431 }
432 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700433 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800434 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700435 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700436 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700437 }
Colin Cross16b23492016-01-06 14:41:07 -0800438 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700439 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800440 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800441 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700442 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800443 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800444 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700445 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800446 }
Justin Yun8effde42017-06-23 19:24:43 +0900447 if c.vndkdep != nil {
448 c.AddProperties(c.vndkdep.props()...)
449 }
Stephen Craneba090d12017-05-09 15:44:35 -0700450 if c.lto != nil {
451 c.AddProperties(c.lto.props()...)
452 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700453 if c.pgo != nil {
454 c.AddProperties(c.pgo.props()...)
455 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800456 if c.xom != nil {
457 c.AddProperties(c.xom.props()...)
458 }
Colin Crossca860ac2016-01-04 14:34:37 -0800459 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700460 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800461 }
Colin Crossc472d572015-03-17 15:06:21 -0700462
Colin Crossa9d8bee2018-10-02 13:59:46 -0700463 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
464 switch class {
465 case android.Device:
466 return ctx.Config().DevicePrefer32BitExecutables()
467 case android.HostCross:
468 // Windows builds always prefer 32-bit
469 return true
470 default:
471 return false
472 }
473 })
Colin Cross36242852017-06-23 15:06:31 -0700474 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700475
Colin Cross1f44a3a2017-07-07 14:33:33 -0700476 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700477
Jiyong Park9d452992018-10-03 00:38:19 +0900478 android.InitApexModule(c)
479
Colin Cross36242852017-06-23 15:06:31 -0700480 return c
Colin Crossc472d572015-03-17 15:06:21 -0700481}
482
Colin Crossb916a382016-07-29 17:28:03 -0700483// Returns true for dependency roots (binaries)
484// TODO(ccross): also handle dlopenable libraries
485func (c *Module) isDependencyRoot() bool {
486 if root, ok := c.linker.(interface {
487 isDependencyRoot() bool
488 }); ok {
489 return root.isDependencyRoot()
490 }
491 return false
492}
493
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700494func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700495 return c.Properties.UseVndk
496}
497
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800498func (c *Module) isNdk() bool {
499 return inList(c.Name(), ndkMigratedLibs)
500}
501
502func (c *Module) isLlndk() bool {
503 // Returns true for both LLNDK (public) and LLNDK-private libs.
504 return inList(c.Name(), llndkLibraries)
505}
506
507func (c *Module) isLlndkPublic() bool {
508 // Returns true only for LLNDK (public) libs.
509 return c.isLlndk() && !c.isVndkPrivate()
510}
511
512func (c *Module) isVndkPrivate() bool {
513 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
514 return inList(c.Name(), vndkPrivateLibraries)
515}
516
Justin Yun8effde42017-06-23 19:24:43 +0900517func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800518 if vndkdep := c.vndkdep; vndkdep != nil {
519 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900520 }
521 return false
522}
523
Yi Kong7e53c572018-02-14 18:16:12 +0800524func (c *Module) isPgoCompile() bool {
525 if pgo := c.pgo; pgo != nil {
526 return pgo.Properties.PgoCompile
527 }
528 return false
529}
530
Logan Chienf3511742017-10-31 18:04:35 +0800531func (c *Module) isVndkSp() bool {
532 if vndkdep := c.vndkdep; vndkdep != nil {
533 return vndkdep.isVndkSp()
534 }
535 return false
536}
537
538func (c *Module) isVndkExt() bool {
539 if vndkdep := c.vndkdep; vndkdep != nil {
540 return vndkdep.isVndkExt()
541 }
542 return false
543}
544
545func (c *Module) getVndkExtendsModuleName() string {
546 if vndkdep := c.vndkdep; vndkdep != nil {
547 return vndkdep.getVndkExtendsModuleName()
548 }
549 return ""
550}
551
Jiyong Park82e2bf32017-08-16 14:05:54 +0900552// Returns true only when this module is configured to have core and vendor
553// variants.
554func (c *Module) hasVendorVariant() bool {
555 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
556}
557
Jiyong Parkf9332f12018-02-01 00:54:12 +0900558func (c *Module) inRecovery() bool {
559 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
560}
561
562func (c *Module) onlyInRecovery() bool {
563 return c.ModuleBase.InstallInRecovery()
564}
565
Jiyong Park25fc6a92018-11-18 18:02:45 +0900566func (c *Module) IsStubs() bool {
567 if library, ok := c.linker.(*libraryDecorator); ok {
568 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900569 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
570 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900571 }
572 return false
573}
574
575func (c *Module) HasStubsVariants() bool {
576 if library, ok := c.linker.(*libraryDecorator); ok {
577 return len(library.Properties.Stubs.Versions) > 0
578 }
579 return false
580}
581
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900582func (c *Module) bootstrap() bool {
583 return Bool(c.Properties.Bootstrap)
584}
585
Colin Crossca860ac2016-01-04 14:34:37 -0800586type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700587 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800588 moduleContextImpl
589}
590
Colin Cross37047f12016-12-13 17:06:13 -0800591type depsContext struct {
592 android.BottomUpMutatorContext
593 moduleContextImpl
594}
595
Colin Crossca860ac2016-01-04 14:34:37 -0800596type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700597 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800598 moduleContextImpl
599}
600
Jiyong Park2db76922017-11-08 16:03:48 +0900601func (ctx *moduleContext) SocSpecific() bool {
602 return ctx.ModuleContext.SocSpecific() ||
603 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700604}
605
Colin Crossca860ac2016-01-04 14:34:37 -0800606type moduleContextImpl struct {
607 mod *Module
608 ctx BaseModuleContext
609}
610
Colin Crossb98c8b02016-07-29 13:44:28 -0700611func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800612 return ctx.mod.toolchain(ctx.ctx)
613}
614
615func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000616 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800617}
618
619func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900620 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800621}
622
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700623func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800624 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800625 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700626 }
627 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800628}
629
630func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700631 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700632 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900633 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700634 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900635 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
636 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
637 return "current"
638 }
639 return platform_vndk_ver
640 }
641 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800642 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900643 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700644 }
645 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800646}
647
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700648func (ctx *moduleContextImpl) useVndk() bool {
649 return ctx.mod.useVndk()
650}
Justin Yun8effde42017-06-23 19:24:43 +0900651
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800652func (ctx *moduleContextImpl) isNdk() bool {
653 return ctx.mod.isNdk()
654}
655
656func (ctx *moduleContextImpl) isLlndk() bool {
657 return ctx.mod.isLlndk()
658}
659
660func (ctx *moduleContextImpl) isLlndkPublic() bool {
661 return ctx.mod.isLlndkPublic()
662}
663
664func (ctx *moduleContextImpl) isVndkPrivate() bool {
665 return ctx.mod.isVndkPrivate()
666}
667
Logan Chienf3511742017-10-31 18:04:35 +0800668func (ctx *moduleContextImpl) isVndk() bool {
669 return ctx.mod.isVndk()
670}
671
Yi Kong7e53c572018-02-14 18:16:12 +0800672func (ctx *moduleContextImpl) isPgoCompile() bool {
673 return ctx.mod.isPgoCompile()
674}
675
Justin Yun8effde42017-06-23 19:24:43 +0900676func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800677 return ctx.mod.isVndkSp()
678}
679
680func (ctx *moduleContextImpl) isVndkExt() bool {
681 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900682}
683
Jiyong Parkf9332f12018-02-01 00:54:12 +0900684func (ctx *moduleContextImpl) inRecovery() bool {
685 return ctx.mod.inRecovery()
686}
687
Logan Chien2f2b8902018-07-10 15:01:19 +0800688// Check whether ABI dumps should be created for this module.
689func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump() bool {
690 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
691 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800692 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800693
694 if ctx.ctx.Fuchsia() {
695 return false
696 }
697
Logan Chien2f2b8902018-07-10 15:01:19 +0800698 if sanitize := ctx.mod.sanitize; sanitize != nil {
699 if !sanitize.isVariantOnProductionDevice() {
700 return false
701 }
702 }
703 if !ctx.ctx.Device() {
704 // Host modules do not need ABI dumps.
705 return false
706 }
Logan Chienfa478c02018-12-28 16:25:39 +0800707 if !ctx.mod.IsForPlatform() {
708 // APEX variants do not need ABI dumps.
709 return false
710 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800711 if ctx.isNdk() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800712 return true
713 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800714 if ctx.isLlndkPublic() {
Logan Chienf4b79c62018-08-02 02:27:02 +0800715 return true
716 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800717 if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800718 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
719 // VNDK-private.
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800720 return true
Logan Chien2f2b8902018-07-10 15:01:19 +0800721 }
722 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800723}
724
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700725func (ctx *moduleContextImpl) selectedStl() string {
726 if stl := ctx.mod.stl; stl != nil {
727 return stl.Properties.SelectedStl
728 }
729 return ""
730}
731
Ivan Lozanobd721262018-11-27 14:33:03 -0800732func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
733 return ctx.mod.linker.useClangLld(actx)
734}
735
Colin Crossce75d2c2016-10-06 16:12:58 -0700736func (ctx *moduleContextImpl) baseModuleName() string {
737 return ctx.mod.ModuleBase.BaseModuleName()
738}
739
Logan Chienf3511742017-10-31 18:04:35 +0800740func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
741 return ctx.mod.getVndkExtendsModuleName()
742}
743
Jiyong Park58e364a2019-01-19 19:24:06 +0900744func (ctx *moduleContextImpl) apexName() string {
745 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900746}
747
Jiyong Parkb0788572018-12-20 22:10:17 +0900748func (ctx *moduleContextImpl) hasStubsVariants() bool {
749 return ctx.mod.HasStubsVariants()
750}
751
752func (ctx *moduleContextImpl) isStubs() bool {
753 return ctx.mod.IsStubs()
754}
755
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900756func (ctx *moduleContextImpl) bootstrap() bool {
757 return ctx.mod.bootstrap()
758}
759
Colin Cross635c3b02016-05-18 15:37:25 -0700760func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800761 return &Module{
762 hod: hod,
763 multilib: multilib,
764 }
765}
766
Colin Cross635c3b02016-05-18 15:37:25 -0700767func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800768 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700769 module.features = []feature{
770 &tidyFeature{},
771 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700772 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800773 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800774 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800775 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900776 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700777 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700778 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800779 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800780 return module
781}
782
Colin Crossce75d2c2016-10-06 16:12:58 -0700783func (c *Module) Prebuilt() *android.Prebuilt {
784 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
785 return p.prebuilt()
786 }
787 return nil
788}
789
790func (c *Module) Name() string {
791 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700792 if p, ok := c.linker.(interface {
793 Name(string) string
794 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700795 name = p.Name(name)
796 }
797 return name
798}
799
Alex Light3d673592019-01-18 14:37:31 -0800800func (c *Module) Symlinks() []string {
801 if p, ok := c.installer.(interface {
802 symlinkList() []string
803 }); ok {
804 return p.symlinkList()
805 }
806 return nil
807}
808
Jeff Gaston294356f2017-09-27 17:05:30 -0700809// orderDeps reorders dependencies into a list such that if module A depends on B, then
810// A will precede B in the resultant list.
811// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800812// Note that directSharedDeps should be the analogous static library for each shared lib dep
813func 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 -0700814 // If A depends on B, then
815 // Every list containing A will also contain B later in the list
816 // So, after concatenating all lists, the final instance of B will have come from the same
817 // original list as the final instance of A
818 // So, the final instance of B will be later in the concatenation than the final A
819 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
820 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800821 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700822 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800823 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
824 }
825 for _, dep := range directSharedDeps {
826 orderedAllDeps = append(orderedAllDeps, dep)
827 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700828 }
829
Colin Crossb6715442017-10-24 11:13:31 -0700830 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700831
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800832 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700833 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800834 // resultant list to only what the caller has chosen to include in directStaticDeps
835 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700836
837 return orderedAllDeps, orderedDeclaredDeps
838}
839
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800840func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
841 // convert Module to Path
842 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
843 staticDepFiles := []android.Path{}
844 for _, dep := range staticDeps {
845 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
846 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700847 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800848 sharedDepFiles := []android.Path{}
849 for _, sharedDep := range sharedDeps {
850 staticAnalogue := sharedDep.staticVariant
851 if staticAnalogue != nil {
852 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
853 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
854 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700855 }
856
857 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800858 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700859
860 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700861}
862
Colin Cross635c3b02016-05-18 15:37:25 -0700863func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800864 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700865 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800866 moduleContextImpl: moduleContextImpl{
867 mod: c,
868 },
869 }
870 ctx.ctx = ctx
871
Colin Crossf18e1102017-11-16 14:33:08 -0800872 deps := c.depsToPaths(ctx)
873 if ctx.Failed() {
874 return
875 }
876
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700877 if c.Properties.Clang != nil && *c.Properties.Clang == false {
878 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
879 }
880
Colin Crossca860ac2016-01-04 14:34:37 -0800881 flags := Flags{
882 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800883 }
Colin Crossca860ac2016-01-04 14:34:37 -0800884 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800885 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800886 }
887 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700888 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800889 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700890 if c.stl != nil {
891 flags = c.stl.flags(ctx, flags)
892 }
Colin Cross16b23492016-01-06 14:41:07 -0800893 if c.sanitize != nil {
894 flags = c.sanitize.flags(ctx, flags)
895 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800896 if c.coverage != nil {
897 flags = c.coverage.flags(ctx, flags)
898 }
Stephen Craneba090d12017-05-09 15:44:35 -0700899 if c.lto != nil {
900 flags = c.lto.flags(ctx, flags)
901 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700902 if c.pgo != nil {
903 flags = c.pgo.flags(ctx, flags)
904 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800905 if c.xom != nil {
906 flags = c.xom.flags(ctx, flags)
907 }
Colin Crossca860ac2016-01-04 14:34:37 -0800908 for _, feature := range c.features {
909 flags = feature.flags(ctx, flags)
910 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800911 if ctx.Failed() {
912 return
913 }
914
Colin Crossb98c8b02016-07-29 13:44:28 -0700915 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
916 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
917 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800918
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800919 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
920 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700921 // We need access to all the flags seen by a source file.
922 if c.sabi != nil {
923 flags = c.sabi.flags(ctx, flags)
924 }
Colin Crossca860ac2016-01-04 14:34:37 -0800925 // Optimization to reduce size of build.ninja
926 // Replace the long list of flags for each file with a module-local variable
927 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
928 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
929 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
930 flags.CFlags = []string{"$cflags"}
931 flags.CppFlags = []string{"$cppflags"}
932 flags.AsFlags = []string{"$asflags"}
933
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700934 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800935 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700936 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800937 if ctx.Failed() {
938 return
939 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800940 }
941
Colin Crossca860ac2016-01-04 14:34:37 -0800942 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700943 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800944 if ctx.Failed() {
945 return
946 }
Colin Cross635c3b02016-05-18 15:37:25 -0700947 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +0900948
949 // If a lib is directly included in any of the APEXes, unhide the stubs
950 // variant having the latest version gets visible to make. In addition,
951 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
952 // force anything in the make world to link against the stubs library.
953 // (unless it is explicitly referenced via .bootstrap suffix or the
954 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +0000955 if c.HasStubsVariants() &&
956 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Jiyong Parkb0788572018-12-20 22:10:17 +0900957 !c.inRecovery() && !c.useVndk() && !c.static() && c.IsStubs() {
958 c.Properties.HideFromMake = false // unhide
959 // Note: this is still non-installable
960 }
Colin Crossce75d2c2016-10-06 16:12:58 -0700961 }
Colin Cross5049f022015-03-18 13:28:46 -0700962
Jiyong Park9d452992018-10-03 00:38:19 +0900963 if c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() {
Colin Crossce75d2c2016-10-06 16:12:58 -0700964 c.installer.install(ctx, c.outputFile.Path())
965 if ctx.Failed() {
966 return
Colin Crossca860ac2016-01-04 14:34:37 -0800967 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700968 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800969}
970
Jiyong Park379de2f2018-12-19 02:47:14 +0900971func (c *Module) toolchain(ctx android.BaseContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800972 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700973 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800974 }
Colin Crossca860ac2016-01-04 14:34:37 -0800975 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800976}
977
Colin Crossca860ac2016-01-04 14:34:37 -0800978func (c *Module) begin(ctx BaseModuleContext) {
979 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700980 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700981 }
Colin Crossca860ac2016-01-04 14:34:37 -0800982 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700983 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800984 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700985 if c.stl != nil {
986 c.stl.begin(ctx)
987 }
Colin Cross16b23492016-01-06 14:41:07 -0800988 if c.sanitize != nil {
989 c.sanitize.begin(ctx)
990 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800991 if c.coverage != nil {
992 c.coverage.begin(ctx)
993 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800994 if c.sabi != nil {
995 c.sabi.begin(ctx)
996 }
Justin Yun8effde42017-06-23 19:24:43 +0900997 if c.vndkdep != nil {
998 c.vndkdep.begin(ctx)
999 }
Stephen Craneba090d12017-05-09 15:44:35 -07001000 if c.lto != nil {
1001 c.lto.begin(ctx)
1002 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001003 if c.pgo != nil {
1004 c.pgo.begin(ctx)
1005 }
Colin Crossca860ac2016-01-04 14:34:37 -08001006 for _, feature := range c.features {
1007 feature.begin(ctx)
1008 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001009 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001010 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001011 if err != nil {
1012 ctx.PropertyErrorf("sdk_version", err.Error())
1013 }
Nan Zhang0007d812017-11-07 10:57:05 -08001014 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001015 }
Colin Crossca860ac2016-01-04 14:34:37 -08001016}
1017
Colin Cross37047f12016-12-13 17:06:13 -08001018func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001019 deps := Deps{}
1020
1021 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001022 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001023 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001024 // Add the PGO dependency (the clang_rt.profile runtime library), which
1025 // sometimes depends on symbols from libgcc, before libgcc gets added
1026 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001027 if c.pgo != nil {
1028 deps = c.pgo.deps(ctx, deps)
1029 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001030 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001031 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001032 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001033 if c.stl != nil {
1034 deps = c.stl.deps(ctx, deps)
1035 }
Colin Cross16b23492016-01-06 14:41:07 -08001036 if c.sanitize != nil {
1037 deps = c.sanitize.deps(ctx, deps)
1038 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001039 if c.coverage != nil {
1040 deps = c.coverage.deps(ctx, deps)
1041 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001042 if c.sabi != nil {
1043 deps = c.sabi.deps(ctx, deps)
1044 }
Justin Yun8effde42017-06-23 19:24:43 +09001045 if c.vndkdep != nil {
1046 deps = c.vndkdep.deps(ctx, deps)
1047 }
Stephen Craneba090d12017-05-09 15:44:35 -07001048 if c.lto != nil {
1049 deps = c.lto.deps(ctx, deps)
1050 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001051 for _, feature := range c.features {
1052 deps = feature.deps(ctx, deps)
1053 }
1054
Colin Crossb6715442017-10-24 11:13:31 -07001055 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1056 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1057 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1058 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1059 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1060 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001061 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001062
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001063 for _, lib := range deps.ReexportSharedLibHeaders {
1064 if !inList(lib, deps.SharedLibs) {
1065 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1066 }
1067 }
1068
1069 for _, lib := range deps.ReexportStaticLibHeaders {
1070 if !inList(lib, deps.StaticLibs) {
1071 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1072 }
1073 }
1074
Colin Cross5950f382016-12-13 12:50:57 -08001075 for _, lib := range deps.ReexportHeaderLibHeaders {
1076 if !inList(lib, deps.HeaderLibs) {
1077 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1078 }
1079 }
1080
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001081 for _, gen := range deps.ReexportGeneratedHeaders {
1082 if !inList(gen, deps.GeneratedHeaders) {
1083 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1084 }
1085 }
1086
Colin Crossc99deeb2016-04-11 15:06:20 -07001087 return deps
1088}
1089
Dan Albert7e9d2952016-08-04 13:02:36 -07001090func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001091 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001092 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001093 moduleContextImpl: moduleContextImpl{
1094 mod: c,
1095 },
1096 }
1097 ctx.ctx = ctx
1098
Colin Crossca860ac2016-01-04 14:34:37 -08001099 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001100}
1101
Jiyong Park7ed9de32018-10-15 22:25:07 +09001102// Split name#version into name and version
1103func stubsLibNameAndVersion(name string) (string, string) {
1104 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1105 version := name[sharp+1:]
1106 libname := name[:sharp]
1107 return libname, version
1108 }
1109 return name, ""
1110}
1111
Colin Cross1e676be2016-10-12 14:38:15 -07001112func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001113 ctx := &depsContext{
1114 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001115 moduleContextImpl: moduleContextImpl{
1116 mod: c,
1117 },
1118 }
1119 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001120
Colin Crossc99deeb2016-04-11 15:06:20 -07001121 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001122
Dan Albert914449f2016-06-17 16:45:24 -07001123 variantNdkLibs := []string{}
1124 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001125 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001126 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001127
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001128 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1129 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001130 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001131 // 1. Name of an NDK library that refers to a prebuilt module.
1132 // For each of these, it adds the name of the prebuilt module (which will be in
1133 // prebuilts/ndk) to the list of nonvariant libs.
1134 // 2. Name of an NDK library that refers to an ndk_library module.
1135 // For each of these, it adds the name of the ndk_library module to the list of
1136 // variant libs.
1137 // 3. Anything else (so anything that isn't an NDK library).
1138 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001139 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001140 // The caller can then know to add the variantLibs dependencies differently from the
1141 // nonvariantLibs
1142 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1143 variantLibs = []string{}
1144 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001145 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001146 // strip #version suffix out
1147 name, _ := stubsLibNameAndVersion(entry)
1148 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1149 if !inList(name, ndkMigratedLibs) {
1150 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001151 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001152 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001153 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001154 } else if ctx.useVndk() && inList(name, llndkLibraries) {
1155 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
1156 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, vendorPublicLibraries) {
1157 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001158 if actx.OtherModuleExists(vendorPublicLib) {
1159 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1160 } else {
1161 // This can happen if vendor_public_library module is defined in a
1162 // namespace that isn't visible to the current module. In that case,
1163 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001164 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001165 }
Dan Albert914449f2016-06-17 16:45:24 -07001166 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001167 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001168 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001169 }
1170 }
Dan Albert914449f2016-06-17 16:45:24 -07001171 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001172 }
1173
Dan Albert914449f2016-06-17 16:45:24 -07001174 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1175 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001176 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001177 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001178
Jiyong Park7e636d02019-01-28 16:16:54 +09001179 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001180 if c.linker != nil {
1181 if library, ok := c.linker.(*libraryDecorator); ok {
1182 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001183 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001184 }
1185 }
1186 }
1187
Colin Cross32ec36c2016-12-15 07:39:51 -08001188 for _, lib := range deps.HeaderLibs {
1189 depTag := headerDepTag
1190 if inList(lib, deps.ReexportHeaderLibHeaders) {
1191 depTag = headerExportDepTag
1192 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001193 if buildStubs {
Jiyong Park7e636d02019-01-28 16:16:54 +09001194 actx.AddFarVariationDependencies([]blueprint.Variation{
1195 {Mutator: "arch", Variation: ctx.Target().String()},
Jiyong Park3b1746a2019-01-29 11:15:04 +09001196 {Mutator: "image", Variation: c.imageVariation()},
Jiyong Park7e636d02019-01-28 16:16:54 +09001197 }, depTag, lib)
1198 } else {
1199 actx.AddVariationDependencies(nil, depTag, lib)
1200 }
1201 }
1202
1203 if buildStubs {
1204 // Stubs lib does not have dependency to other static/shared libraries.
1205 // Don't proceed.
1206 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001207 }
Colin Cross5950f382016-12-13 12:50:57 -08001208
Dan Willemsen59339a22018-07-22 21:18:45 -07001209 actx.AddVariationDependencies([]blueprint.Variation{
1210 {Mutator: "link", Variation: "static"},
1211 }, wholeStaticDepTag, deps.WholeStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001212
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001213 for _, lib := range deps.StaticLibs {
1214 depTag := staticDepTag
1215 if inList(lib, deps.ReexportStaticLibHeaders) {
1216 depTag = staticExportDepTag
1217 }
Dan Willemsen59339a22018-07-22 21:18:45 -07001218 actx.AddVariationDependencies([]blueprint.Variation{
1219 {Mutator: "link", Variation: "static"},
1220 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001221 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001222
Dan Willemsen59339a22018-07-22 21:18:45 -07001223 actx.AddVariationDependencies([]blueprint.Variation{
1224 {Mutator: "link", Variation: "static"},
1225 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001226
Jiyong Park25fc6a92018-11-18 18:02:45 +09001227 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1228 var variations []blueprint.Variation
1229 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001230 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001231 if version != "" && versionVariantAvail {
1232 // Version is explicitly specified. i.e. libFoo#30
1233 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1234 depTag.explicitlyVersioned = true
1235 }
1236 actx.AddVariationDependencies(variations, depTag, name)
1237
1238 // If the version is not specified, add dependency to the latest stubs library.
1239 // The stubs library will be used when the depending module is built for APEX and
1240 // the dependent module is not in the same APEX.
1241 latestVersion := latestStubsVersionFor(actx.Config(), name)
1242 if version == "" && latestVersion != "" && versionVariantAvail {
1243 actx.AddVariationDependencies([]blueprint.Variation{
1244 {Mutator: "link", Variation: "shared"},
1245 {Mutator: "version", Variation: latestVersion},
1246 }, depTag, name)
1247 // Note that depTag.explicitlyVersioned is false in this case.
1248 }
1249 }
1250
Jiyong Park7ed9de32018-10-15 22:25:07 +09001251 // shared lib names without the #version suffix
1252 var sharedLibNames []string
1253
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001254 for _, lib := range deps.SharedLibs {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001255 name, version := stubsLibNameAndVersion(lib)
1256 sharedLibNames = append(sharedLibNames, name)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001257 depTag := sharedDepTag
1258 if inList(lib, deps.ReexportSharedLibHeaders) {
1259 depTag = sharedExportDepTag
1260 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001261 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001262 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001263
Jiyong Park7ed9de32018-10-15 22:25:07 +09001264 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001265 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001266 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1267 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1268 // linking against both the stubs lib and the non-stubs lib at the same time.
1269 continue
1270 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001271 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001272 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001273
Dan Willemsen59339a22018-07-22 21:18:45 -07001274 actx.AddVariationDependencies([]blueprint.Variation{
1275 {Mutator: "link", Variation: "shared"},
1276 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001277
Colin Cross68861832016-07-08 10:41:41 -07001278 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001279
1280 for _, gen := range deps.GeneratedHeaders {
1281 depTag := genHeaderDepTag
1282 if inList(gen, deps.ReexportGeneratedHeaders) {
1283 depTag = genHeaderExportDepTag
1284 }
1285 actx.AddDependency(c, depTag, gen)
1286 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001287
Colin Cross42d48b72018-08-29 14:10:52 -07001288 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001289
1290 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001291 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001292 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001293 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001294 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001295 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001296 if deps.LinkerFlagsFile != "" {
1297 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1298 }
1299 if deps.DynamicLinker != "" {
1300 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001301 }
Dan Albert914449f2016-06-17 16:45:24 -07001302
1303 version := ctx.sdkVersion()
1304 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001305 {Mutator: "ndk_api", Variation: version},
1306 {Mutator: "link", Variation: "shared"},
1307 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001308 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001309 {Mutator: "ndk_api", Variation: version},
1310 {Mutator: "link", Variation: "shared"},
1311 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001312
1313 if vndkdep := c.vndkdep; vndkdep != nil {
1314 if vndkdep.isVndkExt() {
1315 baseModuleMode := vendorMode
1316 if actx.DeviceConfig().VndkVersion() == "" {
1317 baseModuleMode = coreMode
1318 }
1319 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001320 {Mutator: "image", Variation: baseModuleMode},
1321 {Mutator: "link", Variation: "shared"},
1322 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001323 }
1324 }
Colin Cross6362e272015-10-29 15:25:03 -07001325}
Colin Cross21b9a242015-03-24 14:15:58 -07001326
Colin Crosse40b4ea2018-10-02 22:25:58 -07001327func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001328 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1329 c.beginMutator(ctx)
1330 }
1331}
1332
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001333// Whether a module can link to another module, taking into
1334// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001335func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001336 if from.Target().Os != android.Android {
1337 // Host code is not restricted
1338 return
1339 }
1340 if from.Properties.UseVndk {
1341 // Though vendor code is limited by the vendor mutator,
1342 // each vendor-available module needs to check
1343 // link-type for VNDK.
1344 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001345 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001346 }
1347 return
1348 }
Nan Zhang0007d812017-11-07 10:57:05 -08001349 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001350 // Platform code can link to anything
1351 return
1352 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001353 if from.inRecovery() {
1354 // Recovery code is not NDK
1355 return
1356 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001357 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1358 // These are always allowed
1359 return
1360 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001361 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1362 // These are allowed, but they don't set sdk_version
1363 return
1364 }
1365 if _, ok := to.linker.(*stubDecorator); ok {
1366 // These aren't real libraries, but are the stub shared libraries that are included in
1367 // the NDK.
1368 return
1369 }
Logan Chien834b9a62019-01-14 15:39:03 +08001370
1371 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" {
1372 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1373 // to link to libc++ (non-NDK and without sdk_version).
1374 return
1375 }
1376
Nan Zhang0007d812017-11-07 10:57:05 -08001377 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001378 // NDK code linking to platform code is never okay.
1379 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1380 ctx.OtherModuleName(to))
1381 }
1382
1383 // At this point we know we have two NDK libraries, but we need to
1384 // check that we're not linking against anything built against a higher
1385 // API level, as it is only valid to link against older or equivalent
1386 // APIs.
1387
Inseob Kim01a28722018-04-11 09:48:45 +09001388 // Current can link against anything.
1389 if String(from.Properties.Sdk_version) != "current" {
1390 // Otherwise we need to check.
1391 if String(to.Properties.Sdk_version) == "current" {
1392 // Current can't be linked against by anything else.
1393 ctx.ModuleErrorf("links %q built against newer API version %q",
1394 ctx.OtherModuleName(to), "current")
1395 } else {
1396 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1397 if err != nil {
1398 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001399 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001400 String(from.Properties.Sdk_version))
1401 }
1402 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1403 if err != nil {
1404 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001405 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001406 String(to.Properties.Sdk_version))
1407 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001408
Inseob Kim01a28722018-04-11 09:48:45 +09001409 if toApi > fromApi {
1410 ctx.ModuleErrorf("links %q built against newer API version %q",
1411 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1412 }
1413 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001414 }
Dan Albert202fe492017-12-15 13:56:59 -08001415
1416 // Also check that the two STL choices are compatible.
1417 fromStl := from.stl.Properties.SelectedStl
1418 toStl := to.stl.Properties.SelectedStl
1419 if fromStl == "" || toStl == "" {
1420 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001421 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001422 // We can be permissive with the system "STL" since it is only the C++
1423 // ABI layer, but in the future we should make sure that everyone is
1424 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001425 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001426 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1427 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1428 to.stl.Properties.SelectedStl)
1429 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001430}
1431
Jiyong Park5fb8c102018-04-09 12:03:06 +09001432// Tests whether the dependent library is okay to be double loaded inside a single process.
1433// If a library is a member of VNDK and at the same time dependencies of an LLNDK library,
1434// it is subject to be double loaded. Such lib should be explicitly marked as double_loaded: true
1435// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
1436func checkDoubleLoadableLibries(ctx android.ModuleContext, from *Module, to *Module) {
1437 if _, ok := from.linker.(*libraryDecorator); !ok {
1438 return
1439 }
1440
1441 if inList(ctx.ModuleName(), llndkLibraries) ||
1442 (from.useVndk() && Bool(from.VendorProperties.Double_loadable)) {
1443 _, depIsLlndk := to.linker.(*llndkStubDecorator)
1444 depIsVndkSp := false
1445 if to.vndkdep != nil && to.vndkdep.isVndkSp() {
1446 depIsVndkSp = true
1447 }
1448 depIsVndk := false
1449 if to.vndkdep != nil && to.vndkdep.isVndk() {
1450 depIsVndk = true
1451 }
1452 depIsDoubleLoadable := Bool(to.VendorProperties.Double_loadable)
1453 if !depIsLlndk && !depIsVndkSp && !depIsDoubleLoadable && depIsVndk {
Steven Moreland742989e2018-11-26 12:41:04 -08001454 ctx.ModuleErrorf("links VNDK library %q that isn't double loadable (not also LL-NDK, "+
1455 "VNDK-SP, or explicitly marked as 'double_loadable').",
Jiyong Park5fb8c102018-04-09 12:03:06 +09001456 ctx.OtherModuleName(to))
1457 }
1458 }
1459}
1460
Colin Crossc99deeb2016-04-11 15:06:20 -07001461// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001462func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001463 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001464
Jeff Gaston294356f2017-09-27 17:05:30 -07001465 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001466 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001467
Colin Crossd11fcda2017-10-23 17:59:01 -07001468 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001469 depName := ctx.OtherModuleName(dep)
1470 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001471
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001472 ccDep, _ := dep.(*Module)
1473 if ccDep == nil {
1474 // handling for a few module types that aren't cc Module but that are also supported
1475 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001476 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001477 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001478 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1479 genRule.GeneratedSourceFiles()...)
1480 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001481 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001482 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001483 // Support exported headers from a generated_sources dependency
1484 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001485 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001486 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001487 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001488 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001489 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001490 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001491 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001492 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001493 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001494 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001495 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1496 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1497
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001498 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001499 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001500 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001501 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001502 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001503 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001504 files := genRule.GeneratedSourceFiles()
1505 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001506 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001507 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001508 ctx.ModuleErrorf("module %q can only generate a single file if used for a linker flag file", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001509 }
1510 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001511 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001512 }
Colin Crossca860ac2016-01-04 14:34:37 -08001513 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001514 return
1515 }
1516
Colin Crossd11fcda2017-10-23 17:59:01 -07001517 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001518 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1519 return
1520 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001521 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001522 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001523 return
1524 }
1525
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001526 // re-exporting flags
1527 if depTag == reuseObjTag {
1528 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001529 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001530 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001531 depPaths.Objs = depPaths.Objs.Append(objs)
1532 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001533 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001534 return
1535 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001536 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001537
1538 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1539 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1540 // won't be matched to sharedDepTag and lateSharedDepTag.
1541 explicitlyVersioned := false
1542 if t, ok := depTag.(dependencyTag); ok {
1543 explicitlyVersioned = t.explicitlyVersioned
1544 t.explicitlyVersioned = false
1545 depTag = t
1546 }
1547
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001548 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001549 depIsStatic := false
1550 switch depTag {
1551 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1552 depIsStatic = true
1553 }
1554 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001555 depIsStubs := dependentLibrary.buildStubs()
1556 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001557 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001558 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001559
1560 var useThisDep bool
1561 if depIsStubs && explicitlyVersioned {
1562 // Always respect dependency to the versioned stubs (i.e. libX#10)
1563 useThisDep = true
1564 } else if !depHasStubs {
1565 // Use non-stub variant if that is the only choice
1566 // (i.e. depending on a lib without stubs.version property)
1567 useThisDep = true
1568 } else if c.IsForPlatform() {
1569 // If not building for APEX, use stubs only when it is from
1570 // an APEX (and not from platform)
1571 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001572 if c.inRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001573 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001574 // always link to non-stub variant
1575 useThisDep = !depIsStubs
1576 }
1577 } else {
1578 // If building for APEX, use stubs only when it is not from
1579 // the same APEX
1580 useThisDep = (depInSameApex != depIsStubs)
1581 }
1582
1583 if !useThisDep {
1584 return // stop processing this dep
1585 }
1586 }
1587
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001588 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001589 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001590 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001591 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001592 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001593
1594 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001595 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001596 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001597 // 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 -07001598 // Re-exported shared library headers must be included as well since they can help us with type information
1599 // about template instantiations (instantiated from their headers).
1600 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001601 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001602 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001603
Logan Chienf3511742017-10-31 18:04:35 +08001604 checkLinkType(ctx, c, ccDep, t)
Jiyong Park5fb8c102018-04-09 12:03:06 +09001605 checkDoubleLoadableLibries(ctx, c, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001606 }
1607
Colin Cross26c34ed2016-09-30 17:10:16 -07001608 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001609 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001610
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001611 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001612 depFile := android.OptionalPath{}
1613
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001614 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001615 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001616 ptr = &depPaths.SharedLibs
1617 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001618 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001619 directSharedDeps = append(directSharedDeps, ccDep)
Jiyong Park64a44f22019-01-18 14:37:08 +09001620 case earlySharedDepTag:
1621 ptr = &depPaths.EarlySharedLibs
1622 depPtr = &depPaths.EarlySharedLibsDeps
1623 depFile = ccDep.linker.(libraryInterface).toc()
1624 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001625 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001626 ptr = &depPaths.LateSharedLibs
1627 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001628 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001629 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001630 ptr = nil
1631 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001632 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001633 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001634 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001635 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001636 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001637 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001638 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001639 return
1640 }
1641
1642 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001643 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001644 for i := range missingDeps {
1645 missingDeps[i] += postfix
1646 }
1647 ctx.AddMissingDependencies(missingDeps)
1648 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001649 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001650 case headerDepTag:
1651 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001652 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001653 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001654 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001655 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001656 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001657 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001658 case dynamicLinkerDepTag:
1659 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001660 }
1661
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001662 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001663 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001664 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001665 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001666 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001667 return
1668 }
1669
1670 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001671 // in static libraries act as if they were whole static libraries. The same goes for
1672 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001673 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1674 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001675 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1676 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001677
Dan Willemsen581341d2017-02-09 16:16:31 -08001678 }
1679
Colin Cross26c34ed2016-09-30 17:10:16 -07001680 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001681 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001682 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001683 return
1684 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001685 *ptr = append(*ptr, linkFile.Path())
1686 }
1687
Colin Crossc99deeb2016-04-11 15:06:20 -07001688 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001689 dep := depFile
1690 if !dep.Valid() {
1691 dep = linkFile
1692 }
1693 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001694 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001695
Logan Chien43d34c32017-12-20 01:17:32 +08001696 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001697 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001698 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001699 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001700 isLLndk := inList(libName, llndkLibraries)
Jiyong Park374510b2018-03-19 18:23:01 +09001701 isVendorPublicLib := inList(libName, vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001702 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1703 if c.useVndk() && bothVendorAndCoreVariantsExist {
1704 // The vendor module in Make will have been renamed to not conflict with the core
1705 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001706 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001707 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001708 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001709 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1710 return libName + recoverySuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001711 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001712 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001713 }
Logan Chien43d34c32017-12-20 01:17:32 +08001714 }
1715
1716 // Export the shared libs to Make.
1717 switch depTag {
Jiyong Park64a44f22019-01-18 14:37:08 +09001718 case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001719 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001720 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08001721 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09001722 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001723 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001724 c.Properties.ApexesProvidingSharedLibs = append(
1725 c.Properties.ApexesProvidingSharedLibs, an)
1726 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09001727 }
1728 }
1729
Jiyong Park27b188b2017-07-18 13:23:39 +09001730 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001731 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001732 c.Properties.AndroidMkSharedLibs = append(
1733 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08001734 case ndkStubDepTag, ndkLateStubDepTag:
1735 ndkStub := ccDep.linker.(*stubDecorator)
1736 c.Properties.AndroidMkSharedLibs = append(
1737 c.Properties.AndroidMkSharedLibs,
1738 depName+"."+ndkStub.properties.ApiLevel)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001739 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1740 c.Properties.AndroidMkStaticLibs = append(
1741 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001742 case runtimeDepTag:
1743 c.Properties.AndroidMkRuntimeLibs = append(
1744 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001745 case wholeStaticDepTag:
1746 c.Properties.AndroidMkWholeStaticLibs = append(
1747 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001748 }
Colin Crossca860ac2016-01-04 14:34:37 -08001749 })
1750
Jeff Gaston294356f2017-09-27 17:05:30 -07001751 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001752 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001753
Colin Crossdd84e052017-05-17 13:44:16 -07001754 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001755 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001756 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001757 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001758 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1759
1760 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001761 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001762 }
Colin Crossdd84e052017-05-17 13:44:16 -07001763
Colin Crossca860ac2016-01-04 14:34:37 -08001764 return depPaths
1765}
1766
1767func (c *Module) InstallInData() bool {
1768 if c.installer == nil {
1769 return false
1770 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001771 return c.installer.inData()
1772}
1773
1774func (c *Module) InstallInSanitizerDir() bool {
1775 if c.installer == nil {
1776 return false
1777 }
1778 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001779 return true
1780 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001781 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001782}
1783
Jiyong Parkf9332f12018-02-01 00:54:12 +09001784func (c *Module) InstallInRecovery() bool {
1785 return c.inRecovery()
1786}
1787
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001788func (c *Module) HostToolPath() android.OptionalPath {
1789 if c.installer == nil {
1790 return android.OptionalPath{}
1791 }
1792 return c.installer.hostToolPath()
1793}
1794
Nan Zhangd4e641b2017-07-12 12:55:28 -07001795func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1796 return c.outputFile
1797}
1798
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001799func (c *Module) Srcs() android.Paths {
1800 if c.outputFile.Valid() {
1801 return android.Paths{c.outputFile.Path()}
1802 }
1803 return android.Paths{}
1804}
1805
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001806func (c *Module) static() bool {
1807 if static, ok := c.linker.(interface {
1808 static() bool
1809 }); ok {
1810 return static.static()
1811 }
1812 return false
1813}
1814
Jiyong Park379de2f2018-12-19 02:47:14 +09001815func (c *Module) staticBinary() bool {
1816 if static, ok := c.linker.(interface {
1817 staticBinary() bool
1818 }); ok {
1819 return static.staticBinary()
1820 }
1821 return false
1822}
1823
Colin Crossb60190a2018-09-04 16:28:17 -07001824func (c *Module) getMakeLinkType() string {
1825 if c.useVndk() {
1826 if inList(c.Name(), vndkCoreLibraries) || inList(c.Name(), vndkSpLibraries) || inList(c.Name(), llndkLibraries) {
1827 if inList(c.Name(), vndkPrivateLibraries) {
1828 return "native:vndk_private"
1829 } else {
1830 return "native:vndk"
1831 }
1832 } else {
1833 return "native:vendor"
1834 }
1835 } else if c.inRecovery() {
1836 return "native:recovery"
1837 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
1838 return "native:ndk:none:none"
1839 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
1840 //family, link := getNdkStlFamilyAndLinkType(c)
1841 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
1842 } else {
1843 return "native:platform"
1844 }
1845}
1846
Jiyong Park9d452992018-10-03 00:38:19 +09001847// Overrides ApexModule.IsInstallabeToApex()
1848// Only shared libraries are installable to APEX.
1849func (c *Module) IsInstallableToApex() bool {
1850 if shared, ok := c.linker.(interface {
1851 shared() bool
1852 }); ok {
1853 return shared.shared()
1854 }
1855 return false
1856}
1857
Jiyong Park3b1746a2019-01-29 11:15:04 +09001858func (c *Module) imageVariation() string {
1859 variation := "core"
1860 if c.useVndk() {
1861 variation = "vendor"
1862 } else if c.inRecovery() {
1863 variation = "recovery"
1864 }
1865 return variation
1866}
1867
Colin Cross2ba19d92015-05-07 15:44:20 -07001868//
Colin Crosscfad1192015-11-02 16:43:11 -08001869// Defaults
1870//
Colin Crossca860ac2016-01-04 14:34:37 -08001871type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001872 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001873 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09001874 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001875}
1876
Colin Cross635c3b02016-05-18 15:37:25 -07001877func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001878}
1879
Colin Cross36242852017-06-23 15:06:31 -07001880func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001881 return DefaultsFactory()
1882}
1883
Colin Cross36242852017-06-23 15:06:31 -07001884func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001885 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001886
Colin Cross36242852017-06-23 15:06:31 -07001887 module.AddProperties(props...)
1888 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001889 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001890 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001891 &BaseCompilerProperties{},
1892 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001893 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001894 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001895 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001896 &TestProperties{},
1897 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001898 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001899 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001900 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001901 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001902 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001903 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001904 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001905 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001906 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001907 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08001908 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001909 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001910 )
Colin Crosscfad1192015-11-02 16:43:11 -08001911
Colin Cross1f44a3a2017-07-07 14:33:33 -07001912 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09001913 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001914
1915 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001916}
1917
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001918const (
1919 // coreMode is the variant used for framework-private libraries, or
1920 // SDK libraries. (which framework-private libraries can use)
1921 coreMode = "core"
1922
1923 // vendorMode is the variant used for /vendor code that compiles
1924 // against the VNDK.
1925 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09001926
1927 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001928)
1929
Jiyong Park6a43f042017-10-12 23:05:00 +09001930func squashVendorSrcs(m *Module) {
1931 if lib, ok := m.compiler.(*libraryDecorator); ok {
1932 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1933 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1934
1935 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1936 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1937 }
1938}
1939
Jiyong Parkf9332f12018-02-01 00:54:12 +09001940func squashRecoverySrcs(m *Module) {
1941 if lib, ok := m.compiler.(*libraryDecorator); ok {
1942 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1943 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
1944
1945 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1946 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
1947 }
1948}
1949
Jiyong Parkda6eb592018-12-19 17:12:36 +09001950func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001951 if mctx.Os() != android.Android {
1952 return
1953 }
1954
Jiyong Park7ed9de32018-10-15 22:25:07 +09001955 if g, ok := mctx.Module().(*genrule.Module); ok {
1956 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09001957 var coreVariantNeeded bool = false
1958 var vendorVariantNeeded bool = false
1959 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09001960 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09001961 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001962 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09001963 coreVariantNeeded = true
1964 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09001965 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09001966 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001967 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09001968 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001969 }
Jiyong Park3f736c92018-05-24 13:36:56 +09001970 if Bool(props.Recovery_available) {
1971 recoveryVariantNeeded = true
1972 }
1973
Jiyong Park413cc742018-06-19 01:46:06 +09001974 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09001975 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09001976 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09001977 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09001978 recoveryVariantNeeded = false
1979 }
1980 }
1981
Jiyong Park3f736c92018-05-24 13:36:56 +09001982 var variants []string
1983 if coreVariantNeeded {
1984 variants = append(variants, coreMode)
1985 }
1986 if vendorVariantNeeded {
1987 variants = append(variants, vendorMode)
1988 }
1989 if recoveryVariantNeeded {
1990 variants = append(variants, recoveryMode)
1991 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001992 mod := mctx.CreateVariations(variants...)
1993 for i, v := range variants {
1994 if v == recoveryMode {
1995 m := mod[i].(*genrule.Module)
1996 m.Extra.(*GenruleExtraProperties).InRecovery = true
1997 }
1998 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001999 }
2000 }
2001
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002002 m, ok := mctx.Module().(*Module)
2003 if !ok {
2004 return
2005 }
2006
2007 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002008 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002009 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002010
2011 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002012 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002013 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002014 return
2015 }
Logan Chienf3511742017-10-31 18:04:35 +08002016
2017 if vndkdep := m.vndkdep; vndkdep != nil {
2018 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002019 if productSpecific {
2020 mctx.PropertyErrorf("product_specific",
2021 "product_specific must not be true when `vndk: {enabled: true}`")
2022 return
2023 }
Logan Chienf3511742017-10-31 18:04:35 +08002024 if vendorSpecific {
2025 if !vndkdep.isVndkExt() {
2026 mctx.PropertyErrorf("vndk",
2027 "must set `extends: \"...\"` to vndk extension")
2028 return
2029 }
2030 } else {
2031 if vndkdep.isVndkExt() {
2032 mctx.PropertyErrorf("vndk",
2033 "must set `vendor: true` to set `extends: %q`",
2034 m.getVndkExtendsModuleName())
2035 return
2036 }
2037 if m.VendorProperties.Vendor_available == nil {
2038 mctx.PropertyErrorf("vndk",
2039 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2040 return
2041 }
2042 }
2043 } else {
2044 if vndkdep.isVndkSp() {
2045 mctx.PropertyErrorf("vndk",
2046 "must set `enabled: true` to set `support_system_process: true`")
2047 return
2048 }
2049 if vndkdep.isVndkExt() {
2050 mctx.PropertyErrorf("vndk",
2051 "must set `enabled: true` to set `extends: %q`",
2052 m.getVndkExtendsModuleName())
2053 return
2054 }
Justin Yun8effde42017-06-23 19:24:43 +09002055 }
2056 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002057
Jiyong Parkf9332f12018-02-01 00:54:12 +09002058 var coreVariantNeeded bool = false
2059 var vendorVariantNeeded bool = false
2060 var recoveryVariantNeeded bool = false
2061
Justin Yun71549282017-11-17 12:10:28 +09002062 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002063 // If the device isn't compiling against the VNDK, we always
2064 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002065 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002066 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2067 // LL-NDK stubs only exist in the vendor variant, since the
2068 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002069 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09002070 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2071 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09002072 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09002073 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002074 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2075 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002076 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002077 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002078 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002079 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002080 coreVariantNeeded = true
2081 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002082 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002083 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09002084 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002085 } else {
2086 // This is either in /system (or similar: /data), or is a
2087 // modules built with the NDK. Modules built with the NDK
2088 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002089 coreVariantNeeded = true
2090 }
2091
2092 if Bool(m.Properties.Recovery_available) {
2093 recoveryVariantNeeded = true
2094 }
2095
2096 if m.ModuleBase.InstallInRecovery() {
2097 recoveryVariantNeeded = true
2098 coreVariantNeeded = false
2099 }
2100
Jiyong Park413cc742018-06-19 01:46:06 +09002101 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002102 primaryArch := mctx.Config().DevicePrimaryArchType()
2103 moduleArch := m.Target().Arch.ArchType
2104 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002105 recoveryVariantNeeded = false
2106 }
2107 }
2108
Jiyong Parkf9332f12018-02-01 00:54:12 +09002109 var variants []string
2110 if coreVariantNeeded {
2111 variants = append(variants, coreMode)
2112 }
2113 if vendorVariantNeeded {
2114 variants = append(variants, vendorMode)
2115 }
2116 if recoveryVariantNeeded {
2117 variants = append(variants, recoveryMode)
2118 }
2119 mod := mctx.CreateVariations(variants...)
2120 for i, v := range variants {
2121 if v == vendorMode {
2122 m := mod[i].(*Module)
2123 m.Properties.UseVndk = true
2124 squashVendorSrcs(m)
2125 } else if v == recoveryMode {
2126 m := mod[i].(*Module)
2127 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002128 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002129 squashRecoverySrcs(m)
2130 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002131 }
2132}
2133
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002134func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002135 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002136 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2137 }
Colin Cross6510f912017-11-29 00:27:14 -08002138 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002139}
2140
Colin Cross06a931b2015-10-28 17:23:31 -07002141var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002142var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002143var BoolPtr = proptools.BoolPtr
2144var String = proptools.String
2145var StringPtr = proptools.StringPtr