blob: 284b58d489e4a158de031286c38028a9d3079de6 [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -07001// Copyright 2015 Google Inc. All rights reserved.
Colin Cross3f40fa42015-01-30 17:27:36 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17// This file contains the module types for compiling C/C++ for Android, and converts the properties
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
Dan Albert9e10cd42016-08-03 14:12:14 -070022 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080023 "strings"
24
Colin Cross97ba0732015-03-23 17:50:24 -070025 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070026 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070027
Colin Cross635c3b02016-05-18 15:37:25 -070028 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070029 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070030 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080031)
32
Colin Cross463a90e2015-06-17 14:20:06 -070033func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070034 android.RegisterModuleType("cc_defaults", defaultsFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070035
Colin Cross1e676be2016-10-12 14:38:15 -070036 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +090037 ctx.BottomUp("image", ImageMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070038 ctx.BottomUp("link", LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +090039 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070040 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
41 ctx.BottomUp("test_per_src", testPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090042 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070043 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimc0907f12019-02-08 21:00:45 +090044 ctx.BottomUp("sysprop", SyspropMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070045 })
Colin Cross16b23492016-01-06 14:41:07 -080046
Colin Cross1e676be2016-10-12 14:38:15 -070047 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
48 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
49 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080050
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070051 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
52 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
53
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000054 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
55 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
56
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080057 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
58 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
59
Colin Cross1e676be2016-10-12 14:38:15 -070060 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
61 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080062
Colin Cross6b753602018-06-21 13:03:07 -070063 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator)
Jiyong Park379de2f2018-12-19 02:47:14 +090064 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080065
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080066 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080067 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070068
69 ctx.TopDown("lto_deps", ltoDepsMutator)
70 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090071
72 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070073 })
Colin Crossb98c8b02016-07-29 13:44:28 -070074
75 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070076}
77
Colin Crossca860ac2016-01-04 14:34:37 -080078type Deps struct {
79 SharedLibs, LateSharedLibs []string
80 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080081 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080082 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070083
Colin Cross5950f382016-12-13 12:50:57 -080084 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070085
Colin Cross81413472016-04-11 14:37:39 -070086 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070087
Dan Willemsenb40aab62016-04-20 14:21:14 -070088 GeneratedSources []string
89 GeneratedHeaders []string
90
Dan Willemsenb3454ab2016-09-28 17:34:58 -070091 ReexportGeneratedHeaders []string
92
Colin Cross97ba0732015-03-23 17:50:24 -070093 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -070094
95 // Used for host bionic
96 LinkerFlagsFile string
97 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -070098}
99
Colin Crossca860ac2016-01-04 14:34:37 -0800100type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700101 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900102 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700103 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900104 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700105 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700106 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700107
Colin Cross26c34ed2016-09-30 17:10:16 -0700108 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700109 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800110 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700111 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700112
Colin Cross26c34ed2016-09-30 17:10:16 -0700113 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700114 GeneratedSources android.Paths
115 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700116
Dan Willemsen76f08272016-07-09 00:14:08 -0700117 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700118 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700119
Colin Cross26c34ed2016-09-30 17:10:16 -0700120 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700121 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700122
123 // Path to the file container flags to use with the linker
124 LinkerFlagsFile android.OptionalPath
125
126 // Path to the dynamic linker binary
127 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700128}
129
Colin Crossca860ac2016-01-04 14:34:37 -0800130type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700131 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
132 ArFlags []string // Flags that apply to ar
133 AsFlags []string // Flags that apply to assembly source files
134 CFlags []string // Flags that apply to C and C++ source files
135 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
136 ConlyFlags []string // Flags that apply to C source files
137 CppFlags []string // Flags that apply to C++ source files
138 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
139 YaccFlags []string // Flags that apply to Yacc source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700140 aidlFlags []string // Flags that apply to aidl source files
141 rsFlags []string // Flags that apply to renderscript source files
142 LdFlags []string // Flags that apply to linker command lines
143 libFlags []string // Flags to add libraries early to the link order
144 TidyFlags []string // Flags that apply to clang-tidy
145 SAbiFlags []string // Flags that apply to header-abi-dumper
146 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700147
Colin Crossc3199482017-03-30 15:03:04 -0700148 // Global include flags that apply to C, C++, and assembly source files
149 // These must be after any module include flags, which will be in GlobalFlags.
150 SystemIncludeFlags []string
151
Colin Crossb98c8b02016-07-29 13:44:28 -0700152 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700153 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800154 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800155 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800156
157 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800158 DynamicLinker string
159
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700160 CFlagsDeps android.Paths // Files depended on by compiler flags
161 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800162
163 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800164
165 protoDeps android.Paths
166 protoFlags []string // Flags that apply to proto source files
167 protoOutTypeFlag string // The output type, --cpp_out for example
168 protoOutParams []string // Flags that modify the output of proto generated files
169 protoC bool // Whether to use C instead of C++
170 protoOptionsFile bool // Whether to look for a .options file next to the .proto
171 ProtoRoot bool
Colin Crossc472d572015-03-17 15:06:21 -0700172}
173
Colin Cross81413472016-04-11 14:37:39 -0700174type ObjectLinkerProperties struct {
175 // names of other cc_object modules to link into this module using partial linking
176 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700177
178 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800179 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700180}
181
Colin Crossca860ac2016-01-04 14:34:37 -0800182// Properties used to compile all C or C++ modules
183type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700184 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800185 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700186
187 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800188 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700189
Jiyong Parkde866cb2018-12-07 23:08:36 +0900190 AndroidMkSharedLibs []string `blueprint:"mutated"`
191 AndroidMkStaticLibs []string `blueprint:"mutated"`
192 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
193 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
194 HideFromMake bool `blueprint:"mutated"`
195 PreventInstall bool `blueprint:"mutated"`
196 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700197
198 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800199
200 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
201 // file
202 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900203
204 // Make this module available when building for recovery
205 Recovery_available *bool
206
207 InRecovery bool `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900208
209 // Allows this module to use non-APEX version of libraries. Useful
210 // for building binaries that are started before APEXes are activated.
211 Bootstrap *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700212}
213
214type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900215 // whether this module should be allowed to be directly depended by other
216 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
217 // If set to true, two variants will be built separately, one like
218 // normal, and the other limited to the set of libraries and headers
219 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700220 //
221 // The vendor variant may be used with a different (newer) /system,
222 // so it shouldn't have any unversioned runtime dependencies, or
223 // make assumptions about the system that may not be true in the
224 // future.
225 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900226 // If set to false, this module becomes inaccessible from /vendor modules.
227 //
228 // Default value is true when vndk: {enabled: true} or vendor: true.
229 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700230 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
231 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900232
233 // whether this module is capable of being loaded with other instance
234 // (possibly an older version) of the same module in the same process.
235 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
236 // can be double loaded in a vendor process if the library is also a
237 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
238 // explicitly marked as `double_loadable: true` by the owner, or the dependency
239 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
240 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800241}
242
Colin Crossca860ac2016-01-04 14:34:37 -0800243type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800244 static() bool
245 staticBinary() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700246 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700247 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800248 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700249 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800250 isNdk() bool
251 isLlndk() bool
252 isLlndkPublic() bool
253 isVndkPrivate() bool
Justin Yun8effde42017-06-23 19:24:43 +0900254 isVndk() bool
255 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800256 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900257 inRecovery() bool
Logan Chien2f2b8902018-07-10 15:01:19 +0800258 shouldCreateVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700259 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700260 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800261 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800262 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800263 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800264 useClangLld(actx ModuleContext) bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900265 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900266 hasStubsVariants() bool
267 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900268 bootstrap() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800269}
270
271type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700272 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800273 ModuleContextIntf
274}
275
276type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700277 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800278 ModuleContextIntf
279}
280
Colin Cross37047f12016-12-13 17:06:13 -0800281type DepsContext interface {
282 android.BottomUpMutatorContext
283 ModuleContextIntf
284}
285
Colin Crossca860ac2016-01-04 14:34:37 -0800286type feature interface {
287 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800288 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800289 flags(ctx ModuleContext, flags Flags) Flags
290 props() []interface{}
291}
292
293type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700294 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800295 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800296 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700297 compilerProps() []interface{}
298
Colin Cross76fada02016-07-27 10:31:13 -0700299 appendCflags([]string)
300 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700301 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800302}
303
304type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700305 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800306 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700307 linkerFlags(ctx ModuleContext, flags Flags) Flags
308 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800309 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700310
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700311 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700312 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900313 unstrippedOutputFilePath() android.Path
Colin Crossca860ac2016-01-04 14:34:37 -0800314}
315
316type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700317 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700318 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800319 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700320 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700321 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900322 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800323}
324
Colin Crossc99deeb2016-04-11 15:06:20 -0700325type dependencyTag struct {
326 blueprint.BaseDependencyTag
327 name string
328 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700329
330 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900331
332 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700333}
334
335var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700336 sharedDepTag = dependencyTag{name: "shared", library: true}
337 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
Jiyong Park64a44f22019-01-18 14:37:08 +0900338 earlySharedDepTag = dependencyTag{name: "early_shared", library: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700339 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
340 staticDepTag = dependencyTag{name: "static", library: true}
341 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
342 lateStaticDepTag = dependencyTag{name: "late static", library: true}
343 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800344 headerDepTag = dependencyTag{name: "header", library: true}
345 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700346 genSourceDepTag = dependencyTag{name: "gen source"}
347 genHeaderDepTag = dependencyTag{name: "gen header"}
348 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
349 objDepTag = dependencyTag{name: "obj"}
350 crtBeginDepTag = dependencyTag{name: "crtbegin"}
351 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700352 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
353 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700354 reuseObjTag = dependencyTag{name: "reuse objects"}
Jiyong Parke4bb9862019-02-01 00:31:10 +0900355 staticVariantTag = dependencyTag{name: "static variant"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700356 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
357 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800358 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800359 runtimeDepTag = dependencyTag{name: "runtime lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700360)
361
Colin Crossca860ac2016-01-04 14:34:37 -0800362// Module contains the properties and members used by all C/C++ module types, and implements
363// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
364// to construct the output file. Behavior can be customized with a Customizer interface
365type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700366 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700367 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900368 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700369
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700370 Properties BaseProperties
371 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700372
Colin Crossca860ac2016-01-04 14:34:37 -0800373 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700374 hod android.HostOrDeviceSupported
375 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700376
Colin Crossca860ac2016-01-04 14:34:37 -0800377 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700378 features []feature
379 compiler compiler
380 linker linker
381 installer installer
382 stl *stl
383 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800384 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800385 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900386 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700387 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700388 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800389 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800390
391 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700392
Colin Cross635c3b02016-05-18 15:37:25 -0700393 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800394
Colin Crossb98c8b02016-07-29 13:44:28 -0700395 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700396
397 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800398
399 // Flags used to compile this module
400 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700401
402 // 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 -0800403 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700404 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800405 depsInLinkOrder android.Paths
406
407 // only non-nil when this is a shared library that reuses the objects of a static library
408 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700409}
410
Jiyong Parkc20eee32018-09-05 22:36:17 +0900411func (c *Module) OutputFile() android.OptionalPath {
412 return c.outputFile
413}
414
Jiyong Park719b4462019-01-13 00:39:51 +0900415func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900416 if c.linker != nil {
417 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900418 }
419 return nil
420}
421
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900422func (c *Module) RelativeInstallPath() string {
423 if c.installer != nil {
424 return c.installer.relativeInstallPath()
425 }
426 return ""
427}
428
Colin Cross36242852017-06-23 15:06:31 -0700429func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700430 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800431 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700432 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800433 }
434 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700435 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800436 }
437 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700438 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800439 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700440 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700441 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700442 }
Colin Cross16b23492016-01-06 14:41:07 -0800443 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700444 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800445 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800446 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700447 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800448 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800449 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700450 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800451 }
Justin Yun8effde42017-06-23 19:24:43 +0900452 if c.vndkdep != nil {
453 c.AddProperties(c.vndkdep.props()...)
454 }
Stephen Craneba090d12017-05-09 15:44:35 -0700455 if c.lto != nil {
456 c.AddProperties(c.lto.props()...)
457 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700458 if c.pgo != nil {
459 c.AddProperties(c.pgo.props()...)
460 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800461 if c.xom != nil {
462 c.AddProperties(c.xom.props()...)
463 }
Colin Crossca860ac2016-01-04 14:34:37 -0800464 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700465 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800466 }
Colin Crossc472d572015-03-17 15:06:21 -0700467
Colin Crossa9d8bee2018-10-02 13:59:46 -0700468 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
469 switch class {
470 case android.Device:
471 return ctx.Config().DevicePrefer32BitExecutables()
472 case android.HostCross:
473 // Windows builds always prefer 32-bit
474 return true
475 default:
476 return false
477 }
478 })
Colin Cross36242852017-06-23 15:06:31 -0700479 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700480
Colin Cross1f44a3a2017-07-07 14:33:33 -0700481 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700482
Jiyong Park9d452992018-10-03 00:38:19 +0900483 android.InitApexModule(c)
484
Colin Cross36242852017-06-23 15:06:31 -0700485 return c
Colin Crossc472d572015-03-17 15:06:21 -0700486}
487
Colin Crossb916a382016-07-29 17:28:03 -0700488// Returns true for dependency roots (binaries)
489// TODO(ccross): also handle dlopenable libraries
490func (c *Module) isDependencyRoot() bool {
491 if root, ok := c.linker.(interface {
492 isDependencyRoot() bool
493 }); ok {
494 return root.isDependencyRoot()
495 }
496 return false
497}
498
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700499func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700500 return c.Properties.UseVndk
501}
502
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800503func (c *Module) isCoverageVariant() bool {
504 return c.coverage.Properties.IsCoverageVariant
505}
506
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800507func (c *Module) isNdk() bool {
508 return inList(c.Name(), ndkMigratedLibs)
509}
510
511func (c *Module) isLlndk() bool {
512 // Returns true for both LLNDK (public) and LLNDK-private libs.
513 return inList(c.Name(), llndkLibraries)
514}
515
516func (c *Module) isLlndkPublic() bool {
517 // Returns true only for LLNDK (public) libs.
518 return c.isLlndk() && !c.isVndkPrivate()
519}
520
521func (c *Module) isVndkPrivate() bool {
522 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
523 return inList(c.Name(), vndkPrivateLibraries)
524}
525
Justin Yun8effde42017-06-23 19:24:43 +0900526func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800527 if vndkdep := c.vndkdep; vndkdep != nil {
528 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900529 }
530 return false
531}
532
Yi Kong7e53c572018-02-14 18:16:12 +0800533func (c *Module) isPgoCompile() bool {
534 if pgo := c.pgo; pgo != nil {
535 return pgo.Properties.PgoCompile
536 }
537 return false
538}
539
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800540func (c *Module) isNDKStubLibrary() bool {
541 if _, ok := c.compiler.(*stubDecorator); ok {
542 return true
543 }
544 return false
545}
546
Logan Chienf3511742017-10-31 18:04:35 +0800547func (c *Module) isVndkSp() bool {
548 if vndkdep := c.vndkdep; vndkdep != nil {
549 return vndkdep.isVndkSp()
550 }
551 return false
552}
553
554func (c *Module) isVndkExt() bool {
555 if vndkdep := c.vndkdep; vndkdep != nil {
556 return vndkdep.isVndkExt()
557 }
558 return false
559}
560
561func (c *Module) getVndkExtendsModuleName() string {
562 if vndkdep := c.vndkdep; vndkdep != nil {
563 return vndkdep.getVndkExtendsModuleName()
564 }
565 return ""
566}
567
Jiyong Park82e2bf32017-08-16 14:05:54 +0900568// Returns true only when this module is configured to have core and vendor
569// variants.
570func (c *Module) hasVendorVariant() bool {
571 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
572}
573
Jiyong Parkf9332f12018-02-01 00:54:12 +0900574func (c *Module) inRecovery() bool {
575 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
576}
577
578func (c *Module) onlyInRecovery() bool {
579 return c.ModuleBase.InstallInRecovery()
580}
581
Jiyong Park25fc6a92018-11-18 18:02:45 +0900582func (c *Module) IsStubs() bool {
583 if library, ok := c.linker.(*libraryDecorator); ok {
584 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900585 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
586 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900587 }
588 return false
589}
590
591func (c *Module) HasStubsVariants() bool {
592 if library, ok := c.linker.(*libraryDecorator); ok {
593 return len(library.Properties.Stubs.Versions) > 0
594 }
595 return false
596}
597
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900598func (c *Module) bootstrap() bool {
599 return Bool(c.Properties.Bootstrap)
600}
601
Colin Crossca860ac2016-01-04 14:34:37 -0800602type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700603 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800604 moduleContextImpl
605}
606
Colin Cross37047f12016-12-13 17:06:13 -0800607type depsContext struct {
608 android.BottomUpMutatorContext
609 moduleContextImpl
610}
611
Colin Crossca860ac2016-01-04 14:34:37 -0800612type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700613 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800614 moduleContextImpl
615}
616
Jiyong Park2db76922017-11-08 16:03:48 +0900617func (ctx *moduleContext) SocSpecific() bool {
618 return ctx.ModuleContext.SocSpecific() ||
619 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700620}
621
Colin Crossca860ac2016-01-04 14:34:37 -0800622type moduleContextImpl struct {
623 mod *Module
624 ctx BaseModuleContext
625}
626
Colin Crossb98c8b02016-07-29 13:44:28 -0700627func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800628 return ctx.mod.toolchain(ctx.ctx)
629}
630
631func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000632 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800633}
634
635func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900636 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800637}
638
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700639func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800640 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800641 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700642 }
643 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800644}
645
646func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700647 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700648 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900649 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700650 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900651 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
652 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
653 return "current"
654 }
655 return platform_vndk_ver
656 }
657 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800658 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900659 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700660 }
661 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800662}
663
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700664func (ctx *moduleContextImpl) useVndk() bool {
665 return ctx.mod.useVndk()
666}
Justin Yun8effde42017-06-23 19:24:43 +0900667
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800668func (ctx *moduleContextImpl) isNdk() bool {
669 return ctx.mod.isNdk()
670}
671
672func (ctx *moduleContextImpl) isLlndk() bool {
673 return ctx.mod.isLlndk()
674}
675
676func (ctx *moduleContextImpl) isLlndkPublic() bool {
677 return ctx.mod.isLlndkPublic()
678}
679
680func (ctx *moduleContextImpl) isVndkPrivate() bool {
681 return ctx.mod.isVndkPrivate()
682}
683
Logan Chienf3511742017-10-31 18:04:35 +0800684func (ctx *moduleContextImpl) isVndk() bool {
685 return ctx.mod.isVndk()
686}
687
Yi Kong7e53c572018-02-14 18:16:12 +0800688func (ctx *moduleContextImpl) isPgoCompile() bool {
689 return ctx.mod.isPgoCompile()
690}
691
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800692func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
693 return ctx.mod.isNDKStubLibrary()
694}
695
Justin Yun8effde42017-06-23 19:24:43 +0900696func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800697 return ctx.mod.isVndkSp()
698}
699
700func (ctx *moduleContextImpl) isVndkExt() bool {
701 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900702}
703
Jiyong Parkf9332f12018-02-01 00:54:12 +0900704func (ctx *moduleContextImpl) inRecovery() bool {
705 return ctx.mod.inRecovery()
706}
707
Logan Chien2f2b8902018-07-10 15:01:19 +0800708// Check whether ABI dumps should be created for this module.
709func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump() bool {
710 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
711 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800712 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800713
714 if ctx.ctx.Fuchsia() {
715 return false
716 }
717
Logan Chien2f2b8902018-07-10 15:01:19 +0800718 if sanitize := ctx.mod.sanitize; sanitize != nil {
719 if !sanitize.isVariantOnProductionDevice() {
720 return false
721 }
722 }
723 if !ctx.ctx.Device() {
724 // Host modules do not need ABI dumps.
725 return false
726 }
Logan Chienfa478c02018-12-28 16:25:39 +0800727 if !ctx.mod.IsForPlatform() {
728 // APEX variants do not need ABI dumps.
729 return false
730 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800731 if ctx.isNdk() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800732 return true
733 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800734 if ctx.isLlndkPublic() {
Logan Chienf4b79c62018-08-02 02:27:02 +0800735 return true
736 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800737 if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800738 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
739 // VNDK-private.
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800740 return true
Logan Chien2f2b8902018-07-10 15:01:19 +0800741 }
742 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800743}
744
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700745func (ctx *moduleContextImpl) selectedStl() string {
746 if stl := ctx.mod.stl; stl != nil {
747 return stl.Properties.SelectedStl
748 }
749 return ""
750}
751
Ivan Lozanobd721262018-11-27 14:33:03 -0800752func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
753 return ctx.mod.linker.useClangLld(actx)
754}
755
Colin Crossce75d2c2016-10-06 16:12:58 -0700756func (ctx *moduleContextImpl) baseModuleName() string {
757 return ctx.mod.ModuleBase.BaseModuleName()
758}
759
Logan Chienf3511742017-10-31 18:04:35 +0800760func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
761 return ctx.mod.getVndkExtendsModuleName()
762}
763
Jiyong Park58e364a2019-01-19 19:24:06 +0900764func (ctx *moduleContextImpl) apexName() string {
765 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900766}
767
Jiyong Parkb0788572018-12-20 22:10:17 +0900768func (ctx *moduleContextImpl) hasStubsVariants() bool {
769 return ctx.mod.HasStubsVariants()
770}
771
772func (ctx *moduleContextImpl) isStubs() bool {
773 return ctx.mod.IsStubs()
774}
775
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900776func (ctx *moduleContextImpl) bootstrap() bool {
777 return ctx.mod.bootstrap()
778}
779
Colin Cross635c3b02016-05-18 15:37:25 -0700780func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800781 return &Module{
782 hod: hod,
783 multilib: multilib,
784 }
785}
786
Colin Cross635c3b02016-05-18 15:37:25 -0700787func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800788 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700789 module.features = []feature{
790 &tidyFeature{},
791 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700792 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800793 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800794 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800795 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900796 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700797 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700798 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800799 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800800 return module
801}
802
Colin Crossce75d2c2016-10-06 16:12:58 -0700803func (c *Module) Prebuilt() *android.Prebuilt {
804 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
805 return p.prebuilt()
806 }
807 return nil
808}
809
810func (c *Module) Name() string {
811 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700812 if p, ok := c.linker.(interface {
813 Name(string) string
814 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700815 name = p.Name(name)
816 }
817 return name
818}
819
Alex Light3d673592019-01-18 14:37:31 -0800820func (c *Module) Symlinks() []string {
821 if p, ok := c.installer.(interface {
822 symlinkList() []string
823 }); ok {
824 return p.symlinkList()
825 }
826 return nil
827}
828
Jeff Gaston294356f2017-09-27 17:05:30 -0700829// orderDeps reorders dependencies into a list such that if module A depends on B, then
830// A will precede B in the resultant list.
831// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800832// Note that directSharedDeps should be the analogous static library for each shared lib dep
833func 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 -0700834 // If A depends on B, then
835 // Every list containing A will also contain B later in the list
836 // So, after concatenating all lists, the final instance of B will have come from the same
837 // original list as the final instance of A
838 // So, the final instance of B will be later in the concatenation than the final A
839 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
840 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800841 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700842 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800843 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
844 }
845 for _, dep := range directSharedDeps {
846 orderedAllDeps = append(orderedAllDeps, dep)
847 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700848 }
849
Colin Crossb6715442017-10-24 11:13:31 -0700850 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700851
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800852 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700853 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800854 // resultant list to only what the caller has chosen to include in directStaticDeps
855 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700856
857 return orderedAllDeps, orderedDeclaredDeps
858}
859
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800860func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
861 // convert Module to Path
862 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
863 staticDepFiles := []android.Path{}
864 for _, dep := range staticDeps {
865 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
866 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700867 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800868 sharedDepFiles := []android.Path{}
869 for _, sharedDep := range sharedDeps {
870 staticAnalogue := sharedDep.staticVariant
871 if staticAnalogue != nil {
872 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
873 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
874 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700875 }
876
877 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800878 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700879
880 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700881}
882
Colin Cross635c3b02016-05-18 15:37:25 -0700883func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800884 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700885 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800886 moduleContextImpl: moduleContextImpl{
887 mod: c,
888 },
889 }
890 ctx.ctx = ctx
891
Colin Crossf18e1102017-11-16 14:33:08 -0800892 deps := c.depsToPaths(ctx)
893 if ctx.Failed() {
894 return
895 }
896
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700897 if c.Properties.Clang != nil && *c.Properties.Clang == false {
898 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
899 }
900
Colin Crossca860ac2016-01-04 14:34:37 -0800901 flags := Flags{
902 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800903 }
Colin Crossca860ac2016-01-04 14:34:37 -0800904 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800905 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800906 }
907 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700908 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800909 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700910 if c.stl != nil {
911 flags = c.stl.flags(ctx, flags)
912 }
Colin Cross16b23492016-01-06 14:41:07 -0800913 if c.sanitize != nil {
914 flags = c.sanitize.flags(ctx, flags)
915 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800916 if c.coverage != nil {
917 flags = c.coverage.flags(ctx, flags)
918 }
Stephen Craneba090d12017-05-09 15:44:35 -0700919 if c.lto != nil {
920 flags = c.lto.flags(ctx, flags)
921 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700922 if c.pgo != nil {
923 flags = c.pgo.flags(ctx, flags)
924 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800925 if c.xom != nil {
926 flags = c.xom.flags(ctx, flags)
927 }
Colin Crossca860ac2016-01-04 14:34:37 -0800928 for _, feature := range c.features {
929 flags = feature.flags(ctx, flags)
930 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800931 if ctx.Failed() {
932 return
933 }
934
Colin Crossb98c8b02016-07-29 13:44:28 -0700935 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
936 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
937 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800938
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800939 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
940 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700941 // We need access to all the flags seen by a source file.
942 if c.sabi != nil {
943 flags = c.sabi.flags(ctx, flags)
944 }
Colin Crossca860ac2016-01-04 14:34:37 -0800945 // Optimization to reduce size of build.ninja
946 // Replace the long list of flags for each file with a module-local variable
947 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
948 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
949 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
950 flags.CFlags = []string{"$cflags"}
951 flags.CppFlags = []string{"$cppflags"}
952 flags.AsFlags = []string{"$asflags"}
953
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700954 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800955 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700956 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800957 if ctx.Failed() {
958 return
959 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800960 }
961
Colin Crossca860ac2016-01-04 14:34:37 -0800962 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700963 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800964 if ctx.Failed() {
965 return
966 }
Colin Cross635c3b02016-05-18 15:37:25 -0700967 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +0900968
969 // If a lib is directly included in any of the APEXes, unhide the stubs
970 // variant having the latest version gets visible to make. In addition,
971 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
972 // force anything in the make world to link against the stubs library.
973 // (unless it is explicitly referenced via .bootstrap suffix or the
974 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +0000975 if c.HasStubsVariants() &&
976 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800977 !c.inRecovery() && !c.useVndk() && !c.static() && !c.isCoverageVariant() &&
978 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +0900979 c.Properties.HideFromMake = false // unhide
980 // Note: this is still non-installable
981 }
Colin Crossce75d2c2016-10-06 16:12:58 -0700982 }
Colin Cross5049f022015-03-18 13:28:46 -0700983
Jiyong Park9d452992018-10-03 00:38:19 +0900984 if c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() {
Colin Crossce75d2c2016-10-06 16:12:58 -0700985 c.installer.install(ctx, c.outputFile.Path())
986 if ctx.Failed() {
987 return
Colin Crossca860ac2016-01-04 14:34:37 -0800988 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700989 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800990}
991
Jiyong Park379de2f2018-12-19 02:47:14 +0900992func (c *Module) toolchain(ctx android.BaseContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800993 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700994 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800995 }
Colin Crossca860ac2016-01-04 14:34:37 -0800996 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800997}
998
Colin Crossca860ac2016-01-04 14:34:37 -0800999func (c *Module) begin(ctx BaseModuleContext) {
1000 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001001 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001002 }
Colin Crossca860ac2016-01-04 14:34:37 -08001003 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001004 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001005 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001006 if c.stl != nil {
1007 c.stl.begin(ctx)
1008 }
Colin Cross16b23492016-01-06 14:41:07 -08001009 if c.sanitize != nil {
1010 c.sanitize.begin(ctx)
1011 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001012 if c.coverage != nil {
1013 c.coverage.begin(ctx)
1014 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001015 if c.sabi != nil {
1016 c.sabi.begin(ctx)
1017 }
Justin Yun8effde42017-06-23 19:24:43 +09001018 if c.vndkdep != nil {
1019 c.vndkdep.begin(ctx)
1020 }
Stephen Craneba090d12017-05-09 15:44:35 -07001021 if c.lto != nil {
1022 c.lto.begin(ctx)
1023 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001024 if c.pgo != nil {
1025 c.pgo.begin(ctx)
1026 }
Colin Crossca860ac2016-01-04 14:34:37 -08001027 for _, feature := range c.features {
1028 feature.begin(ctx)
1029 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001030 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001031 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001032 if err != nil {
1033 ctx.PropertyErrorf("sdk_version", err.Error())
1034 }
Nan Zhang0007d812017-11-07 10:57:05 -08001035 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001036 }
Colin Crossca860ac2016-01-04 14:34:37 -08001037}
1038
Colin Cross37047f12016-12-13 17:06:13 -08001039func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001040 deps := Deps{}
1041
1042 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001043 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001044 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001045 // Add the PGO dependency (the clang_rt.profile runtime library), which
1046 // sometimes depends on symbols from libgcc, before libgcc gets added
1047 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001048 if c.pgo != nil {
1049 deps = c.pgo.deps(ctx, deps)
1050 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001051 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001052 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001053 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001054 if c.stl != nil {
1055 deps = c.stl.deps(ctx, deps)
1056 }
Colin Cross16b23492016-01-06 14:41:07 -08001057 if c.sanitize != nil {
1058 deps = c.sanitize.deps(ctx, deps)
1059 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001060 if c.coverage != nil {
1061 deps = c.coverage.deps(ctx, deps)
1062 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001063 if c.sabi != nil {
1064 deps = c.sabi.deps(ctx, deps)
1065 }
Justin Yun8effde42017-06-23 19:24:43 +09001066 if c.vndkdep != nil {
1067 deps = c.vndkdep.deps(ctx, deps)
1068 }
Stephen Craneba090d12017-05-09 15:44:35 -07001069 if c.lto != nil {
1070 deps = c.lto.deps(ctx, deps)
1071 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001072 for _, feature := range c.features {
1073 deps = feature.deps(ctx, deps)
1074 }
1075
Colin Crossb6715442017-10-24 11:13:31 -07001076 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1077 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1078 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1079 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1080 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1081 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001082 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001083
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001084 for _, lib := range deps.ReexportSharedLibHeaders {
1085 if !inList(lib, deps.SharedLibs) {
1086 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1087 }
1088 }
1089
1090 for _, lib := range deps.ReexportStaticLibHeaders {
1091 if !inList(lib, deps.StaticLibs) {
1092 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1093 }
1094 }
1095
Colin Cross5950f382016-12-13 12:50:57 -08001096 for _, lib := range deps.ReexportHeaderLibHeaders {
1097 if !inList(lib, deps.HeaderLibs) {
1098 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1099 }
1100 }
1101
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001102 for _, gen := range deps.ReexportGeneratedHeaders {
1103 if !inList(gen, deps.GeneratedHeaders) {
1104 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1105 }
1106 }
1107
Colin Crossc99deeb2016-04-11 15:06:20 -07001108 return deps
1109}
1110
Dan Albert7e9d2952016-08-04 13:02:36 -07001111func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001112 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001113 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001114 moduleContextImpl: moduleContextImpl{
1115 mod: c,
1116 },
1117 }
1118 ctx.ctx = ctx
1119
Colin Crossca860ac2016-01-04 14:34:37 -08001120 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001121}
1122
Jiyong Park7ed9de32018-10-15 22:25:07 +09001123// Split name#version into name and version
1124func stubsLibNameAndVersion(name string) (string, string) {
1125 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1126 version := name[sharp+1:]
1127 libname := name[:sharp]
1128 return libname, version
1129 }
1130 return name, ""
1131}
1132
Colin Cross1e676be2016-10-12 14:38:15 -07001133func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001134 ctx := &depsContext{
1135 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001136 moduleContextImpl: moduleContextImpl{
1137 mod: c,
1138 },
1139 }
1140 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001141
Colin Crossc99deeb2016-04-11 15:06:20 -07001142 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001143
Dan Albert914449f2016-06-17 16:45:24 -07001144 variantNdkLibs := []string{}
1145 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001146 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001147 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001148
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001149 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1150 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001151 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001152 // 1. Name of an NDK library that refers to a prebuilt module.
1153 // For each of these, it adds the name of the prebuilt module (which will be in
1154 // prebuilts/ndk) to the list of nonvariant libs.
1155 // 2. Name of an NDK library that refers to an ndk_library module.
1156 // For each of these, it adds the name of the ndk_library module to the list of
1157 // variant libs.
1158 // 3. Anything else (so anything that isn't an NDK library).
1159 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001160 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001161 // The caller can then know to add the variantLibs dependencies differently from the
1162 // nonvariantLibs
1163 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1164 variantLibs = []string{}
1165 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001166 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001167 // strip #version suffix out
1168 name, _ := stubsLibNameAndVersion(entry)
1169 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1170 if !inList(name, ndkMigratedLibs) {
1171 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001172 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001173 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001174 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001175 } else if ctx.useVndk() && inList(name, llndkLibraries) {
1176 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
1177 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, vendorPublicLibraries) {
1178 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001179 if actx.OtherModuleExists(vendorPublicLib) {
1180 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1181 } else {
1182 // This can happen if vendor_public_library module is defined in a
1183 // namespace that isn't visible to the current module. In that case,
1184 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001185 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001186 }
Dan Albert914449f2016-06-17 16:45:24 -07001187 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001188 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001189 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001190 }
1191 }
Dan Albert914449f2016-06-17 16:45:24 -07001192 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001193 }
1194
Dan Albert914449f2016-06-17 16:45:24 -07001195 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1196 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001197 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001198 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001199
Jiyong Park7e636d02019-01-28 16:16:54 +09001200 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001201 if c.linker != nil {
1202 if library, ok := c.linker.(*libraryDecorator); ok {
1203 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001204 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001205 }
1206 }
1207 }
1208
Colin Cross32ec36c2016-12-15 07:39:51 -08001209 for _, lib := range deps.HeaderLibs {
1210 depTag := headerDepTag
1211 if inList(lib, deps.ReexportHeaderLibHeaders) {
1212 depTag = headerExportDepTag
1213 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001214 if buildStubs {
Jiyong Park7e636d02019-01-28 16:16:54 +09001215 actx.AddFarVariationDependencies([]blueprint.Variation{
1216 {Mutator: "arch", Variation: ctx.Target().String()},
Jiyong Park3b1746a2019-01-29 11:15:04 +09001217 {Mutator: "image", Variation: c.imageVariation()},
Jiyong Park7e636d02019-01-28 16:16:54 +09001218 }, depTag, lib)
1219 } else {
1220 actx.AddVariationDependencies(nil, depTag, lib)
1221 }
1222 }
1223
1224 if buildStubs {
1225 // Stubs lib does not have dependency to other static/shared libraries.
1226 // Don't proceed.
1227 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001228 }
Colin Cross5950f382016-12-13 12:50:57 -08001229
Inseob Kimc0907f12019-02-08 21:00:45 +09001230 syspropImplLibraries := syspropImplLibraries(actx.Config())
1231
Jiyong Park5d1598f2019-02-25 22:14:17 +09001232 for _, lib := range deps.WholeStaticLibs {
1233 depTag := wholeStaticDepTag
1234 if impl, ok := syspropImplLibraries[lib]; ok {
1235 lib = impl
1236 }
1237 actx.AddVariationDependencies([]blueprint.Variation{
1238 {Mutator: "link", Variation: "static"},
1239 }, depTag, lib)
1240 }
1241
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001242 for _, lib := range deps.StaticLibs {
1243 depTag := staticDepTag
1244 if inList(lib, deps.ReexportStaticLibHeaders) {
1245 depTag = staticExportDepTag
1246 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001247
1248 if impl, ok := syspropImplLibraries[lib]; ok {
1249 lib = impl
1250 }
1251
Dan Willemsen59339a22018-07-22 21:18:45 -07001252 actx.AddVariationDependencies([]blueprint.Variation{
1253 {Mutator: "link", Variation: "static"},
1254 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001255 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001256
Dan Willemsen59339a22018-07-22 21:18:45 -07001257 actx.AddVariationDependencies([]blueprint.Variation{
1258 {Mutator: "link", Variation: "static"},
1259 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001260
Jiyong Park25fc6a92018-11-18 18:02:45 +09001261 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1262 var variations []blueprint.Variation
1263 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001264 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001265 if version != "" && versionVariantAvail {
1266 // Version is explicitly specified. i.e. libFoo#30
1267 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1268 depTag.explicitlyVersioned = true
1269 }
1270 actx.AddVariationDependencies(variations, depTag, name)
1271
1272 // If the version is not specified, add dependency to the latest stubs library.
1273 // The stubs library will be used when the depending module is built for APEX and
1274 // the dependent module is not in the same APEX.
1275 latestVersion := latestStubsVersionFor(actx.Config(), name)
1276 if version == "" && latestVersion != "" && versionVariantAvail {
1277 actx.AddVariationDependencies([]blueprint.Variation{
1278 {Mutator: "link", Variation: "shared"},
1279 {Mutator: "version", Variation: latestVersion},
1280 }, depTag, name)
1281 // Note that depTag.explicitlyVersioned is false in this case.
1282 }
1283 }
1284
Jiyong Park7ed9de32018-10-15 22:25:07 +09001285 // shared lib names without the #version suffix
1286 var sharedLibNames []string
1287
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001288 for _, lib := range deps.SharedLibs {
1289 depTag := sharedDepTag
1290 if inList(lib, deps.ReexportSharedLibHeaders) {
1291 depTag = sharedExportDepTag
1292 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001293
1294 if impl, ok := syspropImplLibraries[lib]; ok {
1295 lib = impl
1296 }
1297
1298 name, version := stubsLibNameAndVersion(lib)
1299 sharedLibNames = append(sharedLibNames, name)
1300
Jiyong Park25fc6a92018-11-18 18:02:45 +09001301 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001302 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001303
Jiyong Park7ed9de32018-10-15 22:25:07 +09001304 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001305 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001306 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1307 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1308 // linking against both the stubs lib and the non-stubs lib at the same time.
1309 continue
1310 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001311 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001312 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001313
Dan Willemsen59339a22018-07-22 21:18:45 -07001314 actx.AddVariationDependencies([]blueprint.Variation{
1315 {Mutator: "link", Variation: "shared"},
1316 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001317
Colin Cross68861832016-07-08 10:41:41 -07001318 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001319
1320 for _, gen := range deps.GeneratedHeaders {
1321 depTag := genHeaderDepTag
1322 if inList(gen, deps.ReexportGeneratedHeaders) {
1323 depTag = genHeaderExportDepTag
1324 }
1325 actx.AddDependency(c, depTag, gen)
1326 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001327
Colin Cross42d48b72018-08-29 14:10:52 -07001328 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001329
1330 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001331 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001332 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001333 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001334 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001335 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001336 if deps.LinkerFlagsFile != "" {
1337 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1338 }
1339 if deps.DynamicLinker != "" {
1340 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001341 }
Dan Albert914449f2016-06-17 16:45:24 -07001342
1343 version := ctx.sdkVersion()
1344 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001345 {Mutator: "ndk_api", Variation: version},
1346 {Mutator: "link", Variation: "shared"},
1347 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001348 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001349 {Mutator: "ndk_api", Variation: version},
1350 {Mutator: "link", Variation: "shared"},
1351 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001352
1353 if vndkdep := c.vndkdep; vndkdep != nil {
1354 if vndkdep.isVndkExt() {
1355 baseModuleMode := vendorMode
1356 if actx.DeviceConfig().VndkVersion() == "" {
1357 baseModuleMode = coreMode
1358 }
1359 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001360 {Mutator: "image", Variation: baseModuleMode},
1361 {Mutator: "link", Variation: "shared"},
1362 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001363 }
1364 }
Colin Cross6362e272015-10-29 15:25:03 -07001365}
Colin Cross21b9a242015-03-24 14:15:58 -07001366
Colin Crosse40b4ea2018-10-02 22:25:58 -07001367func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001368 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1369 c.beginMutator(ctx)
1370 }
1371}
1372
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001373// Whether a module can link to another module, taking into
1374// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001375func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001376 if from.Target().Os != android.Android {
1377 // Host code is not restricted
1378 return
1379 }
1380 if from.Properties.UseVndk {
1381 // Though vendor code is limited by the vendor mutator,
1382 // each vendor-available module needs to check
1383 // link-type for VNDK.
1384 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001385 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001386 }
1387 return
1388 }
Nan Zhang0007d812017-11-07 10:57:05 -08001389 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001390 // Platform code can link to anything
1391 return
1392 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001393 if from.inRecovery() {
1394 // Recovery code is not NDK
1395 return
1396 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001397 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1398 // These are always allowed
1399 return
1400 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001401 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1402 // These are allowed, but they don't set sdk_version
1403 return
1404 }
1405 if _, ok := to.linker.(*stubDecorator); ok {
1406 // These aren't real libraries, but are the stub shared libraries that are included in
1407 // the NDK.
1408 return
1409 }
Logan Chien834b9a62019-01-14 15:39:03 +08001410
1411 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" {
1412 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1413 // to link to libc++ (non-NDK and without sdk_version).
1414 return
1415 }
1416
Nan Zhang0007d812017-11-07 10:57:05 -08001417 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001418 // NDK code linking to platform code is never okay.
1419 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1420 ctx.OtherModuleName(to))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001421 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001422 }
1423
1424 // At this point we know we have two NDK libraries, but we need to
1425 // check that we're not linking against anything built against a higher
1426 // API level, as it is only valid to link against older or equivalent
1427 // APIs.
1428
Inseob Kim01a28722018-04-11 09:48:45 +09001429 // Current can link against anything.
1430 if String(from.Properties.Sdk_version) != "current" {
1431 // Otherwise we need to check.
1432 if String(to.Properties.Sdk_version) == "current" {
1433 // Current can't be linked against by anything else.
1434 ctx.ModuleErrorf("links %q built against newer API version %q",
1435 ctx.OtherModuleName(to), "current")
1436 } else {
1437 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1438 if err != nil {
1439 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001440 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001441 String(from.Properties.Sdk_version))
1442 }
1443 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1444 if err != nil {
1445 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001446 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001447 String(to.Properties.Sdk_version))
1448 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001449
Inseob Kim01a28722018-04-11 09:48:45 +09001450 if toApi > fromApi {
1451 ctx.ModuleErrorf("links %q built against newer API version %q",
1452 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1453 }
1454 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001455 }
Dan Albert202fe492017-12-15 13:56:59 -08001456
1457 // Also check that the two STL choices are compatible.
1458 fromStl := from.stl.Properties.SelectedStl
1459 toStl := to.stl.Properties.SelectedStl
1460 if fromStl == "" || toStl == "" {
1461 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001462 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001463 // We can be permissive with the system "STL" since it is only the C++
1464 // ABI layer, but in the future we should make sure that everyone is
1465 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001466 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001467 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1468 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1469 to.stl.Properties.SelectedStl)
1470 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001471}
1472
Jiyong Park5fb8c102018-04-09 12:03:06 +09001473// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001474// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1475// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001476// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001477func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
1478 check := func(child, parent android.Module) bool {
1479 to, ok := child.(*Module)
1480 if !ok {
1481 // follow thru cc.Defaults, etc.
1482 return true
1483 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001484
Jooyung Hana70f0672019-01-18 15:20:43 +09001485 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1486 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001487 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001488
1489 // if target lib has no vendor variant, keep checking dependency graph
1490 if !to.hasVendorVariant() {
1491 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001492 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001493
1494 if to.isVndkSp() || inList(child.Name(), llndkLibraries) || Bool(to.VendorProperties.Double_loadable) {
1495 return false
1496 }
1497
1498 var stringPath []string
1499 for _, m := range ctx.GetWalkPath() {
1500 stringPath = append(stringPath, m.Name())
1501 }
1502 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1503 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1504 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1505 return false
1506 }
1507 if module, ok := ctx.Module().(*Module); ok {
1508 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
1509 if inList(ctx.ModuleName(), llndkLibraries) || Bool(module.VendorProperties.Double_loadable) {
1510 ctx.WalkDeps(check)
1511 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001512 }
1513 }
1514}
1515
Colin Crossc99deeb2016-04-11 15:06:20 -07001516// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001517func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001518 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001519
Jeff Gaston294356f2017-09-27 17:05:30 -07001520 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001521 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001522
Colin Crossd11fcda2017-10-23 17:59:01 -07001523 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001524 depName := ctx.OtherModuleName(dep)
1525 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001526
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001527 ccDep, _ := dep.(*Module)
1528 if ccDep == nil {
1529 // handling for a few module types that aren't cc Module but that are also supported
1530 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001531 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001532 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001533 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1534 genRule.GeneratedSourceFiles()...)
1535 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001536 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001537 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001538 // Support exported headers from a generated_sources dependency
1539 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001540 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001541 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001542 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001543 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001544 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001545 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001546 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001547 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001548 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001549 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001550 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1551 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1552
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001553 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001554 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001555 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001556 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001557 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001558 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001559 files := genRule.GeneratedSourceFiles()
1560 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001561 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001562 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001563 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 -07001564 }
1565 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001566 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001567 }
Colin Crossca860ac2016-01-04 14:34:37 -08001568 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001569 return
1570 }
1571
Colin Crossd11fcda2017-10-23 17:59:01 -07001572 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001573 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1574 return
1575 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001576 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001577 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001578 return
1579 }
1580
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001581 // re-exporting flags
1582 if depTag == reuseObjTag {
1583 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001584 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001585 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001586 depPaths.Objs = depPaths.Objs.Append(objs)
1587 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001588 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001589 return
1590 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001591 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001592
Jiyong Parke4bb9862019-02-01 00:31:10 +09001593 if depTag == staticVariantTag {
1594 if _, ok := ccDep.compiler.(libraryInterface); ok {
1595 c.staticVariant = ccDep
1596 return
1597 }
1598 }
1599
Jiyong Park25fc6a92018-11-18 18:02:45 +09001600 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1601 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1602 // won't be matched to sharedDepTag and lateSharedDepTag.
1603 explicitlyVersioned := false
1604 if t, ok := depTag.(dependencyTag); ok {
1605 explicitlyVersioned = t.explicitlyVersioned
1606 t.explicitlyVersioned = false
1607 depTag = t
1608 }
1609
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001610 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001611 depIsStatic := false
1612 switch depTag {
1613 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1614 depIsStatic = true
1615 }
1616 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001617 depIsStubs := dependentLibrary.buildStubs()
1618 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001619 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001620 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001621
1622 var useThisDep bool
1623 if depIsStubs && explicitlyVersioned {
1624 // Always respect dependency to the versioned stubs (i.e. libX#10)
1625 useThisDep = true
1626 } else if !depHasStubs {
1627 // Use non-stub variant if that is the only choice
1628 // (i.e. depending on a lib without stubs.version property)
1629 useThisDep = true
1630 } else if c.IsForPlatform() {
1631 // If not building for APEX, use stubs only when it is from
1632 // an APEX (and not from platform)
1633 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001634 if c.inRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001635 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001636 // always link to non-stub variant
1637 useThisDep = !depIsStubs
1638 }
1639 } else {
1640 // If building for APEX, use stubs only when it is not from
1641 // the same APEX
1642 useThisDep = (depInSameApex != depIsStubs)
1643 }
1644
1645 if !useThisDep {
1646 return // stop processing this dep
1647 }
1648 }
1649
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001650 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001651 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001652 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001653 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001654 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001655
1656 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001657 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001658 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001659 // 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 -07001660 // Re-exported shared library headers must be included as well since they can help us with type information
1661 // about template instantiations (instantiated from their headers).
1662 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001663 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001664 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001665
Logan Chienf3511742017-10-31 18:04:35 +08001666 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001667 }
1668
Colin Cross26c34ed2016-09-30 17:10:16 -07001669 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001670 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001671
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001672 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001673 depFile := android.OptionalPath{}
1674
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001675 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001676 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001677 ptr = &depPaths.SharedLibs
1678 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001679 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001680 directSharedDeps = append(directSharedDeps, ccDep)
Jiyong Park64a44f22019-01-18 14:37:08 +09001681 case earlySharedDepTag:
1682 ptr = &depPaths.EarlySharedLibs
1683 depPtr = &depPaths.EarlySharedLibsDeps
1684 depFile = ccDep.linker.(libraryInterface).toc()
1685 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001686 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001687 ptr = &depPaths.LateSharedLibs
1688 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001689 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001690 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001691 ptr = nil
1692 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001693 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001694 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001695 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001696 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001697 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001698 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001699 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001700 return
1701 }
1702
1703 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001704 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001705 for i := range missingDeps {
1706 missingDeps[i] += postfix
1707 }
1708 ctx.AddMissingDependencies(missingDeps)
1709 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001710 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001711 case headerDepTag:
1712 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001713 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001714 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001715 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001716 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001717 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001718 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001719 case dynamicLinkerDepTag:
1720 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001721 }
1722
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001723 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001724 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001725 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001726 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001727 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001728 return
1729 }
1730
1731 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001732 // in static libraries act as if they were whole static libraries. The same goes for
1733 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001734 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1735 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001736 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1737 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001738
Dan Willemsen581341d2017-02-09 16:16:31 -08001739 }
1740
Colin Cross26c34ed2016-09-30 17:10:16 -07001741 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001742 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001743 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001744 return
1745 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001746 *ptr = append(*ptr, linkFile.Path())
1747 }
1748
Colin Crossc99deeb2016-04-11 15:06:20 -07001749 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001750 dep := depFile
1751 if !dep.Valid() {
1752 dep = linkFile
1753 }
1754 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001755 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001756
Logan Chien43d34c32017-12-20 01:17:32 +08001757 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001758 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001759 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001760 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001761 isLLndk := inList(libName, llndkLibraries)
Jiyong Park374510b2018-03-19 18:23:01 +09001762 isVendorPublicLib := inList(libName, vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001763 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1764 if c.useVndk() && bothVendorAndCoreVariantsExist {
1765 // The vendor module in Make will have been renamed to not conflict with the core
1766 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001767 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001768 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001769 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001770 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1771 return libName + recoverySuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001772 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001773 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001774 }
Logan Chien43d34c32017-12-20 01:17:32 +08001775 }
1776
1777 // Export the shared libs to Make.
1778 switch depTag {
Jiyong Park64a44f22019-01-18 14:37:08 +09001779 case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001780 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001781 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08001782 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09001783 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001784 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001785 c.Properties.ApexesProvidingSharedLibs = append(
1786 c.Properties.ApexesProvidingSharedLibs, an)
1787 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09001788 }
1789 }
1790
Jiyong Park27b188b2017-07-18 13:23:39 +09001791 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001792 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001793 c.Properties.AndroidMkSharedLibs = append(
1794 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08001795 case ndkStubDepTag, ndkLateStubDepTag:
1796 ndkStub := ccDep.linker.(*stubDecorator)
1797 c.Properties.AndroidMkSharedLibs = append(
1798 c.Properties.AndroidMkSharedLibs,
1799 depName+"."+ndkStub.properties.ApiLevel)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001800 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1801 c.Properties.AndroidMkStaticLibs = append(
1802 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001803 case runtimeDepTag:
1804 c.Properties.AndroidMkRuntimeLibs = append(
1805 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001806 case wholeStaticDepTag:
1807 c.Properties.AndroidMkWholeStaticLibs = append(
1808 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001809 }
Colin Crossca860ac2016-01-04 14:34:37 -08001810 })
1811
Jeff Gaston294356f2017-09-27 17:05:30 -07001812 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001813 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001814
Colin Crossdd84e052017-05-17 13:44:16 -07001815 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001816 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001817 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001818 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001819 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1820
1821 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001822 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001823 }
Colin Crossdd84e052017-05-17 13:44:16 -07001824
Colin Crossca860ac2016-01-04 14:34:37 -08001825 return depPaths
1826}
1827
1828func (c *Module) InstallInData() bool {
1829 if c.installer == nil {
1830 return false
1831 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001832 return c.installer.inData()
1833}
1834
1835func (c *Module) InstallInSanitizerDir() bool {
1836 if c.installer == nil {
1837 return false
1838 }
1839 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001840 return true
1841 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001842 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001843}
1844
Jiyong Parkf9332f12018-02-01 00:54:12 +09001845func (c *Module) InstallInRecovery() bool {
1846 return c.inRecovery()
1847}
1848
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001849func (c *Module) HostToolPath() android.OptionalPath {
1850 if c.installer == nil {
1851 return android.OptionalPath{}
1852 }
1853 return c.installer.hostToolPath()
1854}
1855
Nan Zhangd4e641b2017-07-12 12:55:28 -07001856func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1857 return c.outputFile
1858}
1859
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001860func (c *Module) Srcs() android.Paths {
1861 if c.outputFile.Valid() {
1862 return android.Paths{c.outputFile.Path()}
1863 }
1864 return android.Paths{}
1865}
1866
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001867func (c *Module) static() bool {
1868 if static, ok := c.linker.(interface {
1869 static() bool
1870 }); ok {
1871 return static.static()
1872 }
1873 return false
1874}
1875
Jiyong Park379de2f2018-12-19 02:47:14 +09001876func (c *Module) staticBinary() bool {
1877 if static, ok := c.linker.(interface {
1878 staticBinary() bool
1879 }); ok {
1880 return static.staticBinary()
1881 }
1882 return false
1883}
1884
Colin Crossb60190a2018-09-04 16:28:17 -07001885func (c *Module) getMakeLinkType() string {
1886 if c.useVndk() {
1887 if inList(c.Name(), vndkCoreLibraries) || inList(c.Name(), vndkSpLibraries) || inList(c.Name(), llndkLibraries) {
1888 if inList(c.Name(), vndkPrivateLibraries) {
1889 return "native:vndk_private"
1890 } else {
1891 return "native:vndk"
1892 }
1893 } else {
1894 return "native:vendor"
1895 }
1896 } else if c.inRecovery() {
1897 return "native:recovery"
1898 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
1899 return "native:ndk:none:none"
1900 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
1901 //family, link := getNdkStlFamilyAndLinkType(c)
1902 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
1903 } else {
1904 return "native:platform"
1905 }
1906}
1907
Jiyong Park9d452992018-10-03 00:38:19 +09001908// Overrides ApexModule.IsInstallabeToApex()
1909// Only shared libraries are installable to APEX.
1910func (c *Module) IsInstallableToApex() bool {
1911 if shared, ok := c.linker.(interface {
1912 shared() bool
1913 }); ok {
1914 return shared.shared()
1915 }
1916 return false
1917}
1918
Jiyong Park3b1746a2019-01-29 11:15:04 +09001919func (c *Module) imageVariation() string {
1920 variation := "core"
1921 if c.useVndk() {
1922 variation = "vendor"
1923 } else if c.inRecovery() {
1924 variation = "recovery"
1925 }
1926 return variation
1927}
1928
bralee3f49f4d2019-03-04 06:58:15 +08001929func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
1930 dpInfo.Srcs = append(dpInfo.Srcs, c.Srcs().Strings()...)
1931}
1932
Colin Cross2ba19d92015-05-07 15:44:20 -07001933//
Colin Crosscfad1192015-11-02 16:43:11 -08001934// Defaults
1935//
Colin Crossca860ac2016-01-04 14:34:37 -08001936type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001937 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001938 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09001939 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001940}
1941
Colin Cross635c3b02016-05-18 15:37:25 -07001942func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001943}
1944
Colin Cross36242852017-06-23 15:06:31 -07001945func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001946 return DefaultsFactory()
1947}
1948
Colin Cross36242852017-06-23 15:06:31 -07001949func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001950 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001951
Colin Cross36242852017-06-23 15:06:31 -07001952 module.AddProperties(props...)
1953 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001954 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001955 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001956 &BaseCompilerProperties{},
1957 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001958 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001959 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001960 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001961 &TestProperties{},
1962 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001963 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001964 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001965 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001966 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001967 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001968 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001969 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001970 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001971 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001972 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08001973 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001974 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001975 )
Colin Crosscfad1192015-11-02 16:43:11 -08001976
Colin Cross1f44a3a2017-07-07 14:33:33 -07001977 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09001978 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001979
1980 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001981}
1982
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001983const (
1984 // coreMode is the variant used for framework-private libraries, or
1985 // SDK libraries. (which framework-private libraries can use)
1986 coreMode = "core"
1987
1988 // vendorMode is the variant used for /vendor code that compiles
1989 // against the VNDK.
1990 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09001991
1992 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001993)
1994
Jiyong Park6a43f042017-10-12 23:05:00 +09001995func squashVendorSrcs(m *Module) {
1996 if lib, ok := m.compiler.(*libraryDecorator); ok {
1997 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1998 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1999
2000 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2001 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2002 }
2003}
2004
Jiyong Parkf9332f12018-02-01 00:54:12 +09002005func squashRecoverySrcs(m *Module) {
2006 if lib, ok := m.compiler.(*libraryDecorator); ok {
2007 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2008 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2009
2010 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2011 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2012 }
2013}
2014
Jiyong Parkda6eb592018-12-19 17:12:36 +09002015func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002016 if mctx.Os() != android.Android {
2017 return
2018 }
2019
Jiyong Park7ed9de32018-10-15 22:25:07 +09002020 if g, ok := mctx.Module().(*genrule.Module); ok {
2021 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09002022 var coreVariantNeeded bool = false
2023 var vendorVariantNeeded bool = false
2024 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09002025 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09002026 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002027 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09002028 coreVariantNeeded = true
2029 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09002030 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09002031 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002032 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09002033 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002034 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002035 if Bool(props.Recovery_available) {
2036 recoveryVariantNeeded = true
2037 }
2038
Jiyong Park413cc742018-06-19 01:46:06 +09002039 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002040 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09002041 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09002042 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002043 recoveryVariantNeeded = false
2044 }
2045 }
2046
Jiyong Park3f736c92018-05-24 13:36:56 +09002047 var variants []string
2048 if coreVariantNeeded {
2049 variants = append(variants, coreMode)
2050 }
2051 if vendorVariantNeeded {
2052 variants = append(variants, vendorMode)
2053 }
2054 if recoveryVariantNeeded {
2055 variants = append(variants, recoveryMode)
2056 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002057 mod := mctx.CreateVariations(variants...)
2058 for i, v := range variants {
2059 if v == recoveryMode {
2060 m := mod[i].(*genrule.Module)
2061 m.Extra.(*GenruleExtraProperties).InRecovery = true
2062 }
2063 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002064 }
2065 }
2066
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002067 m, ok := mctx.Module().(*Module)
2068 if !ok {
2069 return
2070 }
2071
2072 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002073 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002074 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002075
2076 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002077 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002078 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002079 return
2080 }
Logan Chienf3511742017-10-31 18:04:35 +08002081
2082 if vndkdep := m.vndkdep; vndkdep != nil {
2083 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002084 if productSpecific {
2085 mctx.PropertyErrorf("product_specific",
2086 "product_specific must not be true when `vndk: {enabled: true}`")
2087 return
2088 }
Logan Chienf3511742017-10-31 18:04:35 +08002089 if vendorSpecific {
2090 if !vndkdep.isVndkExt() {
2091 mctx.PropertyErrorf("vndk",
2092 "must set `extends: \"...\"` to vndk extension")
2093 return
2094 }
2095 } else {
2096 if vndkdep.isVndkExt() {
2097 mctx.PropertyErrorf("vndk",
2098 "must set `vendor: true` to set `extends: %q`",
2099 m.getVndkExtendsModuleName())
2100 return
2101 }
2102 if m.VendorProperties.Vendor_available == nil {
2103 mctx.PropertyErrorf("vndk",
2104 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2105 return
2106 }
2107 }
2108 } else {
2109 if vndkdep.isVndkSp() {
2110 mctx.PropertyErrorf("vndk",
2111 "must set `enabled: true` to set `support_system_process: true`")
2112 return
2113 }
2114 if vndkdep.isVndkExt() {
2115 mctx.PropertyErrorf("vndk",
2116 "must set `enabled: true` to set `extends: %q`",
2117 m.getVndkExtendsModuleName())
2118 return
2119 }
Justin Yun8effde42017-06-23 19:24:43 +09002120 }
2121 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002122
Jiyong Parkf9332f12018-02-01 00:54:12 +09002123 var coreVariantNeeded bool = false
2124 var vendorVariantNeeded bool = false
2125 var recoveryVariantNeeded bool = false
2126
Justin Yun71549282017-11-17 12:10:28 +09002127 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002128 // If the device isn't compiling against the VNDK, we always
2129 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002130 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002131 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2132 // LL-NDK stubs only exist in the vendor variant, since the
2133 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002134 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09002135 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2136 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09002137 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09002138 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002139 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2140 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002141 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002142 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002143 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002144 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002145 coreVariantNeeded = true
2146 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002147 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002148 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09002149 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002150 } else {
2151 // This is either in /system (or similar: /data), or is a
2152 // modules built with the NDK. Modules built with the NDK
2153 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002154 coreVariantNeeded = true
2155 }
2156
2157 if Bool(m.Properties.Recovery_available) {
2158 recoveryVariantNeeded = true
2159 }
2160
2161 if m.ModuleBase.InstallInRecovery() {
2162 recoveryVariantNeeded = true
2163 coreVariantNeeded = false
2164 }
2165
Jiyong Park413cc742018-06-19 01:46:06 +09002166 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002167 primaryArch := mctx.Config().DevicePrimaryArchType()
2168 moduleArch := m.Target().Arch.ArchType
2169 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002170 recoveryVariantNeeded = false
2171 }
2172 }
2173
Jiyong Parkf9332f12018-02-01 00:54:12 +09002174 var variants []string
2175 if coreVariantNeeded {
2176 variants = append(variants, coreMode)
2177 }
2178 if vendorVariantNeeded {
2179 variants = append(variants, vendorMode)
2180 }
2181 if recoveryVariantNeeded {
2182 variants = append(variants, recoveryMode)
2183 }
2184 mod := mctx.CreateVariations(variants...)
2185 for i, v := range variants {
2186 if v == vendorMode {
2187 m := mod[i].(*Module)
2188 m.Properties.UseVndk = true
2189 squashVendorSrcs(m)
2190 } else if v == recoveryMode {
2191 m := mod[i].(*Module)
2192 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002193 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002194 squashRecoverySrcs(m)
2195 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002196 }
2197}
2198
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002199func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002200 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002201 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2202 }
Colin Cross6510f912017-11-29 00:27:14 -08002203 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002204}
2205
Colin Cross06a931b2015-10-28 17:23:31 -07002206var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002207var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002208var BoolPtr = proptools.BoolPtr
2209var String = proptools.String
2210var StringPtr = proptools.StringPtr