blob: e55c5760fa8f50230e33b81f355d9f9d93e59bd0 [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 (
Colin Cross41955e82019-05-29 14:40:35 -070022 "fmt"
Logan Chien41eabe62019-04-10 13:33:58 +080023 "io"
Dan Albert9e10cd42016-08-03 14:12:14 -070024 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080025 "strings"
26
Colin Cross97ba0732015-03-23 17:50:24 -070027 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070028 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070029
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070031 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070032 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080033)
34
Colin Cross463a90e2015-06-17 14:20:06 -070035func init() {
Paul Duffin036e7002019-12-19 19:16:28 +000036 RegisterCCBuildComponents(android.InitRegistrationContext)
Colin Cross463a90e2015-06-17 14:20:06 -070037
Paul Duffin036e7002019-12-19 19:16:28 +000038 pctx.Import("android/soong/cc/config")
39}
40
41func RegisterCCBuildComponents(ctx android.RegistrationContext) {
42 ctx.RegisterModuleType("cc_defaults", defaultsFactory)
43
44 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Inseob Kim64c43952019-08-26 16:52:35 +090045 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070046 ctx.BottomUp("link", LinkageMutator).Parallel()
Jooyung Hanb90e4912019-12-09 18:21:48 +090047 ctx.BottomUp("ndk_api", NdkApiMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +010048 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090049 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070050 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimac1e9862019-12-09 18:15:47 +090051 ctx.BottomUp("sysprop_cc", SyspropMutator).Parallel()
Inseob Kimeec88e12020-01-22 11:11:29 +090052 ctx.BottomUp("vendor_snapshot", VendorSnapshotMutator).Parallel()
53 ctx.BottomUp("vendor_snapshot_source", VendorSnapshotSourceMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070054 })
Colin Cross16b23492016-01-06 14:41:07 -080055
Paul Duffin036e7002019-12-19 19:16:28 +000056 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Cross1e676be2016-10-12 14:38:15 -070057 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
58 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080059
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070060 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
61 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
62
Mitch Phillipsbfeade62019-05-01 14:42:05 -070063 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
64 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
65
Jiyong Park1d1119f2019-07-29 21:27:18 +090066 // cfi mutator shouldn't run before sanitizers that return true for
67 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000068 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
69 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
70
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080071 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
72 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
73
Colin Cross1e676be2016-10-12 14:38:15 -070074 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
75 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080076
Colin Cross0b908332019-06-19 23:00:20 -070077 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090078 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080079
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080080 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080081 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070082
83 ctx.TopDown("lto_deps", ltoDepsMutator)
84 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090085
86 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070087 })
Colin Crossb98c8b02016-07-29 13:44:28 -070088
Sasha Smundak2a4549e2018-11-05 16:49:08 -080089 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070090}
91
Colin Crossca860ac2016-01-04 14:34:37 -080092type Deps struct {
93 SharedLibs, LateSharedLibs []string
94 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080095 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080096 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070097
Colin Cross5950f382016-12-13 12:50:57 -080098 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070099
Colin Cross81413472016-04-11 14:37:39 -0700100 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700101
Dan Willemsenb40aab62016-04-20 14:21:14 -0700102 GeneratedSources []string
103 GeneratedHeaders []string
Inseob Kimd110f872019-12-06 13:15:38 +0900104 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700105
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700106 ReexportGeneratedHeaders []string
107
Colin Cross97ba0732015-03-23 17:50:24 -0700108 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700109
110 // Used for host bionic
111 LinkerFlagsFile string
112 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700113}
114
Colin Crossca860ac2016-01-04 14:34:37 -0800115type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700116 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900117 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700118 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900119 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700120 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700121 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700122
Colin Cross26c34ed2016-09-30 17:10:16 -0700123 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700124 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800125 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700126 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700127
Colin Cross26c34ed2016-09-30 17:10:16 -0700128 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700129 GeneratedSources android.Paths
130 GeneratedHeaders android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900131 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700132
Inseob Kimd110f872019-12-06 13:15:38 +0900133 Flags []string
134 IncludeDirs android.Paths
135 SystemIncludeDirs android.Paths
136 ReexportedDirs android.Paths
137 ReexportedSystemDirs android.Paths
138 ReexportedFlags []string
139 ReexportedGeneratedHeaders android.Paths
140 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700141
Colin Cross26c34ed2016-09-30 17:10:16 -0700142 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700143 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700144
145 // Path to the file container flags to use with the linker
146 LinkerFlagsFile android.OptionalPath
147
148 // Path to the dynamic linker binary
149 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700150}
151
Colin Cross4af21ed2019-11-04 09:37:55 -0800152// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
153// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
154// command line so they can be overridden by the local module flags).
155type LocalOrGlobalFlags struct {
156 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700157 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800158 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700159 CFlags []string // Flags that apply to C and C++ source files
160 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
161 ConlyFlags []string // Flags that apply to C source files
162 CppFlags []string // Flags that apply to C++ source files
163 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700164 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800165}
166
167type Flags struct {
168 Local LocalOrGlobalFlags
169 Global LocalOrGlobalFlags
170
171 aidlFlags []string // Flags that apply to aidl source files
172 rsFlags []string // Flags that apply to renderscript source files
173 libFlags []string // Flags to add libraries early to the link order
174 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
175 TidyFlags []string // Flags that apply to clang-tidy
176 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700177
Colin Crossc3199482017-03-30 15:03:04 -0700178 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800179 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700180 SystemIncludeFlags []string
181
Colin Crossb98c8b02016-07-29 13:44:28 -0700182 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700183 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800184 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800185 SAbiDump bool
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800186 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800187
188 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800189 DynamicLinker string
190
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700191 CFlagsDeps android.Paths // Files depended on by compiler flags
192 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800193
Dan Willemsen98ab3112019-08-27 21:20:40 -0700194 AssemblerWithCpp bool
195 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800196
Colin Cross19878da2019-03-28 14:45:07 -0700197 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700198 protoC bool // Whether to use C instead of C++
199 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700200
201 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700202}
203
Colin Crossca860ac2016-01-04 14:34:37 -0800204// Properties used to compile all C or C++ modules
205type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700206 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800207 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700208
209 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800210 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700211
Jiyong Parkde866cb2018-12-07 23:08:36 +0900212 AndroidMkSharedLibs []string `blueprint:"mutated"`
213 AndroidMkStaticLibs []string `blueprint:"mutated"`
214 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
215 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
216 HideFromMake bool `blueprint:"mutated"`
217 PreventInstall bool `blueprint:"mutated"`
218 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700219
Justin Yun5f7f7e82019-11-18 19:52:14 +0900220 ImageVariationPrefix string `blueprint:"mutated"`
221 VndkVersion string `blueprint:"mutated"`
222 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800223
224 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
225 // file
226 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900227
Yifan Hong1b3348d2020-01-21 15:53:22 -0800228 // Make this module available when building for ramdisk
229 Ramdisk_available *bool
230
Jiyong Parkf9332f12018-02-01 00:54:12 +0900231 // Make this module available when building for recovery
232 Recovery_available *bool
233
Colin Crossae6c5202019-11-20 13:35:50 -0800234 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800235 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800236 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800237 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900238 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900239
240 // Allows this module to use non-APEX version of libraries. Useful
241 // for building binaries that are started before APEXes are activated.
242 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900243
244 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
245 // see soong/cc/config/vndk.go
246 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900247
248 // Used by vendor snapshot to record dependencies from snapshot modules.
249 SnapshotSharedLibs []string `blueprint:"mutated"`
250 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700251}
252
253type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900254 // whether this module should be allowed to be directly depended by other
255 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900256 // In addition, this module should be allowed to be directly depended by
257 // product modules with `product_specific: true`.
258 // If set to true, three variants will be built separately, one like
259 // normal, another limited to the set of libraries and headers
260 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700261 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900262 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700263 // so it shouldn't have any unversioned runtime dependencies, or
264 // make assumptions about the system that may not be true in the
265 // future.
266 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900267 // If set to false, this module becomes inaccessible from /vendor or /product
268 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900269 //
270 // Default value is true when vndk: {enabled: true} or vendor: true.
271 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700272 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900273 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700274 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900275
276 // whether this module is capable of being loaded with other instance
277 // (possibly an older version) of the same module in the same process.
278 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
279 // can be double loaded in a vendor process if the library is also a
280 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
281 // explicitly marked as `double_loadable: true` by the owner, or the dependency
282 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
283 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800284}
285
Colin Crossca860ac2016-01-04 14:34:37 -0800286type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800287 static() bool
288 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900289 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700290 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700291 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800292 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700293 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800294 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900295 isLlndk(config android.Config) bool
296 isLlndkPublic(config android.Config) bool
297 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900298 isVndk() bool
299 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800300 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900301 inProduct() bool
302 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800303 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900304 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800305 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700306 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700307 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800308 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800309 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800310 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800311 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800312 isForPlatform() bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900313 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900314 hasStubsVariants() bool
315 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900316 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800317 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700318 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800319}
320
321type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700322 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800323 ModuleContextIntf
324}
325
326type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700327 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800328 ModuleContextIntf
329}
330
Colin Cross37047f12016-12-13 17:06:13 -0800331type DepsContext interface {
332 android.BottomUpMutatorContext
333 ModuleContextIntf
334}
335
Colin Crossca860ac2016-01-04 14:34:37 -0800336type feature interface {
337 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800338 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800339 flags(ctx ModuleContext, flags Flags) Flags
340 props() []interface{}
341}
342
343type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700344 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800345 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800346 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700347 compilerProps() []interface{}
348
Colin Cross76fada02016-07-27 10:31:13 -0700349 appendCflags([]string)
350 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700351 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800352}
353
354type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700355 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800356 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700357 linkerFlags(ctx ModuleContext, flags Flags) Flags
358 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800359 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700360
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700361 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700362 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900363 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700364
365 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900366 coverageOutputFilePath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800367}
368
369type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700370 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700371 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800372 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700373 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700374 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900375 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800376}
377
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800378type xref interface {
379 XrefCcFiles() android.Paths
380}
381
Colin Crossc99deeb2016-04-11 15:06:20 -0700382var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700383 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
384 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
385 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
386 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
387 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
388 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
389 headerDepTag = DependencyTag{Name: "header", Library: true}
390 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
391 genSourceDepTag = DependencyTag{Name: "gen source"}
392 genHeaderDepTag = DependencyTag{Name: "gen header"}
393 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
394 objDepTag = DependencyTag{Name: "obj"}
395 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
396 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
397 reuseObjTag = DependencyTag{Name: "reuse objects"}
398 staticVariantTag = DependencyTag{Name: "static variant"}
399 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
400 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
401 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
402 runtimeDepTag = DependencyTag{Name: "runtime lib"}
403 coverageDepTag = DependencyTag{Name: "coverage"}
404 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700405)
406
Roland Levillainf89cd092019-07-29 16:22:59 +0100407func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700408 ccDepTag, ok := depTag.(DependencyTag)
409 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100410}
411
412func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700413 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100414 return ok && ccDepTag == runtimeDepTag
415}
416
417func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700418 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100419 return ok && ccDepTag == testPerSrcDepTag
420}
421
Colin Crossca860ac2016-01-04 14:34:37 -0800422// Module contains the properties and members used by all C/C++ module types, and implements
423// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
424// to construct the output file. Behavior can be customized with a Customizer interface
425type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700426 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700427 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900428 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900429 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700430
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700431 Properties BaseProperties
432 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700433
Colin Crossca860ac2016-01-04 14:34:37 -0800434 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700435 hod android.HostOrDeviceSupported
436 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700437
Paul Duffina0843f62019-12-13 19:50:38 +0000438 // Allowable SdkMemberTypes of this module type.
439 sdkMemberTypes []android.SdkMemberType
440
Colin Crossca860ac2016-01-04 14:34:37 -0800441 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700442 features []feature
443 compiler compiler
444 linker linker
445 installer installer
446 stl *stl
447 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800448 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800449 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900450 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700451 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700452 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800453 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800454
Colin Cross635c3b02016-05-18 15:37:25 -0700455 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800456
Colin Crossb98c8b02016-07-29 13:44:28 -0700457 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700458
459 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800460
461 // Flags used to compile this module
462 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700463
464 // 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 -0800465 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700466 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800467 depsInLinkOrder android.Paths
468
469 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700470 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900471
472 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800473 // Kythe (source file indexer) paths for this compilation module
474 kytheFiles android.Paths
Colin Crossc472d572015-03-17 15:06:21 -0700475}
476
Ivan Lozano52767be2019-10-18 14:49:46 -0700477func (c *Module) Toc() android.OptionalPath {
478 if c.linker != nil {
479 if library, ok := c.linker.(libraryInterface); ok {
480 return library.toc()
481 }
482 }
483 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
484}
485
486func (c *Module) ApiLevel() string {
487 if c.linker != nil {
488 if stub, ok := c.linker.(*stubDecorator); ok {
489 return stub.properties.ApiLevel
490 }
491 }
492 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
493}
494
495func (c *Module) Static() bool {
496 if c.linker != nil {
497 if library, ok := c.linker.(libraryInterface); ok {
498 return library.static()
499 }
500 }
501 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
502}
503
504func (c *Module) Shared() bool {
505 if c.linker != nil {
506 if library, ok := c.linker.(libraryInterface); ok {
507 return library.shared()
508 }
509 }
510 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
511}
512
513func (c *Module) SelectedStl() string {
514 return c.stl.Properties.SelectedStl
515}
516
517func (c *Module) ToolchainLibrary() bool {
518 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
519 return true
520 }
521 return false
522}
523
524func (c *Module) NdkPrebuiltStl() bool {
525 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
526 return true
527 }
528 return false
529}
530
531func (c *Module) StubDecorator() bool {
532 if _, ok := c.linker.(*stubDecorator); ok {
533 return true
534 }
535 return false
536}
537
538func (c *Module) SdkVersion() string {
539 return String(c.Properties.Sdk_version)
540}
541
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800542func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700543 if c.linker != nil {
544 if library, ok := c.linker.(exportedFlagsProducer); ok {
545 return library.exportedDirs()
546 }
547 }
548 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
549}
550
551func (c *Module) HasStaticVariant() bool {
552 if c.staticVariant != nil {
553 return true
554 }
555 return false
556}
557
558func (c *Module) GetStaticVariant() LinkableInterface {
559 return c.staticVariant
560}
561
562func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
563 c.depsInLinkOrder = depsInLinkOrder
564}
565
566func (c *Module) GetDepsInLinkOrder() []android.Path {
567 return c.depsInLinkOrder
568}
569
570func (c *Module) StubsVersions() []string {
571 if c.linker != nil {
572 if library, ok := c.linker.(*libraryDecorator); ok {
573 return library.Properties.Stubs.Versions
574 }
575 }
576 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
577}
578
579func (c *Module) CcLibrary() bool {
580 if c.linker != nil {
581 if _, ok := c.linker.(*libraryDecorator); ok {
582 return true
583 }
584 }
585 return false
586}
587
588func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700589 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700590 return true
591 }
592 return false
593}
594
Ivan Lozano2b262972019-11-21 12:30:50 -0800595func (c *Module) NonCcVariants() bool {
596 return false
597}
598
Ivan Lozano183a3212019-10-18 14:18:45 -0700599func (c *Module) SetBuildStubs() {
600 if c.linker != nil {
601 if library, ok := c.linker.(*libraryDecorator); ok {
602 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700603 c.Properties.HideFromMake = true
604 c.sanitize = nil
605 c.stl = nil
606 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700607 return
608 }
609 }
610 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
611}
612
Ivan Lozano52767be2019-10-18 14:49:46 -0700613func (c *Module) BuildStubs() bool {
614 if c.linker != nil {
615 if library, ok := c.linker.(*libraryDecorator); ok {
616 return library.buildStubs()
617 }
618 }
619 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
620}
621
Ivan Lozano183a3212019-10-18 14:18:45 -0700622func (c *Module) SetStubsVersions(version string) {
623 if c.linker != nil {
624 if library, ok := c.linker.(*libraryDecorator); ok {
625 library.MutatedProperties.StubsVersion = version
626 return
627 }
628 }
629 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
630}
631
632func (c *Module) SetStatic() {
633 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700634 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700635 library.setStatic()
636 return
637 }
638 }
639 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
640}
641
642func (c *Module) SetShared() {
643 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700644 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700645 library.setShared()
646 return
647 }
648 }
649 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
650}
651
652func (c *Module) BuildStaticVariant() bool {
653 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700654 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700655 return library.buildStatic()
656 }
657 }
658 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
659}
660
661func (c *Module) BuildSharedVariant() bool {
662 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700663 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700664 return library.buildShared()
665 }
666 }
667 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
668}
669
670func (c *Module) Module() android.Module {
671 return c
672}
673
Jiyong Parkc20eee32018-09-05 22:36:17 +0900674func (c *Module) OutputFile() android.OptionalPath {
675 return c.outputFile
676}
677
Ivan Lozano183a3212019-10-18 14:18:45 -0700678var _ LinkableInterface = (*Module)(nil)
679
Jiyong Park719b4462019-01-13 00:39:51 +0900680func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900681 if c.linker != nil {
682 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900683 }
684 return nil
685}
686
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900687func (c *Module) CoverageOutputFile() android.OptionalPath {
688 if c.linker != nil {
689 return c.linker.coverageOutputFilePath()
690 }
691 return android.OptionalPath{}
692}
693
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900694func (c *Module) RelativeInstallPath() string {
695 if c.installer != nil {
696 return c.installer.relativeInstallPath()
697 }
698 return ""
699}
700
Jooyung Han344d5432019-08-23 11:17:39 +0900701func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900702 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900703}
704
Colin Cross36242852017-06-23 15:06:31 -0700705func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700706 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800707 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700708 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800709 }
710 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700711 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800712 }
713 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700714 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800715 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700716 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700717 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700718 }
Colin Cross16b23492016-01-06 14:41:07 -0800719 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700720 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800721 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800722 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700723 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800724 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800725 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700726 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800727 }
Justin Yun8effde42017-06-23 19:24:43 +0900728 if c.vndkdep != nil {
729 c.AddProperties(c.vndkdep.props()...)
730 }
Stephen Craneba090d12017-05-09 15:44:35 -0700731 if c.lto != nil {
732 c.AddProperties(c.lto.props()...)
733 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700734 if c.pgo != nil {
735 c.AddProperties(c.pgo.props()...)
736 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800737 if c.xom != nil {
738 c.AddProperties(c.xom.props()...)
739 }
Colin Crossca860ac2016-01-04 14:34:37 -0800740 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700741 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800742 }
Colin Crossc472d572015-03-17 15:06:21 -0700743
Colin Crossa9d8bee2018-10-02 13:59:46 -0700744 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
745 switch class {
746 case android.Device:
747 return ctx.Config().DevicePrefer32BitExecutables()
748 case android.HostCross:
749 // Windows builds always prefer 32-bit
750 return true
751 default:
752 return false
753 }
754 })
Colin Cross36242852017-06-23 15:06:31 -0700755 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900756 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900757 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900758 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900759
Colin Cross36242852017-06-23 15:06:31 -0700760 return c
Colin Crossc472d572015-03-17 15:06:21 -0700761}
762
Colin Crossb916a382016-07-29 17:28:03 -0700763// Returns true for dependency roots (binaries)
764// TODO(ccross): also handle dlopenable libraries
765func (c *Module) isDependencyRoot() bool {
766 if root, ok := c.linker.(interface {
767 isDependencyRoot() bool
768 }); ok {
769 return root.isDependencyRoot()
770 }
771 return false
772}
773
Justin Yun5f7f7e82019-11-18 19:52:14 +0900774// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
775// "product" and "vendor" variant modules return true for this function.
776// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
777// "soc_specific: true" and more vendor installed modules are included here.
778// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
779// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700780func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900781 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700782}
783
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800784func (c *Module) isCoverageVariant() bool {
785 return c.coverage.Properties.IsCoverageVariant
786}
787
Peter Collingbournead84f972019-12-17 16:46:18 -0800788func (c *Module) IsNdk() bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800789 return inList(c.Name(), ndkMigratedLibs)
790}
791
Inseob Kim9516ee92019-05-09 10:56:13 +0900792func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800793 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900794 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800795}
796
Inseob Kim9516ee92019-05-09 10:56:13 +0900797func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800798 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900799 name := c.BaseModuleName()
800 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800801}
802
Inseob Kim9516ee92019-05-09 10:56:13 +0900803func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800804 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900805 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800806}
807
Ivan Lozano52767be2019-10-18 14:49:46 -0700808func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800809 if vndkdep := c.vndkdep; vndkdep != nil {
810 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900811 }
812 return false
813}
814
Yi Kong7e53c572018-02-14 18:16:12 +0800815func (c *Module) isPgoCompile() bool {
816 if pgo := c.pgo; pgo != nil {
817 return pgo.Properties.PgoCompile
818 }
819 return false
820}
821
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800822func (c *Module) isNDKStubLibrary() bool {
823 if _, ok := c.compiler.(*stubDecorator); ok {
824 return true
825 }
826 return false
827}
828
Logan Chienf3511742017-10-31 18:04:35 +0800829func (c *Module) isVndkSp() bool {
830 if vndkdep := c.vndkdep; vndkdep != nil {
831 return vndkdep.isVndkSp()
832 }
833 return false
834}
835
836func (c *Module) isVndkExt() bool {
837 if vndkdep := c.vndkdep; vndkdep != nil {
838 return vndkdep.isVndkExt()
839 }
840 return false
841}
842
Ivan Lozano52767be2019-10-18 14:49:46 -0700843func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900844 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800845}
846
Logan Chienf3511742017-10-31 18:04:35 +0800847func (c *Module) getVndkExtendsModuleName() string {
848 if vndkdep := c.vndkdep; vndkdep != nil {
849 return vndkdep.getVndkExtendsModuleName()
850 }
851 return ""
852}
853
Justin Yun5f7f7e82019-11-18 19:52:14 +0900854// Returns true only when this module is configured to have core, product and vendor
Jiyong Park82e2bf32017-08-16 14:05:54 +0900855// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700856func (c *Module) HasVendorVariant() bool {
857 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900858}
859
Justin Yun5f7f7e82019-11-18 19:52:14 +0900860const (
861 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
862 // against the VNDK.
863 VendorVariationPrefix = "vendor."
864
865 // ProductVariationPrefix is the variant prefix used for /product code that compiles
866 // against the VNDK.
867 ProductVariationPrefix = "product."
868)
869
870// Returns true if the module is "product" variant. Usually these modules are installed in /product
871func (c *Module) inProduct() bool {
872 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
873}
874
875// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
876func (c *Module) inVendor() bool {
877 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
878}
879
Yifan Hong1b3348d2020-01-21 15:53:22 -0800880func (c *Module) InRamdisk() bool {
881 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
882}
883
Ivan Lozano52767be2019-10-18 14:49:46 -0700884func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800885 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900886}
887
Yifan Hong1b3348d2020-01-21 15:53:22 -0800888func (c *Module) OnlyInRamdisk() bool {
889 return c.ModuleBase.InstallInRamdisk()
890}
891
Ivan Lozano52767be2019-10-18 14:49:46 -0700892func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900893 return c.ModuleBase.InstallInRecovery()
894}
895
Jiyong Park25fc6a92018-11-18 18:02:45 +0900896func (c *Module) IsStubs() bool {
897 if library, ok := c.linker.(*libraryDecorator); ok {
898 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900899 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
900 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900901 }
902 return false
903}
904
905func (c *Module) HasStubsVariants() bool {
906 if library, ok := c.linker.(*libraryDecorator); ok {
907 return len(library.Properties.Stubs.Versions) > 0
908 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700909 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
910 return len(library.Properties.Stubs.Versions) > 0
911 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900912 return false
913}
914
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900915func (c *Module) bootstrap() bool {
916 return Bool(c.Properties.Bootstrap)
917}
918
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700919func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700920 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
921 if c.Target().NativeBridge == android.NativeBridgeEnabled {
922 return false
923 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700924 return c.linker != nil && c.linker.nativeCoverage()
925}
926
Inseob Kim8471cda2019-11-15 09:59:12 +0900927func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kimeec88e12020-01-22 11:11:29 +0900928 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
929 return true
930 }
931 if _, ok := c.linker.(*vendorSnapshotLibraryDecorator); ok {
932 return true
933 }
934 if _, ok := c.linker.(*vendorSnapshotBinaryDecorator); ok {
935 return true
936 }
937 return false
Inseob Kim8471cda2019-11-15 09:59:12 +0900938}
939
Jiyong Park73c54ee2019-10-22 20:31:18 +0900940func (c *Module) ExportedIncludeDirs() android.Paths {
941 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
942 return flagsProducer.exportedDirs()
943 }
Jiyong Park232e7852019-11-04 12:23:40 +0900944 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900945}
946
947func (c *Module) ExportedSystemIncludeDirs() android.Paths {
948 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
949 return flagsProducer.exportedSystemDirs()
950 }
Jiyong Park232e7852019-11-04 12:23:40 +0900951 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900952}
953
954func (c *Module) ExportedFlags() []string {
955 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
956 return flagsProducer.exportedFlags()
957 }
Jiyong Park232e7852019-11-04 12:23:40 +0900958 return nil
959}
960
961func (c *Module) ExportedDeps() android.Paths {
962 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
963 return flagsProducer.exportedDeps()
964 }
965 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900966}
967
Inseob Kimd110f872019-12-06 13:15:38 +0900968func (c *Module) ExportedGeneratedHeaders() android.Paths {
969 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
970 return flagsProducer.exportedGeneratedHeaders()
971 }
972 return nil
973}
974
Jiyong Parkf1194352019-02-25 11:05:47 +0900975func isBionic(name string) bool {
976 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +0000977 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +0900978 return true
979 }
980 return false
981}
982
Martin Stjernholm279de572019-09-10 23:18:20 +0100983func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700984 if name == "libclang_rt.hwasan-aarch64-android" {
985 return inList("hwaddress", config.SanitizeDevice())
986 }
987 return isBionic(name)
988}
989
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800990func (c *Module) XrefCcFiles() android.Paths {
991 return c.kytheFiles
992}
993
Colin Crossca860ac2016-01-04 14:34:37 -0800994type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700995 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800996 moduleContextImpl
997}
998
Colin Cross37047f12016-12-13 17:06:13 -0800999type depsContext struct {
1000 android.BottomUpMutatorContext
1001 moduleContextImpl
1002}
1003
Colin Crossca860ac2016-01-04 14:34:37 -08001004type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001005 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001006 moduleContextImpl
1007}
1008
Justin Yun5f7f7e82019-11-18 19:52:14 +09001009func (ctx *moduleContext) ProductSpecific() bool {
1010 return ctx.ModuleContext.ProductSpecific() ||
1011 (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
1012}
1013
Jiyong Park2db76922017-11-08 16:03:48 +09001014func (ctx *moduleContext) SocSpecific() bool {
1015 return ctx.ModuleContext.SocSpecific() ||
Justin Yun5f7f7e82019-11-18 19:52:14 +09001016 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001017}
1018
Colin Crossca860ac2016-01-04 14:34:37 -08001019type moduleContextImpl struct {
1020 mod *Module
1021 ctx BaseModuleContext
1022}
1023
Colin Crossb98c8b02016-07-29 13:44:28 -07001024func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001025 return ctx.mod.toolchain(ctx.ctx)
1026}
1027
1028func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001029 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001030}
1031
1032func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001033 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001034}
1035
Jiyong Park1d1119f2019-07-29 21:27:18 +09001036func (ctx *moduleContextImpl) header() bool {
1037 return ctx.mod.header()
1038}
1039
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001040func (ctx *moduleContextImpl) useSdk() bool {
Yifan Hong1b3348d2020-01-21 15:53:22 -08001041 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRamdisk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -08001042 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -07001043 }
1044 return false
Colin Crossca860ac2016-01-04 14:34:37 -08001045}
1046
1047func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001048 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001049 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001050 vndkVer := ctx.mod.VndkVersion()
1051 if inList(vndkVer, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
1052 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001053 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001054 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001055 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001056 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001057 }
1058 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001059}
1060
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001061func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001062 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001063}
Justin Yun8effde42017-06-23 19:24:43 +09001064
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001065func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001066 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001067}
1068
Inseob Kim9516ee92019-05-09 10:56:13 +09001069func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1070 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001071}
1072
Inseob Kim9516ee92019-05-09 10:56:13 +09001073func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1074 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001075}
1076
Inseob Kim9516ee92019-05-09 10:56:13 +09001077func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1078 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001079}
1080
Logan Chienf3511742017-10-31 18:04:35 +08001081func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001082 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001083}
1084
Yi Kong7e53c572018-02-14 18:16:12 +08001085func (ctx *moduleContextImpl) isPgoCompile() bool {
1086 return ctx.mod.isPgoCompile()
1087}
1088
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001089func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1090 return ctx.mod.isNDKStubLibrary()
1091}
1092
Justin Yun8effde42017-06-23 19:24:43 +09001093func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001094 return ctx.mod.isVndkSp()
1095}
1096
1097func (ctx *moduleContextImpl) isVndkExt() bool {
1098 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001099}
1100
Vic Yangefd249e2018-11-12 20:19:56 -08001101func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001102 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001103}
1104
Justin Yun5f7f7e82019-11-18 19:52:14 +09001105func (ctx *moduleContextImpl) inProduct() bool {
1106 return ctx.mod.inProduct()
1107}
1108
1109func (ctx *moduleContextImpl) inVendor() bool {
1110 return ctx.mod.inVendor()
1111}
1112
Yifan Hong1b3348d2020-01-21 15:53:22 -08001113func (ctx *moduleContextImpl) inRamdisk() bool {
1114 return ctx.mod.InRamdisk()
1115}
1116
Jiyong Parkf9332f12018-02-01 00:54:12 +09001117func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001118 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001119}
1120
Logan Chien2f2b8902018-07-10 15:01:19 +08001121// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001122func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001123 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1124 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001125 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001126
1127 if ctx.ctx.Fuchsia() {
1128 return false
1129 }
1130
Logan Chien2f2b8902018-07-10 15:01:19 +08001131 if sanitize := ctx.mod.sanitize; sanitize != nil {
1132 if !sanitize.isVariantOnProductionDevice() {
1133 return false
1134 }
1135 }
1136 if !ctx.ctx.Device() {
1137 // Host modules do not need ABI dumps.
1138 return false
1139 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001140 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001141 // Stubs do not need ABI dumps.
1142 return false
1143 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001144 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001145}
1146
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001147func (ctx *moduleContextImpl) selectedStl() string {
1148 if stl := ctx.mod.stl; stl != nil {
1149 return stl.Properties.SelectedStl
1150 }
1151 return ""
1152}
1153
Ivan Lozanobd721262018-11-27 14:33:03 -08001154func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1155 return ctx.mod.linker.useClangLld(actx)
1156}
1157
Colin Crossce75d2c2016-10-06 16:12:58 -07001158func (ctx *moduleContextImpl) baseModuleName() string {
1159 return ctx.mod.ModuleBase.BaseModuleName()
1160}
1161
Logan Chienf3511742017-10-31 18:04:35 +08001162func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1163 return ctx.mod.getVndkExtendsModuleName()
1164}
1165
Logan Chiene274fc92019-12-03 11:18:32 -08001166func (ctx *moduleContextImpl) isForPlatform() bool {
1167 return ctx.mod.IsForPlatform()
1168}
1169
Jiyong Park58e364a2019-01-19 19:24:06 +09001170func (ctx *moduleContextImpl) apexName() string {
1171 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001172}
1173
Jiyong Parkb0788572018-12-20 22:10:17 +09001174func (ctx *moduleContextImpl) hasStubsVariants() bool {
1175 return ctx.mod.HasStubsVariants()
1176}
1177
1178func (ctx *moduleContextImpl) isStubs() bool {
1179 return ctx.mod.IsStubs()
1180}
1181
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001182func (ctx *moduleContextImpl) bootstrap() bool {
1183 return ctx.mod.bootstrap()
1184}
1185
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001186func (ctx *moduleContextImpl) nativeCoverage() bool {
1187 return ctx.mod.nativeCoverage()
1188}
1189
Colin Cross635c3b02016-05-18 15:37:25 -07001190func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001191 return &Module{
1192 hod: hod,
1193 multilib: multilib,
1194 }
1195}
1196
Colin Cross635c3b02016-05-18 15:37:25 -07001197func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001198 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001199 module.features = []feature{
1200 &tidyFeature{},
1201 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001202 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001203 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001204 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001205 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001206 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001207 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001208 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -08001209 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -08001210 return module
1211}
1212
Colin Crossce75d2c2016-10-06 16:12:58 -07001213func (c *Module) Prebuilt() *android.Prebuilt {
1214 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1215 return p.prebuilt()
1216 }
1217 return nil
1218}
1219
1220func (c *Module) Name() string {
1221 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001222 if p, ok := c.linker.(interface {
1223 Name(string) string
1224 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001225 name = p.Name(name)
1226 }
1227 return name
1228}
1229
Alex Light3d673592019-01-18 14:37:31 -08001230func (c *Module) Symlinks() []string {
1231 if p, ok := c.installer.(interface {
1232 symlinkList() []string
1233 }); ok {
1234 return p.symlinkList()
1235 }
1236 return nil
1237}
1238
Jeff Gaston294356f2017-09-27 17:05:30 -07001239// orderDeps reorders dependencies into a list such that if module A depends on B, then
1240// A will precede B in the resultant list.
1241// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001242// Note that directSharedDeps should be the analogous static library for each shared lib dep
1243func 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 -07001244 // If A depends on B, then
1245 // Every list containing A will also contain B later in the list
1246 // So, after concatenating all lists, the final instance of B will have come from the same
1247 // original list as the final instance of A
1248 // So, the final instance of B will be later in the concatenation than the final A
1249 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1250 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001251 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001252 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001253 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1254 }
1255 for _, dep := range directSharedDeps {
1256 orderedAllDeps = append(orderedAllDeps, dep)
1257 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001258 }
1259
Colin Crossb6715442017-10-24 11:13:31 -07001260 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001261
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001262 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001263 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001264 // resultant list to only what the caller has chosen to include in directStaticDeps
1265 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001266
1267 return orderedAllDeps, orderedDeclaredDeps
1268}
1269
Ivan Lozano183a3212019-10-18 14:18:45 -07001270func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001271 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001272 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001273 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1274 staticDepFiles := []android.Path{}
1275 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001276 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1277 if dep.OutputFile().Valid() {
1278 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1279 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1280 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001281 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001282 sharedDepFiles := []android.Path{}
1283 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001284 if sharedDep.HasStaticVariant() {
1285 staticAnalogue := sharedDep.GetStaticVariant()
1286 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1287 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001288 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001289 }
1290
1291 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001292 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1293 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001294
1295 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001296}
1297
Roland Levillainf89cd092019-07-29 16:22:59 +01001298func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1299 test, ok := c.linker.(testPerSrc)
1300 return ok && test.isAllTestsVariation()
1301}
1302
Justin Yun5f7f7e82019-11-18 19:52:14 +09001303func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1304 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1305 // "current", it will append the VNDK version to the name suffix.
1306 var vndkVersion string
1307 var nameSuffix string
1308 if c.inProduct() {
1309 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1310 nameSuffix = productSuffix
1311 } else {
1312 vndkVersion = ctx.DeviceConfig().VndkVersion()
1313 nameSuffix = vendorSuffix
1314 }
1315 if vndkVersion == "current" {
1316 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1317 }
1318 if c.Properties.VndkVersion != vndkVersion {
1319 // add version suffix only if the module is using different vndk version than the
1320 // version in product or vendor partition.
1321 nameSuffix += "." + c.Properties.VndkVersion
1322 }
1323 return nameSuffix
1324}
1325
Colin Cross635c3b02016-05-18 15:37:25 -07001326func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001327 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001328 //
1329 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1330 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1331 // module and return early, as this module does not produce an output file per se.
1332 if c.IsTestPerSrcAllTestsVariation() {
1333 c.outputFile = android.OptionalPath{}
1334 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001335 }
1336
Jooyung Han38002912019-05-16 04:01:54 +09001337 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001338
Inseob Kim64c43952019-08-26 16:52:35 +09001339 c.Properties.SubName = ""
1340
1341 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1342 c.Properties.SubName += nativeBridgeSuffix
1343 }
1344
Justin Yun5f7f7e82019-11-18 19:52:14 +09001345 _, llndk := c.linker.(*llndkStubDecorator)
1346 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1347 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1348 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1349 // added for product variant only when we have vendor and product variants with core
1350 // variant. The suffix is not added for vendor-only or product-only module.
1351 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1352 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001353 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1354 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1355 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001356 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1357 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001358 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001359 c.Properties.SubName += recoverySuffix
1360 }
1361
Colin Crossca860ac2016-01-04 14:34:37 -08001362 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001363 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001364 moduleContextImpl: moduleContextImpl{
1365 mod: c,
1366 },
1367 }
1368 ctx.ctx = ctx
1369
Colin Crossf18e1102017-11-16 14:33:08 -08001370 deps := c.depsToPaths(ctx)
1371 if ctx.Failed() {
1372 return
1373 }
1374
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001375 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1376 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1377 }
1378
Colin Crossca860ac2016-01-04 14:34:37 -08001379 flags := Flags{
1380 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001381 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001382 }
Colin Crossca860ac2016-01-04 14:34:37 -08001383 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001384 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001385 }
1386 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001387 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001388 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001389 if c.stl != nil {
1390 flags = c.stl.flags(ctx, flags)
1391 }
Colin Cross16b23492016-01-06 14:41:07 -08001392 if c.sanitize != nil {
1393 flags = c.sanitize.flags(ctx, flags)
1394 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001395 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001396 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001397 }
Stephen Craneba090d12017-05-09 15:44:35 -07001398 if c.lto != nil {
1399 flags = c.lto.flags(ctx, flags)
1400 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001401 if c.pgo != nil {
1402 flags = c.pgo.flags(ctx, flags)
1403 }
Ivan Lozano074ec482018-11-21 08:59:37 -08001404 if c.xom != nil {
1405 flags = c.xom.flags(ctx, flags)
1406 }
Colin Crossca860ac2016-01-04 14:34:37 -08001407 for _, feature := range c.features {
1408 flags = feature.flags(ctx, flags)
1409 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001410 if ctx.Failed() {
1411 return
1412 }
1413
Colin Cross4af21ed2019-11-04 09:37:55 -08001414 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1415 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1416 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001417
Colin Cross4af21ed2019-11-04 09:37:55 -08001418 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001419
1420 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001421 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001422 }
1423 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001424 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001425 }
1426
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001427 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001428 // We need access to all the flags seen by a source file.
1429 if c.sabi != nil {
1430 flags = c.sabi.flags(ctx, flags)
1431 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001432
Colin Cross4af21ed2019-11-04 09:37:55 -08001433 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001434
Colin Crossca860ac2016-01-04 14:34:37 -08001435 // Optimization to reduce size of build.ninja
1436 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001437 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1438 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1439 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1440 flags.Local.CFlags = []string{"$cflags"}
1441 flags.Local.CppFlags = []string{"$cppflags"}
1442 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001443
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001444 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001445 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001446 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001447 if ctx.Failed() {
1448 return
1449 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001450 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001451 }
1452
Colin Crossca860ac2016-01-04 14:34:37 -08001453 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001454 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001455 if ctx.Failed() {
1456 return
1457 }
Colin Cross635c3b02016-05-18 15:37:25 -07001458 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001459
1460 // If a lib is directly included in any of the APEXes, unhide the stubs
1461 // variant having the latest version gets visible to make. In addition,
1462 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1463 // force anything in the make world to link against the stubs library.
1464 // (unless it is explicitly referenced via .bootstrap suffix or the
1465 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001466 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001467 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001468 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001469 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001470 c.Properties.HideFromMake = false // unhide
1471 // Note: this is still non-installable
1472 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001473 }
Colin Cross5049f022015-03-18 13:28:46 -07001474
Inseob Kim1f086e22019-05-09 13:29:15 +09001475 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001476 c.installer.install(ctx, c.outputFile.Path())
1477 if ctx.Failed() {
1478 return
Colin Crossca860ac2016-01-04 14:34:37 -08001479 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001480 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001481}
1482
Colin Cross0ea8ba82019-06-06 14:33:29 -07001483func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001484 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001485 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001486 }
Colin Crossca860ac2016-01-04 14:34:37 -08001487 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001488}
1489
Colin Crossca860ac2016-01-04 14:34:37 -08001490func (c *Module) begin(ctx BaseModuleContext) {
1491 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001492 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001493 }
Colin Crossca860ac2016-01-04 14:34:37 -08001494 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001495 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001496 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001497 if c.stl != nil {
1498 c.stl.begin(ctx)
1499 }
Colin Cross16b23492016-01-06 14:41:07 -08001500 if c.sanitize != nil {
1501 c.sanitize.begin(ctx)
1502 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001503 if c.coverage != nil {
1504 c.coverage.begin(ctx)
1505 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001506 if c.sabi != nil {
1507 c.sabi.begin(ctx)
1508 }
Justin Yun8effde42017-06-23 19:24:43 +09001509 if c.vndkdep != nil {
1510 c.vndkdep.begin(ctx)
1511 }
Stephen Craneba090d12017-05-09 15:44:35 -07001512 if c.lto != nil {
1513 c.lto.begin(ctx)
1514 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001515 if c.pgo != nil {
1516 c.pgo.begin(ctx)
1517 }
Colin Crossca860ac2016-01-04 14:34:37 -08001518 for _, feature := range c.features {
1519 feature.begin(ctx)
1520 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001521 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001522 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001523 if err != nil {
1524 ctx.PropertyErrorf("sdk_version", err.Error())
1525 }
Nan Zhang0007d812017-11-07 10:57:05 -08001526 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001527 }
Colin Crossca860ac2016-01-04 14:34:37 -08001528}
1529
Colin Cross37047f12016-12-13 17:06:13 -08001530func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001531 deps := Deps{}
1532
1533 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001534 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001535 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001536 // Add the PGO dependency (the clang_rt.profile runtime library), which
1537 // sometimes depends on symbols from libgcc, before libgcc gets added
1538 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001539 if c.pgo != nil {
1540 deps = c.pgo.deps(ctx, deps)
1541 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001542 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001543 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001544 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001545 if c.stl != nil {
1546 deps = c.stl.deps(ctx, deps)
1547 }
Colin Cross16b23492016-01-06 14:41:07 -08001548 if c.sanitize != nil {
1549 deps = c.sanitize.deps(ctx, deps)
1550 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001551 if c.coverage != nil {
1552 deps = c.coverage.deps(ctx, deps)
1553 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001554 if c.sabi != nil {
1555 deps = c.sabi.deps(ctx, deps)
1556 }
Justin Yun8effde42017-06-23 19:24:43 +09001557 if c.vndkdep != nil {
1558 deps = c.vndkdep.deps(ctx, deps)
1559 }
Stephen Craneba090d12017-05-09 15:44:35 -07001560 if c.lto != nil {
1561 deps = c.lto.deps(ctx, deps)
1562 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001563 for _, feature := range c.features {
1564 deps = feature.deps(ctx, deps)
1565 }
1566
Colin Crossb6715442017-10-24 11:13:31 -07001567 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1568 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1569 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1570 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1571 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1572 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001573 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001574
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001575 for _, lib := range deps.ReexportSharedLibHeaders {
1576 if !inList(lib, deps.SharedLibs) {
1577 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1578 }
1579 }
1580
1581 for _, lib := range deps.ReexportStaticLibHeaders {
1582 if !inList(lib, deps.StaticLibs) {
1583 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1584 }
1585 }
1586
Colin Cross5950f382016-12-13 12:50:57 -08001587 for _, lib := range deps.ReexportHeaderLibHeaders {
1588 if !inList(lib, deps.HeaderLibs) {
1589 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1590 }
1591 }
1592
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001593 for _, gen := range deps.ReexportGeneratedHeaders {
1594 if !inList(gen, deps.GeneratedHeaders) {
1595 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1596 }
1597 }
1598
Colin Crossc99deeb2016-04-11 15:06:20 -07001599 return deps
1600}
1601
Dan Albert7e9d2952016-08-04 13:02:36 -07001602func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001603 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001604 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001605 moduleContextImpl: moduleContextImpl{
1606 mod: c,
1607 },
1608 }
1609 ctx.ctx = ctx
1610
Colin Crossca860ac2016-01-04 14:34:37 -08001611 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001612}
1613
Jiyong Park7ed9de32018-10-15 22:25:07 +09001614// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001615func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001616 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1617 version := name[sharp+1:]
1618 libname := name[:sharp]
1619 return libname, version
1620 }
1621 return name, ""
1622}
1623
Colin Cross1e676be2016-10-12 14:38:15 -07001624func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001625 if !c.Enabled() {
1626 return
1627 }
1628
Colin Cross37047f12016-12-13 17:06:13 -08001629 ctx := &depsContext{
1630 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001631 moduleContextImpl: moduleContextImpl{
1632 mod: c,
1633 },
1634 }
1635 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001636
Colin Crossc99deeb2016-04-11 15:06:20 -07001637 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001638
Dan Albert914449f2016-06-17 16:45:24 -07001639 variantNdkLibs := []string{}
1640 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001641 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001642 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001643
Inseob Kimeec88e12020-01-22 11:11:29 +09001644 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001645 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001646 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001647 // 1. Name of an NDK library that refers to a prebuilt module.
1648 // For each of these, it adds the name of the prebuilt module (which will be in
1649 // prebuilts/ndk) to the list of nonvariant libs.
1650 // 2. Name of an NDK library that refers to an ndk_library module.
1651 // For each of these, it adds the name of the ndk_library module to the list of
1652 // variant libs.
1653 // 3. Anything else (so anything that isn't an NDK library).
1654 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001655 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001656 // The caller can then know to add the variantLibs dependencies differently from the
1657 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001658
Inseob Kim9516ee92019-05-09 10:56:13 +09001659 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001660 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1661
1662 rewriteVendorLibs := func(lib string) string {
1663 if isLlndkLibrary(lib, ctx.Config()) {
1664 return lib + llndkLibrarySuffix
1665 }
1666
1667 // only modules with BOARD_VNDK_VERSION uses snapshot.
1668 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1669 return lib
1670 }
1671
1672 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1673 return snapshot
1674 }
1675
1676 return lib
1677 }
1678
1679 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001680 variantLibs = []string{}
1681 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001682 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001683 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001684 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001685 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1686 if !inList(name, ndkMigratedLibs) {
1687 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001688 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001689 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001690 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001691 } else if ctx.useVndk() {
1692 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001693 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001694 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001695 if actx.OtherModuleExists(vendorPublicLib) {
1696 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1697 } else {
1698 // This can happen if vendor_public_library module is defined in a
1699 // namespace that isn't visible to the current module. In that case,
1700 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001701 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001702 }
Dan Albert914449f2016-06-17 16:45:24 -07001703 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001704 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001705 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001706 }
1707 }
Dan Albert914449f2016-06-17 16:45:24 -07001708 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001709 }
1710
Inseob Kimeec88e12020-01-22 11:11:29 +09001711 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1712 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1713 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1714 if ctx.useVndk() {
1715 for idx, lib := range deps.RuntimeLibs {
1716 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1717 }
1718 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001719 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001720
Jiyong Park7e636d02019-01-28 16:16:54 +09001721 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001722 if c.linker != nil {
1723 if library, ok := c.linker.(*libraryDecorator); ok {
1724 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001725 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001726 }
1727 }
1728 }
1729
Inseob Kimeec88e12020-01-22 11:11:29 +09001730 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1731 // only modules with BOARD_VNDK_VERSION uses snapshot.
1732 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1733 return lib
1734 }
1735
1736 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1737 return snapshot
1738 }
1739
1740 return lib
1741 }
1742
1743 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001744 for _, lib := range deps.HeaderLibs {
1745 depTag := headerDepTag
1746 if inList(lib, deps.ReexportHeaderLibHeaders) {
1747 depTag = headerExportDepTag
1748 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001749
1750 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1751
Jiyong Park7e636d02019-01-28 16:16:54 +09001752 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001753 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001754 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001755 } else {
1756 actx.AddVariationDependencies(nil, depTag, lib)
1757 }
1758 }
1759
1760 if buildStubs {
1761 // Stubs lib does not have dependency to other static/shared libraries.
1762 // Don't proceed.
1763 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001764 }
Colin Cross5950f382016-12-13 12:50:57 -08001765
Inseob Kimc0907f12019-02-08 21:00:45 +09001766 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001767 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001768
Jiyong Park5d1598f2019-02-25 22:14:17 +09001769 for _, lib := range deps.WholeStaticLibs {
1770 depTag := wholeStaticDepTag
1771 if impl, ok := syspropImplLibraries[lib]; ok {
1772 lib = impl
1773 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001774
1775 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1776
Jiyong Park5d1598f2019-02-25 22:14:17 +09001777 actx.AddVariationDependencies([]blueprint.Variation{
1778 {Mutator: "link", Variation: "static"},
1779 }, depTag, lib)
1780 }
1781
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001782 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001783 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001784 if inList(lib, deps.ReexportStaticLibHeaders) {
1785 depTag = staticExportDepTag
1786 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001787
1788 if impl, ok := syspropImplLibraries[lib]; ok {
1789 lib = impl
1790 }
1791
Inseob Kimeec88e12020-01-22 11:11:29 +09001792 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1793
Dan Willemsen59339a22018-07-22 21:18:45 -07001794 actx.AddVariationDependencies([]blueprint.Variation{
1795 {Mutator: "link", Variation: "static"},
1796 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001797 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001798
Inseob Kimeec88e12020-01-22 11:11:29 +09001799 for _, lib := range deps.LateStaticLibs {
1800 actx.AddVariationDependencies([]blueprint.Variation{
1801 {Mutator: "link", Variation: "static"},
1802 }, lateStaticDepTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
1803 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001804
Ivan Lozano183a3212019-10-18 14:18:45 -07001805 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001806 var variations []blueprint.Variation
1807 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Yifan Hong1b3348d2020-01-21 15:53:22 -08001808 versionVariantAvail := !ctx.useVndk() && !c.InRecovery() && !c.InRamdisk()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001809 if version != "" && versionVariantAvail {
1810 // Version is explicitly specified. i.e. libFoo#30
1811 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001812 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001813 }
1814 actx.AddVariationDependencies(variations, depTag, name)
1815
1816 // If the version is not specified, add dependency to the latest stubs library.
1817 // The stubs library will be used when the depending module is built for APEX and
1818 // the dependent module is not in the same APEX.
Jiyong Park73c54ee2019-10-22 20:31:18 +09001819 latestVersion := LatestStubsVersionFor(actx.Config(), name)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001820 if version == "" && latestVersion != "" && versionVariantAvail {
1821 actx.AddVariationDependencies([]blueprint.Variation{
1822 {Mutator: "link", Variation: "shared"},
1823 {Mutator: "version", Variation: latestVersion},
1824 }, depTag, name)
Ivan Lozano183a3212019-10-18 14:18:45 -07001825 // Note that depTag.ExplicitlyVersioned is false in this case.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001826 }
1827 }
1828
Jiyong Park7ed9de32018-10-15 22:25:07 +09001829 // shared lib names without the #version suffix
1830 var sharedLibNames []string
1831
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001832 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001833 depTag := SharedDepTag
Jiyong Parkd7536ba2020-01-16 17:14:23 +09001834 if c.static() {
1835 depTag = SharedFromStaticDepTag
1836 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001837 if inList(lib, deps.ReexportSharedLibHeaders) {
1838 depTag = sharedExportDepTag
1839 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001840
1841 if impl, ok := syspropImplLibraries[lib]; ok {
1842 lib = impl
1843 }
1844
Jiyong Park73c54ee2019-10-22 20:31:18 +09001845 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001846 sharedLibNames = append(sharedLibNames, name)
1847
Jiyong Park25fc6a92018-11-18 18:02:45 +09001848 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001849 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001850
Jiyong Park7ed9de32018-10-15 22:25:07 +09001851 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001852 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001853 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1854 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1855 // linking against both the stubs lib and the non-stubs lib at the same time.
1856 continue
1857 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001858 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001859 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001860
Dan Willemsen59339a22018-07-22 21:18:45 -07001861 actx.AddVariationDependencies([]blueprint.Variation{
1862 {Mutator: "link", Variation: "shared"},
1863 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001864
Colin Cross68861832016-07-08 10:41:41 -07001865 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001866
1867 for _, gen := range deps.GeneratedHeaders {
1868 depTag := genHeaderDepTag
1869 if inList(gen, deps.ReexportGeneratedHeaders) {
1870 depTag = genHeaderExportDepTag
1871 }
1872 actx.AddDependency(c, depTag, gen)
1873 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001874
Colin Cross42d48b72018-08-29 14:10:52 -07001875 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001876
1877 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001878 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001879 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001880 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001881 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001882 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001883 if deps.LinkerFlagsFile != "" {
1884 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1885 }
1886 if deps.DynamicLinker != "" {
1887 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001888 }
Dan Albert914449f2016-06-17 16:45:24 -07001889
1890 version := ctx.sdkVersion()
1891 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001892 {Mutator: "ndk_api", Variation: version},
1893 {Mutator: "link", Variation: "shared"},
1894 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001895 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001896 {Mutator: "ndk_api", Variation: version},
1897 {Mutator: "link", Variation: "shared"},
1898 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001899
1900 if vndkdep := c.vndkdep; vndkdep != nil {
1901 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08001902 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08001903 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07001904 {Mutator: "link", Variation: "shared"},
1905 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001906 }
1907 }
Colin Cross6362e272015-10-29 15:25:03 -07001908}
Colin Cross21b9a242015-03-24 14:15:58 -07001909
Colin Crosse40b4ea2018-10-02 22:25:58 -07001910func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001911 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1912 c.beginMutator(ctx)
1913 }
1914}
1915
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001916// Whether a module can link to another module, taking into
1917// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07001918func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
1919 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001920 // Host code is not restricted
1921 return
1922 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001923
1924 // VNDK is cc.Module supported only for now.
1925 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001926 // Though vendor code is limited by the vendor mutator,
1927 // each vendor-available module needs to check
1928 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07001929 if ccTo, ok := to.(*Module); ok {
1930 if ccFrom.vndkdep != nil {
1931 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
1932 }
1933 } else {
1934 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001935 }
1936 return
1937 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001938 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001939 // Platform code can link to anything
1940 return
1941 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08001942 if from.InRamdisk() {
1943 // Ramdisk code is not NDK
1944 return
1945 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001946 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09001947 // Recovery code is not NDK
1948 return
1949 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001950 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001951 // These are always allowed
1952 return
1953 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001954 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001955 // These are allowed, but they don't set sdk_version
1956 return
1957 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001958 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001959 // These aren't real libraries, but are the stub shared libraries that are included in
1960 // the NDK.
1961 return
1962 }
Logan Chien834b9a62019-01-14 15:39:03 +08001963
Ivan Lozano52767be2019-10-18 14:49:46 -07001964 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08001965 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1966 // to link to libc++ (non-NDK and without sdk_version).
1967 return
1968 }
1969
Ivan Lozano52767be2019-10-18 14:49:46 -07001970 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001971 // NDK code linking to platform code is never okay.
1972 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001973 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001974 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001975 }
1976
1977 // At this point we know we have two NDK libraries, but we need to
1978 // check that we're not linking against anything built against a higher
1979 // API level, as it is only valid to link against older or equivalent
1980 // APIs.
1981
Inseob Kim01a28722018-04-11 09:48:45 +09001982 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07001983 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001984 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07001985 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001986 // Current can't be linked against by anything else.
1987 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001988 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09001989 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07001990 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001991 if err != nil {
1992 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001993 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001994 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001995 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001996 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001997 if err != nil {
1998 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001999 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002000 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002001 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002002
Inseob Kim01a28722018-04-11 09:48:45 +09002003 if toApi > fromApi {
2004 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002005 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002006 }
2007 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002008 }
Dan Albert202fe492017-12-15 13:56:59 -08002009
2010 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002011 fromStl := from.SelectedStl()
2012 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002013 if fromStl == "" || toStl == "" {
2014 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002015 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002016 // We can be permissive with the system "STL" since it is only the C++
2017 // ABI layer, but in the future we should make sure that everyone is
2018 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002019 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002020 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002021 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2022 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002023 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002024}
2025
Jiyong Park5fb8c102018-04-09 12:03:06 +09002026// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002027// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2028// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002029// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002030func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2031 check := func(child, parent android.Module) bool {
2032 to, ok := child.(*Module)
2033 if !ok {
2034 // follow thru cc.Defaults, etc.
2035 return true
2036 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002037
Jooyung Hana70f0672019-01-18 15:20:43 +09002038 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2039 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002040 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002041
2042 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002043 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002044 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002045 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002046
Jooyung Han0302a842019-10-30 18:43:49 +09002047 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002048 return false
2049 }
2050
2051 var stringPath []string
2052 for _, m := range ctx.GetWalkPath() {
2053 stringPath = append(stringPath, m.Name())
2054 }
2055 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2056 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2057 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2058 return false
2059 }
2060 if module, ok := ctx.Module().(*Module); ok {
2061 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002062 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002063 ctx.WalkDeps(check)
2064 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002065 }
2066 }
2067}
2068
Colin Crossc99deeb2016-04-11 15:06:20 -07002069// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002070func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002071 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002072
Ivan Lozano183a3212019-10-18 14:18:45 -07002073 directStaticDeps := []LinkableInterface{}
2074 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002075
Inseob Kim9516ee92019-05-09 10:56:13 +09002076 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2077
Inseob Kim69378442019-06-03 19:10:47 +09002078 reexportExporter := func(exporter exportedFlagsProducer) {
2079 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2080 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2081 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2082 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002083 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002084 }
2085
Colin Crossd11fcda2017-10-23 17:59:01 -07002086 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002087 depName := ctx.OtherModuleName(dep)
2088 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002089
Ivan Lozano52767be2019-10-18 14:49:46 -07002090 ccDep, ok := dep.(LinkableInterface)
2091 if !ok {
2092
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002093 // handling for a few module types that aren't cc Module but that are also supported
2094 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002095 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002096 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002097 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2098 genRule.GeneratedSourceFiles()...)
2099 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002100 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002101 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002102 // Support exported headers from a generated_sources dependency
2103 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002104 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002105 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002106 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Inseob Kimd110f872019-12-06 13:15:38 +09002107 genRule.GeneratedSourceFiles()...)
2108 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002109 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002110 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002111 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002112 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002113 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002114 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2115 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002116 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002117 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
Jiyong Park74955042019-10-22 20:19:51 +09002118 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002119
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002120 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002121 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002122 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002123 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002124 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002125 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002126 files := genRule.GeneratedSourceFiles()
2127 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002128 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002129 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002130 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 -07002131 }
2132 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002133 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002134 }
Colin Crossca860ac2016-01-04 14:34:37 -08002135 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002136 return
2137 }
2138
Colin Crossfe17f6f2019-03-28 19:30:56 -07002139 if depTag == android.ProtoPluginDepTag {
2140 return
2141 }
2142
Colin Crossd11fcda2017-10-23 17:59:01 -07002143 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002144 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2145 return
2146 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002147 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002148 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002149 return
2150 }
2151
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002152 // re-exporting flags
2153 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002154 // reusing objects only make sense for cc.Modules.
2155 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002156 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002157 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002158 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002159 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002160 return
2161 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002162 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002163
Jiyong Parke4bb9862019-02-01 00:31:10 +09002164 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002165 // staticVariants are a cc.Module specific concept.
2166 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002167 c.staticVariant = ccDep
2168 return
2169 }
2170 }
2171
Ivan Lozano183a3212019-10-18 14:18:45 -07002172 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
2173 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
2174 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002175 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07002176 if t, ok := depTag.(DependencyTag); ok {
2177 explicitlyVersioned = t.ExplicitlyVersioned
2178 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002179 depTag = t
2180 }
2181
Ivan Lozano183a3212019-10-18 14:18:45 -07002182 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002183 depIsStatic := false
2184 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002185 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002186 depIsStatic = true
2187 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002188 if ccDep.CcLibrary() && !depIsStatic {
2189 depIsStubs := ccDep.BuildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09002190 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002191 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002192 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002193
2194 var useThisDep bool
2195 if depIsStubs && explicitlyVersioned {
2196 // Always respect dependency to the versioned stubs (i.e. libX#10)
2197 useThisDep = true
2198 } else if !depHasStubs {
2199 // Use non-stub variant if that is the only choice
2200 // (i.e. depending on a lib without stubs.version property)
2201 useThisDep = true
2202 } else if c.IsForPlatform() {
2203 // If not building for APEX, use stubs only when it is from
2204 // an APEX (and not from platform)
2205 useThisDep = (depInPlatform != depIsStubs)
Yifan Hong1b3348d2020-01-21 15:53:22 -08002206 if c.InRamdisk() || c.InRecovery() || c.bootstrap() {
2207 // However, for ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002208 // always link to non-stub variant
2209 useThisDep = !depIsStubs
2210 }
2211 } else {
2212 // If building for APEX, use stubs only when it is not from
2213 // the same APEX
2214 useThisDep = (depInSameApex != depIsStubs)
2215 }
2216
2217 if !useThisDep {
2218 return // stop processing this dep
2219 }
2220 }
2221
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002222 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2223
Ivan Lozano52767be2019-10-18 14:49:46 -07002224 // Exporting flags only makes sense for cc.Modules
2225 if _, ok := ccDep.(*Module); ok {
2226 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002227 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002228 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedGeneratedHeaders()...)
2229 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002230 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002231
Ivan Lozano52767be2019-10-18 14:49:46 -07002232 if t.ReexportFlags {
2233 reexportExporter(i)
2234 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2235 // Re-exported shared library headers must be included as well since they can help us with type information
2236 // about template instantiations (instantiated from their headers).
2237 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2238 // scripts.
2239 c.sabi.Properties.ReexportedIncludes = append(
2240 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2241 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002242 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002243 }
Logan Chienf3511742017-10-31 18:04:35 +08002244 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002245 }
2246
Colin Cross26c34ed2016-09-30 17:10:16 -07002247 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002248 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002249
Ivan Lozano52767be2019-10-18 14:49:46 -07002250 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002251 depFile := android.OptionalPath{}
2252
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002253 switch depTag {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002254 case ndkStubDepTag, SharedDepTag, SharedFromStaticDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002255 ptr = &depPaths.SharedLibs
2256 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002257 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002258 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002259
Jiyong Park64a44f22019-01-18 14:37:08 +09002260 case earlySharedDepTag:
2261 ptr = &depPaths.EarlySharedLibs
2262 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002263 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002264 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002265 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002266 ptr = &depPaths.LateSharedLibs
2267 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002268 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002269 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002270 ptr = nil
2271 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002272 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002273 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002274 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002275 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002276 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002277 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002278 return
2279 }
2280
Ivan Lozano52767be2019-10-18 14:49:46 -07002281 // Because the static library objects are included, this only makes sense
2282 // in the context of proper cc.Modules.
2283 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2284 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2285 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2286 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2287 for i := range missingDeps {
2288 missingDeps[i] += postfix
2289 }
2290 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002291 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002292 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2293 } else {
2294 ctx.ModuleErrorf(
2295 "non-cc.Modules cannot be included as whole static libraries.", depName)
2296 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002297 }
Colin Cross5950f382016-12-13 12:50:57 -08002298 case headerDepTag:
2299 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002300 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002301 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002302 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002303 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002304 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002305 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002306 case dynamicLinkerDepTag:
2307 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002308 }
2309
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002310 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002311 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002312 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002313 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002314 return
2315 }
2316
2317 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002318 // in static libraries act as if they were whole static libraries. The same goes for
2319 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002320 // This should only be done for cc.Modules
2321 if c, ok := ccDep.(*Module); ok {
2322 staticLib := c.linker.(libraryInterface)
2323 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2324 staticLib.objs().coverageFiles...)
2325 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2326 staticLib.objs().sAbiDumpFiles...)
2327 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002328 }
2329
Colin Cross26c34ed2016-09-30 17:10:16 -07002330 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002331 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002332 if !ctx.Config().AllowMissingDependencies() {
2333 ctx.ModuleErrorf("module %q missing output file", depName)
2334 } else {
2335 ctx.AddMissingDependencies([]string{depName})
2336 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002337 return
2338 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002339 *ptr = append(*ptr, linkFile.Path())
2340 }
2341
Colin Crossc99deeb2016-04-11 15:06:20 -07002342 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002343 dep := depFile
2344 if !dep.Valid() {
2345 dep = linkFile
2346 }
2347 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002348 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002349
Inseob Kimeec88e12020-01-22 11:11:29 +09002350 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2351
2352 baseLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002353 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002354 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002355 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kimeec88e12020-01-22 11:11:29 +09002356 return libName
2357 }
2358
2359 makeLibName := func(depName string) string {
2360 libName := baseLibName(depName)
Jooyung Han0302a842019-10-30 18:43:49 +09002361 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002362 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002363 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002364
Inseob Kimeec88e12020-01-22 11:11:29 +09002365 if c, ok := ccDep.(*Module); ok {
2366 // Use base module name for snapshots when exporting to Makefile.
2367 if c.isSnapshotPrebuilt() && !c.IsVndk() {
2368 baseName := c.BaseModuleName()
2369 if vendorSuffixModules[baseName] {
2370 return baseName + ".vendor"
2371 } else {
2372 return baseName
2373 }
2374 }
2375 }
2376
Yifan Hong1b3348d2020-01-21 15:53:22 -08002377 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002378 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2379 // core module instead.
2380 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002381 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002382 // The vendor module in Make will have been renamed to not conflict with the core
2383 // module, so update the dependency name here accordingly.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002384 return libName + c.getNameSuffixWithVndkVersion(ctx)
Jiyong Park374510b2018-03-19 18:23:01 +09002385 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002386 return libName + vendorPublicLibrarySuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08002387 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2388 return libName + ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002389 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002390 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002391 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002392 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002393 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002394 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002395 }
Logan Chien43d34c32017-12-20 01:17:32 +08002396 }
2397
2398 // Export the shared libs to Make.
2399 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002400 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002401 if ccDep.CcLibrary() {
2402 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002403 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002404 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002405 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002406 c.Properties.ApexesProvidingSharedLibs = append(
2407 c.Properties.ApexesProvidingSharedLibs, an)
2408 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002409 }
2410 }
2411
Jiyong Park27b188b2017-07-18 13:23:39 +09002412 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002413 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002414 c.Properties.AndroidMkSharedLibs = append(
2415 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002416 // Record baseLibName for snapshots.
2417 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002418 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002419 c.Properties.AndroidMkSharedLibs = append(
2420 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002421 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002422 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002423 c.Properties.AndroidMkStaticLibs = append(
2424 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002425 case runtimeDepTag:
2426 c.Properties.AndroidMkRuntimeLibs = append(
2427 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002428 // Record baseLibName for snapshots.
2429 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002430 case wholeStaticDepTag:
2431 c.Properties.AndroidMkWholeStaticLibs = append(
2432 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002433 }
Colin Crossca860ac2016-01-04 14:34:37 -08002434 })
2435
Jeff Gaston294356f2017-09-27 17:05:30 -07002436 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002437 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002438
Colin Crossdd84e052017-05-17 13:44:16 -07002439 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002440 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002441 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2442 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002443 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kimd110f872019-12-06 13:15:38 +09002444 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002445 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2446 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002447 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002448 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002449 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002450
2451 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002452 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002453 }
Colin Crossdd84e052017-05-17 13:44:16 -07002454
Colin Crossca860ac2016-01-04 14:34:37 -08002455 return depPaths
2456}
2457
2458func (c *Module) InstallInData() bool {
2459 if c.installer == nil {
2460 return false
2461 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002462 return c.installer.inData()
2463}
2464
2465func (c *Module) InstallInSanitizerDir() bool {
2466 if c.installer == nil {
2467 return false
2468 }
2469 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002470 return true
2471 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002472 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002473}
2474
Yifan Hong1b3348d2020-01-21 15:53:22 -08002475func (c *Module) InstallInRamdisk() bool {
2476 return c.InRamdisk()
2477}
2478
Jiyong Parkf9332f12018-02-01 00:54:12 +09002479func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002480 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002481}
2482
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002483func (c *Module) HostToolPath() android.OptionalPath {
2484 if c.installer == nil {
2485 return android.OptionalPath{}
2486 }
2487 return c.installer.hostToolPath()
2488}
2489
Nan Zhangd4e641b2017-07-12 12:55:28 -07002490func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2491 return c.outputFile
2492}
2493
Colin Cross41955e82019-05-29 14:40:35 -07002494func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2495 switch tag {
2496 case "":
2497 if c.outputFile.Valid() {
2498 return android.Paths{c.outputFile.Path()}, nil
2499 }
2500 return android.Paths{}, nil
2501 default:
2502 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002503 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002504}
2505
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002506func (c *Module) static() bool {
2507 if static, ok := c.linker.(interface {
2508 static() bool
2509 }); ok {
2510 return static.static()
2511 }
2512 return false
2513}
2514
Jiyong Park379de2f2018-12-19 02:47:14 +09002515func (c *Module) staticBinary() bool {
2516 if static, ok := c.linker.(interface {
2517 staticBinary() bool
2518 }); ok {
2519 return static.staticBinary()
2520 }
2521 return false
2522}
2523
Jiyong Park1d1119f2019-07-29 21:27:18 +09002524func (c *Module) header() bool {
2525 if h, ok := c.linker.(interface {
2526 header() bool
2527 }); ok {
2528 return h.header()
2529 }
2530 return false
2531}
2532
Jooyung Han38002912019-05-16 04:01:54 +09002533func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002534 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002535 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2536 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002537 return "native:vndk"
2538 }
Jooyung Han38002912019-05-16 04:01:54 +09002539 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002540 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002541 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002542 if Bool(c.VendorProperties.Vendor_available) {
2543 return "native:vndk"
2544 }
2545 return "native:vndk_private"
2546 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002547 if c.inProduct() {
2548 return "native:product"
2549 }
Jooyung Han38002912019-05-16 04:01:54 +09002550 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002551 } else if c.InRamdisk() {
2552 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002553 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002554 return "native:recovery"
2555 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2556 return "native:ndk:none:none"
2557 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2558 //family, link := getNdkStlFamilyAndLinkType(c)
2559 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002560 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002561 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002562 } else {
2563 return "native:platform"
2564 }
2565}
2566
Jiyong Park9d452992018-10-03 00:38:19 +09002567// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002568// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002569func (c *Module) IsInstallableToApex() bool {
2570 if shared, ok := c.linker.(interface {
2571 shared() bool
2572 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002573 // Stub libs and prebuilt libs in a versioned SDK are not
2574 // installable to APEX even though they are shared libs.
2575 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002576 } else if _, ok := c.linker.(testPerSrc); ok {
2577 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002578 }
2579 return false
2580}
2581
Jiyong Parka90ca002019-10-07 15:47:24 +09002582func (c *Module) AvailableFor(what string) bool {
2583 if linker, ok := c.linker.(interface {
2584 availableFor(string) bool
2585 }); ok {
2586 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2587 } else {
2588 return c.ApexModuleBase.AvailableFor(what)
2589 }
2590}
2591
Inseob Kim1f086e22019-05-09 13:29:15 +09002592func (c *Module) installable() bool {
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002593 ret := c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid()
2594
2595 // The platform variant doesn't need further condition. Apex variants however might not
2596 // be installable because it will likely to be included in the APEX and won't appear
2597 // in the system partition.
2598 if c.IsForPlatform() {
2599 return ret
2600 }
2601
2602 // Special case for modules that are configured to be installed to /data, which includes
2603 // test modules. For these modules, both APEX and non-APEX variants are considered as
2604 // installable. This is because even the APEX variants won't be included in the APEX, but
2605 // will anyway be installed to /data/*.
2606 // See b/146995717
2607 if c.InstallInData() {
2608 return ret
2609 }
2610
2611 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002612}
2613
Logan Chien41eabe62019-04-10 13:33:58 +08002614func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2615 if c.linker != nil {
2616 if library, ok := c.linker.(*libraryDecorator); ok {
2617 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2618 }
2619 }
2620}
2621
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002622func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002623 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002624 if cc, ok := dep.(*Module); ok {
2625 if cc.HasStubsVariants() && depTag.Shared && depTag.Library {
2626 // dynamic dep to a stubs lib crosses APEX boundary
2627 return false
2628 }
2629 if depTag.FromStatic {
2630 // shared_lib dependency from a static lib is considered as crossing
2631 // the APEX boundary because the dependency doesn't actually is
2632 // linked; the dependency is used only during the compilation phase.
2633 return false
2634 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002635 }
2636 }
2637 return true
2638}
2639
Colin Cross2ba19d92015-05-07 15:44:20 -07002640//
Colin Crosscfad1192015-11-02 16:43:11 -08002641// Defaults
2642//
Colin Crossca860ac2016-01-04 14:34:37 -08002643type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002644 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002645 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002646 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002647}
2648
Patrice Arrudac249c712019-03-19 17:00:29 -07002649// cc_defaults provides a set of properties that can be inherited by other cc
2650// modules. A module can use the properties from a cc_defaults using
2651// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2652// merged (when possible) by prepending the default module's values to the
2653// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002654func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002655 return DefaultsFactory()
2656}
2657
Colin Cross36242852017-06-23 15:06:31 -07002658func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002659 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002660
Colin Cross36242852017-06-23 15:06:31 -07002661 module.AddProperties(props...)
2662 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002663 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002664 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002665 &BaseCompilerProperties{},
2666 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002667 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002668 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002669 &StaticProperties{},
2670 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002671 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002672 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002673 &TestProperties{},
2674 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002675 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002676 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002677 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002678 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002679 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002680 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002681 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002682 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002683 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002684 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002685 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002686 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002687 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002688 )
Colin Crosscfad1192015-11-02 16:43:11 -08002689
Jooyung Hancc372c52019-09-25 15:18:44 +09002690 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002691
2692 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002693}
2694
Jiyong Park6a43f042017-10-12 23:05:00 +09002695func squashVendorSrcs(m *Module) {
2696 if lib, ok := m.compiler.(*libraryDecorator); ok {
2697 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2698 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2699
2700 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2701 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2702 }
2703}
2704
Jiyong Parkf9332f12018-02-01 00:54:12 +09002705func squashRecoverySrcs(m *Module) {
2706 if lib, ok := m.compiler.(*libraryDecorator); ok {
2707 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2708 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2709
2710 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2711 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2712 }
2713}
2714
Colin Cross7228ecd2019-11-18 16:00:16 -08002715var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002716
Colin Cross7228ecd2019-11-18 16:00:16 -08002717func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002718 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002719 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002720 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002721
2722 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002723 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002724 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002725 }
Logan Chienf3511742017-10-31 18:04:35 +08002726
2727 if vndkdep := m.vndkdep; vndkdep != nil {
2728 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002729 if productSpecific {
2730 mctx.PropertyErrorf("product_specific",
2731 "product_specific must not be true when `vndk: {enabled: true}`")
Justin Yun9357f4a2018-11-28 15:14:47 +09002732 }
Logan Chienf3511742017-10-31 18:04:35 +08002733 if vendorSpecific {
2734 if !vndkdep.isVndkExt() {
2735 mctx.PropertyErrorf("vndk",
2736 "must set `extends: \"...\"` to vndk extension")
Logan Chienf3511742017-10-31 18:04:35 +08002737 }
2738 } else {
2739 if vndkdep.isVndkExt() {
2740 mctx.PropertyErrorf("vndk",
2741 "must set `vendor: true` to set `extends: %q`",
2742 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002743 }
2744 if m.VendorProperties.Vendor_available == nil {
2745 mctx.PropertyErrorf("vndk",
2746 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08002747 }
2748 }
2749 } else {
2750 if vndkdep.isVndkSp() {
2751 mctx.PropertyErrorf("vndk",
2752 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08002753 }
2754 if vndkdep.isVndkExt() {
2755 mctx.PropertyErrorf("vndk",
2756 "must set `enabled: true` to set `extends: %q`",
2757 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002758 }
Justin Yun8effde42017-06-23 19:24:43 +09002759 }
2760 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002761
Jiyong Parkf9332f12018-02-01 00:54:12 +09002762 var coreVariantNeeded bool = false
Yifan Hong1b3348d2020-01-21 15:53:22 -08002763 var ramdiskVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002764 var recoveryVariantNeeded bool = false
2765
Inseob Kim64c43952019-08-26 16:52:35 +09002766 var vendorVariants []string
Justin Yun5f7f7e82019-11-18 19:52:14 +09002767 var productVariants []string
Inseob Kim64c43952019-08-26 16:52:35 +09002768
2769 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09002770 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
2771 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
2772 if boardVndkVersion == "current" {
2773 boardVndkVersion = platformVndkVersion
2774 }
2775 if productVndkVersion == "current" {
2776 productVndkVersion = platformVndkVersion
Inseob Kim64c43952019-08-26 16:52:35 +09002777 }
2778
Justin Yun5f7f7e82019-11-18 19:52:14 +09002779 if boardVndkVersion == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002780 // If the device isn't compiling against the VNDK, we always
2781 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002782 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002783 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002784 // LL-NDK stubs only exist in the vendor and product variants,
2785 // since the real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002786 vendorVariants = append(vendorVariants,
2787 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002788 boardVndkVersion,
2789 )
2790 productVariants = append(productVariants,
2791 platformVndkVersion,
2792 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002793 )
Jiyong Park2a454122017-10-19 15:59:33 +09002794 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2795 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002796 vendorVariants = append(vendorVariants,
2797 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002798 boardVndkVersion,
2799 )
2800 productVariants = append(productVariants,
2801 platformVndkVersion,
2802 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002803 )
Inseob Kimeec88e12020-01-22 11:11:29 +09002804 } else if m.isSnapshotPrebuilt() {
Justin Yun71549282017-11-17 12:10:28 +09002805 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2806 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kimeec88e12020-01-22 11:11:29 +09002807 if snapshot, ok := m.linker.(interface {
2808 version() string
2809 }); ok {
2810 vendorVariants = append(vendorVariants, snapshot.version())
2811 } else {
2812 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
2813 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002814 } else if m.HasVendorVariant() && !vendorSpecific {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002815 // This will be available in /system, /vendor and /product
2816 // or a /system directory that is available to vendor and product.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002817 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002818 vendorVariants = append(vendorVariants, platformVndkVersion)
Justin Yun5f7f7e82019-11-18 19:52:14 +09002819 productVariants = append(productVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09002820 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
2821 // code is PLATFORM_VNDK_VERSION.
2822 // On the other hand, vendor_available modules which are not VNDK should
2823 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002824 // vendor_available modules are also available to /product.
Inseob Kimbc093672019-11-01 11:29:44 +09002825 if !m.IsVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002826 vendorVariants = append(vendorVariants, boardVndkVersion)
2827 productVariants = append(productVariants, productVndkVersion)
Inseob Kim64c43952019-08-26 16:52:35 +09002828 }
Logan Chienf3511742017-10-31 18:04:35 +08002829 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002830 // This will be available in /vendor (or /odm) only
Justin Yun5f7f7e82019-11-18 19:52:14 +09002831 vendorVariants = append(vendorVariants, boardVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002832 } else {
2833 // This is either in /system (or similar: /data), or is a
2834 // modules built with the NDK. Modules built with the NDK
2835 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002836 coreVariantNeeded = true
2837 }
2838
Justin Yun5f7f7e82019-11-18 19:52:14 +09002839 if boardVndkVersion != "" && productVndkVersion != "" {
2840 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
2841 // The module has "product_specific: true" that does not create core variant.
2842 coreVariantNeeded = false
2843 productVariants = append(productVariants, productVndkVersion)
2844 }
2845 } else {
2846 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
2847 // restriction to use system libs.
2848 // No product variants defined in this case.
2849 productVariants = []string{}
2850 }
2851
Yifan Hong1b3348d2020-01-21 15:53:22 -08002852 if Bool(m.Properties.Ramdisk_available) {
2853 ramdiskVariantNeeded = true
2854 }
2855
2856 if m.ModuleBase.InstallInRamdisk() {
2857 ramdiskVariantNeeded = true
2858 coreVariantNeeded = false
2859 }
2860
Jiyong Parkf9332f12018-02-01 00:54:12 +09002861 if Bool(m.Properties.Recovery_available) {
2862 recoveryVariantNeeded = true
2863 }
2864
2865 if m.ModuleBase.InstallInRecovery() {
2866 recoveryVariantNeeded = true
2867 coreVariantNeeded = false
2868 }
2869
Inseob Kim64c43952019-08-26 16:52:35 +09002870 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002871 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
2872 }
2873
2874 for _, variant := range android.FirstUniqueStrings(productVariants) {
2875 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09002876 }
Colin Cross7228ecd2019-11-18 16:00:16 -08002877
Yifan Hong1b3348d2020-01-21 15:53:22 -08002878 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Colin Cross7228ecd2019-11-18 16:00:16 -08002879 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
2880 m.Properties.CoreVariantNeeded = coreVariantNeeded
2881}
2882
2883func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
2884 return c.Properties.CoreVariantNeeded
2885}
2886
Yifan Hong1b3348d2020-01-21 15:53:22 -08002887func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
2888 return c.Properties.RamdiskVariantNeeded
2889}
2890
Colin Cross7228ecd2019-11-18 16:00:16 -08002891func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
2892 return c.Properties.RecoveryVariantNeeded
2893}
2894
2895func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002896 return c.Properties.ExtraVariants
Colin Cross7228ecd2019-11-18 16:00:16 -08002897}
2898
2899func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
2900 m := module.(*Module)
Yifan Hong1b3348d2020-01-21 15:53:22 -08002901 if variant == android.RamdiskVariation {
2902 m.MakeAsPlatform()
2903 } else if variant == android.RecoveryVariation {
Colin Cross7228ecd2019-11-18 16:00:16 -08002904 m.MakeAsPlatform()
2905 squashRecoverySrcs(m)
2906 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002907 m.Properties.ImageVariationPrefix = VendorVariationPrefix
Colin Cross7228ecd2019-11-18 16:00:16 -08002908 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
2909 squashVendorSrcs(m)
Inseob Kimeec88e12020-01-22 11:11:29 +09002910
2911 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
2912 // Hide other vendor variants to avoid collision.
2913 vndkVersion := ctx.DeviceConfig().VndkVersion()
2914 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
2915 m.Properties.HideFromMake = true
2916 m.SkipInstall()
2917 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002918 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
2919 m.Properties.ImageVariationPrefix = ProductVariationPrefix
2920 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
2921 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002922 }
2923}
2924
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002925func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002926 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002927 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2928 }
Colin Cross6510f912017-11-29 00:27:14 -08002929 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002930}
2931
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002932func kytheExtractAllFactory() android.Singleton {
2933 return &kytheExtractAllSingleton{}
2934}
2935
2936type kytheExtractAllSingleton struct {
2937}
2938
2939func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2940 var xrefTargets android.Paths
2941 ctx.VisitAllModules(func(module android.Module) {
2942 if ccModule, ok := module.(xref); ok {
2943 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
2944 }
2945 })
2946 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
2947 if len(xrefTargets) > 0 {
2948 ctx.Build(pctx, android.BuildParams{
2949 Rule: blueprint.Phony,
2950 Output: android.PathForPhony(ctx, "xref_cxx"),
2951 Inputs: xrefTargets,
2952 //Default: true,
2953 })
2954 }
2955}
2956
Colin Cross06a931b2015-10-28 17:23:31 -07002957var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002958var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002959var BoolPtr = proptools.BoolPtr
2960var String = proptools.String
2961var StringPtr = proptools.StringPtr