blob: 49dce18f91194e4e77c023811796e6d5316ffd08 [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
Jiyong Parkd5bd6d32019-07-29 21:27:18 +090054 // cfi mutator shouldn't run before sanitizers that return true for
55 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000056 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
57 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
58
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080059 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
60 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
61
Colin Cross1e676be2016-10-12 14:38:15 -070062 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
63 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080064
Colin Cross6b753602018-06-21 13:03:07 -070065 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator)
Jiyong Park379de2f2018-12-19 02:47:14 +090066 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080067
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080068 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080069 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070070
71 ctx.TopDown("lto_deps", ltoDepsMutator)
72 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090073
74 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070075 })
Colin Crossb98c8b02016-07-29 13:44:28 -070076
77 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070078}
79
Colin Crossca860ac2016-01-04 14:34:37 -080080type Deps struct {
81 SharedLibs, LateSharedLibs []string
82 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080083 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080084 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070085
Colin Cross5950f382016-12-13 12:50:57 -080086 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070087
Colin Cross81413472016-04-11 14:37:39 -070088 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070089
Dan Willemsenb40aab62016-04-20 14:21:14 -070090 GeneratedSources []string
91 GeneratedHeaders []string
92
Dan Willemsenb3454ab2016-09-28 17:34:58 -070093 ReexportGeneratedHeaders []string
94
Colin Cross97ba0732015-03-23 17:50:24 -070095 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -070096
97 // Used for host bionic
98 LinkerFlagsFile string
99 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700100}
101
Colin Crossca860ac2016-01-04 14:34:37 -0800102type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700103 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900104 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700105 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900106 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700107 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700108 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700109
Colin Cross26c34ed2016-09-30 17:10:16 -0700110 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700111 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800112 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700113 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700114
Colin Cross26c34ed2016-09-30 17:10:16 -0700115 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700116 GeneratedSources android.Paths
117 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700118
Dan Willemsen76f08272016-07-09 00:14:08 -0700119 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700120 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700121
Colin Cross26c34ed2016-09-30 17:10:16 -0700122 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700123 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700124
125 // Path to the file container flags to use with the linker
126 LinkerFlagsFile android.OptionalPath
127
128 // Path to the dynamic linker binary
129 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700130}
131
Colin Crossca860ac2016-01-04 14:34:37 -0800132type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700133 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
134 ArFlags []string // Flags that apply to ar
135 AsFlags []string // Flags that apply to assembly source files
136 CFlags []string // Flags that apply to C and C++ source files
137 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
138 ConlyFlags []string // Flags that apply to C source files
139 CppFlags []string // Flags that apply to C++ source files
140 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
141 YaccFlags []string // Flags that apply to Yacc source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700142 aidlFlags []string // Flags that apply to aidl source files
143 rsFlags []string // Flags that apply to renderscript source files
144 LdFlags []string // Flags that apply to linker command lines
145 libFlags []string // Flags to add libraries early to the link order
146 TidyFlags []string // Flags that apply to clang-tidy
147 SAbiFlags []string // Flags that apply to header-abi-dumper
148 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700149
Colin Crossc3199482017-03-30 15:03:04 -0700150 // Global include flags that apply to C, C++, and assembly source files
151 // These must be after any module include flags, which will be in GlobalFlags.
152 SystemIncludeFlags []string
153
Colin Crossb98c8b02016-07-29 13:44:28 -0700154 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700155 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800156 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800157 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800158
159 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800160 DynamicLinker string
161
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700162 CFlagsDeps android.Paths // Files depended on by compiler flags
163 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800164
165 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800166
Colin Cross19878da2019-03-28 14:45:07 -0700167 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700168 protoC bool // Whether to use C instead of C++
169 protoOptionsFile bool // Whether to look for a .options file next to the .proto
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
Jiyong Parkd5bd6d32019-07-29 21:27:18 +0900244 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700245 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700246 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800247 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700248 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800249 isNdk() bool
250 isLlndk() bool
251 isLlndkPublic() bool
252 isVndkPrivate() bool
Justin Yun8effde42017-06-23 19:24:43 +0900253 isVndk() bool
254 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800255 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900256 inRecovery() bool
Logan Chien2f2b8902018-07-10 15:01:19 +0800257 shouldCreateVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700258 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700259 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800260 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800261 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800262 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800263 useClangLld(actx ModuleContext) bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900264 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900265 hasStubsVariants() bool
266 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900267 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800268 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700269 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800270}
271
272type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700273 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800274 ModuleContextIntf
275}
276
277type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700278 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800279 ModuleContextIntf
280}
281
Colin Cross37047f12016-12-13 17:06:13 -0800282type DepsContext interface {
283 android.BottomUpMutatorContext
284 ModuleContextIntf
285}
286
Colin Crossca860ac2016-01-04 14:34:37 -0800287type feature interface {
288 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800289 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800290 flags(ctx ModuleContext, flags Flags) Flags
291 props() []interface{}
292}
293
294type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700295 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800296 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800297 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700298 compilerProps() []interface{}
299
Colin Cross76fada02016-07-27 10:31:13 -0700300 appendCflags([]string)
301 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700302 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800303}
304
305type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700306 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800307 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700308 linkerFlags(ctx ModuleContext, flags Flags) Flags
309 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800310 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700311
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700312 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700313 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900314 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700315
316 nativeCoverage() bool
Jiyong Park49932f32019-08-09 14:44:36 +0900317 coverageOutputFilePath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800318}
319
320type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700321 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700322 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800323 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700324 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700325 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900326 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800327}
328
Colin Crossc99deeb2016-04-11 15:06:20 -0700329type dependencyTag struct {
330 blueprint.BaseDependencyTag
331 name string
332 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700333
334 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900335
336 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700337}
338
339var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700340 sharedDepTag = dependencyTag{name: "shared", library: true}
341 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
Jiyong Park64a44f22019-01-18 14:37:08 +0900342 earlySharedDepTag = dependencyTag{name: "early_shared", library: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700343 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
344 staticDepTag = dependencyTag{name: "static", library: true}
345 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
346 lateStaticDepTag = dependencyTag{name: "late static", library: true}
347 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800348 headerDepTag = dependencyTag{name: "header", library: true}
349 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700350 genSourceDepTag = dependencyTag{name: "gen source"}
351 genHeaderDepTag = dependencyTag{name: "gen header"}
352 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
353 objDepTag = dependencyTag{name: "obj"}
354 crtBeginDepTag = dependencyTag{name: "crtbegin"}
355 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700356 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
357 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700358 reuseObjTag = dependencyTag{name: "reuse objects"}
Jiyong Parke4bb9862019-02-01 00:31:10 +0900359 staticVariantTag = dependencyTag{name: "static variant"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700360 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
361 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800362 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800363 runtimeDepTag = dependencyTag{name: "runtime lib"}
Pirama Arumuga Nainar2363a2b2019-07-02 14:55:35 -0700364 coverageDepTag = dependencyTag{name: "coverage"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700365)
366
Colin Crossca860ac2016-01-04 14:34:37 -0800367// Module contains the properties and members used by all C/C++ module types, and implements
368// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
369// to construct the output file. Behavior can be customized with a Customizer interface
370type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700371 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700372 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900373 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700374
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700375 Properties BaseProperties
376 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700377
Colin Crossca860ac2016-01-04 14:34:37 -0800378 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700379 hod android.HostOrDeviceSupported
380 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700381
Colin Crossca860ac2016-01-04 14:34:37 -0800382 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700383 features []feature
384 compiler compiler
385 linker linker
386 installer installer
387 stl *stl
388 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800389 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800390 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900391 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700392 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700393 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800394 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800395
396 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700397
Colin Cross635c3b02016-05-18 15:37:25 -0700398 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800399
Colin Crossb98c8b02016-07-29 13:44:28 -0700400 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700401
402 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800403
404 // Flags used to compile this module
405 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700406
407 // 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 -0800408 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700409 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800410 depsInLinkOrder android.Paths
411
412 // only non-nil when this is a shared library that reuses the objects of a static library
413 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700414}
415
Jiyong Parkc20eee32018-09-05 22:36:17 +0900416func (c *Module) OutputFile() android.OptionalPath {
417 return c.outputFile
418}
419
Jiyong Park719b4462019-01-13 00:39:51 +0900420func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900421 if c.linker != nil {
422 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900423 }
424 return nil
425}
426
Jiyong Park49932f32019-08-09 14:44:36 +0900427func (c *Module) CoverageOutputFile() android.OptionalPath {
428 if c.linker != nil {
429 return c.linker.coverageOutputFilePath()
430 }
431 return android.OptionalPath{}
432}
433
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900434func (c *Module) RelativeInstallPath() string {
435 if c.installer != nil {
436 return c.installer.relativeInstallPath()
437 }
438 return ""
439}
440
Colin Cross36242852017-06-23 15:06:31 -0700441func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700442 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800443 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700444 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800445 }
446 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700447 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800448 }
449 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700450 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800451 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700452 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700453 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700454 }
Colin Cross16b23492016-01-06 14:41:07 -0800455 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700456 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800457 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800458 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700459 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800460 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800461 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700462 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800463 }
Justin Yun8effde42017-06-23 19:24:43 +0900464 if c.vndkdep != nil {
465 c.AddProperties(c.vndkdep.props()...)
466 }
Stephen Craneba090d12017-05-09 15:44:35 -0700467 if c.lto != nil {
468 c.AddProperties(c.lto.props()...)
469 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700470 if c.pgo != nil {
471 c.AddProperties(c.pgo.props()...)
472 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800473 if c.xom != nil {
474 c.AddProperties(c.xom.props()...)
475 }
Colin Crossca860ac2016-01-04 14:34:37 -0800476 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700477 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800478 }
Colin Crossc472d572015-03-17 15:06:21 -0700479
Colin Crossa9d8bee2018-10-02 13:59:46 -0700480 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
481 switch class {
482 case android.Device:
483 return ctx.Config().DevicePrefer32BitExecutables()
484 case android.HostCross:
485 // Windows builds always prefer 32-bit
486 return true
487 default:
488 return false
489 }
490 })
Colin Cross36242852017-06-23 15:06:31 -0700491 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700492
Colin Cross1f44a3a2017-07-07 14:33:33 -0700493 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700494
Jiyong Park9d452992018-10-03 00:38:19 +0900495 android.InitApexModule(c)
496
Colin Cross36242852017-06-23 15:06:31 -0700497 return c
Colin Crossc472d572015-03-17 15:06:21 -0700498}
499
Colin Crossb916a382016-07-29 17:28:03 -0700500// Returns true for dependency roots (binaries)
501// TODO(ccross): also handle dlopenable libraries
502func (c *Module) isDependencyRoot() bool {
503 if root, ok := c.linker.(interface {
504 isDependencyRoot() bool
505 }); ok {
506 return root.isDependencyRoot()
507 }
508 return false
509}
510
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700511func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700512 return c.Properties.UseVndk
513}
514
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800515func (c *Module) isCoverageVariant() bool {
516 return c.coverage.Properties.IsCoverageVariant
517}
518
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800519func (c *Module) isNdk() bool {
520 return inList(c.Name(), ndkMigratedLibs)
521}
522
523func (c *Module) isLlndk() bool {
524 // Returns true for both LLNDK (public) and LLNDK-private libs.
525 return inList(c.Name(), llndkLibraries)
526}
527
528func (c *Module) isLlndkPublic() bool {
529 // Returns true only for LLNDK (public) libs.
530 return c.isLlndk() && !c.isVndkPrivate()
531}
532
533func (c *Module) isVndkPrivate() bool {
534 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
535 return inList(c.Name(), vndkPrivateLibraries)
536}
537
Justin Yun8effde42017-06-23 19:24:43 +0900538func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800539 if vndkdep := c.vndkdep; vndkdep != nil {
540 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900541 }
542 return false
543}
544
Yi Kong7e53c572018-02-14 18:16:12 +0800545func (c *Module) isPgoCompile() bool {
546 if pgo := c.pgo; pgo != nil {
547 return pgo.Properties.PgoCompile
548 }
549 return false
550}
551
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800552func (c *Module) isNDKStubLibrary() bool {
553 if _, ok := c.compiler.(*stubDecorator); ok {
554 return true
555 }
556 return false
557}
558
Logan Chienf3511742017-10-31 18:04:35 +0800559func (c *Module) isVndkSp() bool {
560 if vndkdep := c.vndkdep; vndkdep != nil {
561 return vndkdep.isVndkSp()
562 }
563 return false
564}
565
566func (c *Module) isVndkExt() bool {
567 if vndkdep := c.vndkdep; vndkdep != nil {
568 return vndkdep.isVndkExt()
569 }
570 return false
571}
572
Vic Yangefd249e2018-11-12 20:19:56 -0800573func (c *Module) mustUseVendorVariant() bool {
574 return c.isVndkSp() || inList(c.Name(), config.VndkMustUseVendorVariantList)
575}
576
Logan Chienf3511742017-10-31 18:04:35 +0800577func (c *Module) getVndkExtendsModuleName() string {
578 if vndkdep := c.vndkdep; vndkdep != nil {
579 return vndkdep.getVndkExtendsModuleName()
580 }
581 return ""
582}
583
Jiyong Park82e2bf32017-08-16 14:05:54 +0900584// Returns true only when this module is configured to have core and vendor
585// variants.
586func (c *Module) hasVendorVariant() bool {
587 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
588}
589
Jiyong Parkf9332f12018-02-01 00:54:12 +0900590func (c *Module) inRecovery() bool {
591 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
592}
593
594func (c *Module) onlyInRecovery() bool {
595 return c.ModuleBase.InstallInRecovery()
596}
597
Jiyong Park25fc6a92018-11-18 18:02:45 +0900598func (c *Module) IsStubs() bool {
599 if library, ok := c.linker.(*libraryDecorator); ok {
600 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900601 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
602 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900603 }
604 return false
605}
606
607func (c *Module) HasStubsVariants() bool {
608 if library, ok := c.linker.(*libraryDecorator); ok {
609 return len(library.Properties.Stubs.Versions) > 0
610 }
Peter Collingbournee1629272019-04-24 14:41:12 -0700611 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
612 return len(library.Properties.Stubs.Versions) > 0
613 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900614 return false
615}
616
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900617func (c *Module) bootstrap() bool {
618 return Bool(c.Properties.Bootstrap)
619}
620
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700621func (c *Module) nativeCoverage() bool {
622 return c.linker != nil && c.linker.nativeCoverage()
623}
624
Jiyong Parkf1194352019-02-25 11:05:47 +0900625func isBionic(name string) bool {
626 switch name {
627 case "libc", "libm", "libdl", "linker":
628 return true
629 }
630 return false
631}
632
Peter Collingbournee1629272019-04-24 14:41:12 -0700633func installToBootstrap(name string, config android.Config) bool {
634 if name == "libclang_rt.hwasan-aarch64-android" {
635 return inList("hwaddress", config.SanitizeDevice())
636 }
637 return isBionic(name)
638}
639
Colin Crossca860ac2016-01-04 14:34:37 -0800640type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700641 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800642 moduleContextImpl
643}
644
Colin Cross37047f12016-12-13 17:06:13 -0800645type depsContext struct {
646 android.BottomUpMutatorContext
647 moduleContextImpl
648}
649
Colin Crossca860ac2016-01-04 14:34:37 -0800650type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700651 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800652 moduleContextImpl
653}
654
Jiyong Park2db76922017-11-08 16:03:48 +0900655func (ctx *moduleContext) SocSpecific() bool {
656 return ctx.ModuleContext.SocSpecific() ||
657 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700658}
659
Colin Crossca860ac2016-01-04 14:34:37 -0800660type moduleContextImpl struct {
661 mod *Module
662 ctx BaseModuleContext
663}
664
Colin Crossb98c8b02016-07-29 13:44:28 -0700665func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800666 return ctx.mod.toolchain(ctx.ctx)
667}
668
669func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000670 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800671}
672
673func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900674 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800675}
676
Jiyong Parkd5bd6d32019-07-29 21:27:18 +0900677func (ctx *moduleContextImpl) header() bool {
678 return ctx.mod.header()
679}
680
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700681func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800682 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800683 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700684 }
685 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800686}
687
688func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700689 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700690 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900691 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700692 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900693 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
694 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
695 return "current"
696 }
697 return platform_vndk_ver
698 }
699 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800700 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900701 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700702 }
703 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800704}
705
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700706func (ctx *moduleContextImpl) useVndk() bool {
707 return ctx.mod.useVndk()
708}
Justin Yun8effde42017-06-23 19:24:43 +0900709
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800710func (ctx *moduleContextImpl) isNdk() bool {
711 return ctx.mod.isNdk()
712}
713
714func (ctx *moduleContextImpl) isLlndk() bool {
715 return ctx.mod.isLlndk()
716}
717
718func (ctx *moduleContextImpl) isLlndkPublic() bool {
719 return ctx.mod.isLlndkPublic()
720}
721
722func (ctx *moduleContextImpl) isVndkPrivate() bool {
723 return ctx.mod.isVndkPrivate()
724}
725
Logan Chienf3511742017-10-31 18:04:35 +0800726func (ctx *moduleContextImpl) isVndk() bool {
727 return ctx.mod.isVndk()
728}
729
Yi Kong7e53c572018-02-14 18:16:12 +0800730func (ctx *moduleContextImpl) isPgoCompile() bool {
731 return ctx.mod.isPgoCompile()
732}
733
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800734func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
735 return ctx.mod.isNDKStubLibrary()
736}
737
Justin Yun8effde42017-06-23 19:24:43 +0900738func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800739 return ctx.mod.isVndkSp()
740}
741
742func (ctx *moduleContextImpl) isVndkExt() bool {
743 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900744}
745
Vic Yangefd249e2018-11-12 20:19:56 -0800746func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
747 return ctx.mod.mustUseVendorVariant()
748}
749
Jiyong Parkf9332f12018-02-01 00:54:12 +0900750func (ctx *moduleContextImpl) inRecovery() bool {
751 return ctx.mod.inRecovery()
752}
753
Logan Chien2f2b8902018-07-10 15:01:19 +0800754// Check whether ABI dumps should be created for this module.
755func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump() bool {
756 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
757 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800758 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800759
760 if ctx.ctx.Fuchsia() {
761 return false
762 }
763
Logan Chien2f2b8902018-07-10 15:01:19 +0800764 if sanitize := ctx.mod.sanitize; sanitize != nil {
765 if !sanitize.isVariantOnProductionDevice() {
766 return false
767 }
768 }
769 if !ctx.ctx.Device() {
770 // Host modules do not need ABI dumps.
771 return false
772 }
Logan Chienfa478c02018-12-28 16:25:39 +0800773 if !ctx.mod.IsForPlatform() {
774 // APEX variants do not need ABI dumps.
775 return false
776 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800777 if ctx.isNdk() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800778 return true
779 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800780 if ctx.isLlndkPublic() {
Logan Chienf4b79c62018-08-02 02:27:02 +0800781 return true
782 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800783 if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800784 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
785 // VNDK-private.
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800786 return true
Logan Chien2f2b8902018-07-10 15:01:19 +0800787 }
788 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800789}
790
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700791func (ctx *moduleContextImpl) selectedStl() string {
792 if stl := ctx.mod.stl; stl != nil {
793 return stl.Properties.SelectedStl
794 }
795 return ""
796}
797
Ivan Lozanobd721262018-11-27 14:33:03 -0800798func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
799 return ctx.mod.linker.useClangLld(actx)
800}
801
Colin Crossce75d2c2016-10-06 16:12:58 -0700802func (ctx *moduleContextImpl) baseModuleName() string {
803 return ctx.mod.ModuleBase.BaseModuleName()
804}
805
Logan Chienf3511742017-10-31 18:04:35 +0800806func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
807 return ctx.mod.getVndkExtendsModuleName()
808}
809
Jiyong Park58e364a2019-01-19 19:24:06 +0900810func (ctx *moduleContextImpl) apexName() string {
811 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900812}
813
Jiyong Parkb0788572018-12-20 22:10:17 +0900814func (ctx *moduleContextImpl) hasStubsVariants() bool {
815 return ctx.mod.HasStubsVariants()
816}
817
818func (ctx *moduleContextImpl) isStubs() bool {
819 return ctx.mod.IsStubs()
820}
821
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900822func (ctx *moduleContextImpl) bootstrap() bool {
823 return ctx.mod.bootstrap()
824}
825
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700826func (ctx *moduleContextImpl) nativeCoverage() bool {
827 return ctx.mod.nativeCoverage()
828}
829
Colin Cross635c3b02016-05-18 15:37:25 -0700830func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800831 return &Module{
832 hod: hod,
833 multilib: multilib,
834 }
835}
836
Colin Cross635c3b02016-05-18 15:37:25 -0700837func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800838 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700839 module.features = []feature{
840 &tidyFeature{},
841 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700842 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800843 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800844 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800845 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900846 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700847 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700848 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800849 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800850 return module
851}
852
Colin Crossce75d2c2016-10-06 16:12:58 -0700853func (c *Module) Prebuilt() *android.Prebuilt {
854 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
855 return p.prebuilt()
856 }
857 return nil
858}
859
860func (c *Module) Name() string {
861 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700862 if p, ok := c.linker.(interface {
863 Name(string) string
864 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700865 name = p.Name(name)
866 }
867 return name
868}
869
Alex Light3d673592019-01-18 14:37:31 -0800870func (c *Module) Symlinks() []string {
871 if p, ok := c.installer.(interface {
872 symlinkList() []string
873 }); ok {
874 return p.symlinkList()
875 }
876 return nil
877}
878
Jeff Gaston294356f2017-09-27 17:05:30 -0700879// orderDeps reorders dependencies into a list such that if module A depends on B, then
880// A will precede B in the resultant list.
881// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800882// Note that directSharedDeps should be the analogous static library for each shared lib dep
883func 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 -0700884 // If A depends on B, then
885 // Every list containing A will also contain B later in the list
886 // So, after concatenating all lists, the final instance of B will have come from the same
887 // original list as the final instance of A
888 // So, the final instance of B will be later in the concatenation than the final A
889 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
890 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800891 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700892 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800893 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
894 }
895 for _, dep := range directSharedDeps {
896 orderedAllDeps = append(orderedAllDeps, dep)
897 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700898 }
899
Colin Crossb6715442017-10-24 11:13:31 -0700900 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700901
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800902 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700903 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800904 // resultant list to only what the caller has chosen to include in directStaticDeps
905 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700906
907 return orderedAllDeps, orderedDeclaredDeps
908}
909
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800910func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
911 // convert Module to Path
912 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
913 staticDepFiles := []android.Path{}
914 for _, dep := range staticDeps {
915 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
916 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700917 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800918 sharedDepFiles := []android.Path{}
919 for _, sharedDep := range sharedDeps {
920 staticAnalogue := sharedDep.staticVariant
921 if staticAnalogue != nil {
922 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
923 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
924 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700925 }
926
927 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800928 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700929
930 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700931}
932
Colin Cross635c3b02016-05-18 15:37:25 -0700933func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800934 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700935 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800936 moduleContextImpl: moduleContextImpl{
937 mod: c,
938 },
939 }
940 ctx.ctx = ctx
941
Colin Crossf18e1102017-11-16 14:33:08 -0800942 deps := c.depsToPaths(ctx)
943 if ctx.Failed() {
944 return
945 }
946
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700947 if c.Properties.Clang != nil && *c.Properties.Clang == false {
948 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
949 }
950
Colin Crossca860ac2016-01-04 14:34:37 -0800951 flags := Flags{
952 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800953 }
Colin Crossca860ac2016-01-04 14:34:37 -0800954 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800955 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800956 }
957 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700958 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800959 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700960 if c.stl != nil {
961 flags = c.stl.flags(ctx, flags)
962 }
Colin Cross16b23492016-01-06 14:41:07 -0800963 if c.sanitize != nil {
964 flags = c.sanitize.flags(ctx, flags)
965 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800966 if c.coverage != nil {
Pirama Arumuga Nainar2363a2b2019-07-02 14:55:35 -0700967 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -0800968 }
Stephen Craneba090d12017-05-09 15:44:35 -0700969 if c.lto != nil {
970 flags = c.lto.flags(ctx, flags)
971 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700972 if c.pgo != nil {
973 flags = c.pgo.flags(ctx, flags)
974 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800975 if c.xom != nil {
976 flags = c.xom.flags(ctx, flags)
977 }
Colin Crossca860ac2016-01-04 14:34:37 -0800978 for _, feature := range c.features {
979 flags = feature.flags(ctx, flags)
980 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800981 if ctx.Failed() {
982 return
983 }
984
Colin Crossb98c8b02016-07-29 13:44:28 -0700985 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
986 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
987 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800988
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800989 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
990 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700991 // We need access to all the flags seen by a source file.
992 if c.sabi != nil {
993 flags = c.sabi.flags(ctx, flags)
994 }
Colin Crossca860ac2016-01-04 14:34:37 -0800995 // Optimization to reduce size of build.ninja
996 // Replace the long list of flags for each file with a module-local variable
997 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
998 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
999 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
1000 flags.CFlags = []string{"$cflags"}
1001 flags.CppFlags = []string{"$cppflags"}
1002 flags.AsFlags = []string{"$asflags"}
1003
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001004 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001005 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001006 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001007 if ctx.Failed() {
1008 return
1009 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001010 }
1011
Colin Crossca860ac2016-01-04 14:34:37 -08001012 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001013 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001014 if ctx.Failed() {
1015 return
1016 }
Colin Cross635c3b02016-05-18 15:37:25 -07001017 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001018
1019 // If a lib is directly included in any of the APEXes, unhide the stubs
1020 // variant having the latest version gets visible to make. In addition,
1021 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1022 // force anything in the make world to link against the stubs library.
1023 // (unless it is explicitly referenced via .bootstrap suffix or the
1024 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001025 if c.HasStubsVariants() &&
1026 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001027 !c.inRecovery() && !c.useVndk() && !c.static() && !c.isCoverageVariant() &&
1028 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001029 c.Properties.HideFromMake = false // unhide
1030 // Note: this is still non-installable
1031 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001032 }
Colin Cross5049f022015-03-18 13:28:46 -07001033
Jiyong Park9d452992018-10-03 00:38:19 +09001034 if c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001035 c.installer.install(ctx, c.outputFile.Path())
1036 if ctx.Failed() {
1037 return
Colin Crossca860ac2016-01-04 14:34:37 -08001038 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001039 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001040}
1041
Jiyong Park379de2f2018-12-19 02:47:14 +09001042func (c *Module) toolchain(ctx android.BaseContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001043 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001044 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001045 }
Colin Crossca860ac2016-01-04 14:34:37 -08001046 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001047}
1048
Colin Crossca860ac2016-01-04 14:34:37 -08001049func (c *Module) begin(ctx BaseModuleContext) {
1050 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001051 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001052 }
Colin Crossca860ac2016-01-04 14:34:37 -08001053 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001054 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001055 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001056 if c.stl != nil {
1057 c.stl.begin(ctx)
1058 }
Colin Cross16b23492016-01-06 14:41:07 -08001059 if c.sanitize != nil {
1060 c.sanitize.begin(ctx)
1061 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001062 if c.coverage != nil {
1063 c.coverage.begin(ctx)
1064 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001065 if c.sabi != nil {
1066 c.sabi.begin(ctx)
1067 }
Justin Yun8effde42017-06-23 19:24:43 +09001068 if c.vndkdep != nil {
1069 c.vndkdep.begin(ctx)
1070 }
Stephen Craneba090d12017-05-09 15:44:35 -07001071 if c.lto != nil {
1072 c.lto.begin(ctx)
1073 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001074 if c.pgo != nil {
1075 c.pgo.begin(ctx)
1076 }
Colin Crossca860ac2016-01-04 14:34:37 -08001077 for _, feature := range c.features {
1078 feature.begin(ctx)
1079 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001080 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001081 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001082 if err != nil {
1083 ctx.PropertyErrorf("sdk_version", err.Error())
1084 }
Nan Zhang0007d812017-11-07 10:57:05 -08001085 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001086 }
Colin Crossca860ac2016-01-04 14:34:37 -08001087}
1088
Colin Cross37047f12016-12-13 17:06:13 -08001089func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001090 deps := Deps{}
1091
1092 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001093 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001094 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001095 // Add the PGO dependency (the clang_rt.profile runtime library), which
1096 // sometimes depends on symbols from libgcc, before libgcc gets added
1097 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001098 if c.pgo != nil {
1099 deps = c.pgo.deps(ctx, deps)
1100 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001101 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001102 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001103 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001104 if c.stl != nil {
1105 deps = c.stl.deps(ctx, deps)
1106 }
Colin Cross16b23492016-01-06 14:41:07 -08001107 if c.sanitize != nil {
1108 deps = c.sanitize.deps(ctx, deps)
1109 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001110 if c.coverage != nil {
1111 deps = c.coverage.deps(ctx, deps)
1112 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001113 if c.sabi != nil {
1114 deps = c.sabi.deps(ctx, deps)
1115 }
Justin Yun8effde42017-06-23 19:24:43 +09001116 if c.vndkdep != nil {
1117 deps = c.vndkdep.deps(ctx, deps)
1118 }
Stephen Craneba090d12017-05-09 15:44:35 -07001119 if c.lto != nil {
1120 deps = c.lto.deps(ctx, deps)
1121 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001122 for _, feature := range c.features {
1123 deps = feature.deps(ctx, deps)
1124 }
1125
Colin Crossb6715442017-10-24 11:13:31 -07001126 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1127 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1128 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1129 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1130 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1131 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001132 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001133
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001134 for _, lib := range deps.ReexportSharedLibHeaders {
1135 if !inList(lib, deps.SharedLibs) {
1136 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1137 }
1138 }
1139
1140 for _, lib := range deps.ReexportStaticLibHeaders {
1141 if !inList(lib, deps.StaticLibs) {
1142 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1143 }
1144 }
1145
Colin Cross5950f382016-12-13 12:50:57 -08001146 for _, lib := range deps.ReexportHeaderLibHeaders {
1147 if !inList(lib, deps.HeaderLibs) {
1148 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1149 }
1150 }
1151
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001152 for _, gen := range deps.ReexportGeneratedHeaders {
1153 if !inList(gen, deps.GeneratedHeaders) {
1154 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1155 }
1156 }
1157
Colin Crossc99deeb2016-04-11 15:06:20 -07001158 return deps
1159}
1160
Dan Albert7e9d2952016-08-04 13:02:36 -07001161func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001162 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001163 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001164 moduleContextImpl: moduleContextImpl{
1165 mod: c,
1166 },
1167 }
1168 ctx.ctx = ctx
1169
Colin Crossca860ac2016-01-04 14:34:37 -08001170 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001171}
1172
Jiyong Park7ed9de32018-10-15 22:25:07 +09001173// Split name#version into name and version
1174func stubsLibNameAndVersion(name string) (string, string) {
1175 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1176 version := name[sharp+1:]
1177 libname := name[:sharp]
1178 return libname, version
1179 }
1180 return name, ""
1181}
1182
Colin Cross1e676be2016-10-12 14:38:15 -07001183func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001184 ctx := &depsContext{
1185 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001186 moduleContextImpl: moduleContextImpl{
1187 mod: c,
1188 },
1189 }
1190 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001191
Colin Crossc99deeb2016-04-11 15:06:20 -07001192 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001193
Dan Albert914449f2016-06-17 16:45:24 -07001194 variantNdkLibs := []string{}
1195 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001196 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001197 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001198
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001199 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1200 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001201 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001202 // 1. Name of an NDK library that refers to a prebuilt module.
1203 // For each of these, it adds the name of the prebuilt module (which will be in
1204 // prebuilts/ndk) to the list of nonvariant libs.
1205 // 2. Name of an NDK library that refers to an ndk_library module.
1206 // For each of these, it adds the name of the ndk_library module to the list of
1207 // variant libs.
1208 // 3. Anything else (so anything that isn't an NDK library).
1209 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001210 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001211 // The caller can then know to add the variantLibs dependencies differently from the
1212 // nonvariantLibs
1213 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1214 variantLibs = []string{}
1215 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001216 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001217 // strip #version suffix out
1218 name, _ := stubsLibNameAndVersion(entry)
1219 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1220 if !inList(name, ndkMigratedLibs) {
1221 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001222 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001223 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001224 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001225 } else if ctx.useVndk() && inList(name, llndkLibraries) {
1226 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
1227 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, vendorPublicLibraries) {
1228 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001229 if actx.OtherModuleExists(vendorPublicLib) {
1230 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1231 } else {
1232 // This can happen if vendor_public_library module is defined in a
1233 // namespace that isn't visible to the current module. In that case,
1234 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001235 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001236 }
Dan Albert914449f2016-06-17 16:45:24 -07001237 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001238 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001239 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001240 }
1241 }
Dan Albert914449f2016-06-17 16:45:24 -07001242 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001243 }
1244
Dan Albert914449f2016-06-17 16:45:24 -07001245 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1246 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001247 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001248 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001249
Jiyong Park7e636d02019-01-28 16:16:54 +09001250 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001251 if c.linker != nil {
1252 if library, ok := c.linker.(*libraryDecorator); ok {
1253 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001254 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001255 }
1256 }
1257 }
1258
Colin Cross32ec36c2016-12-15 07:39:51 -08001259 for _, lib := range deps.HeaderLibs {
1260 depTag := headerDepTag
1261 if inList(lib, deps.ReexportHeaderLibHeaders) {
1262 depTag = headerExportDepTag
1263 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001264 if buildStubs {
Jiyong Park7e636d02019-01-28 16:16:54 +09001265 actx.AddFarVariationDependencies([]blueprint.Variation{
1266 {Mutator: "arch", Variation: ctx.Target().String()},
Jiyong Park3b1746a2019-01-29 11:15:04 +09001267 {Mutator: "image", Variation: c.imageVariation()},
Jiyong Park7e636d02019-01-28 16:16:54 +09001268 }, depTag, lib)
1269 } else {
1270 actx.AddVariationDependencies(nil, depTag, lib)
1271 }
1272 }
1273
1274 if buildStubs {
1275 // Stubs lib does not have dependency to other static/shared libraries.
1276 // Don't proceed.
1277 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001278 }
Colin Cross5950f382016-12-13 12:50:57 -08001279
Inseob Kimc0907f12019-02-08 21:00:45 +09001280 syspropImplLibraries := syspropImplLibraries(actx.Config())
1281
Jiyong Park5d1598f2019-02-25 22:14:17 +09001282 for _, lib := range deps.WholeStaticLibs {
1283 depTag := wholeStaticDepTag
1284 if impl, ok := syspropImplLibraries[lib]; ok {
1285 lib = impl
1286 }
1287 actx.AddVariationDependencies([]blueprint.Variation{
1288 {Mutator: "link", Variation: "static"},
1289 }, depTag, lib)
1290 }
1291
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001292 for _, lib := range deps.StaticLibs {
1293 depTag := staticDepTag
1294 if inList(lib, deps.ReexportStaticLibHeaders) {
1295 depTag = staticExportDepTag
1296 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001297
1298 if impl, ok := syspropImplLibraries[lib]; ok {
1299 lib = impl
1300 }
1301
Dan Willemsen59339a22018-07-22 21:18:45 -07001302 actx.AddVariationDependencies([]blueprint.Variation{
1303 {Mutator: "link", Variation: "static"},
1304 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001305 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001306
Dan Willemsen59339a22018-07-22 21:18:45 -07001307 actx.AddVariationDependencies([]blueprint.Variation{
1308 {Mutator: "link", Variation: "static"},
1309 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001310
Jiyong Park25fc6a92018-11-18 18:02:45 +09001311 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1312 var variations []blueprint.Variation
1313 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001314 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001315 if version != "" && versionVariantAvail {
1316 // Version is explicitly specified. i.e. libFoo#30
1317 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1318 depTag.explicitlyVersioned = true
1319 }
1320 actx.AddVariationDependencies(variations, depTag, name)
1321
1322 // If the version is not specified, add dependency to the latest stubs library.
1323 // The stubs library will be used when the depending module is built for APEX and
1324 // the dependent module is not in the same APEX.
1325 latestVersion := latestStubsVersionFor(actx.Config(), name)
1326 if version == "" && latestVersion != "" && versionVariantAvail {
1327 actx.AddVariationDependencies([]blueprint.Variation{
1328 {Mutator: "link", Variation: "shared"},
1329 {Mutator: "version", Variation: latestVersion},
1330 }, depTag, name)
1331 // Note that depTag.explicitlyVersioned is false in this case.
1332 }
1333 }
1334
Jiyong Park7ed9de32018-10-15 22:25:07 +09001335 // shared lib names without the #version suffix
1336 var sharedLibNames []string
1337
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001338 for _, lib := range deps.SharedLibs {
1339 depTag := sharedDepTag
1340 if inList(lib, deps.ReexportSharedLibHeaders) {
1341 depTag = sharedExportDepTag
1342 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001343
1344 if impl, ok := syspropImplLibraries[lib]; ok {
1345 lib = impl
1346 }
1347
1348 name, version := stubsLibNameAndVersion(lib)
1349 sharedLibNames = append(sharedLibNames, name)
1350
Jiyong Park25fc6a92018-11-18 18:02:45 +09001351 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001352 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001353
Jiyong Park7ed9de32018-10-15 22:25:07 +09001354 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001355 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001356 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1357 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1358 // linking against both the stubs lib and the non-stubs lib at the same time.
1359 continue
1360 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001361 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001362 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001363
Dan Willemsen59339a22018-07-22 21:18:45 -07001364 actx.AddVariationDependencies([]blueprint.Variation{
1365 {Mutator: "link", Variation: "shared"},
1366 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001367
Colin Cross68861832016-07-08 10:41:41 -07001368 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001369
1370 for _, gen := range deps.GeneratedHeaders {
1371 depTag := genHeaderDepTag
1372 if inList(gen, deps.ReexportGeneratedHeaders) {
1373 depTag = genHeaderExportDepTag
1374 }
1375 actx.AddDependency(c, depTag, gen)
1376 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001377
Colin Cross42d48b72018-08-29 14:10:52 -07001378 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001379
1380 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001381 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001382 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001383 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001384 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001385 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001386 if deps.LinkerFlagsFile != "" {
1387 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1388 }
1389 if deps.DynamicLinker != "" {
1390 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001391 }
Dan Albert914449f2016-06-17 16:45:24 -07001392
1393 version := ctx.sdkVersion()
1394 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001395 {Mutator: "ndk_api", Variation: version},
1396 {Mutator: "link", Variation: "shared"},
1397 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001398 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001399 {Mutator: "ndk_api", Variation: version},
1400 {Mutator: "link", Variation: "shared"},
1401 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001402
1403 if vndkdep := c.vndkdep; vndkdep != nil {
1404 if vndkdep.isVndkExt() {
1405 baseModuleMode := vendorMode
1406 if actx.DeviceConfig().VndkVersion() == "" {
1407 baseModuleMode = coreMode
1408 }
1409 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001410 {Mutator: "image", Variation: baseModuleMode},
1411 {Mutator: "link", Variation: "shared"},
1412 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001413 }
1414 }
Colin Cross6362e272015-10-29 15:25:03 -07001415}
Colin Cross21b9a242015-03-24 14:15:58 -07001416
Colin Crosse40b4ea2018-10-02 22:25:58 -07001417func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001418 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1419 c.beginMutator(ctx)
1420 }
1421}
1422
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001423// Whether a module can link to another module, taking into
1424// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001425func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001426 if from.Target().Os != android.Android {
1427 // Host code is not restricted
1428 return
1429 }
1430 if from.Properties.UseVndk {
1431 // Though vendor code is limited by the vendor mutator,
1432 // each vendor-available module needs to check
1433 // link-type for VNDK.
1434 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001435 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001436 }
1437 return
1438 }
Nan Zhang0007d812017-11-07 10:57:05 -08001439 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001440 // Platform code can link to anything
1441 return
1442 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001443 if from.inRecovery() {
1444 // Recovery code is not NDK
1445 return
1446 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001447 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1448 // These are always allowed
1449 return
1450 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001451 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1452 // These are allowed, but they don't set sdk_version
1453 return
1454 }
1455 if _, ok := to.linker.(*stubDecorator); ok {
1456 // These aren't real libraries, but are the stub shared libraries that are included in
1457 // the NDK.
1458 return
1459 }
Logan Chien834b9a62019-01-14 15:39:03 +08001460
1461 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" {
1462 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1463 // to link to libc++ (non-NDK and without sdk_version).
1464 return
1465 }
1466
Nan Zhang0007d812017-11-07 10:57:05 -08001467 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001468 // NDK code linking to platform code is never okay.
1469 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1470 ctx.OtherModuleName(to))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001471 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001472 }
1473
1474 // At this point we know we have two NDK libraries, but we need to
1475 // check that we're not linking against anything built against a higher
1476 // API level, as it is only valid to link against older or equivalent
1477 // APIs.
1478
Inseob Kim01a28722018-04-11 09:48:45 +09001479 // Current can link against anything.
1480 if String(from.Properties.Sdk_version) != "current" {
1481 // Otherwise we need to check.
1482 if String(to.Properties.Sdk_version) == "current" {
1483 // Current can't be linked against by anything else.
1484 ctx.ModuleErrorf("links %q built against newer API version %q",
1485 ctx.OtherModuleName(to), "current")
1486 } else {
1487 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1488 if err != nil {
1489 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001490 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001491 String(from.Properties.Sdk_version))
1492 }
1493 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1494 if err != nil {
1495 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001496 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001497 String(to.Properties.Sdk_version))
1498 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001499
Inseob Kim01a28722018-04-11 09:48:45 +09001500 if toApi > fromApi {
1501 ctx.ModuleErrorf("links %q built against newer API version %q",
1502 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1503 }
1504 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001505 }
Dan Albert202fe492017-12-15 13:56:59 -08001506
1507 // Also check that the two STL choices are compatible.
1508 fromStl := from.stl.Properties.SelectedStl
1509 toStl := to.stl.Properties.SelectedStl
1510 if fromStl == "" || toStl == "" {
1511 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001512 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001513 // We can be permissive with the system "STL" since it is only the C++
1514 // ABI layer, but in the future we should make sure that everyone is
1515 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001516 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001517 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1518 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1519 to.stl.Properties.SelectedStl)
1520 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001521}
1522
Jiyong Park5fb8c102018-04-09 12:03:06 +09001523// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001524// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1525// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001526// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001527func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
1528 check := func(child, parent android.Module) bool {
1529 to, ok := child.(*Module)
1530 if !ok {
1531 // follow thru cc.Defaults, etc.
1532 return true
1533 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001534
Jooyung Hana70f0672019-01-18 15:20:43 +09001535 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1536 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001537 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001538
1539 // if target lib has no vendor variant, keep checking dependency graph
1540 if !to.hasVendorVariant() {
1541 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001542 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001543
1544 if to.isVndkSp() || inList(child.Name(), llndkLibraries) || Bool(to.VendorProperties.Double_loadable) {
1545 return false
1546 }
1547
1548 var stringPath []string
1549 for _, m := range ctx.GetWalkPath() {
1550 stringPath = append(stringPath, m.Name())
1551 }
1552 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1553 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1554 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1555 return false
1556 }
1557 if module, ok := ctx.Module().(*Module); ok {
1558 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
1559 if inList(ctx.ModuleName(), llndkLibraries) || Bool(module.VendorProperties.Double_loadable) {
1560 ctx.WalkDeps(check)
1561 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001562 }
1563 }
1564}
1565
Colin Crossc99deeb2016-04-11 15:06:20 -07001566// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001567func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001568 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001569
Jeff Gaston294356f2017-09-27 17:05:30 -07001570 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001571 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001572
Colin Crossd11fcda2017-10-23 17:59:01 -07001573 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001574 depName := ctx.OtherModuleName(dep)
1575 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001576
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001577 ccDep, _ := dep.(*Module)
1578 if ccDep == nil {
1579 // handling for a few module types that aren't cc Module but that are also supported
1580 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001581 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001582 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001583 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1584 genRule.GeneratedSourceFiles()...)
1585 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001586 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001587 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001588 // Support exported headers from a generated_sources dependency
1589 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001590 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001591 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001592 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001593 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001594 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001595 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001596 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001597 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001598 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001599 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001600 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1601 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1602
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001603 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001604 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001605 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001606 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001607 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001608 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001609 files := genRule.GeneratedSourceFiles()
1610 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001611 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001612 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001613 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 -07001614 }
1615 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001616 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001617 }
Colin Crossca860ac2016-01-04 14:34:37 -08001618 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001619 return
1620 }
1621
Colin Crossfe17f6f2019-03-28 19:30:56 -07001622 if depTag == android.ProtoPluginDepTag {
1623 return
1624 }
1625
Colin Crossd11fcda2017-10-23 17:59:01 -07001626 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001627 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1628 return
1629 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001630 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001631 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001632 return
1633 }
1634
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001635 // re-exporting flags
1636 if depTag == reuseObjTag {
1637 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001638 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001639 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001640 depPaths.Objs = depPaths.Objs.Append(objs)
1641 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001642 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001643 return
1644 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001645 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001646
Jiyong Parke4bb9862019-02-01 00:31:10 +09001647 if depTag == staticVariantTag {
1648 if _, ok := ccDep.compiler.(libraryInterface); ok {
1649 c.staticVariant = ccDep
1650 return
1651 }
1652 }
1653
Jiyong Park25fc6a92018-11-18 18:02:45 +09001654 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1655 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1656 // won't be matched to sharedDepTag and lateSharedDepTag.
1657 explicitlyVersioned := false
1658 if t, ok := depTag.(dependencyTag); ok {
1659 explicitlyVersioned = t.explicitlyVersioned
1660 t.explicitlyVersioned = false
1661 depTag = t
1662 }
1663
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001664 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001665 depIsStatic := false
1666 switch depTag {
1667 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1668 depIsStatic = true
1669 }
1670 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001671 depIsStubs := dependentLibrary.buildStubs()
1672 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001673 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001674 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001675
1676 var useThisDep bool
1677 if depIsStubs && explicitlyVersioned {
1678 // Always respect dependency to the versioned stubs (i.e. libX#10)
1679 useThisDep = true
1680 } else if !depHasStubs {
1681 // Use non-stub variant if that is the only choice
1682 // (i.e. depending on a lib without stubs.version property)
1683 useThisDep = true
1684 } else if c.IsForPlatform() {
1685 // If not building for APEX, use stubs only when it is from
1686 // an APEX (and not from platform)
1687 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001688 if c.inRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001689 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001690 // always link to non-stub variant
1691 useThisDep = !depIsStubs
1692 }
1693 } else {
1694 // If building for APEX, use stubs only when it is not from
1695 // the same APEX
1696 useThisDep = (depInSameApex != depIsStubs)
1697 }
1698
1699 if !useThisDep {
1700 return // stop processing this dep
1701 }
1702 }
1703
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001704 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001705 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001706 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001707 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001708 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001709
1710 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001711 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001712 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001713 // 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 -07001714 // Re-exported shared library headers must be included as well since they can help us with type information
1715 // about template instantiations (instantiated from their headers).
1716 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001717 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001718 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001719
Logan Chienf3511742017-10-31 18:04:35 +08001720 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001721 }
1722
Colin Cross26c34ed2016-09-30 17:10:16 -07001723 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001724 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001725
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001726 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001727 depFile := android.OptionalPath{}
1728
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001729 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001730 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001731 ptr = &depPaths.SharedLibs
1732 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001733 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001734 directSharedDeps = append(directSharedDeps, ccDep)
Jiyong Park64a44f22019-01-18 14:37:08 +09001735 case earlySharedDepTag:
1736 ptr = &depPaths.EarlySharedLibs
1737 depPtr = &depPaths.EarlySharedLibsDeps
1738 depFile = ccDep.linker.(libraryInterface).toc()
1739 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001740 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001741 ptr = &depPaths.LateSharedLibs
1742 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001743 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001744 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001745 ptr = nil
1746 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001747 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001748 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001749 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001750 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001751 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001752 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001753 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001754 return
1755 }
1756
1757 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001758 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001759 for i := range missingDeps {
1760 missingDeps[i] += postfix
1761 }
1762 ctx.AddMissingDependencies(missingDeps)
1763 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001764 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001765 case headerDepTag:
1766 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001767 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001768 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001769 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001770 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001771 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001772 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001773 case dynamicLinkerDepTag:
1774 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001775 }
1776
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001777 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001778 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001779 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001780 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001781 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001782 return
1783 }
1784
1785 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001786 // in static libraries act as if they were whole static libraries. The same goes for
1787 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001788 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1789 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001790 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1791 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001792
Dan Willemsen581341d2017-02-09 16:16:31 -08001793 }
1794
Colin Cross26c34ed2016-09-30 17:10:16 -07001795 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001796 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001797 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001798 return
1799 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001800 *ptr = append(*ptr, linkFile.Path())
1801 }
1802
Colin Crossc99deeb2016-04-11 15:06:20 -07001803 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001804 dep := depFile
1805 if !dep.Valid() {
1806 dep = linkFile
1807 }
1808 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001809 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001810
Logan Chien43d34c32017-12-20 01:17:32 +08001811 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001812 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001813 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001814 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001815 isLLndk := inList(libName, llndkLibraries)
Jiyong Park374510b2018-03-19 18:23:01 +09001816 isVendorPublicLib := inList(libName, vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001817 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08001818
1819 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.isVndk() && !ccDep.mustUseVendorVariant() {
1820 // The vendor module is a no-vendor-variant VNDK library. Depend on the
1821 // core module instead.
1822 return libName
1823 } else if c.useVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001824 // The vendor module in Make will have been renamed to not conflict with the core
1825 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001826 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001827 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001828 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001829 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1830 return libName + recoverySuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001831 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001832 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001833 }
Logan Chien43d34c32017-12-20 01:17:32 +08001834 }
1835
1836 // Export the shared libs to Make.
1837 switch depTag {
Jiyong Park64a44f22019-01-18 14:37:08 +09001838 case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001839 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001840 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08001841 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09001842 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001843 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001844 c.Properties.ApexesProvidingSharedLibs = append(
1845 c.Properties.ApexesProvidingSharedLibs, an)
1846 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09001847 }
1848 }
1849
Jiyong Park27b188b2017-07-18 13:23:39 +09001850 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001851 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001852 c.Properties.AndroidMkSharedLibs = append(
1853 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08001854 case ndkStubDepTag, ndkLateStubDepTag:
1855 ndkStub := ccDep.linker.(*stubDecorator)
1856 c.Properties.AndroidMkSharedLibs = append(
1857 c.Properties.AndroidMkSharedLibs,
1858 depName+"."+ndkStub.properties.ApiLevel)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001859 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1860 c.Properties.AndroidMkStaticLibs = append(
1861 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001862 case runtimeDepTag:
1863 c.Properties.AndroidMkRuntimeLibs = append(
1864 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001865 case wholeStaticDepTag:
1866 c.Properties.AndroidMkWholeStaticLibs = append(
1867 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001868 }
Colin Crossca860ac2016-01-04 14:34:37 -08001869 })
1870
Jeff Gaston294356f2017-09-27 17:05:30 -07001871 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001872 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001873
Colin Crossdd84e052017-05-17 13:44:16 -07001874 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001875 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001876 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001877 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001878 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1879
1880 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001881 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001882 }
Colin Crossdd84e052017-05-17 13:44:16 -07001883
Colin Crossca860ac2016-01-04 14:34:37 -08001884 return depPaths
1885}
1886
1887func (c *Module) InstallInData() bool {
1888 if c.installer == nil {
1889 return false
1890 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001891 return c.installer.inData()
1892}
1893
1894func (c *Module) InstallInSanitizerDir() bool {
1895 if c.installer == nil {
1896 return false
1897 }
1898 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001899 return true
1900 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001901 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001902}
1903
Jiyong Parkf9332f12018-02-01 00:54:12 +09001904func (c *Module) InstallInRecovery() bool {
1905 return c.inRecovery()
1906}
1907
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001908func (c *Module) HostToolPath() android.OptionalPath {
1909 if c.installer == nil {
1910 return android.OptionalPath{}
1911 }
1912 return c.installer.hostToolPath()
1913}
1914
Nan Zhangd4e641b2017-07-12 12:55:28 -07001915func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1916 return c.outputFile
1917}
1918
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001919func (c *Module) Srcs() android.Paths {
1920 if c.outputFile.Valid() {
1921 return android.Paths{c.outputFile.Path()}
1922 }
1923 return android.Paths{}
1924}
1925
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001926func (c *Module) static() bool {
1927 if static, ok := c.linker.(interface {
1928 static() bool
1929 }); ok {
1930 return static.static()
1931 }
1932 return false
1933}
1934
Jiyong Park379de2f2018-12-19 02:47:14 +09001935func (c *Module) staticBinary() bool {
1936 if static, ok := c.linker.(interface {
1937 staticBinary() bool
1938 }); ok {
1939 return static.staticBinary()
1940 }
1941 return false
1942}
1943
Jiyong Parkd5bd6d32019-07-29 21:27:18 +09001944func (c *Module) header() bool {
1945 if h, ok := c.linker.(interface {
1946 header() bool
1947 }); ok {
1948 return h.header()
1949 }
1950 return false
1951}
1952
Colin Crossb60190a2018-09-04 16:28:17 -07001953func (c *Module) getMakeLinkType() string {
1954 if c.useVndk() {
1955 if inList(c.Name(), vndkCoreLibraries) || inList(c.Name(), vndkSpLibraries) || inList(c.Name(), llndkLibraries) {
1956 if inList(c.Name(), vndkPrivateLibraries) {
1957 return "native:vndk_private"
1958 } else {
1959 return "native:vndk"
1960 }
1961 } else {
1962 return "native:vendor"
1963 }
1964 } else if c.inRecovery() {
1965 return "native:recovery"
1966 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
1967 return "native:ndk:none:none"
1968 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
1969 //family, link := getNdkStlFamilyAndLinkType(c)
1970 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Vic Yangefd249e2018-11-12 20:19:56 -08001971 } else if inList(c.Name(), vndkUsingCoreVariantLibraries) {
1972 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07001973 } else {
1974 return "native:platform"
1975 }
1976}
1977
Jiyong Park9d452992018-10-03 00:38:19 +09001978// Overrides ApexModule.IsInstallabeToApex()
1979// Only shared libraries are installable to APEX.
1980func (c *Module) IsInstallableToApex() bool {
1981 if shared, ok := c.linker.(interface {
1982 shared() bool
1983 }); ok {
1984 return shared.shared()
1985 }
1986 return false
1987}
1988
Jiyong Park3b1746a2019-01-29 11:15:04 +09001989func (c *Module) imageVariation() string {
1990 variation := "core"
1991 if c.useVndk() {
1992 variation = "vendor"
1993 } else if c.inRecovery() {
1994 variation = "recovery"
1995 }
1996 return variation
1997}
1998
bralee3f49f4d2019-03-04 06:58:15 +08001999func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
2000 dpInfo.Srcs = append(dpInfo.Srcs, c.Srcs().Strings()...)
2001}
2002
Colin Cross2ba19d92015-05-07 15:44:20 -07002003//
Colin Crosscfad1192015-11-02 16:43:11 -08002004// Defaults
2005//
Colin Crossca860ac2016-01-04 14:34:37 -08002006type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002007 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002008 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002009 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002010}
2011
Colin Cross635c3b02016-05-18 15:37:25 -07002012func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08002013}
2014
Patrice Arrudac249c712019-03-19 17:00:29 -07002015// cc_defaults provides a set of properties that can be inherited by other cc
2016// modules. A module can use the properties from a cc_defaults using
2017// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2018// merged (when possible) by prepending the default module's values to the
2019// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002020func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002021 return DefaultsFactory()
2022}
2023
Colin Cross36242852017-06-23 15:06:31 -07002024func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002025 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002026
Colin Cross36242852017-06-23 15:06:31 -07002027 module.AddProperties(props...)
2028 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002029 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002030 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002031 &BaseCompilerProperties{},
2032 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002033 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002034 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002035 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002036 &TestProperties{},
2037 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002038 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002039 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002040 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002041 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002042 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002043 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002044 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002045 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002046 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002047 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002048 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002049 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002050 )
Colin Crosscfad1192015-11-02 16:43:11 -08002051
Colin Cross1f44a3a2017-07-07 14:33:33 -07002052 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09002053 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002054
2055 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002056}
2057
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002058const (
2059 // coreMode is the variant used for framework-private libraries, or
2060 // SDK libraries. (which framework-private libraries can use)
2061 coreMode = "core"
2062
2063 // vendorMode is the variant used for /vendor code that compiles
2064 // against the VNDK.
2065 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09002066
2067 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002068)
2069
Jiyong Park6a43f042017-10-12 23:05:00 +09002070func squashVendorSrcs(m *Module) {
2071 if lib, ok := m.compiler.(*libraryDecorator); ok {
2072 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2073 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2074
2075 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2076 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2077 }
2078}
2079
Jiyong Parkf9332f12018-02-01 00:54:12 +09002080func squashRecoverySrcs(m *Module) {
2081 if lib, ok := m.compiler.(*libraryDecorator); ok {
2082 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2083 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2084
2085 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2086 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2087 }
2088}
2089
Jiyong Parkda6eb592018-12-19 17:12:36 +09002090func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002091 if mctx.Os() != android.Android {
2092 return
2093 }
2094
Jiyong Park7ed9de32018-10-15 22:25:07 +09002095 if g, ok := mctx.Module().(*genrule.Module); ok {
2096 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09002097 var coreVariantNeeded bool = false
2098 var vendorVariantNeeded bool = false
2099 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09002100 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09002101 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002102 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09002103 coreVariantNeeded = true
2104 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09002105 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09002106 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002107 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09002108 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002109 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002110 if Bool(props.Recovery_available) {
2111 recoveryVariantNeeded = true
2112 }
2113
Jiyong Park413cc742018-06-19 01:46:06 +09002114 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002115 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09002116 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09002117 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002118 recoveryVariantNeeded = false
2119 }
2120 }
2121
Jiyong Park3f736c92018-05-24 13:36:56 +09002122 var variants []string
2123 if coreVariantNeeded {
2124 variants = append(variants, coreMode)
2125 }
2126 if vendorVariantNeeded {
2127 variants = append(variants, vendorMode)
2128 }
2129 if recoveryVariantNeeded {
2130 variants = append(variants, recoveryMode)
2131 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002132 mod := mctx.CreateVariations(variants...)
2133 for i, v := range variants {
2134 if v == recoveryMode {
2135 m := mod[i].(*genrule.Module)
2136 m.Extra.(*GenruleExtraProperties).InRecovery = true
2137 }
2138 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002139 }
2140 }
2141
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002142 m, ok := mctx.Module().(*Module)
2143 if !ok {
2144 return
2145 }
2146
2147 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002148 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002149 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002150
2151 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002152 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002153 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002154 return
2155 }
Logan Chienf3511742017-10-31 18:04:35 +08002156
2157 if vndkdep := m.vndkdep; vndkdep != nil {
2158 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002159 if productSpecific {
2160 mctx.PropertyErrorf("product_specific",
2161 "product_specific must not be true when `vndk: {enabled: true}`")
2162 return
2163 }
Logan Chienf3511742017-10-31 18:04:35 +08002164 if vendorSpecific {
2165 if !vndkdep.isVndkExt() {
2166 mctx.PropertyErrorf("vndk",
2167 "must set `extends: \"...\"` to vndk extension")
2168 return
2169 }
2170 } else {
2171 if vndkdep.isVndkExt() {
2172 mctx.PropertyErrorf("vndk",
2173 "must set `vendor: true` to set `extends: %q`",
2174 m.getVndkExtendsModuleName())
2175 return
2176 }
2177 if m.VendorProperties.Vendor_available == nil {
2178 mctx.PropertyErrorf("vndk",
2179 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2180 return
2181 }
2182 }
2183 } else {
2184 if vndkdep.isVndkSp() {
2185 mctx.PropertyErrorf("vndk",
2186 "must set `enabled: true` to set `support_system_process: true`")
2187 return
2188 }
2189 if vndkdep.isVndkExt() {
2190 mctx.PropertyErrorf("vndk",
2191 "must set `enabled: true` to set `extends: %q`",
2192 m.getVndkExtendsModuleName())
2193 return
2194 }
Justin Yun8effde42017-06-23 19:24:43 +09002195 }
2196 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002197
Jiyong Parkf9332f12018-02-01 00:54:12 +09002198 var coreVariantNeeded bool = false
2199 var vendorVariantNeeded bool = false
2200 var recoveryVariantNeeded bool = false
2201
Justin Yun71549282017-11-17 12:10:28 +09002202 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002203 // If the device isn't compiling against the VNDK, we always
2204 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002205 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002206 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2207 // LL-NDK stubs only exist in the vendor variant, since the
2208 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002209 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09002210 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2211 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09002212 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09002213 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002214 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2215 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002216 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002217 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002218 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002219 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002220 coreVariantNeeded = true
2221 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002222 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002223 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09002224 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002225 } else {
2226 // This is either in /system (or similar: /data), or is a
2227 // modules built with the NDK. Modules built with the NDK
2228 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002229 coreVariantNeeded = true
2230 }
2231
2232 if Bool(m.Properties.Recovery_available) {
2233 recoveryVariantNeeded = true
2234 }
2235
2236 if m.ModuleBase.InstallInRecovery() {
2237 recoveryVariantNeeded = true
2238 coreVariantNeeded = false
2239 }
2240
Jiyong Park413cc742018-06-19 01:46:06 +09002241 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002242 primaryArch := mctx.Config().DevicePrimaryArchType()
2243 moduleArch := m.Target().Arch.ArchType
2244 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002245 recoveryVariantNeeded = false
2246 }
2247 }
2248
Jiyong Parkf9332f12018-02-01 00:54:12 +09002249 var variants []string
2250 if coreVariantNeeded {
2251 variants = append(variants, coreMode)
2252 }
2253 if vendorVariantNeeded {
2254 variants = append(variants, vendorMode)
2255 }
2256 if recoveryVariantNeeded {
2257 variants = append(variants, recoveryMode)
2258 }
2259 mod := mctx.CreateVariations(variants...)
2260 for i, v := range variants {
2261 if v == vendorMode {
2262 m := mod[i].(*Module)
2263 m.Properties.UseVndk = true
2264 squashVendorSrcs(m)
2265 } else if v == recoveryMode {
2266 m := mod[i].(*Module)
2267 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002268 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002269 squashRecoverySrcs(m)
2270 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002271 }
2272}
2273
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002274func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002275 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002276 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2277 }
Colin Cross6510f912017-11-29 00:27:14 -08002278 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002279}
2280
Colin Cross06a931b2015-10-28 17:23:31 -07002281var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002282var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002283var BoolPtr = proptools.BoolPtr
2284var String = proptools.String
2285var StringPtr = proptools.StringPtr