blob: 117bbc2a814a3b6f3dc9d9e704497dc15061a3a9 [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 Nainar1acd4472018-12-10 15:12:40 -080066 ctx.BottomUp("coverage", coverageMutator).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
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800261 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800262 useClangLld(actx ModuleContext) bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900263 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900264 hasStubsVariants() bool
265 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900266 bootstrap() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800267}
268
269type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700270 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800271 ModuleContextIntf
272}
273
274type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700275 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800276 ModuleContextIntf
277}
278
Colin Cross37047f12016-12-13 17:06:13 -0800279type DepsContext interface {
280 android.BottomUpMutatorContext
281 ModuleContextIntf
282}
283
Colin Crossca860ac2016-01-04 14:34:37 -0800284type feature interface {
285 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800286 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800287 flags(ctx ModuleContext, flags Flags) Flags
288 props() []interface{}
289}
290
291type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700292 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800293 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800294 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700295 compilerProps() []interface{}
296
Colin Cross76fada02016-07-27 10:31:13 -0700297 appendCflags([]string)
298 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700299 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800300}
301
302type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700303 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800304 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700305 linkerFlags(ctx ModuleContext, flags Flags) Flags
306 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800307 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700308
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700309 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700310 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900311 unstrippedOutputFilePath() android.Path
Colin Crossca860ac2016-01-04 14:34:37 -0800312}
313
314type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700315 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700316 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800317 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700318 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700319 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900320 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800321}
322
Colin Crossc99deeb2016-04-11 15:06:20 -0700323type dependencyTag struct {
324 blueprint.BaseDependencyTag
325 name string
326 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700327
328 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900329
330 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700331}
332
333var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700334 sharedDepTag = dependencyTag{name: "shared", library: true}
335 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
Jiyong Park64a44f22019-01-18 14:37:08 +0900336 earlySharedDepTag = dependencyTag{name: "early_shared", library: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700337 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
338 staticDepTag = dependencyTag{name: "static", library: true}
339 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
340 lateStaticDepTag = dependencyTag{name: "late static", library: true}
341 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800342 headerDepTag = dependencyTag{name: "header", library: true}
343 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700344 genSourceDepTag = dependencyTag{name: "gen source"}
345 genHeaderDepTag = dependencyTag{name: "gen header"}
346 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
347 objDepTag = dependencyTag{name: "obj"}
348 crtBeginDepTag = dependencyTag{name: "crtbegin"}
349 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700350 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
351 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700352 reuseObjTag = dependencyTag{name: "reuse objects"}
Jiyong Parke4bb9862019-02-01 00:31:10 +0900353 staticVariantTag = dependencyTag{name: "static variant"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700354 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
355 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800356 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800357 runtimeDepTag = dependencyTag{name: "runtime lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700358)
359
Colin Crossca860ac2016-01-04 14:34:37 -0800360// Module contains the properties and members used by all C/C++ module types, and implements
361// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
362// to construct the output file. Behavior can be customized with a Customizer interface
363type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700364 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700365 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900366 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700367
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700368 Properties BaseProperties
369 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700370
Colin Crossca860ac2016-01-04 14:34:37 -0800371 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700372 hod android.HostOrDeviceSupported
373 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700374
Colin Crossca860ac2016-01-04 14:34:37 -0800375 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700376 features []feature
377 compiler compiler
378 linker linker
379 installer installer
380 stl *stl
381 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800382 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800383 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900384 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700385 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700386 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800387 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800388
389 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700390
Colin Cross635c3b02016-05-18 15:37:25 -0700391 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800392
Colin Crossb98c8b02016-07-29 13:44:28 -0700393 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700394
395 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800396
397 // Flags used to compile this module
398 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700399
400 // 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 -0800401 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700402 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800403 depsInLinkOrder android.Paths
404
405 // only non-nil when this is a shared library that reuses the objects of a static library
406 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700407}
408
Jiyong Parkc20eee32018-09-05 22:36:17 +0900409func (c *Module) OutputFile() android.OptionalPath {
410 return c.outputFile
411}
412
Jiyong Park719b4462019-01-13 00:39:51 +0900413func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900414 if c.linker != nil {
415 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900416 }
417 return nil
418}
419
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900420func (c *Module) RelativeInstallPath() string {
421 if c.installer != nil {
422 return c.installer.relativeInstallPath()
423 }
424 return ""
425}
426
Colin Cross36242852017-06-23 15:06:31 -0700427func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700428 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800429 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700430 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800431 }
432 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700433 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800434 }
435 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700436 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800437 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700438 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700439 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700440 }
Colin Cross16b23492016-01-06 14:41:07 -0800441 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700442 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800443 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800444 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700445 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800446 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800447 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700448 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800449 }
Justin Yun8effde42017-06-23 19:24:43 +0900450 if c.vndkdep != nil {
451 c.AddProperties(c.vndkdep.props()...)
452 }
Stephen Craneba090d12017-05-09 15:44:35 -0700453 if c.lto != nil {
454 c.AddProperties(c.lto.props()...)
455 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700456 if c.pgo != nil {
457 c.AddProperties(c.pgo.props()...)
458 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800459 if c.xom != nil {
460 c.AddProperties(c.xom.props()...)
461 }
Colin Crossca860ac2016-01-04 14:34:37 -0800462 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700463 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800464 }
Colin Crossc472d572015-03-17 15:06:21 -0700465
Colin Crossa9d8bee2018-10-02 13:59:46 -0700466 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
467 switch class {
468 case android.Device:
469 return ctx.Config().DevicePrefer32BitExecutables()
470 case android.HostCross:
471 // Windows builds always prefer 32-bit
472 return true
473 default:
474 return false
475 }
476 })
Colin Cross36242852017-06-23 15:06:31 -0700477 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700478
Colin Cross1f44a3a2017-07-07 14:33:33 -0700479 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700480
Jiyong Park9d452992018-10-03 00:38:19 +0900481 android.InitApexModule(c)
482
Colin Cross36242852017-06-23 15:06:31 -0700483 return c
Colin Crossc472d572015-03-17 15:06:21 -0700484}
485
Colin Crossb916a382016-07-29 17:28:03 -0700486// Returns true for dependency roots (binaries)
487// TODO(ccross): also handle dlopenable libraries
488func (c *Module) isDependencyRoot() bool {
489 if root, ok := c.linker.(interface {
490 isDependencyRoot() bool
491 }); ok {
492 return root.isDependencyRoot()
493 }
494 return false
495}
496
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700497func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700498 return c.Properties.UseVndk
499}
500
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800501func (c *Module) isCoverageVariant() bool {
502 return c.coverage.Properties.IsCoverageVariant
503}
504
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800505func (c *Module) isNdk() bool {
506 return inList(c.Name(), ndkMigratedLibs)
507}
508
509func (c *Module) isLlndk() bool {
510 // Returns true for both LLNDK (public) and LLNDK-private libs.
511 return inList(c.Name(), llndkLibraries)
512}
513
514func (c *Module) isLlndkPublic() bool {
515 // Returns true only for LLNDK (public) libs.
516 return c.isLlndk() && !c.isVndkPrivate()
517}
518
519func (c *Module) isVndkPrivate() bool {
520 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
521 return inList(c.Name(), vndkPrivateLibraries)
522}
523
Justin Yun8effde42017-06-23 19:24:43 +0900524func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800525 if vndkdep := c.vndkdep; vndkdep != nil {
526 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900527 }
528 return false
529}
530
Yi Kong7e53c572018-02-14 18:16:12 +0800531func (c *Module) isPgoCompile() bool {
532 if pgo := c.pgo; pgo != nil {
533 return pgo.Properties.PgoCompile
534 }
535 return false
536}
537
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800538func (c *Module) isNDKStubLibrary() bool {
539 if _, ok := c.compiler.(*stubDecorator); ok {
540 return true
541 }
542 return false
543}
544
Logan Chienf3511742017-10-31 18:04:35 +0800545func (c *Module) isVndkSp() bool {
546 if vndkdep := c.vndkdep; vndkdep != nil {
547 return vndkdep.isVndkSp()
548 }
549 return false
550}
551
552func (c *Module) isVndkExt() bool {
553 if vndkdep := c.vndkdep; vndkdep != nil {
554 return vndkdep.isVndkExt()
555 }
556 return false
557}
558
559func (c *Module) getVndkExtendsModuleName() string {
560 if vndkdep := c.vndkdep; vndkdep != nil {
561 return vndkdep.getVndkExtendsModuleName()
562 }
563 return ""
564}
565
Jiyong Park82e2bf32017-08-16 14:05:54 +0900566// Returns true only when this module is configured to have core and vendor
567// variants.
568func (c *Module) hasVendorVariant() bool {
569 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
570}
571
Jiyong Parkf9332f12018-02-01 00:54:12 +0900572func (c *Module) inRecovery() bool {
573 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
574}
575
576func (c *Module) onlyInRecovery() bool {
577 return c.ModuleBase.InstallInRecovery()
578}
579
Jiyong Park25fc6a92018-11-18 18:02:45 +0900580func (c *Module) IsStubs() bool {
581 if library, ok := c.linker.(*libraryDecorator); ok {
582 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900583 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
584 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900585 }
586 return false
587}
588
589func (c *Module) HasStubsVariants() bool {
590 if library, ok := c.linker.(*libraryDecorator); ok {
591 return len(library.Properties.Stubs.Versions) > 0
592 }
593 return false
594}
595
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900596func (c *Module) bootstrap() bool {
597 return Bool(c.Properties.Bootstrap)
598}
599
Colin Crossca860ac2016-01-04 14:34:37 -0800600type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700601 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800602 moduleContextImpl
603}
604
Colin Cross37047f12016-12-13 17:06:13 -0800605type depsContext struct {
606 android.BottomUpMutatorContext
607 moduleContextImpl
608}
609
Colin Crossca860ac2016-01-04 14:34:37 -0800610type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700611 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800612 moduleContextImpl
613}
614
Jiyong Park2db76922017-11-08 16:03:48 +0900615func (ctx *moduleContext) SocSpecific() bool {
616 return ctx.ModuleContext.SocSpecific() ||
617 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700618}
619
Colin Crossca860ac2016-01-04 14:34:37 -0800620type moduleContextImpl struct {
621 mod *Module
622 ctx BaseModuleContext
623}
624
Colin Crossb98c8b02016-07-29 13:44:28 -0700625func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800626 return ctx.mod.toolchain(ctx.ctx)
627}
628
629func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000630 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800631}
632
633func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900634 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800635}
636
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700637func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800638 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800639 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700640 }
641 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800642}
643
644func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700645 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700646 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900647 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700648 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900649 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
650 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
651 return "current"
652 }
653 return platform_vndk_ver
654 }
655 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800656 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900657 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700658 }
659 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800660}
661
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700662func (ctx *moduleContextImpl) useVndk() bool {
663 return ctx.mod.useVndk()
664}
Justin Yun8effde42017-06-23 19:24:43 +0900665
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800666func (ctx *moduleContextImpl) isNdk() bool {
667 return ctx.mod.isNdk()
668}
669
670func (ctx *moduleContextImpl) isLlndk() bool {
671 return ctx.mod.isLlndk()
672}
673
674func (ctx *moduleContextImpl) isLlndkPublic() bool {
675 return ctx.mod.isLlndkPublic()
676}
677
678func (ctx *moduleContextImpl) isVndkPrivate() bool {
679 return ctx.mod.isVndkPrivate()
680}
681
Logan Chienf3511742017-10-31 18:04:35 +0800682func (ctx *moduleContextImpl) isVndk() bool {
683 return ctx.mod.isVndk()
684}
685
Yi Kong7e53c572018-02-14 18:16:12 +0800686func (ctx *moduleContextImpl) isPgoCompile() bool {
687 return ctx.mod.isPgoCompile()
688}
689
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800690func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
691 return ctx.mod.isNDKStubLibrary()
692}
693
Justin Yun8effde42017-06-23 19:24:43 +0900694func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800695 return ctx.mod.isVndkSp()
696}
697
698func (ctx *moduleContextImpl) isVndkExt() bool {
699 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900700}
701
Jiyong Parkf9332f12018-02-01 00:54:12 +0900702func (ctx *moduleContextImpl) inRecovery() bool {
703 return ctx.mod.inRecovery()
704}
705
Logan Chien2f2b8902018-07-10 15:01:19 +0800706// Check whether ABI dumps should be created for this module.
707func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump() bool {
708 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
709 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800710 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800711
712 if ctx.ctx.Fuchsia() {
713 return false
714 }
715
Logan Chien2f2b8902018-07-10 15:01:19 +0800716 if sanitize := ctx.mod.sanitize; sanitize != nil {
717 if !sanitize.isVariantOnProductionDevice() {
718 return false
719 }
720 }
721 if !ctx.ctx.Device() {
722 // Host modules do not need ABI dumps.
723 return false
724 }
Logan Chienfa478c02018-12-28 16:25:39 +0800725 if !ctx.mod.IsForPlatform() {
726 // APEX variants do not need ABI dumps.
727 return false
728 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800729 if ctx.isNdk() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800730 return true
731 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800732 if ctx.isLlndkPublic() {
Logan Chienf4b79c62018-08-02 02:27:02 +0800733 return true
734 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800735 if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800736 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
737 // VNDK-private.
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800738 return true
Logan Chien2f2b8902018-07-10 15:01:19 +0800739 }
740 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800741}
742
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700743func (ctx *moduleContextImpl) selectedStl() string {
744 if stl := ctx.mod.stl; stl != nil {
745 return stl.Properties.SelectedStl
746 }
747 return ""
748}
749
Ivan Lozanobd721262018-11-27 14:33:03 -0800750func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
751 return ctx.mod.linker.useClangLld(actx)
752}
753
Colin Crossce75d2c2016-10-06 16:12:58 -0700754func (ctx *moduleContextImpl) baseModuleName() string {
755 return ctx.mod.ModuleBase.BaseModuleName()
756}
757
Logan Chienf3511742017-10-31 18:04:35 +0800758func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
759 return ctx.mod.getVndkExtendsModuleName()
760}
761
Jiyong Park58e364a2019-01-19 19:24:06 +0900762func (ctx *moduleContextImpl) apexName() string {
763 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900764}
765
Jiyong Parkb0788572018-12-20 22:10:17 +0900766func (ctx *moduleContextImpl) hasStubsVariants() bool {
767 return ctx.mod.HasStubsVariants()
768}
769
770func (ctx *moduleContextImpl) isStubs() bool {
771 return ctx.mod.IsStubs()
772}
773
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900774func (ctx *moduleContextImpl) bootstrap() bool {
775 return ctx.mod.bootstrap()
776}
777
Colin Cross635c3b02016-05-18 15:37:25 -0700778func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800779 return &Module{
780 hod: hod,
781 multilib: multilib,
782 }
783}
784
Colin Cross635c3b02016-05-18 15:37:25 -0700785func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800786 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700787 module.features = []feature{
788 &tidyFeature{},
789 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700790 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800791 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800792 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800793 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900794 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700795 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700796 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800797 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800798 return module
799}
800
Colin Crossce75d2c2016-10-06 16:12:58 -0700801func (c *Module) Prebuilt() *android.Prebuilt {
802 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
803 return p.prebuilt()
804 }
805 return nil
806}
807
808func (c *Module) Name() string {
809 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700810 if p, ok := c.linker.(interface {
811 Name(string) string
812 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700813 name = p.Name(name)
814 }
815 return name
816}
817
Alex Light3d673592019-01-18 14:37:31 -0800818func (c *Module) Symlinks() []string {
819 if p, ok := c.installer.(interface {
820 symlinkList() []string
821 }); ok {
822 return p.symlinkList()
823 }
824 return nil
825}
826
Jeff Gaston294356f2017-09-27 17:05:30 -0700827// orderDeps reorders dependencies into a list such that if module A depends on B, then
828// A will precede B in the resultant list.
829// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800830// Note that directSharedDeps should be the analogous static library for each shared lib dep
831func 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 -0700832 // If A depends on B, then
833 // Every list containing A will also contain B later in the list
834 // So, after concatenating all lists, the final instance of B will have come from the same
835 // original list as the final instance of A
836 // So, the final instance of B will be later in the concatenation than the final A
837 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
838 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800839 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700840 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800841 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
842 }
843 for _, dep := range directSharedDeps {
844 orderedAllDeps = append(orderedAllDeps, dep)
845 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700846 }
847
Colin Crossb6715442017-10-24 11:13:31 -0700848 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700849
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800850 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700851 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800852 // resultant list to only what the caller has chosen to include in directStaticDeps
853 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700854
855 return orderedAllDeps, orderedDeclaredDeps
856}
857
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800858func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
859 // convert Module to Path
860 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
861 staticDepFiles := []android.Path{}
862 for _, dep := range staticDeps {
863 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
864 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700865 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800866 sharedDepFiles := []android.Path{}
867 for _, sharedDep := range sharedDeps {
868 staticAnalogue := sharedDep.staticVariant
869 if staticAnalogue != nil {
870 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
871 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
872 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700873 }
874
875 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800876 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700877
878 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700879}
880
Colin Cross635c3b02016-05-18 15:37:25 -0700881func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800882 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700883 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800884 moduleContextImpl: moduleContextImpl{
885 mod: c,
886 },
887 }
888 ctx.ctx = ctx
889
Colin Crossf18e1102017-11-16 14:33:08 -0800890 deps := c.depsToPaths(ctx)
891 if ctx.Failed() {
892 return
893 }
894
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700895 if c.Properties.Clang != nil && *c.Properties.Clang == false {
896 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
897 }
898
Colin Crossca860ac2016-01-04 14:34:37 -0800899 flags := Flags{
900 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800901 }
Colin Crossca860ac2016-01-04 14:34:37 -0800902 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800903 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800904 }
905 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700906 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800907 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700908 if c.stl != nil {
909 flags = c.stl.flags(ctx, flags)
910 }
Colin Cross16b23492016-01-06 14:41:07 -0800911 if c.sanitize != nil {
912 flags = c.sanitize.flags(ctx, flags)
913 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800914 if c.coverage != nil {
915 flags = c.coverage.flags(ctx, flags)
916 }
Stephen Craneba090d12017-05-09 15:44:35 -0700917 if c.lto != nil {
918 flags = c.lto.flags(ctx, flags)
919 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700920 if c.pgo != nil {
921 flags = c.pgo.flags(ctx, flags)
922 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800923 if c.xom != nil {
924 flags = c.xom.flags(ctx, flags)
925 }
Colin Crossca860ac2016-01-04 14:34:37 -0800926 for _, feature := range c.features {
927 flags = feature.flags(ctx, flags)
928 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800929 if ctx.Failed() {
930 return
931 }
932
Colin Crossb98c8b02016-07-29 13:44:28 -0700933 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
934 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
935 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800936
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800937 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
938 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700939 // We need access to all the flags seen by a source file.
940 if c.sabi != nil {
941 flags = c.sabi.flags(ctx, flags)
942 }
Colin Crossca860ac2016-01-04 14:34:37 -0800943 // Optimization to reduce size of build.ninja
944 // Replace the long list of flags for each file with a module-local variable
945 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
946 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
947 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
948 flags.CFlags = []string{"$cflags"}
949 flags.CppFlags = []string{"$cppflags"}
950 flags.AsFlags = []string{"$asflags"}
951
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700952 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800953 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700954 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800955 if ctx.Failed() {
956 return
957 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800958 }
959
Colin Crossca860ac2016-01-04 14:34:37 -0800960 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700961 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800962 if ctx.Failed() {
963 return
964 }
Colin Cross635c3b02016-05-18 15:37:25 -0700965 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +0900966
967 // If a lib is directly included in any of the APEXes, unhide the stubs
968 // variant having the latest version gets visible to make. In addition,
969 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
970 // force anything in the make world to link against the stubs library.
971 // (unless it is explicitly referenced via .bootstrap suffix or the
972 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +0000973 if c.HasStubsVariants() &&
974 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800975 !c.inRecovery() && !c.useVndk() && !c.static() && !c.isCoverageVariant() &&
976 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +0900977 c.Properties.HideFromMake = false // unhide
978 // Note: this is still non-installable
979 }
Colin Crossce75d2c2016-10-06 16:12:58 -0700980 }
Colin Cross5049f022015-03-18 13:28:46 -0700981
Jiyong Park9d452992018-10-03 00:38:19 +0900982 if c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() {
Colin Crossce75d2c2016-10-06 16:12:58 -0700983 c.installer.install(ctx, c.outputFile.Path())
984 if ctx.Failed() {
985 return
Colin Crossca860ac2016-01-04 14:34:37 -0800986 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700987 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800988}
989
Jiyong Park379de2f2018-12-19 02:47:14 +0900990func (c *Module) toolchain(ctx android.BaseContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800991 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700992 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800993 }
Colin Crossca860ac2016-01-04 14:34:37 -0800994 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800995}
996
Colin Crossca860ac2016-01-04 14:34:37 -0800997func (c *Module) begin(ctx BaseModuleContext) {
998 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700999 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001000 }
Colin Crossca860ac2016-01-04 14:34:37 -08001001 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001002 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001003 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001004 if c.stl != nil {
1005 c.stl.begin(ctx)
1006 }
Colin Cross16b23492016-01-06 14:41:07 -08001007 if c.sanitize != nil {
1008 c.sanitize.begin(ctx)
1009 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001010 if c.coverage != nil {
1011 c.coverage.begin(ctx)
1012 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001013 if c.sabi != nil {
1014 c.sabi.begin(ctx)
1015 }
Justin Yun8effde42017-06-23 19:24:43 +09001016 if c.vndkdep != nil {
1017 c.vndkdep.begin(ctx)
1018 }
Stephen Craneba090d12017-05-09 15:44:35 -07001019 if c.lto != nil {
1020 c.lto.begin(ctx)
1021 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001022 if c.pgo != nil {
1023 c.pgo.begin(ctx)
1024 }
Colin Crossca860ac2016-01-04 14:34:37 -08001025 for _, feature := range c.features {
1026 feature.begin(ctx)
1027 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001028 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001029 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001030 if err != nil {
1031 ctx.PropertyErrorf("sdk_version", err.Error())
1032 }
Nan Zhang0007d812017-11-07 10:57:05 -08001033 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001034 }
Colin Crossca860ac2016-01-04 14:34:37 -08001035}
1036
Colin Cross37047f12016-12-13 17:06:13 -08001037func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001038 deps := Deps{}
1039
1040 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001041 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001042 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001043 // Add the PGO dependency (the clang_rt.profile runtime library), which
1044 // sometimes depends on symbols from libgcc, before libgcc gets added
1045 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001046 if c.pgo != nil {
1047 deps = c.pgo.deps(ctx, deps)
1048 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001049 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001050 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001051 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001052 if c.stl != nil {
1053 deps = c.stl.deps(ctx, deps)
1054 }
Colin Cross16b23492016-01-06 14:41:07 -08001055 if c.sanitize != nil {
1056 deps = c.sanitize.deps(ctx, deps)
1057 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001058 if c.coverage != nil {
1059 deps = c.coverage.deps(ctx, deps)
1060 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001061 if c.sabi != nil {
1062 deps = c.sabi.deps(ctx, deps)
1063 }
Justin Yun8effde42017-06-23 19:24:43 +09001064 if c.vndkdep != nil {
1065 deps = c.vndkdep.deps(ctx, deps)
1066 }
Stephen Craneba090d12017-05-09 15:44:35 -07001067 if c.lto != nil {
1068 deps = c.lto.deps(ctx, deps)
1069 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001070 for _, feature := range c.features {
1071 deps = feature.deps(ctx, deps)
1072 }
1073
Colin Crossb6715442017-10-24 11:13:31 -07001074 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1075 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1076 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1077 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1078 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1079 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001080 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001081
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001082 for _, lib := range deps.ReexportSharedLibHeaders {
1083 if !inList(lib, deps.SharedLibs) {
1084 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1085 }
1086 }
1087
1088 for _, lib := range deps.ReexportStaticLibHeaders {
1089 if !inList(lib, deps.StaticLibs) {
1090 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1091 }
1092 }
1093
Colin Cross5950f382016-12-13 12:50:57 -08001094 for _, lib := range deps.ReexportHeaderLibHeaders {
1095 if !inList(lib, deps.HeaderLibs) {
1096 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1097 }
1098 }
1099
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001100 for _, gen := range deps.ReexportGeneratedHeaders {
1101 if !inList(gen, deps.GeneratedHeaders) {
1102 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1103 }
1104 }
1105
Colin Crossc99deeb2016-04-11 15:06:20 -07001106 return deps
1107}
1108
Dan Albert7e9d2952016-08-04 13:02:36 -07001109func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001110 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001111 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001112 moduleContextImpl: moduleContextImpl{
1113 mod: c,
1114 },
1115 }
1116 ctx.ctx = ctx
1117
Colin Crossca860ac2016-01-04 14:34:37 -08001118 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001119}
1120
Jiyong Park7ed9de32018-10-15 22:25:07 +09001121// Split name#version into name and version
1122func stubsLibNameAndVersion(name string) (string, string) {
1123 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1124 version := name[sharp+1:]
1125 libname := name[:sharp]
1126 return libname, version
1127 }
1128 return name, ""
1129}
1130
Colin Cross1e676be2016-10-12 14:38:15 -07001131func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001132 ctx := &depsContext{
1133 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001134 moduleContextImpl: moduleContextImpl{
1135 mod: c,
1136 },
1137 }
1138 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001139
Colin Crossc99deeb2016-04-11 15:06:20 -07001140 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001141
Dan Albert914449f2016-06-17 16:45:24 -07001142 variantNdkLibs := []string{}
1143 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001144 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001145 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001146
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001147 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1148 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001149 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001150 // 1. Name of an NDK library that refers to a prebuilt module.
1151 // For each of these, it adds the name of the prebuilt module (which will be in
1152 // prebuilts/ndk) to the list of nonvariant libs.
1153 // 2. Name of an NDK library that refers to an ndk_library module.
1154 // For each of these, it adds the name of the ndk_library module to the list of
1155 // variant libs.
1156 // 3. Anything else (so anything that isn't an NDK library).
1157 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001158 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001159 // The caller can then know to add the variantLibs dependencies differently from the
1160 // nonvariantLibs
1161 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1162 variantLibs = []string{}
1163 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001164 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001165 // strip #version suffix out
1166 name, _ := stubsLibNameAndVersion(entry)
1167 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1168 if !inList(name, ndkMigratedLibs) {
1169 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001170 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001171 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001172 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001173 } else if ctx.useVndk() && inList(name, llndkLibraries) {
1174 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
1175 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, vendorPublicLibraries) {
1176 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001177 if actx.OtherModuleExists(vendorPublicLib) {
1178 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1179 } else {
1180 // This can happen if vendor_public_library module is defined in a
1181 // namespace that isn't visible to the current module. In that case,
1182 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001183 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001184 }
Dan Albert914449f2016-06-17 16:45:24 -07001185 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001186 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001187 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001188 }
1189 }
Dan Albert914449f2016-06-17 16:45:24 -07001190 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001191 }
1192
Dan Albert914449f2016-06-17 16:45:24 -07001193 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1194 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001195 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001196 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001197
Jiyong Park7e636d02019-01-28 16:16:54 +09001198 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001199 if c.linker != nil {
1200 if library, ok := c.linker.(*libraryDecorator); ok {
1201 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001202 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001203 }
1204 }
1205 }
1206
Colin Cross32ec36c2016-12-15 07:39:51 -08001207 for _, lib := range deps.HeaderLibs {
1208 depTag := headerDepTag
1209 if inList(lib, deps.ReexportHeaderLibHeaders) {
1210 depTag = headerExportDepTag
1211 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001212 if buildStubs {
Jiyong Park7e636d02019-01-28 16:16:54 +09001213 actx.AddFarVariationDependencies([]blueprint.Variation{
1214 {Mutator: "arch", Variation: ctx.Target().String()},
Jiyong Park3b1746a2019-01-29 11:15:04 +09001215 {Mutator: "image", Variation: c.imageVariation()},
Jiyong Park7e636d02019-01-28 16:16:54 +09001216 }, depTag, lib)
1217 } else {
1218 actx.AddVariationDependencies(nil, depTag, lib)
1219 }
1220 }
1221
1222 if buildStubs {
1223 // Stubs lib does not have dependency to other static/shared libraries.
1224 // Don't proceed.
1225 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001226 }
Colin Cross5950f382016-12-13 12:50:57 -08001227
Inseob Kimc0907f12019-02-08 21:00:45 +09001228 syspropImplLibraries := syspropImplLibraries(actx.Config())
1229
Jiyong Park5d1598f2019-02-25 22:14:17 +09001230 for _, lib := range deps.WholeStaticLibs {
1231 depTag := wholeStaticDepTag
1232 if impl, ok := syspropImplLibraries[lib]; ok {
1233 lib = impl
1234 }
1235 actx.AddVariationDependencies([]blueprint.Variation{
1236 {Mutator: "link", Variation: "static"},
1237 }, depTag, lib)
1238 }
1239
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001240 for _, lib := range deps.StaticLibs {
1241 depTag := staticDepTag
1242 if inList(lib, deps.ReexportStaticLibHeaders) {
1243 depTag = staticExportDepTag
1244 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001245
1246 if impl, ok := syspropImplLibraries[lib]; ok {
1247 lib = impl
1248 }
1249
Dan Willemsen59339a22018-07-22 21:18:45 -07001250 actx.AddVariationDependencies([]blueprint.Variation{
1251 {Mutator: "link", Variation: "static"},
1252 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001253 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001254
Dan Willemsen59339a22018-07-22 21:18:45 -07001255 actx.AddVariationDependencies([]blueprint.Variation{
1256 {Mutator: "link", Variation: "static"},
1257 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001258
Jiyong Park25fc6a92018-11-18 18:02:45 +09001259 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1260 var variations []blueprint.Variation
1261 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001262 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001263 if version != "" && versionVariantAvail {
1264 // Version is explicitly specified. i.e. libFoo#30
1265 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1266 depTag.explicitlyVersioned = true
1267 }
1268 actx.AddVariationDependencies(variations, depTag, name)
1269
1270 // If the version is not specified, add dependency to the latest stubs library.
1271 // The stubs library will be used when the depending module is built for APEX and
1272 // the dependent module is not in the same APEX.
1273 latestVersion := latestStubsVersionFor(actx.Config(), name)
1274 if version == "" && latestVersion != "" && versionVariantAvail {
1275 actx.AddVariationDependencies([]blueprint.Variation{
1276 {Mutator: "link", Variation: "shared"},
1277 {Mutator: "version", Variation: latestVersion},
1278 }, depTag, name)
1279 // Note that depTag.explicitlyVersioned is false in this case.
1280 }
1281 }
1282
Jiyong Park7ed9de32018-10-15 22:25:07 +09001283 // shared lib names without the #version suffix
1284 var sharedLibNames []string
1285
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001286 for _, lib := range deps.SharedLibs {
1287 depTag := sharedDepTag
1288 if inList(lib, deps.ReexportSharedLibHeaders) {
1289 depTag = sharedExportDepTag
1290 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001291
1292 if impl, ok := syspropImplLibraries[lib]; ok {
1293 lib = impl
1294 }
1295
1296 name, version := stubsLibNameAndVersion(lib)
1297 sharedLibNames = append(sharedLibNames, name)
1298
Jiyong Park25fc6a92018-11-18 18:02:45 +09001299 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001300 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001301
Jiyong Park7ed9de32018-10-15 22:25:07 +09001302 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001303 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001304 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1305 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1306 // linking against both the stubs lib and the non-stubs lib at the same time.
1307 continue
1308 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001309 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001310 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001311
Dan Willemsen59339a22018-07-22 21:18:45 -07001312 actx.AddVariationDependencies([]blueprint.Variation{
1313 {Mutator: "link", Variation: "shared"},
1314 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001315
Colin Cross68861832016-07-08 10:41:41 -07001316 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001317
1318 for _, gen := range deps.GeneratedHeaders {
1319 depTag := genHeaderDepTag
1320 if inList(gen, deps.ReexportGeneratedHeaders) {
1321 depTag = genHeaderExportDepTag
1322 }
1323 actx.AddDependency(c, depTag, gen)
1324 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001325
Colin Cross42d48b72018-08-29 14:10:52 -07001326 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001327
1328 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001329 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001330 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001331 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001332 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001333 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001334 if deps.LinkerFlagsFile != "" {
1335 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1336 }
1337 if deps.DynamicLinker != "" {
1338 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001339 }
Dan Albert914449f2016-06-17 16:45:24 -07001340
1341 version := ctx.sdkVersion()
1342 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001343 {Mutator: "ndk_api", Variation: version},
1344 {Mutator: "link", Variation: "shared"},
1345 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001346 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001347 {Mutator: "ndk_api", Variation: version},
1348 {Mutator: "link", Variation: "shared"},
1349 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001350
1351 if vndkdep := c.vndkdep; vndkdep != nil {
1352 if vndkdep.isVndkExt() {
1353 baseModuleMode := vendorMode
1354 if actx.DeviceConfig().VndkVersion() == "" {
1355 baseModuleMode = coreMode
1356 }
1357 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001358 {Mutator: "image", Variation: baseModuleMode},
1359 {Mutator: "link", Variation: "shared"},
1360 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001361 }
1362 }
Colin Cross6362e272015-10-29 15:25:03 -07001363}
Colin Cross21b9a242015-03-24 14:15:58 -07001364
Colin Crosse40b4ea2018-10-02 22:25:58 -07001365func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001366 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1367 c.beginMutator(ctx)
1368 }
1369}
1370
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001371// Whether a module can link to another module, taking into
1372// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001373func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001374 if from.Target().Os != android.Android {
1375 // Host code is not restricted
1376 return
1377 }
1378 if from.Properties.UseVndk {
1379 // Though vendor code is limited by the vendor mutator,
1380 // each vendor-available module needs to check
1381 // link-type for VNDK.
1382 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001383 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001384 }
1385 return
1386 }
Nan Zhang0007d812017-11-07 10:57:05 -08001387 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001388 // Platform code can link to anything
1389 return
1390 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001391 if from.inRecovery() {
1392 // Recovery code is not NDK
1393 return
1394 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001395 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1396 // These are always allowed
1397 return
1398 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001399 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1400 // These are allowed, but they don't set sdk_version
1401 return
1402 }
1403 if _, ok := to.linker.(*stubDecorator); ok {
1404 // These aren't real libraries, but are the stub shared libraries that are included in
1405 // the NDK.
1406 return
1407 }
Logan Chien834b9a62019-01-14 15:39:03 +08001408
1409 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" {
1410 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1411 // to link to libc++ (non-NDK and without sdk_version).
1412 return
1413 }
1414
Nan Zhang0007d812017-11-07 10:57:05 -08001415 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001416 // NDK code linking to platform code is never okay.
1417 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1418 ctx.OtherModuleName(to))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001419 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001420 }
1421
1422 // At this point we know we have two NDK libraries, but we need to
1423 // check that we're not linking against anything built against a higher
1424 // API level, as it is only valid to link against older or equivalent
1425 // APIs.
1426
Inseob Kim01a28722018-04-11 09:48:45 +09001427 // Current can link against anything.
1428 if String(from.Properties.Sdk_version) != "current" {
1429 // Otherwise we need to check.
1430 if String(to.Properties.Sdk_version) == "current" {
1431 // Current can't be linked against by anything else.
1432 ctx.ModuleErrorf("links %q built against newer API version %q",
1433 ctx.OtherModuleName(to), "current")
1434 } else {
1435 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1436 if err != nil {
1437 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001438 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001439 String(from.Properties.Sdk_version))
1440 }
1441 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1442 if err != nil {
1443 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001444 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001445 String(to.Properties.Sdk_version))
1446 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001447
Inseob Kim01a28722018-04-11 09:48:45 +09001448 if toApi > fromApi {
1449 ctx.ModuleErrorf("links %q built against newer API version %q",
1450 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1451 }
1452 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001453 }
Dan Albert202fe492017-12-15 13:56:59 -08001454
1455 // Also check that the two STL choices are compatible.
1456 fromStl := from.stl.Properties.SelectedStl
1457 toStl := to.stl.Properties.SelectedStl
1458 if fromStl == "" || toStl == "" {
1459 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001460 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001461 // We can be permissive with the system "STL" since it is only the C++
1462 // ABI layer, but in the future we should make sure that everyone is
1463 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001464 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001465 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1466 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1467 to.stl.Properties.SelectedStl)
1468 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001469}
1470
Jiyong Park5fb8c102018-04-09 12:03:06 +09001471// Tests whether the dependent library is okay to be double loaded inside a single process.
1472// If a library is a member of VNDK and at the same time dependencies of an LLNDK library,
1473// it is subject to be double loaded. Such lib should be explicitly marked as double_loaded: true
1474// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
1475func checkDoubleLoadableLibries(ctx android.ModuleContext, from *Module, to *Module) {
1476 if _, ok := from.linker.(*libraryDecorator); !ok {
1477 return
1478 }
1479
1480 if inList(ctx.ModuleName(), llndkLibraries) ||
1481 (from.useVndk() && Bool(from.VendorProperties.Double_loadable)) {
1482 _, depIsLlndk := to.linker.(*llndkStubDecorator)
1483 depIsVndkSp := false
1484 if to.vndkdep != nil && to.vndkdep.isVndkSp() {
1485 depIsVndkSp = true
1486 }
1487 depIsVndk := false
1488 if to.vndkdep != nil && to.vndkdep.isVndk() {
1489 depIsVndk = true
1490 }
1491 depIsDoubleLoadable := Bool(to.VendorProperties.Double_loadable)
1492 if !depIsLlndk && !depIsVndkSp && !depIsDoubleLoadable && depIsVndk {
Steven Moreland742989e2018-11-26 12:41:04 -08001493 ctx.ModuleErrorf("links VNDK library %q that isn't double loadable (not also LL-NDK, "+
1494 "VNDK-SP, or explicitly marked as 'double_loadable').",
Jiyong Park5fb8c102018-04-09 12:03:06 +09001495 ctx.OtherModuleName(to))
1496 }
1497 }
1498}
1499
Colin Crossc99deeb2016-04-11 15:06:20 -07001500// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001501func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001502 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001503
Jeff Gaston294356f2017-09-27 17:05:30 -07001504 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001505 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001506
Colin Crossd11fcda2017-10-23 17:59:01 -07001507 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001508 depName := ctx.OtherModuleName(dep)
1509 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001510
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001511 ccDep, _ := dep.(*Module)
1512 if ccDep == nil {
1513 // handling for a few module types that aren't cc Module but that are also supported
1514 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001515 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001516 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001517 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1518 genRule.GeneratedSourceFiles()...)
1519 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001520 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001521 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001522 // Support exported headers from a generated_sources dependency
1523 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001524 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001525 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001526 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001527 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001528 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001529 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001530 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001531 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001532 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001533 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001534 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1535 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1536
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001537 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001538 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001539 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001540 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001541 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001542 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001543 files := genRule.GeneratedSourceFiles()
1544 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001545 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001546 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001547 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 -07001548 }
1549 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001550 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001551 }
Colin Crossca860ac2016-01-04 14:34:37 -08001552 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001553 return
1554 }
1555
Colin Crossd11fcda2017-10-23 17:59:01 -07001556 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001557 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1558 return
1559 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001560 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001561 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001562 return
1563 }
1564
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001565 // re-exporting flags
1566 if depTag == reuseObjTag {
1567 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001568 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001569 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001570 depPaths.Objs = depPaths.Objs.Append(objs)
1571 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001572 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001573 return
1574 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001575 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001576
Jiyong Parke4bb9862019-02-01 00:31:10 +09001577 if depTag == staticVariantTag {
1578 if _, ok := ccDep.compiler.(libraryInterface); ok {
1579 c.staticVariant = ccDep
1580 return
1581 }
1582 }
1583
Jiyong Park25fc6a92018-11-18 18:02:45 +09001584 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1585 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1586 // won't be matched to sharedDepTag and lateSharedDepTag.
1587 explicitlyVersioned := false
1588 if t, ok := depTag.(dependencyTag); ok {
1589 explicitlyVersioned = t.explicitlyVersioned
1590 t.explicitlyVersioned = false
1591 depTag = t
1592 }
1593
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001594 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001595 depIsStatic := false
1596 switch depTag {
1597 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1598 depIsStatic = true
1599 }
1600 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001601 depIsStubs := dependentLibrary.buildStubs()
1602 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001603 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001604 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001605
1606 var useThisDep bool
1607 if depIsStubs && explicitlyVersioned {
1608 // Always respect dependency to the versioned stubs (i.e. libX#10)
1609 useThisDep = true
1610 } else if !depHasStubs {
1611 // Use non-stub variant if that is the only choice
1612 // (i.e. depending on a lib without stubs.version property)
1613 useThisDep = true
1614 } else if c.IsForPlatform() {
1615 // If not building for APEX, use stubs only when it is from
1616 // an APEX (and not from platform)
1617 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001618 if c.inRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001619 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001620 // always link to non-stub variant
1621 useThisDep = !depIsStubs
1622 }
1623 } else {
1624 // If building for APEX, use stubs only when it is not from
1625 // the same APEX
1626 useThisDep = (depInSameApex != depIsStubs)
1627 }
1628
1629 if !useThisDep {
1630 return // stop processing this dep
1631 }
1632 }
1633
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001634 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001635 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001636 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001637 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001638 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001639
1640 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001641 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001642 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001643 // 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 -07001644 // Re-exported shared library headers must be included as well since they can help us with type information
1645 // about template instantiations (instantiated from their headers).
1646 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001647 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001648 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001649
Logan Chienf3511742017-10-31 18:04:35 +08001650 checkLinkType(ctx, c, ccDep, t)
Jiyong Park5fb8c102018-04-09 12:03:06 +09001651 checkDoubleLoadableLibries(ctx, c, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001652 }
1653
Colin Cross26c34ed2016-09-30 17:10:16 -07001654 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001655 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001656
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001657 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001658 depFile := android.OptionalPath{}
1659
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001660 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001661 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001662 ptr = &depPaths.SharedLibs
1663 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001664 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001665 directSharedDeps = append(directSharedDeps, ccDep)
Jiyong Park64a44f22019-01-18 14:37:08 +09001666 case earlySharedDepTag:
1667 ptr = &depPaths.EarlySharedLibs
1668 depPtr = &depPaths.EarlySharedLibsDeps
1669 depFile = ccDep.linker.(libraryInterface).toc()
1670 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001671 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001672 ptr = &depPaths.LateSharedLibs
1673 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001674 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001675 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001676 ptr = nil
1677 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001678 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001679 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001680 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001681 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001682 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001683 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001684 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001685 return
1686 }
1687
1688 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001689 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001690 for i := range missingDeps {
1691 missingDeps[i] += postfix
1692 }
1693 ctx.AddMissingDependencies(missingDeps)
1694 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001695 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001696 case headerDepTag:
1697 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001698 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001699 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001700 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001701 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001702 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001703 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001704 case dynamicLinkerDepTag:
1705 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001706 }
1707
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001708 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001709 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001710 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001711 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001712 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001713 return
1714 }
1715
1716 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001717 // in static libraries act as if they were whole static libraries. The same goes for
1718 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001719 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1720 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001721 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1722 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001723
Dan Willemsen581341d2017-02-09 16:16:31 -08001724 }
1725
Colin Cross26c34ed2016-09-30 17:10:16 -07001726 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001727 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001728 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001729 return
1730 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001731 *ptr = append(*ptr, linkFile.Path())
1732 }
1733
Colin Crossc99deeb2016-04-11 15:06:20 -07001734 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001735 dep := depFile
1736 if !dep.Valid() {
1737 dep = linkFile
1738 }
1739 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001740 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001741
Logan Chien43d34c32017-12-20 01:17:32 +08001742 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001743 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001744 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001745 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001746 isLLndk := inList(libName, llndkLibraries)
Jiyong Park374510b2018-03-19 18:23:01 +09001747 isVendorPublicLib := inList(libName, vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001748 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1749 if c.useVndk() && bothVendorAndCoreVariantsExist {
1750 // The vendor module in Make will have been renamed to not conflict with the core
1751 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001752 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001753 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001754 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001755 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1756 return libName + recoverySuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001757 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001758 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001759 }
Logan Chien43d34c32017-12-20 01:17:32 +08001760 }
1761
1762 // Export the shared libs to Make.
1763 switch depTag {
Jiyong Park64a44f22019-01-18 14:37:08 +09001764 case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001765 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001766 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08001767 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09001768 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001769 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001770 c.Properties.ApexesProvidingSharedLibs = append(
1771 c.Properties.ApexesProvidingSharedLibs, an)
1772 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09001773 }
1774 }
1775
Jiyong Park27b188b2017-07-18 13:23:39 +09001776 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001777 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001778 c.Properties.AndroidMkSharedLibs = append(
1779 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08001780 case ndkStubDepTag, ndkLateStubDepTag:
1781 ndkStub := ccDep.linker.(*stubDecorator)
1782 c.Properties.AndroidMkSharedLibs = append(
1783 c.Properties.AndroidMkSharedLibs,
1784 depName+"."+ndkStub.properties.ApiLevel)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001785 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1786 c.Properties.AndroidMkStaticLibs = append(
1787 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001788 case runtimeDepTag:
1789 c.Properties.AndroidMkRuntimeLibs = append(
1790 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001791 case wholeStaticDepTag:
1792 c.Properties.AndroidMkWholeStaticLibs = append(
1793 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001794 }
Colin Crossca860ac2016-01-04 14:34:37 -08001795 })
1796
Jeff Gaston294356f2017-09-27 17:05:30 -07001797 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001798 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001799
Colin Crossdd84e052017-05-17 13:44:16 -07001800 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001801 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001802 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001803 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001804 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1805
1806 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001807 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001808 }
Colin Crossdd84e052017-05-17 13:44:16 -07001809
Colin Crossca860ac2016-01-04 14:34:37 -08001810 return depPaths
1811}
1812
1813func (c *Module) InstallInData() bool {
1814 if c.installer == nil {
1815 return false
1816 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001817 return c.installer.inData()
1818}
1819
1820func (c *Module) InstallInSanitizerDir() bool {
1821 if c.installer == nil {
1822 return false
1823 }
1824 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001825 return true
1826 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001827 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001828}
1829
Jiyong Parkf9332f12018-02-01 00:54:12 +09001830func (c *Module) InstallInRecovery() bool {
1831 return c.inRecovery()
1832}
1833
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001834func (c *Module) HostToolPath() android.OptionalPath {
1835 if c.installer == nil {
1836 return android.OptionalPath{}
1837 }
1838 return c.installer.hostToolPath()
1839}
1840
Nan Zhangd4e641b2017-07-12 12:55:28 -07001841func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1842 return c.outputFile
1843}
1844
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001845func (c *Module) Srcs() android.Paths {
1846 if c.outputFile.Valid() {
1847 return android.Paths{c.outputFile.Path()}
1848 }
1849 return android.Paths{}
1850}
1851
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001852func (c *Module) static() bool {
1853 if static, ok := c.linker.(interface {
1854 static() bool
1855 }); ok {
1856 return static.static()
1857 }
1858 return false
1859}
1860
Jiyong Park379de2f2018-12-19 02:47:14 +09001861func (c *Module) staticBinary() bool {
1862 if static, ok := c.linker.(interface {
1863 staticBinary() bool
1864 }); ok {
1865 return static.staticBinary()
1866 }
1867 return false
1868}
1869
Colin Crossb60190a2018-09-04 16:28:17 -07001870func (c *Module) getMakeLinkType() string {
1871 if c.useVndk() {
1872 if inList(c.Name(), vndkCoreLibraries) || inList(c.Name(), vndkSpLibraries) || inList(c.Name(), llndkLibraries) {
1873 if inList(c.Name(), vndkPrivateLibraries) {
1874 return "native:vndk_private"
1875 } else {
1876 return "native:vndk"
1877 }
1878 } else {
1879 return "native:vendor"
1880 }
1881 } else if c.inRecovery() {
1882 return "native:recovery"
1883 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
1884 return "native:ndk:none:none"
1885 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
1886 //family, link := getNdkStlFamilyAndLinkType(c)
1887 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
1888 } else {
1889 return "native:platform"
1890 }
1891}
1892
Jiyong Park9d452992018-10-03 00:38:19 +09001893// Overrides ApexModule.IsInstallabeToApex()
1894// Only shared libraries are installable to APEX.
1895func (c *Module) IsInstallableToApex() bool {
1896 if shared, ok := c.linker.(interface {
1897 shared() bool
1898 }); ok {
1899 return shared.shared()
1900 }
1901 return false
1902}
1903
Jiyong Park3b1746a2019-01-29 11:15:04 +09001904func (c *Module) imageVariation() string {
1905 variation := "core"
1906 if c.useVndk() {
1907 variation = "vendor"
1908 } else if c.inRecovery() {
1909 variation = "recovery"
1910 }
1911 return variation
1912}
1913
bralee3f49f4d2019-03-04 06:58:15 +08001914func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
1915 dpInfo.Srcs = append(dpInfo.Srcs, c.Srcs().Strings()...)
1916}
1917
Colin Cross2ba19d92015-05-07 15:44:20 -07001918//
Colin Crosscfad1192015-11-02 16:43:11 -08001919// Defaults
1920//
Colin Crossca860ac2016-01-04 14:34:37 -08001921type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001922 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001923 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09001924 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001925}
1926
Colin Cross635c3b02016-05-18 15:37:25 -07001927func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001928}
1929
Colin Cross36242852017-06-23 15:06:31 -07001930func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001931 return DefaultsFactory()
1932}
1933
Colin Cross36242852017-06-23 15:06:31 -07001934func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001935 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001936
Colin Cross36242852017-06-23 15:06:31 -07001937 module.AddProperties(props...)
1938 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001939 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001940 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001941 &BaseCompilerProperties{},
1942 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001943 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001944 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001945 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001946 &TestProperties{},
1947 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001948 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001949 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001950 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001951 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001952 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001953 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001954 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001955 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001956 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001957 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08001958 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001959 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001960 )
Colin Crosscfad1192015-11-02 16:43:11 -08001961
Colin Cross1f44a3a2017-07-07 14:33:33 -07001962 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09001963 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001964
1965 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001966}
1967
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001968const (
1969 // coreMode is the variant used for framework-private libraries, or
1970 // SDK libraries. (which framework-private libraries can use)
1971 coreMode = "core"
1972
1973 // vendorMode is the variant used for /vendor code that compiles
1974 // against the VNDK.
1975 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09001976
1977 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001978)
1979
Jiyong Park6a43f042017-10-12 23:05:00 +09001980func squashVendorSrcs(m *Module) {
1981 if lib, ok := m.compiler.(*libraryDecorator); ok {
1982 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1983 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1984
1985 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1986 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1987 }
1988}
1989
Jiyong Parkf9332f12018-02-01 00:54:12 +09001990func squashRecoverySrcs(m *Module) {
1991 if lib, ok := m.compiler.(*libraryDecorator); ok {
1992 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1993 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
1994
1995 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1996 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
1997 }
1998}
1999
Jiyong Parkda6eb592018-12-19 17:12:36 +09002000func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002001 if mctx.Os() != android.Android {
2002 return
2003 }
2004
Jiyong Park7ed9de32018-10-15 22:25:07 +09002005 if g, ok := mctx.Module().(*genrule.Module); ok {
2006 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09002007 var coreVariantNeeded bool = false
2008 var vendorVariantNeeded bool = false
2009 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09002010 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09002011 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002012 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09002013 coreVariantNeeded = true
2014 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09002015 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09002016 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002017 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09002018 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002019 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002020 if Bool(props.Recovery_available) {
2021 recoveryVariantNeeded = true
2022 }
2023
Jiyong Park413cc742018-06-19 01:46:06 +09002024 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002025 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09002026 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09002027 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002028 recoveryVariantNeeded = false
2029 }
2030 }
2031
Jiyong Park3f736c92018-05-24 13:36:56 +09002032 var variants []string
2033 if coreVariantNeeded {
2034 variants = append(variants, coreMode)
2035 }
2036 if vendorVariantNeeded {
2037 variants = append(variants, vendorMode)
2038 }
2039 if recoveryVariantNeeded {
2040 variants = append(variants, recoveryMode)
2041 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002042 mod := mctx.CreateVariations(variants...)
2043 for i, v := range variants {
2044 if v == recoveryMode {
2045 m := mod[i].(*genrule.Module)
2046 m.Extra.(*GenruleExtraProperties).InRecovery = true
2047 }
2048 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002049 }
2050 }
2051
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002052 m, ok := mctx.Module().(*Module)
2053 if !ok {
2054 return
2055 }
2056
2057 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002058 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002059 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002060
2061 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002062 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002063 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002064 return
2065 }
Logan Chienf3511742017-10-31 18:04:35 +08002066
2067 if vndkdep := m.vndkdep; vndkdep != nil {
2068 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002069 if productSpecific {
2070 mctx.PropertyErrorf("product_specific",
2071 "product_specific must not be true when `vndk: {enabled: true}`")
2072 return
2073 }
Logan Chienf3511742017-10-31 18:04:35 +08002074 if vendorSpecific {
2075 if !vndkdep.isVndkExt() {
2076 mctx.PropertyErrorf("vndk",
2077 "must set `extends: \"...\"` to vndk extension")
2078 return
2079 }
2080 } else {
2081 if vndkdep.isVndkExt() {
2082 mctx.PropertyErrorf("vndk",
2083 "must set `vendor: true` to set `extends: %q`",
2084 m.getVndkExtendsModuleName())
2085 return
2086 }
2087 if m.VendorProperties.Vendor_available == nil {
2088 mctx.PropertyErrorf("vndk",
2089 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2090 return
2091 }
2092 }
2093 } else {
2094 if vndkdep.isVndkSp() {
2095 mctx.PropertyErrorf("vndk",
2096 "must set `enabled: true` to set `support_system_process: true`")
2097 return
2098 }
2099 if vndkdep.isVndkExt() {
2100 mctx.PropertyErrorf("vndk",
2101 "must set `enabled: true` to set `extends: %q`",
2102 m.getVndkExtendsModuleName())
2103 return
2104 }
Justin Yun8effde42017-06-23 19:24:43 +09002105 }
2106 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002107
Jiyong Parkf9332f12018-02-01 00:54:12 +09002108 var coreVariantNeeded bool = false
2109 var vendorVariantNeeded bool = false
2110 var recoveryVariantNeeded bool = false
2111
Justin Yun71549282017-11-17 12:10:28 +09002112 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002113 // If the device isn't compiling against the VNDK, we always
2114 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002115 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002116 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2117 // LL-NDK stubs only exist in the vendor variant, since the
2118 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002119 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09002120 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2121 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09002122 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09002123 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002124 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2125 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002126 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002127 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002128 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002129 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002130 coreVariantNeeded = true
2131 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002132 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002133 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09002134 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002135 } else {
2136 // This is either in /system (or similar: /data), or is a
2137 // modules built with the NDK. Modules built with the NDK
2138 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002139 coreVariantNeeded = true
2140 }
2141
2142 if Bool(m.Properties.Recovery_available) {
2143 recoveryVariantNeeded = true
2144 }
2145
2146 if m.ModuleBase.InstallInRecovery() {
2147 recoveryVariantNeeded = true
2148 coreVariantNeeded = false
2149 }
2150
Jiyong Park413cc742018-06-19 01:46:06 +09002151 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002152 primaryArch := mctx.Config().DevicePrimaryArchType()
2153 moduleArch := m.Target().Arch.ArchType
2154 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002155 recoveryVariantNeeded = false
2156 }
2157 }
2158
Jiyong Parkf9332f12018-02-01 00:54:12 +09002159 var variants []string
2160 if coreVariantNeeded {
2161 variants = append(variants, coreMode)
2162 }
2163 if vendorVariantNeeded {
2164 variants = append(variants, vendorMode)
2165 }
2166 if recoveryVariantNeeded {
2167 variants = append(variants, recoveryMode)
2168 }
2169 mod := mctx.CreateVariations(variants...)
2170 for i, v := range variants {
2171 if v == vendorMode {
2172 m := mod[i].(*Module)
2173 m.Properties.UseVndk = true
2174 squashVendorSrcs(m)
2175 } else if v == recoveryMode {
2176 m := mod[i].(*Module)
2177 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002178 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002179 squashRecoverySrcs(m)
2180 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002181 }
2182}
2183
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002184func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002185 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002186 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2187 }
Colin Cross6510f912017-11-29 00:27:14 -08002188 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002189}
2190
Colin Cross06a931b2015-10-28 17:23:31 -07002191var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002192var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002193var BoolPtr = proptools.BoolPtr
2194var String = proptools.String
2195var StringPtr = proptools.StringPtr