blob: 081da123021e4669ff0254b222df77a6df77d27f [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()
Inseob Kimc0907f12019-02-08 21:00:45 +090044 ctx.BottomUp("sysprop", SyspropMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070045 })
Colin Cross16b23492016-01-06 14:41:07 -080046
Colin Cross1e676be2016-10-12 14:38:15 -070047 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
48 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
49 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080050
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070051 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
52 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
53
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000054 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
55 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
56
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080057 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
58 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
59
Colin Cross1e676be2016-10-12 14:38:15 -070060 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
61 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080062
Colin Cross6b753602018-06-21 13:03:07 -070063 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator)
Jiyong Park379de2f2018-12-19 02:47:14 +090064 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080065
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +000066 ctx.BottomUp("coverage", coverageLinkingMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080067 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070068
69 ctx.TopDown("lto_deps", ltoDepsMutator)
70 ctx.BottomUp("lto", ltoMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070071 })
Colin Crossb98c8b02016-07-29 13:44:28 -070072
73 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070074}
75
Colin Crossca860ac2016-01-04 14:34:37 -080076type Deps struct {
77 SharedLibs, LateSharedLibs []string
78 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080079 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080080 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070081
Colin Cross5950f382016-12-13 12:50:57 -080082 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070083
Colin Cross81413472016-04-11 14:37:39 -070084 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070085
Dan Willemsenb40aab62016-04-20 14:21:14 -070086 GeneratedSources []string
87 GeneratedHeaders []string
88
Dan Willemsenb3454ab2016-09-28 17:34:58 -070089 ReexportGeneratedHeaders []string
90
Colin Cross97ba0732015-03-23 17:50:24 -070091 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -070092
93 // Used for host bionic
94 LinkerFlagsFile string
95 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -070096}
97
Colin Crossca860ac2016-01-04 14:34:37 -080098type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -070099 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900100 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700101 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900102 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700103 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700104 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700105
Colin Cross26c34ed2016-09-30 17:10:16 -0700106 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700107 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800108 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700109 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700110
Colin Cross26c34ed2016-09-30 17:10:16 -0700111 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700112 GeneratedSources android.Paths
113 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700114
Dan Willemsen76f08272016-07-09 00:14:08 -0700115 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700116 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700117
Colin Cross26c34ed2016-09-30 17:10:16 -0700118 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700119 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700120
121 // Path to the file container flags to use with the linker
122 LinkerFlagsFile android.OptionalPath
123
124 // Path to the dynamic linker binary
125 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700126}
127
Colin Crossca860ac2016-01-04 14:34:37 -0800128type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700129 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
130 ArFlags []string // Flags that apply to ar
131 AsFlags []string // Flags that apply to assembly source files
132 CFlags []string // Flags that apply to C and C++ source files
133 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
134 ConlyFlags []string // Flags that apply to C source files
135 CppFlags []string // Flags that apply to C++ source files
136 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
137 YaccFlags []string // Flags that apply to Yacc source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700138 aidlFlags []string // Flags that apply to aidl source files
139 rsFlags []string // Flags that apply to renderscript source files
140 LdFlags []string // Flags that apply to linker command lines
141 libFlags []string // Flags to add libraries early to the link order
142 TidyFlags []string // Flags that apply to clang-tidy
143 SAbiFlags []string // Flags that apply to header-abi-dumper
144 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700145
Colin Crossc3199482017-03-30 15:03:04 -0700146 // Global include flags that apply to C, C++, and assembly source files
147 // These must be after any module include flags, which will be in GlobalFlags.
148 SystemIncludeFlags []string
149
Colin Crossb98c8b02016-07-29 13:44:28 -0700150 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700151 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800152 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800153 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800154
155 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800156 DynamicLinker string
157
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700158 CFlagsDeps android.Paths // Files depended on by compiler flags
159 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800160
161 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800162
163 protoDeps android.Paths
164 protoFlags []string // Flags that apply to proto source files
165 protoOutTypeFlag string // The output type, --cpp_out for example
166 protoOutParams []string // Flags that modify the output of proto generated files
167 protoC bool // Whether to use C instead of C++
168 protoOptionsFile bool // Whether to look for a .options file next to the .proto
169 ProtoRoot bool
Colin Crossc472d572015-03-17 15:06:21 -0700170}
171
Colin Cross81413472016-04-11 14:37:39 -0700172type ObjectLinkerProperties struct {
173 // names of other cc_object modules to link into this module using partial linking
174 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700175
176 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800177 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700178}
179
Colin Crossca860ac2016-01-04 14:34:37 -0800180// Properties used to compile all C or C++ modules
181type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700182 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800183 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700184
185 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800186 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700187
Jiyong Parkde866cb2018-12-07 23:08:36 +0900188 AndroidMkSharedLibs []string `blueprint:"mutated"`
189 AndroidMkStaticLibs []string `blueprint:"mutated"`
190 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
191 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
192 HideFromMake bool `blueprint:"mutated"`
193 PreventInstall bool `blueprint:"mutated"`
194 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700195
196 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800197
198 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
199 // file
200 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900201
202 // Make this module available when building for recovery
203 Recovery_available *bool
204
205 InRecovery bool `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900206
207 // Allows this module to use non-APEX version of libraries. Useful
208 // for building binaries that are started before APEXes are activated.
209 Bootstrap *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700210}
211
212type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900213 // whether this module should be allowed to be directly depended by other
214 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
215 // If set to true, two variants will be built separately, one like
216 // normal, and the other limited to the set of libraries and headers
217 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700218 //
219 // The vendor variant may be used with a different (newer) /system,
220 // so it shouldn't have any unversioned runtime dependencies, or
221 // make assumptions about the system that may not be true in the
222 // future.
223 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900224 // If set to false, this module becomes inaccessible from /vendor modules.
225 //
226 // Default value is true when vndk: {enabled: true} or vendor: true.
227 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700228 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
229 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900230
231 // whether this module is capable of being loaded with other instance
232 // (possibly an older version) of the same module in the same process.
233 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
234 // can be double loaded in a vendor process if the library is also a
235 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
236 // explicitly marked as `double_loadable: true` by the owner, or the dependency
237 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
238 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800239}
240
Colin Crossca860ac2016-01-04 14:34:37 -0800241type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800242 static() bool
243 staticBinary() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700244 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700245 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800246 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700247 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800248 isNdk() bool
249 isLlndk() bool
250 isLlndkPublic() bool
251 isVndkPrivate() bool
Justin Yun8effde42017-06-23 19:24:43 +0900252 isVndk() bool
253 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800254 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900255 inRecovery() bool
Logan Chien2f2b8902018-07-10 15:01:19 +0800256 shouldCreateVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700257 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700258 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800259 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800260 isPgoCompile() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800261 useClangLld(actx ModuleContext) bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900262 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900263 hasStubsVariants() bool
264 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900265 bootstrap() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800266}
267
268type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700269 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800270 ModuleContextIntf
271}
272
273type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700274 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800275 ModuleContextIntf
276}
277
Colin Cross37047f12016-12-13 17:06:13 -0800278type DepsContext interface {
279 android.BottomUpMutatorContext
280 ModuleContextIntf
281}
282
Colin Crossca860ac2016-01-04 14:34:37 -0800283type feature interface {
284 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800285 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800286 flags(ctx ModuleContext, flags Flags) Flags
287 props() []interface{}
288}
289
290type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700291 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800292 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800293 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700294 compilerProps() []interface{}
295
Colin Cross76fada02016-07-27 10:31:13 -0700296 appendCflags([]string)
297 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700298 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800299}
300
301type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700302 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800303 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700304 linkerFlags(ctx ModuleContext, flags Flags) Flags
305 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800306 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700307
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700308 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700309 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900310 unstrippedOutputFilePath() android.Path
Colin Crossca860ac2016-01-04 14:34:37 -0800311}
312
313type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700314 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700315 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800316 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700317 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700318 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900319 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800320}
321
Colin Crossc99deeb2016-04-11 15:06:20 -0700322type dependencyTag struct {
323 blueprint.BaseDependencyTag
324 name string
325 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700326
327 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900328
329 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700330}
331
332var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700333 sharedDepTag = dependencyTag{name: "shared", library: true}
334 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
Jiyong Park64a44f22019-01-18 14:37:08 +0900335 earlySharedDepTag = dependencyTag{name: "early_shared", library: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700336 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
337 staticDepTag = dependencyTag{name: "static", library: true}
338 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
339 lateStaticDepTag = dependencyTag{name: "late static", library: true}
340 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800341 headerDepTag = dependencyTag{name: "header", library: true}
342 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700343 genSourceDepTag = dependencyTag{name: "gen source"}
344 genHeaderDepTag = dependencyTag{name: "gen header"}
345 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
346 objDepTag = dependencyTag{name: "obj"}
347 crtBeginDepTag = dependencyTag{name: "crtbegin"}
348 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700349 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
350 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700351 reuseObjTag = dependencyTag{name: "reuse objects"}
Jiyong Parke4bb9862019-02-01 00:31:10 +0900352 staticVariantTag = dependencyTag{name: "static variant"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700353 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
354 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800355 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800356 runtimeDepTag = dependencyTag{name: "runtime lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700357)
358
Colin Crossca860ac2016-01-04 14:34:37 -0800359// Module contains the properties and members used by all C/C++ module types, and implements
360// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
361// to construct the output file. Behavior can be customized with a Customizer interface
362type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700363 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700364 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900365 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700366
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700367 Properties BaseProperties
368 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700369
Colin Crossca860ac2016-01-04 14:34:37 -0800370 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700371 hod android.HostOrDeviceSupported
372 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700373
Colin Crossca860ac2016-01-04 14:34:37 -0800374 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700375 features []feature
376 compiler compiler
377 linker linker
378 installer installer
379 stl *stl
380 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800381 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800382 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900383 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700384 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700385 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800386 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800387
388 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700389
Colin Cross635c3b02016-05-18 15:37:25 -0700390 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800391
Colin Crossb98c8b02016-07-29 13:44:28 -0700392 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700393
394 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800395
396 // Flags used to compile this module
397 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700398
399 // 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 -0800400 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700401 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800402 depsInLinkOrder android.Paths
403
404 // only non-nil when this is a shared library that reuses the objects of a static library
405 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700406}
407
Jiyong Parkc20eee32018-09-05 22:36:17 +0900408func (c *Module) OutputFile() android.OptionalPath {
409 return c.outputFile
410}
411
Jiyong Park719b4462019-01-13 00:39:51 +0900412func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900413 if c.linker != nil {
414 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900415 }
416 return nil
417}
418
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900419func (c *Module) RelativeInstallPath() string {
420 if c.installer != nil {
421 return c.installer.relativeInstallPath()
422 }
423 return ""
424}
425
Colin Cross36242852017-06-23 15:06:31 -0700426func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700427 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800428 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700429 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800430 }
431 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700432 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800433 }
434 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700435 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800436 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700437 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700438 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700439 }
Colin Cross16b23492016-01-06 14:41:07 -0800440 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700441 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800442 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800443 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700444 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800445 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800446 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700447 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800448 }
Justin Yun8effde42017-06-23 19:24:43 +0900449 if c.vndkdep != nil {
450 c.AddProperties(c.vndkdep.props()...)
451 }
Stephen Craneba090d12017-05-09 15:44:35 -0700452 if c.lto != nil {
453 c.AddProperties(c.lto.props()...)
454 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700455 if c.pgo != nil {
456 c.AddProperties(c.pgo.props()...)
457 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800458 if c.xom != nil {
459 c.AddProperties(c.xom.props()...)
460 }
Colin Crossca860ac2016-01-04 14:34:37 -0800461 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700462 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800463 }
Colin Crossc472d572015-03-17 15:06:21 -0700464
Colin Crossa9d8bee2018-10-02 13:59:46 -0700465 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
466 switch class {
467 case android.Device:
468 return ctx.Config().DevicePrefer32BitExecutables()
469 case android.HostCross:
470 // Windows builds always prefer 32-bit
471 return true
472 default:
473 return false
474 }
475 })
Colin Cross36242852017-06-23 15:06:31 -0700476 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700477
Colin Cross1f44a3a2017-07-07 14:33:33 -0700478 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700479
Jiyong Park9d452992018-10-03 00:38:19 +0900480 android.InitApexModule(c)
481
Colin Cross36242852017-06-23 15:06:31 -0700482 return c
Colin Crossc472d572015-03-17 15:06:21 -0700483}
484
Colin Crossb916a382016-07-29 17:28:03 -0700485// Returns true for dependency roots (binaries)
486// TODO(ccross): also handle dlopenable libraries
487func (c *Module) isDependencyRoot() bool {
488 if root, ok := c.linker.(interface {
489 isDependencyRoot() bool
490 }); ok {
491 return root.isDependencyRoot()
492 }
493 return false
494}
495
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700496func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700497 return c.Properties.UseVndk
498}
499
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800500func (c *Module) isNdk() bool {
501 return inList(c.Name(), ndkMigratedLibs)
502}
503
504func (c *Module) isLlndk() bool {
505 // Returns true for both LLNDK (public) and LLNDK-private libs.
506 return inList(c.Name(), llndkLibraries)
507}
508
509func (c *Module) isLlndkPublic() bool {
510 // Returns true only for LLNDK (public) libs.
511 return c.isLlndk() && !c.isVndkPrivate()
512}
513
514func (c *Module) isVndkPrivate() bool {
515 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
516 return inList(c.Name(), vndkPrivateLibraries)
517}
518
Justin Yun8effde42017-06-23 19:24:43 +0900519func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800520 if vndkdep := c.vndkdep; vndkdep != nil {
521 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900522 }
523 return false
524}
525
Yi Kong7e53c572018-02-14 18:16:12 +0800526func (c *Module) isPgoCompile() bool {
527 if pgo := c.pgo; pgo != nil {
528 return pgo.Properties.PgoCompile
529 }
530 return false
531}
532
Logan Chienf3511742017-10-31 18:04:35 +0800533func (c *Module) isVndkSp() bool {
534 if vndkdep := c.vndkdep; vndkdep != nil {
535 return vndkdep.isVndkSp()
536 }
537 return false
538}
539
540func (c *Module) isVndkExt() bool {
541 if vndkdep := c.vndkdep; vndkdep != nil {
542 return vndkdep.isVndkExt()
543 }
544 return false
545}
546
547func (c *Module) getVndkExtendsModuleName() string {
548 if vndkdep := c.vndkdep; vndkdep != nil {
549 return vndkdep.getVndkExtendsModuleName()
550 }
551 return ""
552}
553
Jiyong Park82e2bf32017-08-16 14:05:54 +0900554// Returns true only when this module is configured to have core and vendor
555// variants.
556func (c *Module) hasVendorVariant() bool {
557 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
558}
559
Jiyong Parkf9332f12018-02-01 00:54:12 +0900560func (c *Module) inRecovery() bool {
561 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
562}
563
564func (c *Module) onlyInRecovery() bool {
565 return c.ModuleBase.InstallInRecovery()
566}
567
Jiyong Park25fc6a92018-11-18 18:02:45 +0900568func (c *Module) IsStubs() bool {
569 if library, ok := c.linker.(*libraryDecorator); ok {
570 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900571 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
572 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900573 }
574 return false
575}
576
577func (c *Module) HasStubsVariants() bool {
578 if library, ok := c.linker.(*libraryDecorator); ok {
579 return len(library.Properties.Stubs.Versions) > 0
580 }
581 return false
582}
583
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900584func (c *Module) bootstrap() bool {
585 return Bool(c.Properties.Bootstrap)
586}
587
Colin Crossca860ac2016-01-04 14:34:37 -0800588type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700589 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800590 moduleContextImpl
591}
592
Colin Cross37047f12016-12-13 17:06:13 -0800593type depsContext struct {
594 android.BottomUpMutatorContext
595 moduleContextImpl
596}
597
Colin Crossca860ac2016-01-04 14:34:37 -0800598type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700599 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800600 moduleContextImpl
601}
602
Jiyong Park2db76922017-11-08 16:03:48 +0900603func (ctx *moduleContext) SocSpecific() bool {
604 return ctx.ModuleContext.SocSpecific() ||
605 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700606}
607
Colin Crossca860ac2016-01-04 14:34:37 -0800608type moduleContextImpl struct {
609 mod *Module
610 ctx BaseModuleContext
611}
612
Colin Crossb98c8b02016-07-29 13:44:28 -0700613func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800614 return ctx.mod.toolchain(ctx.ctx)
615}
616
617func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000618 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800619}
620
621func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900622 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800623}
624
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700625func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800626 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800627 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700628 }
629 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800630}
631
632func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700633 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700634 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900635 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700636 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900637 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
638 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
639 return "current"
640 }
641 return platform_vndk_ver
642 }
643 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800644 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900645 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700646 }
647 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800648}
649
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700650func (ctx *moduleContextImpl) useVndk() bool {
651 return ctx.mod.useVndk()
652}
Justin Yun8effde42017-06-23 19:24:43 +0900653
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800654func (ctx *moduleContextImpl) isNdk() bool {
655 return ctx.mod.isNdk()
656}
657
658func (ctx *moduleContextImpl) isLlndk() bool {
659 return ctx.mod.isLlndk()
660}
661
662func (ctx *moduleContextImpl) isLlndkPublic() bool {
663 return ctx.mod.isLlndkPublic()
664}
665
666func (ctx *moduleContextImpl) isVndkPrivate() bool {
667 return ctx.mod.isVndkPrivate()
668}
669
Logan Chienf3511742017-10-31 18:04:35 +0800670func (ctx *moduleContextImpl) isVndk() bool {
671 return ctx.mod.isVndk()
672}
673
Yi Kong7e53c572018-02-14 18:16:12 +0800674func (ctx *moduleContextImpl) isPgoCompile() bool {
675 return ctx.mod.isPgoCompile()
676}
677
Justin Yun8effde42017-06-23 19:24:43 +0900678func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800679 return ctx.mod.isVndkSp()
680}
681
682func (ctx *moduleContextImpl) isVndkExt() bool {
683 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900684}
685
Jiyong Parkf9332f12018-02-01 00:54:12 +0900686func (ctx *moduleContextImpl) inRecovery() bool {
687 return ctx.mod.inRecovery()
688}
689
Logan Chien2f2b8902018-07-10 15:01:19 +0800690// Check whether ABI dumps should be created for this module.
691func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump() bool {
692 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
693 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800694 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800695
696 if ctx.ctx.Fuchsia() {
697 return false
698 }
699
Logan Chien2f2b8902018-07-10 15:01:19 +0800700 if sanitize := ctx.mod.sanitize; sanitize != nil {
701 if !sanitize.isVariantOnProductionDevice() {
702 return false
703 }
704 }
705 if !ctx.ctx.Device() {
706 // Host modules do not need ABI dumps.
707 return false
708 }
Logan Chienfa478c02018-12-28 16:25:39 +0800709 if !ctx.mod.IsForPlatform() {
710 // APEX variants do not need ABI dumps.
711 return false
712 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800713 if ctx.isNdk() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800714 return true
715 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800716 if ctx.isLlndkPublic() {
Logan Chienf4b79c62018-08-02 02:27:02 +0800717 return true
718 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800719 if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800720 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
721 // VNDK-private.
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800722 return true
Logan Chien2f2b8902018-07-10 15:01:19 +0800723 }
724 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800725}
726
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700727func (ctx *moduleContextImpl) selectedStl() string {
728 if stl := ctx.mod.stl; stl != nil {
729 return stl.Properties.SelectedStl
730 }
731 return ""
732}
733
Ivan Lozanobd721262018-11-27 14:33:03 -0800734func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
735 return ctx.mod.linker.useClangLld(actx)
736}
737
Colin Crossce75d2c2016-10-06 16:12:58 -0700738func (ctx *moduleContextImpl) baseModuleName() string {
739 return ctx.mod.ModuleBase.BaseModuleName()
740}
741
Logan Chienf3511742017-10-31 18:04:35 +0800742func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
743 return ctx.mod.getVndkExtendsModuleName()
744}
745
Jiyong Park58e364a2019-01-19 19:24:06 +0900746func (ctx *moduleContextImpl) apexName() string {
747 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900748}
749
Jiyong Parkb0788572018-12-20 22:10:17 +0900750func (ctx *moduleContextImpl) hasStubsVariants() bool {
751 return ctx.mod.HasStubsVariants()
752}
753
754func (ctx *moduleContextImpl) isStubs() bool {
755 return ctx.mod.IsStubs()
756}
757
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900758func (ctx *moduleContextImpl) bootstrap() bool {
759 return ctx.mod.bootstrap()
760}
761
Colin Cross635c3b02016-05-18 15:37:25 -0700762func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800763 return &Module{
764 hod: hod,
765 multilib: multilib,
766 }
767}
768
Colin Cross635c3b02016-05-18 15:37:25 -0700769func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800770 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700771 module.features = []feature{
772 &tidyFeature{},
773 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700774 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800775 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800776 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800777 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900778 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700779 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700780 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800781 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800782 return module
783}
784
Colin Crossce75d2c2016-10-06 16:12:58 -0700785func (c *Module) Prebuilt() *android.Prebuilt {
786 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
787 return p.prebuilt()
788 }
789 return nil
790}
791
792func (c *Module) Name() string {
793 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700794 if p, ok := c.linker.(interface {
795 Name(string) string
796 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700797 name = p.Name(name)
798 }
799 return name
800}
801
Alex Light3d673592019-01-18 14:37:31 -0800802func (c *Module) Symlinks() []string {
803 if p, ok := c.installer.(interface {
804 symlinkList() []string
805 }); ok {
806 return p.symlinkList()
807 }
808 return nil
809}
810
Jeff Gaston294356f2017-09-27 17:05:30 -0700811// orderDeps reorders dependencies into a list such that if module A depends on B, then
812// A will precede B in the resultant list.
813// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800814// Note that directSharedDeps should be the analogous static library for each shared lib dep
815func 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 -0700816 // If A depends on B, then
817 // Every list containing A will also contain B later in the list
818 // So, after concatenating all lists, the final instance of B will have come from the same
819 // original list as the final instance of A
820 // So, the final instance of B will be later in the concatenation than the final A
821 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
822 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800823 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700824 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800825 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
826 }
827 for _, dep := range directSharedDeps {
828 orderedAllDeps = append(orderedAllDeps, dep)
829 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700830 }
831
Colin Crossb6715442017-10-24 11:13:31 -0700832 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700833
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800834 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700835 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800836 // resultant list to only what the caller has chosen to include in directStaticDeps
837 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700838
839 return orderedAllDeps, orderedDeclaredDeps
840}
841
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800842func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
843 // convert Module to Path
844 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
845 staticDepFiles := []android.Path{}
846 for _, dep := range staticDeps {
847 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
848 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700849 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800850 sharedDepFiles := []android.Path{}
851 for _, sharedDep := range sharedDeps {
852 staticAnalogue := sharedDep.staticVariant
853 if staticAnalogue != nil {
854 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
855 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
856 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700857 }
858
859 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800860 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700861
862 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700863}
864
Colin Cross635c3b02016-05-18 15:37:25 -0700865func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800866 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700867 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800868 moduleContextImpl: moduleContextImpl{
869 mod: c,
870 },
871 }
872 ctx.ctx = ctx
873
Colin Crossf18e1102017-11-16 14:33:08 -0800874 deps := c.depsToPaths(ctx)
875 if ctx.Failed() {
876 return
877 }
878
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700879 if c.Properties.Clang != nil && *c.Properties.Clang == false {
880 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
881 }
882
Colin Crossca860ac2016-01-04 14:34:37 -0800883 flags := Flags{
884 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800885 }
Colin Crossca860ac2016-01-04 14:34:37 -0800886 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800887 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800888 }
889 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700890 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800891 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700892 if c.stl != nil {
893 flags = c.stl.flags(ctx, flags)
894 }
Colin Cross16b23492016-01-06 14:41:07 -0800895 if c.sanitize != nil {
896 flags = c.sanitize.flags(ctx, flags)
897 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800898 if c.coverage != nil {
899 flags = c.coverage.flags(ctx, flags)
900 }
Stephen Craneba090d12017-05-09 15:44:35 -0700901 if c.lto != nil {
902 flags = c.lto.flags(ctx, flags)
903 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700904 if c.pgo != nil {
905 flags = c.pgo.flags(ctx, flags)
906 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800907 if c.xom != nil {
908 flags = c.xom.flags(ctx, flags)
909 }
Colin Crossca860ac2016-01-04 14:34:37 -0800910 for _, feature := range c.features {
911 flags = feature.flags(ctx, flags)
912 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800913 if ctx.Failed() {
914 return
915 }
916
Colin Crossb98c8b02016-07-29 13:44:28 -0700917 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
918 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
919 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800920
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800921 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
922 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700923 // We need access to all the flags seen by a source file.
924 if c.sabi != nil {
925 flags = c.sabi.flags(ctx, flags)
926 }
Colin Crossca860ac2016-01-04 14:34:37 -0800927 // Optimization to reduce size of build.ninja
928 // Replace the long list of flags for each file with a module-local variable
929 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
930 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
931 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
932 flags.CFlags = []string{"$cflags"}
933 flags.CppFlags = []string{"$cppflags"}
934 flags.AsFlags = []string{"$asflags"}
935
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700936 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800937 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700938 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800939 if ctx.Failed() {
940 return
941 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800942 }
943
Colin Crossca860ac2016-01-04 14:34:37 -0800944 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700945 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800946 if ctx.Failed() {
947 return
948 }
Colin Cross635c3b02016-05-18 15:37:25 -0700949 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +0900950
951 // If a lib is directly included in any of the APEXes, unhide the stubs
952 // variant having the latest version gets visible to make. In addition,
953 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
954 // force anything in the make world to link against the stubs library.
955 // (unless it is explicitly referenced via .bootstrap suffix or the
956 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +0000957 if c.HasStubsVariants() &&
958 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Jiyong Parkb0788572018-12-20 22:10:17 +0900959 !c.inRecovery() && !c.useVndk() && !c.static() && c.IsStubs() {
960 c.Properties.HideFromMake = false // unhide
961 // Note: this is still non-installable
962 }
Colin Crossce75d2c2016-10-06 16:12:58 -0700963 }
Colin Cross5049f022015-03-18 13:28:46 -0700964
Jiyong Park9d452992018-10-03 00:38:19 +0900965 if c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() {
Colin Crossce75d2c2016-10-06 16:12:58 -0700966 c.installer.install(ctx, c.outputFile.Path())
967 if ctx.Failed() {
968 return
Colin Crossca860ac2016-01-04 14:34:37 -0800969 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700970 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800971}
972
Jiyong Park379de2f2018-12-19 02:47:14 +0900973func (c *Module) toolchain(ctx android.BaseContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800974 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700975 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800976 }
Colin Crossca860ac2016-01-04 14:34:37 -0800977 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800978}
979
Colin Crossca860ac2016-01-04 14:34:37 -0800980func (c *Module) begin(ctx BaseModuleContext) {
981 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700982 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700983 }
Colin Crossca860ac2016-01-04 14:34:37 -0800984 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700985 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800986 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700987 if c.stl != nil {
988 c.stl.begin(ctx)
989 }
Colin Cross16b23492016-01-06 14:41:07 -0800990 if c.sanitize != nil {
991 c.sanitize.begin(ctx)
992 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800993 if c.coverage != nil {
994 c.coverage.begin(ctx)
995 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800996 if c.sabi != nil {
997 c.sabi.begin(ctx)
998 }
Justin Yun8effde42017-06-23 19:24:43 +0900999 if c.vndkdep != nil {
1000 c.vndkdep.begin(ctx)
1001 }
Stephen Craneba090d12017-05-09 15:44:35 -07001002 if c.lto != nil {
1003 c.lto.begin(ctx)
1004 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001005 if c.pgo != nil {
1006 c.pgo.begin(ctx)
1007 }
Colin Crossca860ac2016-01-04 14:34:37 -08001008 for _, feature := range c.features {
1009 feature.begin(ctx)
1010 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001011 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001012 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001013 if err != nil {
1014 ctx.PropertyErrorf("sdk_version", err.Error())
1015 }
Nan Zhang0007d812017-11-07 10:57:05 -08001016 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001017 }
Colin Crossca860ac2016-01-04 14:34:37 -08001018}
1019
Colin Cross37047f12016-12-13 17:06:13 -08001020func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001021 deps := Deps{}
1022
1023 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001024 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001025 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001026 // Add the PGO dependency (the clang_rt.profile runtime library), which
1027 // sometimes depends on symbols from libgcc, before libgcc gets added
1028 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001029 if c.pgo != nil {
1030 deps = c.pgo.deps(ctx, deps)
1031 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001032 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001033 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001034 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001035 if c.stl != nil {
1036 deps = c.stl.deps(ctx, deps)
1037 }
Colin Cross16b23492016-01-06 14:41:07 -08001038 if c.sanitize != nil {
1039 deps = c.sanitize.deps(ctx, deps)
1040 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001041 if c.coverage != nil {
1042 deps = c.coverage.deps(ctx, deps)
1043 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001044 if c.sabi != nil {
1045 deps = c.sabi.deps(ctx, deps)
1046 }
Justin Yun8effde42017-06-23 19:24:43 +09001047 if c.vndkdep != nil {
1048 deps = c.vndkdep.deps(ctx, deps)
1049 }
Stephen Craneba090d12017-05-09 15:44:35 -07001050 if c.lto != nil {
1051 deps = c.lto.deps(ctx, deps)
1052 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001053 for _, feature := range c.features {
1054 deps = feature.deps(ctx, deps)
1055 }
1056
Colin Crossb6715442017-10-24 11:13:31 -07001057 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1058 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1059 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1060 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1061 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1062 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001063 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001064
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001065 for _, lib := range deps.ReexportSharedLibHeaders {
1066 if !inList(lib, deps.SharedLibs) {
1067 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1068 }
1069 }
1070
1071 for _, lib := range deps.ReexportStaticLibHeaders {
1072 if !inList(lib, deps.StaticLibs) {
1073 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1074 }
1075 }
1076
Colin Cross5950f382016-12-13 12:50:57 -08001077 for _, lib := range deps.ReexportHeaderLibHeaders {
1078 if !inList(lib, deps.HeaderLibs) {
1079 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1080 }
1081 }
1082
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001083 for _, gen := range deps.ReexportGeneratedHeaders {
1084 if !inList(gen, deps.GeneratedHeaders) {
1085 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1086 }
1087 }
1088
Colin Crossc99deeb2016-04-11 15:06:20 -07001089 return deps
1090}
1091
Dan Albert7e9d2952016-08-04 13:02:36 -07001092func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001093 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001094 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001095 moduleContextImpl: moduleContextImpl{
1096 mod: c,
1097 },
1098 }
1099 ctx.ctx = ctx
1100
Colin Crossca860ac2016-01-04 14:34:37 -08001101 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001102}
1103
Jiyong Park7ed9de32018-10-15 22:25:07 +09001104// Split name#version into name and version
1105func stubsLibNameAndVersion(name string) (string, string) {
1106 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1107 version := name[sharp+1:]
1108 libname := name[:sharp]
1109 return libname, version
1110 }
1111 return name, ""
1112}
1113
Colin Cross1e676be2016-10-12 14:38:15 -07001114func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001115 ctx := &depsContext{
1116 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001117 moduleContextImpl: moduleContextImpl{
1118 mod: c,
1119 },
1120 }
1121 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001122
Colin Crossc99deeb2016-04-11 15:06:20 -07001123 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001124
Dan Albert914449f2016-06-17 16:45:24 -07001125 variantNdkLibs := []string{}
1126 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001127 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001128 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001129
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001130 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1131 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001132 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001133 // 1. Name of an NDK library that refers to a prebuilt module.
1134 // For each of these, it adds the name of the prebuilt module (which will be in
1135 // prebuilts/ndk) to the list of nonvariant libs.
1136 // 2. Name of an NDK library that refers to an ndk_library module.
1137 // For each of these, it adds the name of the ndk_library module to the list of
1138 // variant libs.
1139 // 3. Anything else (so anything that isn't an NDK library).
1140 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001141 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001142 // The caller can then know to add the variantLibs dependencies differently from the
1143 // nonvariantLibs
1144 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1145 variantLibs = []string{}
1146 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001147 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001148 // strip #version suffix out
1149 name, _ := stubsLibNameAndVersion(entry)
1150 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1151 if !inList(name, ndkMigratedLibs) {
1152 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001153 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001154 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001155 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001156 } else if ctx.useVndk() && inList(name, llndkLibraries) {
1157 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
1158 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, vendorPublicLibraries) {
1159 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001160 if actx.OtherModuleExists(vendorPublicLib) {
1161 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1162 } else {
1163 // This can happen if vendor_public_library module is defined in a
1164 // namespace that isn't visible to the current module. In that case,
1165 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001166 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001167 }
Dan Albert914449f2016-06-17 16:45:24 -07001168 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001169 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001170 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001171 }
1172 }
Dan Albert914449f2016-06-17 16:45:24 -07001173 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001174 }
1175
Dan Albert914449f2016-06-17 16:45:24 -07001176 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1177 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001178 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001179 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001180
Jiyong Park7e636d02019-01-28 16:16:54 +09001181 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001182 if c.linker != nil {
1183 if library, ok := c.linker.(*libraryDecorator); ok {
1184 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001185 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001186 }
1187 }
1188 }
1189
Colin Cross32ec36c2016-12-15 07:39:51 -08001190 for _, lib := range deps.HeaderLibs {
1191 depTag := headerDepTag
1192 if inList(lib, deps.ReexportHeaderLibHeaders) {
1193 depTag = headerExportDepTag
1194 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001195 if buildStubs {
Jiyong Park7e636d02019-01-28 16:16:54 +09001196 actx.AddFarVariationDependencies([]blueprint.Variation{
1197 {Mutator: "arch", Variation: ctx.Target().String()},
Jiyong Park3b1746a2019-01-29 11:15:04 +09001198 {Mutator: "image", Variation: c.imageVariation()},
Jiyong Park7e636d02019-01-28 16:16:54 +09001199 }, depTag, lib)
1200 } else {
1201 actx.AddVariationDependencies(nil, depTag, lib)
1202 }
1203 }
1204
1205 if buildStubs {
1206 // Stubs lib does not have dependency to other static/shared libraries.
1207 // Don't proceed.
1208 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001209 }
Colin Cross5950f382016-12-13 12:50:57 -08001210
Dan Willemsen59339a22018-07-22 21:18:45 -07001211 actx.AddVariationDependencies([]blueprint.Variation{
1212 {Mutator: "link", Variation: "static"},
1213 }, wholeStaticDepTag, deps.WholeStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001214
Inseob Kimc0907f12019-02-08 21:00:45 +09001215 syspropImplLibraries := syspropImplLibraries(actx.Config())
1216
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001217 for _, lib := range deps.StaticLibs {
1218 depTag := staticDepTag
1219 if inList(lib, deps.ReexportStaticLibHeaders) {
1220 depTag = staticExportDepTag
1221 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001222
1223 if impl, ok := syspropImplLibraries[lib]; ok {
1224 lib = impl
1225 }
1226
Dan Willemsen59339a22018-07-22 21:18:45 -07001227 actx.AddVariationDependencies([]blueprint.Variation{
1228 {Mutator: "link", Variation: "static"},
1229 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001230 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001231
Dan Willemsen59339a22018-07-22 21:18:45 -07001232 actx.AddVariationDependencies([]blueprint.Variation{
1233 {Mutator: "link", Variation: "static"},
1234 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001235
Jiyong Park25fc6a92018-11-18 18:02:45 +09001236 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1237 var variations []blueprint.Variation
1238 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001239 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001240 if version != "" && versionVariantAvail {
1241 // Version is explicitly specified. i.e. libFoo#30
1242 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1243 depTag.explicitlyVersioned = true
1244 }
1245 actx.AddVariationDependencies(variations, depTag, name)
1246
1247 // If the version is not specified, add dependency to the latest stubs library.
1248 // The stubs library will be used when the depending module is built for APEX and
1249 // the dependent module is not in the same APEX.
1250 latestVersion := latestStubsVersionFor(actx.Config(), name)
1251 if version == "" && latestVersion != "" && versionVariantAvail {
1252 actx.AddVariationDependencies([]blueprint.Variation{
1253 {Mutator: "link", Variation: "shared"},
1254 {Mutator: "version", Variation: latestVersion},
1255 }, depTag, name)
1256 // Note that depTag.explicitlyVersioned is false in this case.
1257 }
1258 }
1259
Jiyong Park7ed9de32018-10-15 22:25:07 +09001260 // shared lib names without the #version suffix
1261 var sharedLibNames []string
1262
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001263 for _, lib := range deps.SharedLibs {
1264 depTag := sharedDepTag
1265 if inList(lib, deps.ReexportSharedLibHeaders) {
1266 depTag = sharedExportDepTag
1267 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001268
1269 if impl, ok := syspropImplLibraries[lib]; ok {
1270 lib = impl
1271 }
1272
1273 name, version := stubsLibNameAndVersion(lib)
1274 sharedLibNames = append(sharedLibNames, name)
1275
Jiyong Park25fc6a92018-11-18 18:02:45 +09001276 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001277 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001278
Jiyong Park7ed9de32018-10-15 22:25:07 +09001279 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001280 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001281 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1282 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1283 // linking against both the stubs lib and the non-stubs lib at the same time.
1284 continue
1285 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001286 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001287 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001288
Dan Willemsen59339a22018-07-22 21:18:45 -07001289 actx.AddVariationDependencies([]blueprint.Variation{
1290 {Mutator: "link", Variation: "shared"},
1291 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001292
Colin Cross68861832016-07-08 10:41:41 -07001293 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001294
1295 for _, gen := range deps.GeneratedHeaders {
1296 depTag := genHeaderDepTag
1297 if inList(gen, deps.ReexportGeneratedHeaders) {
1298 depTag = genHeaderExportDepTag
1299 }
1300 actx.AddDependency(c, depTag, gen)
1301 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001302
Colin Cross42d48b72018-08-29 14:10:52 -07001303 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001304
1305 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001306 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001307 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001308 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001309 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001310 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001311 if deps.LinkerFlagsFile != "" {
1312 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1313 }
1314 if deps.DynamicLinker != "" {
1315 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001316 }
Dan Albert914449f2016-06-17 16:45:24 -07001317
1318 version := ctx.sdkVersion()
1319 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001320 {Mutator: "ndk_api", Variation: version},
1321 {Mutator: "link", Variation: "shared"},
1322 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001323 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001324 {Mutator: "ndk_api", Variation: version},
1325 {Mutator: "link", Variation: "shared"},
1326 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001327
1328 if vndkdep := c.vndkdep; vndkdep != nil {
1329 if vndkdep.isVndkExt() {
1330 baseModuleMode := vendorMode
1331 if actx.DeviceConfig().VndkVersion() == "" {
1332 baseModuleMode = coreMode
1333 }
1334 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001335 {Mutator: "image", Variation: baseModuleMode},
1336 {Mutator: "link", Variation: "shared"},
1337 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001338 }
1339 }
Colin Cross6362e272015-10-29 15:25:03 -07001340}
Colin Cross21b9a242015-03-24 14:15:58 -07001341
Colin Crosse40b4ea2018-10-02 22:25:58 -07001342func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001343 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1344 c.beginMutator(ctx)
1345 }
1346}
1347
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001348// Whether a module can link to another module, taking into
1349// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001350func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001351 if from.Target().Os != android.Android {
1352 // Host code is not restricted
1353 return
1354 }
1355 if from.Properties.UseVndk {
1356 // Though vendor code is limited by the vendor mutator,
1357 // each vendor-available module needs to check
1358 // link-type for VNDK.
1359 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001360 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001361 }
1362 return
1363 }
Nan Zhang0007d812017-11-07 10:57:05 -08001364 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001365 // Platform code can link to anything
1366 return
1367 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001368 if from.inRecovery() {
1369 // Recovery code is not NDK
1370 return
1371 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001372 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1373 // These are always allowed
1374 return
1375 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001376 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1377 // These are allowed, but they don't set sdk_version
1378 return
1379 }
1380 if _, ok := to.linker.(*stubDecorator); ok {
1381 // These aren't real libraries, but are the stub shared libraries that are included in
1382 // the NDK.
1383 return
1384 }
Logan Chien834b9a62019-01-14 15:39:03 +08001385
1386 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" {
1387 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1388 // to link to libc++ (non-NDK and without sdk_version).
1389 return
1390 }
1391
Nan Zhang0007d812017-11-07 10:57:05 -08001392 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001393 // NDK code linking to platform code is never okay.
1394 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1395 ctx.OtherModuleName(to))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001396 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001397 }
1398
1399 // At this point we know we have two NDK libraries, but we need to
1400 // check that we're not linking against anything built against a higher
1401 // API level, as it is only valid to link against older or equivalent
1402 // APIs.
1403
Inseob Kim01a28722018-04-11 09:48:45 +09001404 // Current can link against anything.
1405 if String(from.Properties.Sdk_version) != "current" {
1406 // Otherwise we need to check.
1407 if String(to.Properties.Sdk_version) == "current" {
1408 // Current can't be linked against by anything else.
1409 ctx.ModuleErrorf("links %q built against newer API version %q",
1410 ctx.OtherModuleName(to), "current")
1411 } else {
1412 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1413 if err != nil {
1414 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001415 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001416 String(from.Properties.Sdk_version))
1417 }
1418 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1419 if err != nil {
1420 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001421 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001422 String(to.Properties.Sdk_version))
1423 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001424
Inseob Kim01a28722018-04-11 09:48:45 +09001425 if toApi > fromApi {
1426 ctx.ModuleErrorf("links %q built against newer API version %q",
1427 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1428 }
1429 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001430 }
Dan Albert202fe492017-12-15 13:56:59 -08001431
1432 // Also check that the two STL choices are compatible.
1433 fromStl := from.stl.Properties.SelectedStl
1434 toStl := to.stl.Properties.SelectedStl
1435 if fromStl == "" || toStl == "" {
1436 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001437 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001438 // We can be permissive with the system "STL" since it is only the C++
1439 // ABI layer, but in the future we should make sure that everyone is
1440 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001441 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001442 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1443 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1444 to.stl.Properties.SelectedStl)
1445 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001446}
1447
Jiyong Park5fb8c102018-04-09 12:03:06 +09001448// Tests whether the dependent library is okay to be double loaded inside a single process.
1449// If a library is a member of VNDK and at the same time dependencies of an LLNDK library,
1450// it is subject to be double loaded. Such lib should be explicitly marked as double_loaded: true
1451// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
1452func checkDoubleLoadableLibries(ctx android.ModuleContext, from *Module, to *Module) {
1453 if _, ok := from.linker.(*libraryDecorator); !ok {
1454 return
1455 }
1456
1457 if inList(ctx.ModuleName(), llndkLibraries) ||
1458 (from.useVndk() && Bool(from.VendorProperties.Double_loadable)) {
1459 _, depIsLlndk := to.linker.(*llndkStubDecorator)
1460 depIsVndkSp := false
1461 if to.vndkdep != nil && to.vndkdep.isVndkSp() {
1462 depIsVndkSp = true
1463 }
1464 depIsVndk := false
1465 if to.vndkdep != nil && to.vndkdep.isVndk() {
1466 depIsVndk = true
1467 }
1468 depIsDoubleLoadable := Bool(to.VendorProperties.Double_loadable)
1469 if !depIsLlndk && !depIsVndkSp && !depIsDoubleLoadable && depIsVndk {
Steven Moreland742989e2018-11-26 12:41:04 -08001470 ctx.ModuleErrorf("links VNDK library %q that isn't double loadable (not also LL-NDK, "+
1471 "VNDK-SP, or explicitly marked as 'double_loadable').",
Jiyong Park5fb8c102018-04-09 12:03:06 +09001472 ctx.OtherModuleName(to))
1473 }
1474 }
1475}
1476
Colin Crossc99deeb2016-04-11 15:06:20 -07001477// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001478func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001479 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001480
Jeff Gaston294356f2017-09-27 17:05:30 -07001481 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001482 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001483
Colin Crossd11fcda2017-10-23 17:59:01 -07001484 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001485 depName := ctx.OtherModuleName(dep)
1486 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001487
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001488 ccDep, _ := dep.(*Module)
1489 if ccDep == nil {
1490 // handling for a few module types that aren't cc Module but that are also supported
1491 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001492 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001493 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001494 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1495 genRule.GeneratedSourceFiles()...)
1496 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001497 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001498 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001499 // Support exported headers from a generated_sources dependency
1500 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001501 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001502 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001503 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001504 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001505 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001506 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001507 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001508 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001509 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001510 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001511 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1512 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1513
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001514 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001515 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001516 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001517 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001518 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001519 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001520 files := genRule.GeneratedSourceFiles()
1521 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001522 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001523 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001524 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 -07001525 }
1526 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001527 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001528 }
Colin Crossca860ac2016-01-04 14:34:37 -08001529 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001530 return
1531 }
1532
Colin Crossd11fcda2017-10-23 17:59:01 -07001533 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001534 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1535 return
1536 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001537 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001538 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001539 return
1540 }
1541
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001542 // re-exporting flags
1543 if depTag == reuseObjTag {
1544 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001545 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001546 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001547 depPaths.Objs = depPaths.Objs.Append(objs)
1548 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001549 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001550 return
1551 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001552 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001553
Jiyong Parke4bb9862019-02-01 00:31:10 +09001554 if depTag == staticVariantTag {
1555 if _, ok := ccDep.compiler.(libraryInterface); ok {
1556 c.staticVariant = ccDep
1557 return
1558 }
1559 }
1560
Jiyong Park25fc6a92018-11-18 18:02:45 +09001561 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1562 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1563 // won't be matched to sharedDepTag and lateSharedDepTag.
1564 explicitlyVersioned := false
1565 if t, ok := depTag.(dependencyTag); ok {
1566 explicitlyVersioned = t.explicitlyVersioned
1567 t.explicitlyVersioned = false
1568 depTag = t
1569 }
1570
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001571 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001572 depIsStatic := false
1573 switch depTag {
1574 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1575 depIsStatic = true
1576 }
1577 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001578 depIsStubs := dependentLibrary.buildStubs()
1579 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001580 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001581 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001582
1583 var useThisDep bool
1584 if depIsStubs && explicitlyVersioned {
1585 // Always respect dependency to the versioned stubs (i.e. libX#10)
1586 useThisDep = true
1587 } else if !depHasStubs {
1588 // Use non-stub variant if that is the only choice
1589 // (i.e. depending on a lib without stubs.version property)
1590 useThisDep = true
1591 } else if c.IsForPlatform() {
1592 // If not building for APEX, use stubs only when it is from
1593 // an APEX (and not from platform)
1594 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001595 if c.inRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001596 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001597 // always link to non-stub variant
1598 useThisDep = !depIsStubs
1599 }
1600 } else {
1601 // If building for APEX, use stubs only when it is not from
1602 // the same APEX
1603 useThisDep = (depInSameApex != depIsStubs)
1604 }
1605
1606 if !useThisDep {
1607 return // stop processing this dep
1608 }
1609 }
1610
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001611 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001612 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001613 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001614 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001615 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001616
1617 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001618 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001619 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001620 // 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 -07001621 // Re-exported shared library headers must be included as well since they can help us with type information
1622 // about template instantiations (instantiated from their headers).
1623 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001624 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001625 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001626
Logan Chienf3511742017-10-31 18:04:35 +08001627 checkLinkType(ctx, c, ccDep, t)
Jiyong Park5fb8c102018-04-09 12:03:06 +09001628 checkDoubleLoadableLibries(ctx, c, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001629 }
1630
Colin Cross26c34ed2016-09-30 17:10:16 -07001631 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001632 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001633
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001634 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001635 depFile := android.OptionalPath{}
1636
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001637 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001638 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001639 ptr = &depPaths.SharedLibs
1640 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001641 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001642 directSharedDeps = append(directSharedDeps, ccDep)
Jiyong Park64a44f22019-01-18 14:37:08 +09001643 case earlySharedDepTag:
1644 ptr = &depPaths.EarlySharedLibs
1645 depPtr = &depPaths.EarlySharedLibsDeps
1646 depFile = ccDep.linker.(libraryInterface).toc()
1647 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001648 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001649 ptr = &depPaths.LateSharedLibs
1650 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001651 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001652 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001653 ptr = nil
1654 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001655 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001656 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001657 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001658 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001659 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001660 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001661 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001662 return
1663 }
1664
1665 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001666 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001667 for i := range missingDeps {
1668 missingDeps[i] += postfix
1669 }
1670 ctx.AddMissingDependencies(missingDeps)
1671 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001672 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001673 case headerDepTag:
1674 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001675 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001676 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001677 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001678 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001679 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001680 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001681 case dynamicLinkerDepTag:
1682 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001683 }
1684
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001685 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001686 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001687 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001688 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001689 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001690 return
1691 }
1692
1693 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001694 // in static libraries act as if they were whole static libraries. The same goes for
1695 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001696 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1697 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001698 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1699 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001700
Dan Willemsen581341d2017-02-09 16:16:31 -08001701 }
1702
Colin Cross26c34ed2016-09-30 17:10:16 -07001703 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001704 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001705 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001706 return
1707 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001708 *ptr = append(*ptr, linkFile.Path())
1709 }
1710
Colin Crossc99deeb2016-04-11 15:06:20 -07001711 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001712 dep := depFile
1713 if !dep.Valid() {
1714 dep = linkFile
1715 }
1716 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001717 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001718
Logan Chien43d34c32017-12-20 01:17:32 +08001719 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001720 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001721 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001722 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001723 isLLndk := inList(libName, llndkLibraries)
Jiyong Park374510b2018-03-19 18:23:01 +09001724 isVendorPublicLib := inList(libName, vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001725 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1726 if c.useVndk() && bothVendorAndCoreVariantsExist {
1727 // The vendor module in Make will have been renamed to not conflict with the core
1728 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001729 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001730 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001731 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001732 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1733 return libName + recoverySuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001734 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001735 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001736 }
Logan Chien43d34c32017-12-20 01:17:32 +08001737 }
1738
1739 // Export the shared libs to Make.
1740 switch depTag {
Jiyong Park64a44f22019-01-18 14:37:08 +09001741 case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001742 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001743 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08001744 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09001745 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001746 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001747 c.Properties.ApexesProvidingSharedLibs = append(
1748 c.Properties.ApexesProvidingSharedLibs, an)
1749 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09001750 }
1751 }
1752
Jiyong Park27b188b2017-07-18 13:23:39 +09001753 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001754 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001755 c.Properties.AndroidMkSharedLibs = append(
1756 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08001757 case ndkStubDepTag, ndkLateStubDepTag:
1758 ndkStub := ccDep.linker.(*stubDecorator)
1759 c.Properties.AndroidMkSharedLibs = append(
1760 c.Properties.AndroidMkSharedLibs,
1761 depName+"."+ndkStub.properties.ApiLevel)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001762 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1763 c.Properties.AndroidMkStaticLibs = append(
1764 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001765 case runtimeDepTag:
1766 c.Properties.AndroidMkRuntimeLibs = append(
1767 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001768 case wholeStaticDepTag:
1769 c.Properties.AndroidMkWholeStaticLibs = append(
1770 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001771 }
Colin Crossca860ac2016-01-04 14:34:37 -08001772 })
1773
Jeff Gaston294356f2017-09-27 17:05:30 -07001774 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001775 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001776
Colin Crossdd84e052017-05-17 13:44:16 -07001777 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001778 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001779 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001780 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001781 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1782
1783 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001784 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001785 }
Colin Crossdd84e052017-05-17 13:44:16 -07001786
Colin Crossca860ac2016-01-04 14:34:37 -08001787 return depPaths
1788}
1789
1790func (c *Module) InstallInData() bool {
1791 if c.installer == nil {
1792 return false
1793 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001794 return c.installer.inData()
1795}
1796
1797func (c *Module) InstallInSanitizerDir() bool {
1798 if c.installer == nil {
1799 return false
1800 }
1801 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001802 return true
1803 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001804 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001805}
1806
Jiyong Parkf9332f12018-02-01 00:54:12 +09001807func (c *Module) InstallInRecovery() bool {
1808 return c.inRecovery()
1809}
1810
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001811func (c *Module) HostToolPath() android.OptionalPath {
1812 if c.installer == nil {
1813 return android.OptionalPath{}
1814 }
1815 return c.installer.hostToolPath()
1816}
1817
Nan Zhangd4e641b2017-07-12 12:55:28 -07001818func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1819 return c.outputFile
1820}
1821
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001822func (c *Module) Srcs() android.Paths {
1823 if c.outputFile.Valid() {
1824 return android.Paths{c.outputFile.Path()}
1825 }
1826 return android.Paths{}
1827}
1828
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001829func (c *Module) static() bool {
1830 if static, ok := c.linker.(interface {
1831 static() bool
1832 }); ok {
1833 return static.static()
1834 }
1835 return false
1836}
1837
Jiyong Park379de2f2018-12-19 02:47:14 +09001838func (c *Module) staticBinary() bool {
1839 if static, ok := c.linker.(interface {
1840 staticBinary() bool
1841 }); ok {
1842 return static.staticBinary()
1843 }
1844 return false
1845}
1846
Colin Crossb60190a2018-09-04 16:28:17 -07001847func (c *Module) getMakeLinkType() string {
1848 if c.useVndk() {
1849 if inList(c.Name(), vndkCoreLibraries) || inList(c.Name(), vndkSpLibraries) || inList(c.Name(), llndkLibraries) {
1850 if inList(c.Name(), vndkPrivateLibraries) {
1851 return "native:vndk_private"
1852 } else {
1853 return "native:vndk"
1854 }
1855 } else {
1856 return "native:vendor"
1857 }
1858 } else if c.inRecovery() {
1859 return "native:recovery"
1860 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
1861 return "native:ndk:none:none"
1862 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
1863 //family, link := getNdkStlFamilyAndLinkType(c)
1864 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
1865 } else {
1866 return "native:platform"
1867 }
1868}
1869
Jiyong Park9d452992018-10-03 00:38:19 +09001870// Overrides ApexModule.IsInstallabeToApex()
1871// Only shared libraries are installable to APEX.
1872func (c *Module) IsInstallableToApex() bool {
1873 if shared, ok := c.linker.(interface {
1874 shared() bool
1875 }); ok {
1876 return shared.shared()
1877 }
1878 return false
1879}
1880
Jiyong Park3b1746a2019-01-29 11:15:04 +09001881func (c *Module) imageVariation() string {
1882 variation := "core"
1883 if c.useVndk() {
1884 variation = "vendor"
1885 } else if c.inRecovery() {
1886 variation = "recovery"
1887 }
1888 return variation
1889}
1890
Colin Cross2ba19d92015-05-07 15:44:20 -07001891//
Colin Crosscfad1192015-11-02 16:43:11 -08001892// Defaults
1893//
Colin Crossca860ac2016-01-04 14:34:37 -08001894type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001895 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001896 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09001897 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001898}
1899
Colin Cross635c3b02016-05-18 15:37:25 -07001900func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001901}
1902
Colin Cross36242852017-06-23 15:06:31 -07001903func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001904 return DefaultsFactory()
1905}
1906
Colin Cross36242852017-06-23 15:06:31 -07001907func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001908 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001909
Colin Cross36242852017-06-23 15:06:31 -07001910 module.AddProperties(props...)
1911 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001912 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001913 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001914 &BaseCompilerProperties{},
1915 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001916 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001917 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001918 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001919 &TestProperties{},
1920 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001921 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001922 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001923 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001924 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001925 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001926 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001927 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001928 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001929 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001930 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08001931 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001932 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001933 )
Colin Crosscfad1192015-11-02 16:43:11 -08001934
Colin Cross1f44a3a2017-07-07 14:33:33 -07001935 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09001936 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001937
1938 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001939}
1940
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001941const (
1942 // coreMode is the variant used for framework-private libraries, or
1943 // SDK libraries. (which framework-private libraries can use)
1944 coreMode = "core"
1945
1946 // vendorMode is the variant used for /vendor code that compiles
1947 // against the VNDK.
1948 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09001949
1950 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001951)
1952
Jiyong Park6a43f042017-10-12 23:05:00 +09001953func squashVendorSrcs(m *Module) {
1954 if lib, ok := m.compiler.(*libraryDecorator); ok {
1955 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1956 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1957
1958 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1959 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1960 }
1961}
1962
Jiyong Parkf9332f12018-02-01 00:54:12 +09001963func squashRecoverySrcs(m *Module) {
1964 if lib, ok := m.compiler.(*libraryDecorator); ok {
1965 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1966 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
1967
1968 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1969 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
1970 }
1971}
1972
Jiyong Parkda6eb592018-12-19 17:12:36 +09001973func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001974 if mctx.Os() != android.Android {
1975 return
1976 }
1977
Jiyong Park7ed9de32018-10-15 22:25:07 +09001978 if g, ok := mctx.Module().(*genrule.Module); ok {
1979 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09001980 var coreVariantNeeded bool = false
1981 var vendorVariantNeeded bool = false
1982 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09001983 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09001984 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001985 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09001986 coreVariantNeeded = true
1987 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09001988 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09001989 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001990 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09001991 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001992 }
Jiyong Park3f736c92018-05-24 13:36:56 +09001993 if Bool(props.Recovery_available) {
1994 recoveryVariantNeeded = true
1995 }
1996
Jiyong Park413cc742018-06-19 01:46:06 +09001997 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09001998 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09001999 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09002000 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002001 recoveryVariantNeeded = false
2002 }
2003 }
2004
Jiyong Park3f736c92018-05-24 13:36:56 +09002005 var variants []string
2006 if coreVariantNeeded {
2007 variants = append(variants, coreMode)
2008 }
2009 if vendorVariantNeeded {
2010 variants = append(variants, vendorMode)
2011 }
2012 if recoveryVariantNeeded {
2013 variants = append(variants, recoveryMode)
2014 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002015 mod := mctx.CreateVariations(variants...)
2016 for i, v := range variants {
2017 if v == recoveryMode {
2018 m := mod[i].(*genrule.Module)
2019 m.Extra.(*GenruleExtraProperties).InRecovery = true
2020 }
2021 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002022 }
2023 }
2024
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002025 m, ok := mctx.Module().(*Module)
2026 if !ok {
2027 return
2028 }
2029
2030 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002031 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002032 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002033
2034 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002035 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002036 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002037 return
2038 }
Logan Chienf3511742017-10-31 18:04:35 +08002039
2040 if vndkdep := m.vndkdep; vndkdep != nil {
2041 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002042 if productSpecific {
2043 mctx.PropertyErrorf("product_specific",
2044 "product_specific must not be true when `vndk: {enabled: true}`")
2045 return
2046 }
Logan Chienf3511742017-10-31 18:04:35 +08002047 if vendorSpecific {
2048 if !vndkdep.isVndkExt() {
2049 mctx.PropertyErrorf("vndk",
2050 "must set `extends: \"...\"` to vndk extension")
2051 return
2052 }
2053 } else {
2054 if vndkdep.isVndkExt() {
2055 mctx.PropertyErrorf("vndk",
2056 "must set `vendor: true` to set `extends: %q`",
2057 m.getVndkExtendsModuleName())
2058 return
2059 }
2060 if m.VendorProperties.Vendor_available == nil {
2061 mctx.PropertyErrorf("vndk",
2062 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2063 return
2064 }
2065 }
2066 } else {
2067 if vndkdep.isVndkSp() {
2068 mctx.PropertyErrorf("vndk",
2069 "must set `enabled: true` to set `support_system_process: true`")
2070 return
2071 }
2072 if vndkdep.isVndkExt() {
2073 mctx.PropertyErrorf("vndk",
2074 "must set `enabled: true` to set `extends: %q`",
2075 m.getVndkExtendsModuleName())
2076 return
2077 }
Justin Yun8effde42017-06-23 19:24:43 +09002078 }
2079 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002080
Jiyong Parkf9332f12018-02-01 00:54:12 +09002081 var coreVariantNeeded bool = false
2082 var vendorVariantNeeded bool = false
2083 var recoveryVariantNeeded bool = false
2084
Justin Yun71549282017-11-17 12:10:28 +09002085 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002086 // If the device isn't compiling against the VNDK, we always
2087 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002088 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002089 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2090 // LL-NDK stubs only exist in the vendor variant, since the
2091 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002092 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09002093 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2094 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09002095 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09002096 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002097 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2098 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002099 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002100 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002101 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002102 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002103 coreVariantNeeded = true
2104 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002105 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002106 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09002107 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002108 } else {
2109 // This is either in /system (or similar: /data), or is a
2110 // modules built with the NDK. Modules built with the NDK
2111 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002112 coreVariantNeeded = true
2113 }
2114
2115 if Bool(m.Properties.Recovery_available) {
2116 recoveryVariantNeeded = true
2117 }
2118
2119 if m.ModuleBase.InstallInRecovery() {
2120 recoveryVariantNeeded = true
2121 coreVariantNeeded = false
2122 }
2123
Jiyong Park413cc742018-06-19 01:46:06 +09002124 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002125 primaryArch := mctx.Config().DevicePrimaryArchType()
2126 moduleArch := m.Target().Arch.ArchType
2127 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002128 recoveryVariantNeeded = false
2129 }
2130 }
2131
Jiyong Parkf9332f12018-02-01 00:54:12 +09002132 var variants []string
2133 if coreVariantNeeded {
2134 variants = append(variants, coreMode)
2135 }
2136 if vendorVariantNeeded {
2137 variants = append(variants, vendorMode)
2138 }
2139 if recoveryVariantNeeded {
2140 variants = append(variants, recoveryMode)
2141 }
2142 mod := mctx.CreateVariations(variants...)
2143 for i, v := range variants {
2144 if v == vendorMode {
2145 m := mod[i].(*Module)
2146 m.Properties.UseVndk = true
2147 squashVendorSrcs(m)
2148 } else if v == recoveryMode {
2149 m := mod[i].(*Module)
2150 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002151 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002152 squashRecoverySrcs(m)
2153 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002154 }
2155}
2156
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002157func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002158 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002159 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2160 }
Colin Cross6510f912017-11-29 00:27:14 -08002161 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002162}
2163
Colin Cross06a931b2015-10-28 17:23:31 -07002164var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002165var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002166var BoolPtr = proptools.BoolPtr
2167var String = proptools.String
2168var StringPtr = proptools.StringPtr