blob: f5a15678488f4cb7d52dd9b69c94875b48030bed [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
Vic Yangefd249e2018-11-12 20:19:56 -0800269 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700270 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800271}
272
273type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700274 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800275 ModuleContextIntf
276}
277
278type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700279 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800280 ModuleContextIntf
281}
282
Colin Cross37047f12016-12-13 17:06:13 -0800283type DepsContext interface {
284 android.BottomUpMutatorContext
285 ModuleContextIntf
286}
287
Colin Crossca860ac2016-01-04 14:34:37 -0800288type feature interface {
289 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800290 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800291 flags(ctx ModuleContext, flags Flags) Flags
292 props() []interface{}
293}
294
295type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700296 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800297 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800298 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700299 compilerProps() []interface{}
300
Colin Cross76fada02016-07-27 10:31:13 -0700301 appendCflags([]string)
302 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700303 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800304}
305
306type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700307 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800308 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700309 linkerFlags(ctx ModuleContext, flags Flags) Flags
310 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800311 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700312
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700313 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700314 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900315 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700316
317 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800318}
319
320type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700321 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700322 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800323 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700324 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700325 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900326 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800327}
328
Colin Crossc99deeb2016-04-11 15:06:20 -0700329type dependencyTag struct {
330 blueprint.BaseDependencyTag
331 name string
332 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700333
334 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900335
336 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700337}
338
339var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700340 sharedDepTag = dependencyTag{name: "shared", library: true}
341 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
Jiyong Park64a44f22019-01-18 14:37:08 +0900342 earlySharedDepTag = dependencyTag{name: "early_shared", library: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700343 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
344 staticDepTag = dependencyTag{name: "static", library: true}
345 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
346 lateStaticDepTag = dependencyTag{name: "late static", library: true}
347 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800348 headerDepTag = dependencyTag{name: "header", library: true}
349 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700350 genSourceDepTag = dependencyTag{name: "gen source"}
351 genHeaderDepTag = dependencyTag{name: "gen header"}
352 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
353 objDepTag = dependencyTag{name: "obj"}
354 crtBeginDepTag = dependencyTag{name: "crtbegin"}
355 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700356 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
357 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700358 reuseObjTag = dependencyTag{name: "reuse objects"}
Jiyong Parke4bb9862019-02-01 00:31:10 +0900359 staticVariantTag = dependencyTag{name: "static variant"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700360 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
361 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800362 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800363 runtimeDepTag = dependencyTag{name: "runtime lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700364)
365
Colin Crossca860ac2016-01-04 14:34:37 -0800366// Module contains the properties and members used by all C/C++ module types, and implements
367// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
368// to construct the output file. Behavior can be customized with a Customizer interface
369type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700370 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700371 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900372 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700373
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700374 Properties BaseProperties
375 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700376
Colin Crossca860ac2016-01-04 14:34:37 -0800377 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700378 hod android.HostOrDeviceSupported
379 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700380
Colin Crossca860ac2016-01-04 14:34:37 -0800381 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700382 features []feature
383 compiler compiler
384 linker linker
385 installer installer
386 stl *stl
387 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800388 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800389 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900390 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700391 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700392 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800393 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800394
395 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700396
Colin Cross635c3b02016-05-18 15:37:25 -0700397 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800398
Colin Crossb98c8b02016-07-29 13:44:28 -0700399 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700400
401 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800402
403 // Flags used to compile this module
404 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700405
406 // 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 -0800407 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700408 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800409 depsInLinkOrder android.Paths
410
411 // only non-nil when this is a shared library that reuses the objects of a static library
412 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700413}
414
Jiyong Parkc20eee32018-09-05 22:36:17 +0900415func (c *Module) OutputFile() android.OptionalPath {
416 return c.outputFile
417}
418
Jiyong Park719b4462019-01-13 00:39:51 +0900419func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900420 if c.linker != nil {
421 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900422 }
423 return nil
424}
425
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900426func (c *Module) RelativeInstallPath() string {
427 if c.installer != nil {
428 return c.installer.relativeInstallPath()
429 }
430 return ""
431}
432
Colin Cross36242852017-06-23 15:06:31 -0700433func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700434 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800435 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700436 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800437 }
438 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700439 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800440 }
441 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700442 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800443 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700444 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700445 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700446 }
Colin Cross16b23492016-01-06 14:41:07 -0800447 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700448 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800449 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800450 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700451 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800452 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800453 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700454 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800455 }
Justin Yun8effde42017-06-23 19:24:43 +0900456 if c.vndkdep != nil {
457 c.AddProperties(c.vndkdep.props()...)
458 }
Stephen Craneba090d12017-05-09 15:44:35 -0700459 if c.lto != nil {
460 c.AddProperties(c.lto.props()...)
461 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700462 if c.pgo != nil {
463 c.AddProperties(c.pgo.props()...)
464 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800465 if c.xom != nil {
466 c.AddProperties(c.xom.props()...)
467 }
Colin Crossca860ac2016-01-04 14:34:37 -0800468 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700469 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800470 }
Colin Crossc472d572015-03-17 15:06:21 -0700471
Colin Crossa9d8bee2018-10-02 13:59:46 -0700472 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
473 switch class {
474 case android.Device:
475 return ctx.Config().DevicePrefer32BitExecutables()
476 case android.HostCross:
477 // Windows builds always prefer 32-bit
478 return true
479 default:
480 return false
481 }
482 })
Colin Cross36242852017-06-23 15:06:31 -0700483 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700484
Colin Cross1f44a3a2017-07-07 14:33:33 -0700485 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700486
Jiyong Park9d452992018-10-03 00:38:19 +0900487 android.InitApexModule(c)
488
Colin Cross36242852017-06-23 15:06:31 -0700489 return c
Colin Crossc472d572015-03-17 15:06:21 -0700490}
491
Colin Crossb916a382016-07-29 17:28:03 -0700492// Returns true for dependency roots (binaries)
493// TODO(ccross): also handle dlopenable libraries
494func (c *Module) isDependencyRoot() bool {
495 if root, ok := c.linker.(interface {
496 isDependencyRoot() bool
497 }); ok {
498 return root.isDependencyRoot()
499 }
500 return false
501}
502
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700503func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700504 return c.Properties.UseVndk
505}
506
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800507func (c *Module) isCoverageVariant() bool {
508 return c.coverage.Properties.IsCoverageVariant
509}
510
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800511func (c *Module) isNdk() bool {
512 return inList(c.Name(), ndkMigratedLibs)
513}
514
515func (c *Module) isLlndk() bool {
516 // Returns true for both LLNDK (public) and LLNDK-private libs.
517 return inList(c.Name(), llndkLibraries)
518}
519
520func (c *Module) isLlndkPublic() bool {
521 // Returns true only for LLNDK (public) libs.
522 return c.isLlndk() && !c.isVndkPrivate()
523}
524
525func (c *Module) isVndkPrivate() bool {
526 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
527 return inList(c.Name(), vndkPrivateLibraries)
528}
529
Justin Yun8effde42017-06-23 19:24:43 +0900530func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800531 if vndkdep := c.vndkdep; vndkdep != nil {
532 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900533 }
534 return false
535}
536
Yi Kong7e53c572018-02-14 18:16:12 +0800537func (c *Module) isPgoCompile() bool {
538 if pgo := c.pgo; pgo != nil {
539 return pgo.Properties.PgoCompile
540 }
541 return false
542}
543
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800544func (c *Module) isNDKStubLibrary() bool {
545 if _, ok := c.compiler.(*stubDecorator); ok {
546 return true
547 }
548 return false
549}
550
Logan Chienf3511742017-10-31 18:04:35 +0800551func (c *Module) isVndkSp() bool {
552 if vndkdep := c.vndkdep; vndkdep != nil {
553 return vndkdep.isVndkSp()
554 }
555 return false
556}
557
558func (c *Module) isVndkExt() bool {
559 if vndkdep := c.vndkdep; vndkdep != nil {
560 return vndkdep.isVndkExt()
561 }
562 return false
563}
564
Vic Yangefd249e2018-11-12 20:19:56 -0800565func (c *Module) mustUseVendorVariant() bool {
566 return c.isVndkSp() || inList(c.Name(), config.VndkMustUseVendorVariantList)
567}
568
Logan Chienf3511742017-10-31 18:04:35 +0800569func (c *Module) getVndkExtendsModuleName() string {
570 if vndkdep := c.vndkdep; vndkdep != nil {
571 return vndkdep.getVndkExtendsModuleName()
572 }
573 return ""
574}
575
Jiyong Park82e2bf32017-08-16 14:05:54 +0900576// Returns true only when this module is configured to have core and vendor
577// variants.
578func (c *Module) hasVendorVariant() bool {
579 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
580}
581
Jiyong Parkf9332f12018-02-01 00:54:12 +0900582func (c *Module) inRecovery() bool {
583 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
584}
585
586func (c *Module) onlyInRecovery() bool {
587 return c.ModuleBase.InstallInRecovery()
588}
589
Jiyong Park25fc6a92018-11-18 18:02:45 +0900590func (c *Module) IsStubs() bool {
591 if library, ok := c.linker.(*libraryDecorator); ok {
592 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900593 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
594 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900595 }
596 return false
597}
598
599func (c *Module) HasStubsVariants() bool {
600 if library, ok := c.linker.(*libraryDecorator); ok {
601 return len(library.Properties.Stubs.Versions) > 0
602 }
603 return false
604}
605
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900606func (c *Module) bootstrap() bool {
607 return Bool(c.Properties.Bootstrap)
608}
609
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700610func (c *Module) nativeCoverage() bool {
611 return c.linker != nil && c.linker.nativeCoverage()
612}
613
Jiyong Parkf1194352019-02-25 11:05:47 +0900614func isBionic(name string) bool {
615 switch name {
616 case "libc", "libm", "libdl", "linker":
617 return true
618 }
619 return false
620}
621
Colin Crossca860ac2016-01-04 14:34:37 -0800622type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700623 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800624 moduleContextImpl
625}
626
Colin Cross37047f12016-12-13 17:06:13 -0800627type depsContext struct {
628 android.BottomUpMutatorContext
629 moduleContextImpl
630}
631
Colin Crossca860ac2016-01-04 14:34:37 -0800632type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700633 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800634 moduleContextImpl
635}
636
Jiyong Park2db76922017-11-08 16:03:48 +0900637func (ctx *moduleContext) SocSpecific() bool {
638 return ctx.ModuleContext.SocSpecific() ||
639 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700640}
641
Colin Crossca860ac2016-01-04 14:34:37 -0800642type moduleContextImpl struct {
643 mod *Module
644 ctx BaseModuleContext
645}
646
Colin Crossb98c8b02016-07-29 13:44:28 -0700647func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800648 return ctx.mod.toolchain(ctx.ctx)
649}
650
651func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000652 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800653}
654
655func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900656 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800657}
658
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700659func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800660 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800661 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700662 }
663 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800664}
665
666func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700667 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700668 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900669 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700670 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900671 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
672 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
673 return "current"
674 }
675 return platform_vndk_ver
676 }
677 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800678 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900679 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700680 }
681 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800682}
683
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700684func (ctx *moduleContextImpl) useVndk() bool {
685 return ctx.mod.useVndk()
686}
Justin Yun8effde42017-06-23 19:24:43 +0900687
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800688func (ctx *moduleContextImpl) isNdk() bool {
689 return ctx.mod.isNdk()
690}
691
692func (ctx *moduleContextImpl) isLlndk() bool {
693 return ctx.mod.isLlndk()
694}
695
696func (ctx *moduleContextImpl) isLlndkPublic() bool {
697 return ctx.mod.isLlndkPublic()
698}
699
700func (ctx *moduleContextImpl) isVndkPrivate() bool {
701 return ctx.mod.isVndkPrivate()
702}
703
Logan Chienf3511742017-10-31 18:04:35 +0800704func (ctx *moduleContextImpl) isVndk() bool {
705 return ctx.mod.isVndk()
706}
707
Yi Kong7e53c572018-02-14 18:16:12 +0800708func (ctx *moduleContextImpl) isPgoCompile() bool {
709 return ctx.mod.isPgoCompile()
710}
711
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800712func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
713 return ctx.mod.isNDKStubLibrary()
714}
715
Justin Yun8effde42017-06-23 19:24:43 +0900716func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800717 return ctx.mod.isVndkSp()
718}
719
720func (ctx *moduleContextImpl) isVndkExt() bool {
721 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900722}
723
Vic Yangefd249e2018-11-12 20:19:56 -0800724func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
725 return ctx.mod.mustUseVendorVariant()
726}
727
Jiyong Parkf9332f12018-02-01 00:54:12 +0900728func (ctx *moduleContextImpl) inRecovery() bool {
729 return ctx.mod.inRecovery()
730}
731
Logan Chien2f2b8902018-07-10 15:01:19 +0800732// Check whether ABI dumps should be created for this module.
733func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump() bool {
734 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
735 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800736 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800737
738 if ctx.ctx.Fuchsia() {
739 return false
740 }
741
Logan Chien2f2b8902018-07-10 15:01:19 +0800742 if sanitize := ctx.mod.sanitize; sanitize != nil {
743 if !sanitize.isVariantOnProductionDevice() {
744 return false
745 }
746 }
747 if !ctx.ctx.Device() {
748 // Host modules do not need ABI dumps.
749 return false
750 }
Logan Chienfa478c02018-12-28 16:25:39 +0800751 if !ctx.mod.IsForPlatform() {
752 // APEX variants do not need ABI dumps.
753 return false
754 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800755 if ctx.isNdk() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800756 return true
757 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800758 if ctx.isLlndkPublic() {
Logan Chienf4b79c62018-08-02 02:27:02 +0800759 return true
760 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800761 if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800762 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
763 // VNDK-private.
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800764 return true
Logan Chien2f2b8902018-07-10 15:01:19 +0800765 }
766 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800767}
768
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700769func (ctx *moduleContextImpl) selectedStl() string {
770 if stl := ctx.mod.stl; stl != nil {
771 return stl.Properties.SelectedStl
772 }
773 return ""
774}
775
Ivan Lozanobd721262018-11-27 14:33:03 -0800776func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
777 return ctx.mod.linker.useClangLld(actx)
778}
779
Colin Crossce75d2c2016-10-06 16:12:58 -0700780func (ctx *moduleContextImpl) baseModuleName() string {
781 return ctx.mod.ModuleBase.BaseModuleName()
782}
783
Logan Chienf3511742017-10-31 18:04:35 +0800784func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
785 return ctx.mod.getVndkExtendsModuleName()
786}
787
Jiyong Park58e364a2019-01-19 19:24:06 +0900788func (ctx *moduleContextImpl) apexName() string {
789 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900790}
791
Jiyong Parkb0788572018-12-20 22:10:17 +0900792func (ctx *moduleContextImpl) hasStubsVariants() bool {
793 return ctx.mod.HasStubsVariants()
794}
795
796func (ctx *moduleContextImpl) isStubs() bool {
797 return ctx.mod.IsStubs()
798}
799
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900800func (ctx *moduleContextImpl) bootstrap() bool {
801 return ctx.mod.bootstrap()
802}
803
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700804func (ctx *moduleContextImpl) nativeCoverage() bool {
805 return ctx.mod.nativeCoverage()
806}
807
Colin Cross635c3b02016-05-18 15:37:25 -0700808func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800809 return &Module{
810 hod: hod,
811 multilib: multilib,
812 }
813}
814
Colin Cross635c3b02016-05-18 15:37:25 -0700815func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800816 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700817 module.features = []feature{
818 &tidyFeature{},
819 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700820 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800821 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800822 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800823 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900824 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700825 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700826 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800827 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800828 return module
829}
830
Colin Crossce75d2c2016-10-06 16:12:58 -0700831func (c *Module) Prebuilt() *android.Prebuilt {
832 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
833 return p.prebuilt()
834 }
835 return nil
836}
837
838func (c *Module) Name() string {
839 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700840 if p, ok := c.linker.(interface {
841 Name(string) string
842 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700843 name = p.Name(name)
844 }
845 return name
846}
847
Alex Light3d673592019-01-18 14:37:31 -0800848func (c *Module) Symlinks() []string {
849 if p, ok := c.installer.(interface {
850 symlinkList() []string
851 }); ok {
852 return p.symlinkList()
853 }
854 return nil
855}
856
Jeff Gaston294356f2017-09-27 17:05:30 -0700857// orderDeps reorders dependencies into a list such that if module A depends on B, then
858// A will precede B in the resultant list.
859// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800860// Note that directSharedDeps should be the analogous static library for each shared lib dep
861func 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 -0700862 // If A depends on B, then
863 // Every list containing A will also contain B later in the list
864 // So, after concatenating all lists, the final instance of B will have come from the same
865 // original list as the final instance of A
866 // So, the final instance of B will be later in the concatenation than the final A
867 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
868 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800869 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700870 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800871 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
872 }
873 for _, dep := range directSharedDeps {
874 orderedAllDeps = append(orderedAllDeps, dep)
875 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700876 }
877
Colin Crossb6715442017-10-24 11:13:31 -0700878 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700879
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800880 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700881 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800882 // resultant list to only what the caller has chosen to include in directStaticDeps
883 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700884
885 return orderedAllDeps, orderedDeclaredDeps
886}
887
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800888func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
889 // convert Module to Path
890 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
891 staticDepFiles := []android.Path{}
892 for _, dep := range staticDeps {
893 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
894 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700895 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800896 sharedDepFiles := []android.Path{}
897 for _, sharedDep := range sharedDeps {
898 staticAnalogue := sharedDep.staticVariant
899 if staticAnalogue != nil {
900 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
901 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
902 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700903 }
904
905 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800906 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700907
908 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700909}
910
Colin Cross635c3b02016-05-18 15:37:25 -0700911func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800912 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700913 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800914 moduleContextImpl: moduleContextImpl{
915 mod: c,
916 },
917 }
918 ctx.ctx = ctx
919
Colin Crossf18e1102017-11-16 14:33:08 -0800920 deps := c.depsToPaths(ctx)
921 if ctx.Failed() {
922 return
923 }
924
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700925 if c.Properties.Clang != nil && *c.Properties.Clang == false {
926 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
927 }
928
Colin Crossca860ac2016-01-04 14:34:37 -0800929 flags := Flags{
930 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800931 }
Colin Crossca860ac2016-01-04 14:34:37 -0800932 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800933 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800934 }
935 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700936 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800937 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700938 if c.stl != nil {
939 flags = c.stl.flags(ctx, flags)
940 }
Colin Cross16b23492016-01-06 14:41:07 -0800941 if c.sanitize != nil {
942 flags = c.sanitize.flags(ctx, flags)
943 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800944 if c.coverage != nil {
945 flags = c.coverage.flags(ctx, flags)
946 }
Stephen Craneba090d12017-05-09 15:44:35 -0700947 if c.lto != nil {
948 flags = c.lto.flags(ctx, flags)
949 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700950 if c.pgo != nil {
951 flags = c.pgo.flags(ctx, flags)
952 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800953 if c.xom != nil {
954 flags = c.xom.flags(ctx, flags)
955 }
Colin Crossca860ac2016-01-04 14:34:37 -0800956 for _, feature := range c.features {
957 flags = feature.flags(ctx, flags)
958 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800959 if ctx.Failed() {
960 return
961 }
962
Colin Crossb98c8b02016-07-29 13:44:28 -0700963 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
964 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
965 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800966
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800967 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
968 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700969 // We need access to all the flags seen by a source file.
970 if c.sabi != nil {
971 flags = c.sabi.flags(ctx, flags)
972 }
Colin Crossca860ac2016-01-04 14:34:37 -0800973 // Optimization to reduce size of build.ninja
974 // Replace the long list of flags for each file with a module-local variable
975 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
976 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
977 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
978 flags.CFlags = []string{"$cflags"}
979 flags.CppFlags = []string{"$cppflags"}
980 flags.AsFlags = []string{"$asflags"}
981
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700982 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800983 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700984 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800985 if ctx.Failed() {
986 return
987 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800988 }
989
Colin Crossca860ac2016-01-04 14:34:37 -0800990 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700991 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800992 if ctx.Failed() {
993 return
994 }
Colin Cross635c3b02016-05-18 15:37:25 -0700995 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +0900996
997 // If a lib is directly included in any of the APEXes, unhide the stubs
998 // variant having the latest version gets visible to make. In addition,
999 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1000 // force anything in the make world to link against the stubs library.
1001 // (unless it is explicitly referenced via .bootstrap suffix or the
1002 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001003 if c.HasStubsVariants() &&
1004 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001005 !c.inRecovery() && !c.useVndk() && !c.static() && !c.isCoverageVariant() &&
1006 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001007 c.Properties.HideFromMake = false // unhide
1008 // Note: this is still non-installable
1009 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001010 }
Colin Cross5049f022015-03-18 13:28:46 -07001011
Jiyong Park9d452992018-10-03 00:38:19 +09001012 if c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001013 c.installer.install(ctx, c.outputFile.Path())
1014 if ctx.Failed() {
1015 return
Colin Crossca860ac2016-01-04 14:34:37 -08001016 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001017 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001018}
1019
Jiyong Park379de2f2018-12-19 02:47:14 +09001020func (c *Module) toolchain(ctx android.BaseContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001021 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001022 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001023 }
Colin Crossca860ac2016-01-04 14:34:37 -08001024 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001025}
1026
Colin Crossca860ac2016-01-04 14:34:37 -08001027func (c *Module) begin(ctx BaseModuleContext) {
1028 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001029 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001030 }
Colin Crossca860ac2016-01-04 14:34:37 -08001031 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001032 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001033 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001034 if c.stl != nil {
1035 c.stl.begin(ctx)
1036 }
Colin Cross16b23492016-01-06 14:41:07 -08001037 if c.sanitize != nil {
1038 c.sanitize.begin(ctx)
1039 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001040 if c.coverage != nil {
1041 c.coverage.begin(ctx)
1042 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001043 if c.sabi != nil {
1044 c.sabi.begin(ctx)
1045 }
Justin Yun8effde42017-06-23 19:24:43 +09001046 if c.vndkdep != nil {
1047 c.vndkdep.begin(ctx)
1048 }
Stephen Craneba090d12017-05-09 15:44:35 -07001049 if c.lto != nil {
1050 c.lto.begin(ctx)
1051 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001052 if c.pgo != nil {
1053 c.pgo.begin(ctx)
1054 }
Colin Crossca860ac2016-01-04 14:34:37 -08001055 for _, feature := range c.features {
1056 feature.begin(ctx)
1057 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001058 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001059 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001060 if err != nil {
1061 ctx.PropertyErrorf("sdk_version", err.Error())
1062 }
Nan Zhang0007d812017-11-07 10:57:05 -08001063 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001064 }
Colin Crossca860ac2016-01-04 14:34:37 -08001065}
1066
Colin Cross37047f12016-12-13 17:06:13 -08001067func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001068 deps := Deps{}
1069
1070 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001071 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001072 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001073 // Add the PGO dependency (the clang_rt.profile runtime library), which
1074 // sometimes depends on symbols from libgcc, before libgcc gets added
1075 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001076 if c.pgo != nil {
1077 deps = c.pgo.deps(ctx, deps)
1078 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001079 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001080 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001081 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001082 if c.stl != nil {
1083 deps = c.stl.deps(ctx, deps)
1084 }
Colin Cross16b23492016-01-06 14:41:07 -08001085 if c.sanitize != nil {
1086 deps = c.sanitize.deps(ctx, deps)
1087 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001088 if c.coverage != nil {
1089 deps = c.coverage.deps(ctx, deps)
1090 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001091 if c.sabi != nil {
1092 deps = c.sabi.deps(ctx, deps)
1093 }
Justin Yun8effde42017-06-23 19:24:43 +09001094 if c.vndkdep != nil {
1095 deps = c.vndkdep.deps(ctx, deps)
1096 }
Stephen Craneba090d12017-05-09 15:44:35 -07001097 if c.lto != nil {
1098 deps = c.lto.deps(ctx, deps)
1099 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001100 for _, feature := range c.features {
1101 deps = feature.deps(ctx, deps)
1102 }
1103
Colin Crossb6715442017-10-24 11:13:31 -07001104 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1105 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1106 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1107 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1108 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1109 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001110 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001111
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001112 for _, lib := range deps.ReexportSharedLibHeaders {
1113 if !inList(lib, deps.SharedLibs) {
1114 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1115 }
1116 }
1117
1118 for _, lib := range deps.ReexportStaticLibHeaders {
1119 if !inList(lib, deps.StaticLibs) {
1120 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1121 }
1122 }
1123
Colin Cross5950f382016-12-13 12:50:57 -08001124 for _, lib := range deps.ReexportHeaderLibHeaders {
1125 if !inList(lib, deps.HeaderLibs) {
1126 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1127 }
1128 }
1129
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001130 for _, gen := range deps.ReexportGeneratedHeaders {
1131 if !inList(gen, deps.GeneratedHeaders) {
1132 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1133 }
1134 }
1135
Colin Crossc99deeb2016-04-11 15:06:20 -07001136 return deps
1137}
1138
Dan Albert7e9d2952016-08-04 13:02:36 -07001139func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001140 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001141 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001142 moduleContextImpl: moduleContextImpl{
1143 mod: c,
1144 },
1145 }
1146 ctx.ctx = ctx
1147
Colin Crossca860ac2016-01-04 14:34:37 -08001148 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001149}
1150
Jiyong Park7ed9de32018-10-15 22:25:07 +09001151// Split name#version into name and version
1152func stubsLibNameAndVersion(name string) (string, string) {
1153 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1154 version := name[sharp+1:]
1155 libname := name[:sharp]
1156 return libname, version
1157 }
1158 return name, ""
1159}
1160
Colin Cross1e676be2016-10-12 14:38:15 -07001161func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001162 ctx := &depsContext{
1163 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001164 moduleContextImpl: moduleContextImpl{
1165 mod: c,
1166 },
1167 }
1168 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001169
Colin Crossc99deeb2016-04-11 15:06:20 -07001170 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001171
Dan Albert914449f2016-06-17 16:45:24 -07001172 variantNdkLibs := []string{}
1173 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001174 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001175 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001176
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001177 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1178 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001179 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001180 // 1. Name of an NDK library that refers to a prebuilt module.
1181 // For each of these, it adds the name of the prebuilt module (which will be in
1182 // prebuilts/ndk) to the list of nonvariant libs.
1183 // 2. Name of an NDK library that refers to an ndk_library module.
1184 // For each of these, it adds the name of the ndk_library module to the list of
1185 // variant libs.
1186 // 3. Anything else (so anything that isn't an NDK library).
1187 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001188 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001189 // The caller can then know to add the variantLibs dependencies differently from the
1190 // nonvariantLibs
1191 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1192 variantLibs = []string{}
1193 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001194 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001195 // strip #version suffix out
1196 name, _ := stubsLibNameAndVersion(entry)
1197 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1198 if !inList(name, ndkMigratedLibs) {
1199 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001200 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001201 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001202 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001203 } else if ctx.useVndk() && inList(name, llndkLibraries) {
1204 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
1205 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, vendorPublicLibraries) {
1206 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001207 if actx.OtherModuleExists(vendorPublicLib) {
1208 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1209 } else {
1210 // This can happen if vendor_public_library module is defined in a
1211 // namespace that isn't visible to the current module. In that case,
1212 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001213 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001214 }
Dan Albert914449f2016-06-17 16:45:24 -07001215 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001216 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001217 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001218 }
1219 }
Dan Albert914449f2016-06-17 16:45:24 -07001220 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001221 }
1222
Dan Albert914449f2016-06-17 16:45:24 -07001223 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1224 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001225 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001226 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001227
Jiyong Park7e636d02019-01-28 16:16:54 +09001228 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001229 if c.linker != nil {
1230 if library, ok := c.linker.(*libraryDecorator); ok {
1231 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001232 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001233 }
1234 }
1235 }
1236
Colin Cross32ec36c2016-12-15 07:39:51 -08001237 for _, lib := range deps.HeaderLibs {
1238 depTag := headerDepTag
1239 if inList(lib, deps.ReexportHeaderLibHeaders) {
1240 depTag = headerExportDepTag
1241 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001242 if buildStubs {
Jiyong Park7e636d02019-01-28 16:16:54 +09001243 actx.AddFarVariationDependencies([]blueprint.Variation{
1244 {Mutator: "arch", Variation: ctx.Target().String()},
Jiyong Park3b1746a2019-01-29 11:15:04 +09001245 {Mutator: "image", Variation: c.imageVariation()},
Jiyong Park7e636d02019-01-28 16:16:54 +09001246 }, depTag, lib)
1247 } else {
1248 actx.AddVariationDependencies(nil, depTag, lib)
1249 }
1250 }
1251
1252 if buildStubs {
1253 // Stubs lib does not have dependency to other static/shared libraries.
1254 // Don't proceed.
1255 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001256 }
Colin Cross5950f382016-12-13 12:50:57 -08001257
Inseob Kimc0907f12019-02-08 21:00:45 +09001258 syspropImplLibraries := syspropImplLibraries(actx.Config())
1259
Jiyong Park5d1598f2019-02-25 22:14:17 +09001260 for _, lib := range deps.WholeStaticLibs {
1261 depTag := wholeStaticDepTag
1262 if impl, ok := syspropImplLibraries[lib]; ok {
1263 lib = impl
1264 }
1265 actx.AddVariationDependencies([]blueprint.Variation{
1266 {Mutator: "link", Variation: "static"},
1267 }, depTag, lib)
1268 }
1269
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001270 for _, lib := range deps.StaticLibs {
1271 depTag := staticDepTag
1272 if inList(lib, deps.ReexportStaticLibHeaders) {
1273 depTag = staticExportDepTag
1274 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001275
1276 if impl, ok := syspropImplLibraries[lib]; ok {
1277 lib = impl
1278 }
1279
Dan Willemsen59339a22018-07-22 21:18:45 -07001280 actx.AddVariationDependencies([]blueprint.Variation{
1281 {Mutator: "link", Variation: "static"},
1282 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001283 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001284
Dan Willemsen59339a22018-07-22 21:18:45 -07001285 actx.AddVariationDependencies([]blueprint.Variation{
1286 {Mutator: "link", Variation: "static"},
1287 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001288
Jiyong Park25fc6a92018-11-18 18:02:45 +09001289 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1290 var variations []blueprint.Variation
1291 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001292 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001293 if version != "" && versionVariantAvail {
1294 // Version is explicitly specified. i.e. libFoo#30
1295 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1296 depTag.explicitlyVersioned = true
1297 }
1298 actx.AddVariationDependencies(variations, depTag, name)
1299
1300 // If the version is not specified, add dependency to the latest stubs library.
1301 // The stubs library will be used when the depending module is built for APEX and
1302 // the dependent module is not in the same APEX.
1303 latestVersion := latestStubsVersionFor(actx.Config(), name)
1304 if version == "" && latestVersion != "" && versionVariantAvail {
1305 actx.AddVariationDependencies([]blueprint.Variation{
1306 {Mutator: "link", Variation: "shared"},
1307 {Mutator: "version", Variation: latestVersion},
1308 }, depTag, name)
1309 // Note that depTag.explicitlyVersioned is false in this case.
1310 }
1311 }
1312
Jiyong Park7ed9de32018-10-15 22:25:07 +09001313 // shared lib names without the #version suffix
1314 var sharedLibNames []string
1315
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001316 for _, lib := range deps.SharedLibs {
1317 depTag := sharedDepTag
1318 if inList(lib, deps.ReexportSharedLibHeaders) {
1319 depTag = sharedExportDepTag
1320 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001321
1322 if impl, ok := syspropImplLibraries[lib]; ok {
1323 lib = impl
1324 }
1325
1326 name, version := stubsLibNameAndVersion(lib)
1327 sharedLibNames = append(sharedLibNames, name)
1328
Jiyong Park25fc6a92018-11-18 18:02:45 +09001329 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001330 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001331
Jiyong Park7ed9de32018-10-15 22:25:07 +09001332 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001333 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001334 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1335 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1336 // linking against both the stubs lib and the non-stubs lib at the same time.
1337 continue
1338 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001339 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001340 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001341
Dan Willemsen59339a22018-07-22 21:18:45 -07001342 actx.AddVariationDependencies([]blueprint.Variation{
1343 {Mutator: "link", Variation: "shared"},
1344 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001345
Colin Cross68861832016-07-08 10:41:41 -07001346 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001347
1348 for _, gen := range deps.GeneratedHeaders {
1349 depTag := genHeaderDepTag
1350 if inList(gen, deps.ReexportGeneratedHeaders) {
1351 depTag = genHeaderExportDepTag
1352 }
1353 actx.AddDependency(c, depTag, gen)
1354 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001355
Colin Cross42d48b72018-08-29 14:10:52 -07001356 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001357
1358 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001359 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001360 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001361 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001362 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001363 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001364 if deps.LinkerFlagsFile != "" {
1365 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1366 }
1367 if deps.DynamicLinker != "" {
1368 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001369 }
Dan Albert914449f2016-06-17 16:45:24 -07001370
1371 version := ctx.sdkVersion()
1372 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001373 {Mutator: "ndk_api", Variation: version},
1374 {Mutator: "link", Variation: "shared"},
1375 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001376 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001377 {Mutator: "ndk_api", Variation: version},
1378 {Mutator: "link", Variation: "shared"},
1379 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001380
1381 if vndkdep := c.vndkdep; vndkdep != nil {
1382 if vndkdep.isVndkExt() {
1383 baseModuleMode := vendorMode
1384 if actx.DeviceConfig().VndkVersion() == "" {
1385 baseModuleMode = coreMode
1386 }
1387 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001388 {Mutator: "image", Variation: baseModuleMode},
1389 {Mutator: "link", Variation: "shared"},
1390 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001391 }
1392 }
Colin Cross6362e272015-10-29 15:25:03 -07001393}
Colin Cross21b9a242015-03-24 14:15:58 -07001394
Colin Crosse40b4ea2018-10-02 22:25:58 -07001395func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001396 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1397 c.beginMutator(ctx)
1398 }
1399}
1400
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001401// Whether a module can link to another module, taking into
1402// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001403func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001404 if from.Target().Os != android.Android {
1405 // Host code is not restricted
1406 return
1407 }
1408 if from.Properties.UseVndk {
1409 // Though vendor code is limited by the vendor mutator,
1410 // each vendor-available module needs to check
1411 // link-type for VNDK.
1412 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001413 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001414 }
1415 return
1416 }
Nan Zhang0007d812017-11-07 10:57:05 -08001417 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001418 // Platform code can link to anything
1419 return
1420 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001421 if from.inRecovery() {
1422 // Recovery code is not NDK
1423 return
1424 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001425 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1426 // These are always allowed
1427 return
1428 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001429 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1430 // These are allowed, but they don't set sdk_version
1431 return
1432 }
1433 if _, ok := to.linker.(*stubDecorator); ok {
1434 // These aren't real libraries, but are the stub shared libraries that are included in
1435 // the NDK.
1436 return
1437 }
Logan Chien834b9a62019-01-14 15:39:03 +08001438
1439 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" {
1440 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1441 // to link to libc++ (non-NDK and without sdk_version).
1442 return
1443 }
1444
Nan Zhang0007d812017-11-07 10:57:05 -08001445 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001446 // NDK code linking to platform code is never okay.
1447 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1448 ctx.OtherModuleName(to))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001449 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001450 }
1451
1452 // At this point we know we have two NDK libraries, but we need to
1453 // check that we're not linking against anything built against a higher
1454 // API level, as it is only valid to link against older or equivalent
1455 // APIs.
1456
Inseob Kim01a28722018-04-11 09:48:45 +09001457 // Current can link against anything.
1458 if String(from.Properties.Sdk_version) != "current" {
1459 // Otherwise we need to check.
1460 if String(to.Properties.Sdk_version) == "current" {
1461 // Current can't be linked against by anything else.
1462 ctx.ModuleErrorf("links %q built against newer API version %q",
1463 ctx.OtherModuleName(to), "current")
1464 } else {
1465 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1466 if err != nil {
1467 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001468 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001469 String(from.Properties.Sdk_version))
1470 }
1471 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1472 if err != nil {
1473 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001474 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001475 String(to.Properties.Sdk_version))
1476 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001477
Inseob Kim01a28722018-04-11 09:48:45 +09001478 if toApi > fromApi {
1479 ctx.ModuleErrorf("links %q built against newer API version %q",
1480 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1481 }
1482 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001483 }
Dan Albert202fe492017-12-15 13:56:59 -08001484
1485 // Also check that the two STL choices are compatible.
1486 fromStl := from.stl.Properties.SelectedStl
1487 toStl := to.stl.Properties.SelectedStl
1488 if fromStl == "" || toStl == "" {
1489 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001490 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001491 // We can be permissive with the system "STL" since it is only the C++
1492 // ABI layer, but in the future we should make sure that everyone is
1493 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001494 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001495 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1496 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1497 to.stl.Properties.SelectedStl)
1498 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001499}
1500
Jiyong Park5fb8c102018-04-09 12:03:06 +09001501// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001502// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1503// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001504// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001505func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
1506 check := func(child, parent android.Module) bool {
1507 to, ok := child.(*Module)
1508 if !ok {
1509 // follow thru cc.Defaults, etc.
1510 return true
1511 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001512
Jooyung Hana70f0672019-01-18 15:20:43 +09001513 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1514 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001515 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001516
1517 // if target lib has no vendor variant, keep checking dependency graph
1518 if !to.hasVendorVariant() {
1519 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001520 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001521
1522 if to.isVndkSp() || inList(child.Name(), llndkLibraries) || Bool(to.VendorProperties.Double_loadable) {
1523 return false
1524 }
1525
1526 var stringPath []string
1527 for _, m := range ctx.GetWalkPath() {
1528 stringPath = append(stringPath, m.Name())
1529 }
1530 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1531 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1532 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1533 return false
1534 }
1535 if module, ok := ctx.Module().(*Module); ok {
1536 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
1537 if inList(ctx.ModuleName(), llndkLibraries) || Bool(module.VendorProperties.Double_loadable) {
1538 ctx.WalkDeps(check)
1539 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001540 }
1541 }
1542}
1543
Colin Crossc99deeb2016-04-11 15:06:20 -07001544// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001545func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001546 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001547
Jeff Gaston294356f2017-09-27 17:05:30 -07001548 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001549 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001550
Colin Crossd11fcda2017-10-23 17:59:01 -07001551 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001552 depName := ctx.OtherModuleName(dep)
1553 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001554
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001555 ccDep, _ := dep.(*Module)
1556 if ccDep == nil {
1557 // handling for a few module types that aren't cc Module but that are also supported
1558 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001559 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001560 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001561 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1562 genRule.GeneratedSourceFiles()...)
1563 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001564 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001565 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001566 // Support exported headers from a generated_sources dependency
1567 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001568 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001569 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001570 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001571 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001572 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001573 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001574 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001575 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001576 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001577 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001578 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1579 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1580
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001581 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001582 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001583 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001584 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001585 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001586 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001587 files := genRule.GeneratedSourceFiles()
1588 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001589 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001590 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001591 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 -07001592 }
1593 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001594 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001595 }
Colin Crossca860ac2016-01-04 14:34:37 -08001596 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001597 return
1598 }
1599
Colin Crossd11fcda2017-10-23 17:59:01 -07001600 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001601 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1602 return
1603 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001604 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001605 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001606 return
1607 }
1608
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001609 // re-exporting flags
1610 if depTag == reuseObjTag {
1611 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001612 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001613 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001614 depPaths.Objs = depPaths.Objs.Append(objs)
1615 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001616 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001617 return
1618 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001619 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001620
Jiyong Parke4bb9862019-02-01 00:31:10 +09001621 if depTag == staticVariantTag {
1622 if _, ok := ccDep.compiler.(libraryInterface); ok {
1623 c.staticVariant = ccDep
1624 return
1625 }
1626 }
1627
Jiyong Park25fc6a92018-11-18 18:02:45 +09001628 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1629 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1630 // won't be matched to sharedDepTag and lateSharedDepTag.
1631 explicitlyVersioned := false
1632 if t, ok := depTag.(dependencyTag); ok {
1633 explicitlyVersioned = t.explicitlyVersioned
1634 t.explicitlyVersioned = false
1635 depTag = t
1636 }
1637
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001638 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001639 depIsStatic := false
1640 switch depTag {
1641 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1642 depIsStatic = true
1643 }
1644 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001645 depIsStubs := dependentLibrary.buildStubs()
1646 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001647 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001648 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001649
1650 var useThisDep bool
1651 if depIsStubs && explicitlyVersioned {
1652 // Always respect dependency to the versioned stubs (i.e. libX#10)
1653 useThisDep = true
1654 } else if !depHasStubs {
1655 // Use non-stub variant if that is the only choice
1656 // (i.e. depending on a lib without stubs.version property)
1657 useThisDep = true
1658 } else if c.IsForPlatform() {
1659 // If not building for APEX, use stubs only when it is from
1660 // an APEX (and not from platform)
1661 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001662 if c.inRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001663 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001664 // always link to non-stub variant
1665 useThisDep = !depIsStubs
1666 }
1667 } else {
1668 // If building for APEX, use stubs only when it is not from
1669 // the same APEX
1670 useThisDep = (depInSameApex != depIsStubs)
1671 }
1672
1673 if !useThisDep {
1674 return // stop processing this dep
1675 }
1676 }
1677
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001678 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001679 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001680 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001681 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001682 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001683
1684 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001685 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001686 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001687 // 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 -07001688 // Re-exported shared library headers must be included as well since they can help us with type information
1689 // about template instantiations (instantiated from their headers).
1690 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001691 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001692 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001693
Logan Chienf3511742017-10-31 18:04:35 +08001694 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001695 }
1696
Colin Cross26c34ed2016-09-30 17:10:16 -07001697 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001698 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001699
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001700 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001701 depFile := android.OptionalPath{}
1702
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001703 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001704 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001705 ptr = &depPaths.SharedLibs
1706 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001707 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001708 directSharedDeps = append(directSharedDeps, ccDep)
Jiyong Park64a44f22019-01-18 14:37:08 +09001709 case earlySharedDepTag:
1710 ptr = &depPaths.EarlySharedLibs
1711 depPtr = &depPaths.EarlySharedLibsDeps
1712 depFile = ccDep.linker.(libraryInterface).toc()
1713 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001714 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001715 ptr = &depPaths.LateSharedLibs
1716 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001717 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001718 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001719 ptr = nil
1720 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001721 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001722 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001723 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001724 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001725 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001726 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001727 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001728 return
1729 }
1730
1731 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001732 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001733 for i := range missingDeps {
1734 missingDeps[i] += postfix
1735 }
1736 ctx.AddMissingDependencies(missingDeps)
1737 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001738 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001739 case headerDepTag:
1740 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001741 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001742 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001743 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001744 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001745 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001746 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001747 case dynamicLinkerDepTag:
1748 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001749 }
1750
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001751 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001752 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001753 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001754 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001755 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001756 return
1757 }
1758
1759 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001760 // in static libraries act as if they were whole static libraries. The same goes for
1761 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001762 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1763 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001764 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1765 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001766
Dan Willemsen581341d2017-02-09 16:16:31 -08001767 }
1768
Colin Cross26c34ed2016-09-30 17:10:16 -07001769 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001770 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001771 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001772 return
1773 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001774 *ptr = append(*ptr, linkFile.Path())
1775 }
1776
Colin Crossc99deeb2016-04-11 15:06:20 -07001777 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001778 dep := depFile
1779 if !dep.Valid() {
1780 dep = linkFile
1781 }
1782 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001783 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001784
Logan Chien43d34c32017-12-20 01:17:32 +08001785 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001786 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001787 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001788 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001789 isLLndk := inList(libName, llndkLibraries)
Jiyong Park374510b2018-03-19 18:23:01 +09001790 isVendorPublicLib := inList(libName, vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001791 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08001792
1793 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.isVndk() && !ccDep.mustUseVendorVariant() {
1794 // The vendor module is a no-vendor-variant VNDK library. Depend on the
1795 // core module instead.
1796 return libName
1797 } else if c.useVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001798 // The vendor module in Make will have been renamed to not conflict with the core
1799 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001800 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001801 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001802 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001803 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1804 return libName + recoverySuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001805 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001806 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001807 }
Logan Chien43d34c32017-12-20 01:17:32 +08001808 }
1809
1810 // Export the shared libs to Make.
1811 switch depTag {
Jiyong Park64a44f22019-01-18 14:37:08 +09001812 case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001813 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001814 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08001815 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09001816 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001817 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001818 c.Properties.ApexesProvidingSharedLibs = append(
1819 c.Properties.ApexesProvidingSharedLibs, an)
1820 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09001821 }
1822 }
1823
Jiyong Park27b188b2017-07-18 13:23:39 +09001824 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001825 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001826 c.Properties.AndroidMkSharedLibs = append(
1827 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08001828 case ndkStubDepTag, ndkLateStubDepTag:
1829 ndkStub := ccDep.linker.(*stubDecorator)
1830 c.Properties.AndroidMkSharedLibs = append(
1831 c.Properties.AndroidMkSharedLibs,
1832 depName+"."+ndkStub.properties.ApiLevel)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001833 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1834 c.Properties.AndroidMkStaticLibs = append(
1835 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001836 case runtimeDepTag:
1837 c.Properties.AndroidMkRuntimeLibs = append(
1838 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001839 case wholeStaticDepTag:
1840 c.Properties.AndroidMkWholeStaticLibs = append(
1841 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001842 }
Colin Crossca860ac2016-01-04 14:34:37 -08001843 })
1844
Jeff Gaston294356f2017-09-27 17:05:30 -07001845 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001846 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001847
Colin Crossdd84e052017-05-17 13:44:16 -07001848 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001849 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001850 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001851 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001852 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1853
1854 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001855 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001856 }
Colin Crossdd84e052017-05-17 13:44:16 -07001857
Colin Crossca860ac2016-01-04 14:34:37 -08001858 return depPaths
1859}
1860
1861func (c *Module) InstallInData() bool {
1862 if c.installer == nil {
1863 return false
1864 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001865 return c.installer.inData()
1866}
1867
1868func (c *Module) InstallInSanitizerDir() bool {
1869 if c.installer == nil {
1870 return false
1871 }
1872 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001873 return true
1874 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001875 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001876}
1877
Jiyong Parkf9332f12018-02-01 00:54:12 +09001878func (c *Module) InstallInRecovery() bool {
1879 return c.inRecovery()
1880}
1881
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001882func (c *Module) HostToolPath() android.OptionalPath {
1883 if c.installer == nil {
1884 return android.OptionalPath{}
1885 }
1886 return c.installer.hostToolPath()
1887}
1888
Nan Zhangd4e641b2017-07-12 12:55:28 -07001889func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1890 return c.outputFile
1891}
1892
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001893func (c *Module) Srcs() android.Paths {
1894 if c.outputFile.Valid() {
1895 return android.Paths{c.outputFile.Path()}
1896 }
1897 return android.Paths{}
1898}
1899
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001900func (c *Module) static() bool {
1901 if static, ok := c.linker.(interface {
1902 static() bool
1903 }); ok {
1904 return static.static()
1905 }
1906 return false
1907}
1908
Jiyong Park379de2f2018-12-19 02:47:14 +09001909func (c *Module) staticBinary() bool {
1910 if static, ok := c.linker.(interface {
1911 staticBinary() bool
1912 }); ok {
1913 return static.staticBinary()
1914 }
1915 return false
1916}
1917
Colin Crossb60190a2018-09-04 16:28:17 -07001918func (c *Module) getMakeLinkType() string {
1919 if c.useVndk() {
1920 if inList(c.Name(), vndkCoreLibraries) || inList(c.Name(), vndkSpLibraries) || inList(c.Name(), llndkLibraries) {
1921 if inList(c.Name(), vndkPrivateLibraries) {
1922 return "native:vndk_private"
1923 } else {
1924 return "native:vndk"
1925 }
1926 } else {
1927 return "native:vendor"
1928 }
1929 } else if c.inRecovery() {
1930 return "native:recovery"
1931 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
1932 return "native:ndk:none:none"
1933 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
1934 //family, link := getNdkStlFamilyAndLinkType(c)
1935 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Vic Yangefd249e2018-11-12 20:19:56 -08001936 } else if inList(c.Name(), vndkUsingCoreVariantLibraries) {
1937 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07001938 } else {
1939 return "native:platform"
1940 }
1941}
1942
Jiyong Park9d452992018-10-03 00:38:19 +09001943// Overrides ApexModule.IsInstallabeToApex()
1944// Only shared libraries are installable to APEX.
1945func (c *Module) IsInstallableToApex() bool {
1946 if shared, ok := c.linker.(interface {
1947 shared() bool
1948 }); ok {
1949 return shared.shared()
1950 }
1951 return false
1952}
1953
Jiyong Park3b1746a2019-01-29 11:15:04 +09001954func (c *Module) imageVariation() string {
1955 variation := "core"
1956 if c.useVndk() {
1957 variation = "vendor"
1958 } else if c.inRecovery() {
1959 variation = "recovery"
1960 }
1961 return variation
1962}
1963
bralee3f49f4d2019-03-04 06:58:15 +08001964func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
1965 dpInfo.Srcs = append(dpInfo.Srcs, c.Srcs().Strings()...)
1966}
1967
Colin Cross2ba19d92015-05-07 15:44:20 -07001968//
Colin Crosscfad1192015-11-02 16:43:11 -08001969// Defaults
1970//
Colin Crossca860ac2016-01-04 14:34:37 -08001971type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001972 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001973 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09001974 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001975}
1976
Colin Cross635c3b02016-05-18 15:37:25 -07001977func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001978}
1979
Patrice Arrudac249c712019-03-19 17:00:29 -07001980// cc_defaults provides a set of properties that can be inherited by other cc
1981// modules. A module can use the properties from a cc_defaults using
1982// `defaults: ["<:default_module_name>"]`. Properties of both modules are
1983// merged (when possible) by prepending the default module's values to the
1984// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07001985func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001986 return DefaultsFactory()
1987}
1988
Colin Cross36242852017-06-23 15:06:31 -07001989func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001990 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001991
Colin Cross36242852017-06-23 15:06:31 -07001992 module.AddProperties(props...)
1993 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001994 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001995 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001996 &BaseCompilerProperties{},
1997 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001998 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001999 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002000 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002001 &TestProperties{},
2002 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002003 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002004 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002005 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002006 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002007 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002008 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002009 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002010 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002011 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002012 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002013 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002014 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002015 )
Colin Crosscfad1192015-11-02 16:43:11 -08002016
Colin Cross1f44a3a2017-07-07 14:33:33 -07002017 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09002018 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002019
2020 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002021}
2022
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002023const (
2024 // coreMode is the variant used for framework-private libraries, or
2025 // SDK libraries. (which framework-private libraries can use)
2026 coreMode = "core"
2027
2028 // vendorMode is the variant used for /vendor code that compiles
2029 // against the VNDK.
2030 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09002031
2032 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002033)
2034
Jiyong Park6a43f042017-10-12 23:05:00 +09002035func squashVendorSrcs(m *Module) {
2036 if lib, ok := m.compiler.(*libraryDecorator); ok {
2037 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2038 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2039
2040 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2041 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2042 }
2043}
2044
Jiyong Parkf9332f12018-02-01 00:54:12 +09002045func squashRecoverySrcs(m *Module) {
2046 if lib, ok := m.compiler.(*libraryDecorator); ok {
2047 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2048 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2049
2050 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2051 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2052 }
2053}
2054
Jiyong Parkda6eb592018-12-19 17:12:36 +09002055func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002056 if mctx.Os() != android.Android {
2057 return
2058 }
2059
Jiyong Park7ed9de32018-10-15 22:25:07 +09002060 if g, ok := mctx.Module().(*genrule.Module); ok {
2061 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09002062 var coreVariantNeeded bool = false
2063 var vendorVariantNeeded bool = false
2064 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09002065 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09002066 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002067 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09002068 coreVariantNeeded = true
2069 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09002070 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09002071 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002072 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09002073 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002074 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002075 if Bool(props.Recovery_available) {
2076 recoveryVariantNeeded = true
2077 }
2078
Jiyong Park413cc742018-06-19 01:46:06 +09002079 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002080 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09002081 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09002082 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002083 recoveryVariantNeeded = false
2084 }
2085 }
2086
Jiyong Park3f736c92018-05-24 13:36:56 +09002087 var variants []string
2088 if coreVariantNeeded {
2089 variants = append(variants, coreMode)
2090 }
2091 if vendorVariantNeeded {
2092 variants = append(variants, vendorMode)
2093 }
2094 if recoveryVariantNeeded {
2095 variants = append(variants, recoveryMode)
2096 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002097 mod := mctx.CreateVariations(variants...)
2098 for i, v := range variants {
2099 if v == recoveryMode {
2100 m := mod[i].(*genrule.Module)
2101 m.Extra.(*GenruleExtraProperties).InRecovery = true
2102 }
2103 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002104 }
2105 }
2106
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002107 m, ok := mctx.Module().(*Module)
2108 if !ok {
2109 return
2110 }
2111
2112 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002113 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002114 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002115
2116 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002117 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002118 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002119 return
2120 }
Logan Chienf3511742017-10-31 18:04:35 +08002121
2122 if vndkdep := m.vndkdep; vndkdep != nil {
2123 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002124 if productSpecific {
2125 mctx.PropertyErrorf("product_specific",
2126 "product_specific must not be true when `vndk: {enabled: true}`")
2127 return
2128 }
Logan Chienf3511742017-10-31 18:04:35 +08002129 if vendorSpecific {
2130 if !vndkdep.isVndkExt() {
2131 mctx.PropertyErrorf("vndk",
2132 "must set `extends: \"...\"` to vndk extension")
2133 return
2134 }
2135 } else {
2136 if vndkdep.isVndkExt() {
2137 mctx.PropertyErrorf("vndk",
2138 "must set `vendor: true` to set `extends: %q`",
2139 m.getVndkExtendsModuleName())
2140 return
2141 }
2142 if m.VendorProperties.Vendor_available == nil {
2143 mctx.PropertyErrorf("vndk",
2144 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2145 return
2146 }
2147 }
2148 } else {
2149 if vndkdep.isVndkSp() {
2150 mctx.PropertyErrorf("vndk",
2151 "must set `enabled: true` to set `support_system_process: true`")
2152 return
2153 }
2154 if vndkdep.isVndkExt() {
2155 mctx.PropertyErrorf("vndk",
2156 "must set `enabled: true` to set `extends: %q`",
2157 m.getVndkExtendsModuleName())
2158 return
2159 }
Justin Yun8effde42017-06-23 19:24:43 +09002160 }
2161 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002162
Jiyong Parkf9332f12018-02-01 00:54:12 +09002163 var coreVariantNeeded bool = false
2164 var vendorVariantNeeded bool = false
2165 var recoveryVariantNeeded bool = false
2166
Justin Yun71549282017-11-17 12:10:28 +09002167 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002168 // If the device isn't compiling against the VNDK, we always
2169 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002170 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002171 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2172 // LL-NDK stubs only exist in the vendor variant, since the
2173 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002174 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09002175 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2176 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09002177 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09002178 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002179 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2180 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002181 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002182 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002183 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002184 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002185 coreVariantNeeded = true
2186 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002187 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002188 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09002189 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002190 } else {
2191 // This is either in /system (or similar: /data), or is a
2192 // modules built with the NDK. Modules built with the NDK
2193 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002194 coreVariantNeeded = true
2195 }
2196
2197 if Bool(m.Properties.Recovery_available) {
2198 recoveryVariantNeeded = true
2199 }
2200
2201 if m.ModuleBase.InstallInRecovery() {
2202 recoveryVariantNeeded = true
2203 coreVariantNeeded = false
2204 }
2205
Jiyong Park413cc742018-06-19 01:46:06 +09002206 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002207 primaryArch := mctx.Config().DevicePrimaryArchType()
2208 moduleArch := m.Target().Arch.ArchType
2209 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002210 recoveryVariantNeeded = false
2211 }
2212 }
2213
Jiyong Parkf9332f12018-02-01 00:54:12 +09002214 var variants []string
2215 if coreVariantNeeded {
2216 variants = append(variants, coreMode)
2217 }
2218 if vendorVariantNeeded {
2219 variants = append(variants, vendorMode)
2220 }
2221 if recoveryVariantNeeded {
2222 variants = append(variants, recoveryMode)
2223 }
2224 mod := mctx.CreateVariations(variants...)
2225 for i, v := range variants {
2226 if v == vendorMode {
2227 m := mod[i].(*Module)
2228 m.Properties.UseVndk = true
2229 squashVendorSrcs(m)
2230 } else if v == recoveryMode {
2231 m := mod[i].(*Module)
2232 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002233 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002234 squashRecoverySrcs(m)
2235 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002236 }
2237}
2238
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002239func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002240 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002241 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2242 }
Colin Cross6510f912017-11-29 00:27:14 -08002243 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002244}
2245
Colin Cross06a931b2015-10-28 17:23:31 -07002246var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002247var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002248var BoolPtr = proptools.BoolPtr
2249var String = proptools.String
2250var StringPtr = proptools.StringPtr