blob: 930c19c8e840a201bf131433713ee0667537e253 [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
Peter Collingbournedc4f9862020-02-12 17:13:25 -080098 StaticUnwinderIfLegacy bool
99
Colin Cross5950f382016-12-13 12:50:57 -0800100 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700101
Colin Cross81413472016-04-11 14:37:39 -0700102 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700103
Dan Willemsenb40aab62016-04-20 14:21:14 -0700104 GeneratedSources []string
105 GeneratedHeaders []string
Inseob Kimd110f872019-12-06 13:15:38 +0900106 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700107
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700108 ReexportGeneratedHeaders []string
109
Colin Cross97ba0732015-03-23 17:50:24 -0700110 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700111
112 // Used for host bionic
113 LinkerFlagsFile string
114 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700115}
116
Colin Crossca860ac2016-01-04 14:34:37 -0800117type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700118 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900119 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700120 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900121 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700122 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700123 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700124
Colin Cross26c34ed2016-09-30 17:10:16 -0700125 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700126 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800127 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700128 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700129
Colin Cross26c34ed2016-09-30 17:10:16 -0700130 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700131 GeneratedSources android.Paths
132 GeneratedHeaders android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900133 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700134
Inseob Kimd110f872019-12-06 13:15:38 +0900135 Flags []string
136 IncludeDirs android.Paths
137 SystemIncludeDirs android.Paths
138 ReexportedDirs android.Paths
139 ReexportedSystemDirs android.Paths
140 ReexportedFlags []string
141 ReexportedGeneratedHeaders android.Paths
142 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700143
Colin Cross26c34ed2016-09-30 17:10:16 -0700144 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700145 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700146
147 // Path to the file container flags to use with the linker
148 LinkerFlagsFile android.OptionalPath
149
150 // Path to the dynamic linker binary
151 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700152}
153
Colin Cross4af21ed2019-11-04 09:37:55 -0800154// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
155// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
156// command line so they can be overridden by the local module flags).
157type LocalOrGlobalFlags struct {
158 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700159 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800160 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700161 CFlags []string // Flags that apply to C and C++ source files
162 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
163 ConlyFlags []string // Flags that apply to C source files
164 CppFlags []string // Flags that apply to C++ source files
165 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700166 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800167}
168
169type Flags struct {
170 Local LocalOrGlobalFlags
171 Global LocalOrGlobalFlags
172
173 aidlFlags []string // Flags that apply to aidl source files
174 rsFlags []string // Flags that apply to renderscript source files
175 libFlags []string // Flags to add libraries early to the link order
176 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
177 TidyFlags []string // Flags that apply to clang-tidy
178 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700179
Colin Crossc3199482017-03-30 15:03:04 -0700180 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800181 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700182 SystemIncludeFlags []string
183
Colin Crossb98c8b02016-07-29 13:44:28 -0700184 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700185 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800186 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800187 SAbiDump bool
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800188 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800189
190 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800191 DynamicLinker string
192
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700193 CFlagsDeps android.Paths // Files depended on by compiler flags
194 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800195
Dan Willemsen98ab3112019-08-27 21:20:40 -0700196 AssemblerWithCpp bool
197 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800198
Colin Cross19878da2019-03-28 14:45:07 -0700199 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700200 protoC bool // Whether to use C instead of C++
201 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700202
203 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700204}
205
Colin Crossca860ac2016-01-04 14:34:37 -0800206// Properties used to compile all C or C++ modules
207type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700208 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800209 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700210
211 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800212 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700213
Jiyong Parkde866cb2018-12-07 23:08:36 +0900214 AndroidMkSharedLibs []string `blueprint:"mutated"`
215 AndroidMkStaticLibs []string `blueprint:"mutated"`
216 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
217 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
218 HideFromMake bool `blueprint:"mutated"`
219 PreventInstall bool `blueprint:"mutated"`
220 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700221
Justin Yun5f7f7e82019-11-18 19:52:14 +0900222 ImageVariationPrefix string `blueprint:"mutated"`
223 VndkVersion string `blueprint:"mutated"`
224 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800225
226 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
227 // file
228 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900229
Yifan Hong1b3348d2020-01-21 15:53:22 -0800230 // Make this module available when building for ramdisk
231 Ramdisk_available *bool
232
Jiyong Parkf9332f12018-02-01 00:54:12 +0900233 // Make this module available when building for recovery
234 Recovery_available *bool
235
Colin Crossae6c5202019-11-20 13:35:50 -0800236 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800237 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800238 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800239 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900240 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900241
242 // Allows this module to use non-APEX version of libraries. Useful
243 // for building binaries that are started before APEXes are activated.
244 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900245
246 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
247 // see soong/cc/config/vndk.go
248 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900249
250 // Used by vendor snapshot to record dependencies from snapshot modules.
251 SnapshotSharedLibs []string `blueprint:"mutated"`
252 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700253}
254
255type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900256 // whether this module should be allowed to be directly depended by other
257 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900258 // In addition, this module should be allowed to be directly depended by
259 // product modules with `product_specific: true`.
260 // If set to true, three variants will be built separately, one like
261 // normal, another limited to the set of libraries and headers
262 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700263 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900264 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700265 // so it shouldn't have any unversioned runtime dependencies, or
266 // make assumptions about the system that may not be true in the
267 // future.
268 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900269 // If set to false, this module becomes inaccessible from /vendor or /product
270 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900271 //
272 // Default value is true when vndk: {enabled: true} or vendor: true.
273 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700274 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900275 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700276 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900277
278 // whether this module is capable of being loaded with other instance
279 // (possibly an older version) of the same module in the same process.
280 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
281 // can be double loaded in a vendor process if the library is also a
282 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
283 // explicitly marked as `double_loadable: true` by the owner, or the dependency
284 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
285 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800286}
287
Colin Crossca860ac2016-01-04 14:34:37 -0800288type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800289 static() bool
290 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900291 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700292 toolchain() config.Toolchain
Jooyung Han61c41542020-03-07 03:45:53 +0900293 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700294 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800295 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700296 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800297 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900298 isLlndk(config android.Config) bool
299 isLlndkPublic(config android.Config) bool
300 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900301 isVndk() bool
302 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800303 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900304 inProduct() bool
305 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800306 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900307 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800308 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700309 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700310 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800311 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800312 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800313 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800314 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800315 isForPlatform() bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900316 apexName() string
Jooyung Han61c41542020-03-07 03:45:53 +0900317 apexSdkVersion() int
Jiyong Parkb0788572018-12-20 22:10:17 +0900318 hasStubsVariants() bool
319 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900320 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800321 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700322 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800323}
324
325type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700326 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800327 ModuleContextIntf
328}
329
330type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700331 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800332 ModuleContextIntf
333}
334
Colin Cross37047f12016-12-13 17:06:13 -0800335type DepsContext interface {
336 android.BottomUpMutatorContext
337 ModuleContextIntf
338}
339
Colin Crossca860ac2016-01-04 14:34:37 -0800340type feature interface {
341 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800342 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800343 flags(ctx ModuleContext, flags Flags) Flags
344 props() []interface{}
345}
346
347type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700348 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800349 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800350 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700351 compilerProps() []interface{}
352
Colin Cross76fada02016-07-27 10:31:13 -0700353 appendCflags([]string)
354 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700355 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800356}
357
358type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700359 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800360 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700361 linkerFlags(ctx ModuleContext, flags Flags) Flags
362 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800363 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700364
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700365 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700366 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900367 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700368
369 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900370 coverageOutputFilePath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800371}
372
373type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700374 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700375 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800376 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700377 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700378 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900379 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800380}
381
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800382type xref interface {
383 XrefCcFiles() android.Paths
384}
385
Colin Crossc99deeb2016-04-11 15:06:20 -0700386var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700387 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
388 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
389 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
390 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
391 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800392 staticUnwinderDepTag = DependencyTag{Name: "static unwinder", Library: true}
Ivan Lozano183a3212019-10-18 14:18:45 -0700393 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
394 headerDepTag = DependencyTag{Name: "header", Library: true}
395 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
396 genSourceDepTag = DependencyTag{Name: "gen source"}
397 genHeaderDepTag = DependencyTag{Name: "gen header"}
398 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
399 objDepTag = DependencyTag{Name: "obj"}
400 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
401 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
402 reuseObjTag = DependencyTag{Name: "reuse objects"}
403 staticVariantTag = DependencyTag{Name: "static variant"}
404 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
405 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
406 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
407 runtimeDepTag = DependencyTag{Name: "runtime lib"}
408 coverageDepTag = DependencyTag{Name: "coverage"}
409 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700410)
411
Roland Levillainf89cd092019-07-29 16:22:59 +0100412func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700413 ccDepTag, ok := depTag.(DependencyTag)
414 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100415}
416
417func IsRuntimeDepTag(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 == runtimeDepTag
420}
421
422func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700423 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100424 return ok && ccDepTag == testPerSrcDepTag
425}
426
Colin Crossca860ac2016-01-04 14:34:37 -0800427// Module contains the properties and members used by all C/C++ module types, and implements
428// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
429// to construct the output file. Behavior can be customized with a Customizer interface
430type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700431 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700432 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900433 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900434 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700435
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700436 Properties BaseProperties
437 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700438
Colin Crossca860ac2016-01-04 14:34:37 -0800439 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700440 hod android.HostOrDeviceSupported
441 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700442
Paul Duffina0843f62019-12-13 19:50:38 +0000443 // Allowable SdkMemberTypes of this module type.
444 sdkMemberTypes []android.SdkMemberType
445
Colin Crossca860ac2016-01-04 14:34:37 -0800446 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700447 features []feature
448 compiler compiler
449 linker linker
450 installer installer
451 stl *stl
452 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800453 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800454 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900455 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700456 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700457 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800458
Colin Cross635c3b02016-05-18 15:37:25 -0700459 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800460
Colin Crossb98c8b02016-07-29 13:44:28 -0700461 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700462
463 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800464
465 // Flags used to compile this module
466 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700467
468 // 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 -0800469 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700470 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800471 depsInLinkOrder android.Paths
472
473 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700474 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900475
476 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800477 // Kythe (source file indexer) paths for this compilation module
478 kytheFiles android.Paths
Jooyung Han74066602020-03-20 04:29:24 +0900479
480 // For apex variants, this is set as apex.min_sdk_version
481 apexSdkVersion int
Colin Crossc472d572015-03-17 15:06:21 -0700482}
483
Ivan Lozano52767be2019-10-18 14:49:46 -0700484func (c *Module) Toc() android.OptionalPath {
485 if c.linker != nil {
486 if library, ok := c.linker.(libraryInterface); ok {
487 return library.toc()
488 }
489 }
490 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
491}
492
493func (c *Module) ApiLevel() string {
494 if c.linker != nil {
495 if stub, ok := c.linker.(*stubDecorator); ok {
496 return stub.properties.ApiLevel
497 }
498 }
499 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
500}
501
502func (c *Module) Static() bool {
503 if c.linker != nil {
504 if library, ok := c.linker.(libraryInterface); ok {
505 return library.static()
506 }
507 }
508 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
509}
510
511func (c *Module) Shared() bool {
512 if c.linker != nil {
513 if library, ok := c.linker.(libraryInterface); ok {
514 return library.shared()
515 }
516 }
517 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
518}
519
520func (c *Module) SelectedStl() string {
521 return c.stl.Properties.SelectedStl
522}
523
524func (c *Module) ToolchainLibrary() bool {
525 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
526 return true
527 }
528 return false
529}
530
531func (c *Module) NdkPrebuiltStl() bool {
532 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
533 return true
534 }
535 return false
536}
537
538func (c *Module) StubDecorator() bool {
539 if _, ok := c.linker.(*stubDecorator); ok {
540 return true
541 }
542 return false
543}
544
545func (c *Module) SdkVersion() string {
546 return String(c.Properties.Sdk_version)
547}
548
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800549func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700550 if c.linker != nil {
551 if library, ok := c.linker.(exportedFlagsProducer); ok {
552 return library.exportedDirs()
553 }
554 }
555 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
556}
557
558func (c *Module) HasStaticVariant() bool {
559 if c.staticVariant != nil {
560 return true
561 }
562 return false
563}
564
565func (c *Module) GetStaticVariant() LinkableInterface {
566 return c.staticVariant
567}
568
569func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
570 c.depsInLinkOrder = depsInLinkOrder
571}
572
573func (c *Module) GetDepsInLinkOrder() []android.Path {
574 return c.depsInLinkOrder
575}
576
577func (c *Module) StubsVersions() []string {
578 if c.linker != nil {
579 if library, ok := c.linker.(*libraryDecorator); ok {
580 return library.Properties.Stubs.Versions
581 }
582 }
583 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
584}
585
586func (c *Module) CcLibrary() bool {
587 if c.linker != nil {
588 if _, ok := c.linker.(*libraryDecorator); ok {
589 return true
590 }
591 }
592 return false
593}
594
595func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700596 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700597 return true
598 }
599 return false
600}
601
Ivan Lozano2b262972019-11-21 12:30:50 -0800602func (c *Module) NonCcVariants() bool {
603 return false
604}
605
Ivan Lozano183a3212019-10-18 14:18:45 -0700606func (c *Module) SetBuildStubs() {
607 if c.linker != nil {
608 if library, ok := c.linker.(*libraryDecorator); ok {
609 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700610 c.Properties.HideFromMake = true
611 c.sanitize = nil
612 c.stl = nil
613 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700614 return
615 }
Jooyung Han67a96cd2020-03-13 15:23:36 +0900616 if _, ok := c.linker.(*llndkStubDecorator); ok {
617 c.Properties.HideFromMake = true
618 return
619 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700620 }
621 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
622}
623
Ivan Lozano52767be2019-10-18 14:49:46 -0700624func (c *Module) BuildStubs() bool {
625 if c.linker != nil {
626 if library, ok := c.linker.(*libraryDecorator); ok {
627 return library.buildStubs()
628 }
629 }
630 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
631}
632
Ivan Lozano183a3212019-10-18 14:18:45 -0700633func (c *Module) SetStubsVersions(version string) {
634 if c.linker != nil {
635 if library, ok := c.linker.(*libraryDecorator); ok {
636 library.MutatedProperties.StubsVersion = version
637 return
638 }
Jooyung Han67a96cd2020-03-13 15:23:36 +0900639 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
640 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
641 return
642 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700643 }
644 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
645}
646
Jooyung Han0c4e0162020-02-26 22:45:42 +0900647func (c *Module) StubsVersion() string {
648 if c.linker != nil {
649 if library, ok := c.linker.(*libraryDecorator); ok {
650 return library.MutatedProperties.StubsVersion
651 }
Jooyung Han67a96cd2020-03-13 15:23:36 +0900652 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
653 return llndk.libraryDecorator.MutatedProperties.StubsVersion
654 }
Jooyung Han0c4e0162020-02-26 22:45:42 +0900655 }
656 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
657}
658
Ivan Lozano183a3212019-10-18 14:18:45 -0700659func (c *Module) SetStatic() {
660 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700661 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700662 library.setStatic()
663 return
664 }
665 }
666 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
667}
668
669func (c *Module) SetShared() {
670 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700671 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700672 library.setShared()
673 return
674 }
675 }
676 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
677}
678
679func (c *Module) BuildStaticVariant() bool {
680 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700681 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700682 return library.buildStatic()
683 }
684 }
685 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
686}
687
688func (c *Module) BuildSharedVariant() bool {
689 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700690 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700691 return library.buildShared()
692 }
693 }
694 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
695}
696
697func (c *Module) Module() android.Module {
698 return c
699}
700
Jiyong Parkc20eee32018-09-05 22:36:17 +0900701func (c *Module) OutputFile() android.OptionalPath {
702 return c.outputFile
703}
704
Ivan Lozano183a3212019-10-18 14:18:45 -0700705var _ LinkableInterface = (*Module)(nil)
706
Jiyong Park719b4462019-01-13 00:39:51 +0900707func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900708 if c.linker != nil {
709 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900710 }
711 return nil
712}
713
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900714func (c *Module) CoverageOutputFile() android.OptionalPath {
715 if c.linker != nil {
716 return c.linker.coverageOutputFilePath()
717 }
718 return android.OptionalPath{}
719}
720
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900721func (c *Module) RelativeInstallPath() string {
722 if c.installer != nil {
723 return c.installer.relativeInstallPath()
724 }
725 return ""
726}
727
Jooyung Han344d5432019-08-23 11:17:39 +0900728func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900729 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900730}
731
Colin Cross36242852017-06-23 15:06:31 -0700732func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700733 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800734 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700735 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800736 }
737 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700738 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800739 }
740 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700741 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800742 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700743 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700744 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700745 }
Colin Cross16b23492016-01-06 14:41:07 -0800746 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700747 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800748 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800749 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700750 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800751 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800752 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700753 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800754 }
Justin Yun8effde42017-06-23 19:24:43 +0900755 if c.vndkdep != nil {
756 c.AddProperties(c.vndkdep.props()...)
757 }
Stephen Craneba090d12017-05-09 15:44:35 -0700758 if c.lto != nil {
759 c.AddProperties(c.lto.props()...)
760 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700761 if c.pgo != nil {
762 c.AddProperties(c.pgo.props()...)
763 }
Colin Crossca860ac2016-01-04 14:34:37 -0800764 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700765 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800766 }
Colin Crossc472d572015-03-17 15:06:21 -0700767
Colin Crossa9d8bee2018-10-02 13:59:46 -0700768 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
769 switch class {
770 case android.Device:
771 return ctx.Config().DevicePrefer32BitExecutables()
772 case android.HostCross:
773 // Windows builds always prefer 32-bit
774 return true
775 default:
776 return false
777 }
778 })
Colin Cross36242852017-06-23 15:06:31 -0700779 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900780 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900781 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900782 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900783
Colin Cross36242852017-06-23 15:06:31 -0700784 return c
Colin Crossc472d572015-03-17 15:06:21 -0700785}
786
Colin Crossb916a382016-07-29 17:28:03 -0700787// Returns true for dependency roots (binaries)
788// TODO(ccross): also handle dlopenable libraries
789func (c *Module) isDependencyRoot() bool {
790 if root, ok := c.linker.(interface {
791 isDependencyRoot() bool
792 }); ok {
793 return root.isDependencyRoot()
794 }
795 return false
796}
797
Justin Yun5f7f7e82019-11-18 19:52:14 +0900798// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
799// "product" and "vendor" variant modules return true for this function.
800// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
801// "soc_specific: true" and more vendor installed modules are included here.
802// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
803// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700804func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900805 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700806}
807
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800808func (c *Module) isCoverageVariant() bool {
809 return c.coverage.Properties.IsCoverageVariant
810}
811
Peter Collingbournead84f972019-12-17 16:46:18 -0800812func (c *Module) IsNdk() bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800813 return inList(c.Name(), ndkMigratedLibs)
814}
815
Inseob Kim9516ee92019-05-09 10:56:13 +0900816func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800817 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900818 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800819}
820
Inseob Kim9516ee92019-05-09 10:56:13 +0900821func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800822 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900823 name := c.BaseModuleName()
824 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800825}
826
Inseob Kim9516ee92019-05-09 10:56:13 +0900827func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800828 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900829 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800830}
831
Ivan Lozano52767be2019-10-18 14:49:46 -0700832func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800833 if vndkdep := c.vndkdep; vndkdep != nil {
834 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900835 }
836 return false
837}
838
Yi Kong7e53c572018-02-14 18:16:12 +0800839func (c *Module) isPgoCompile() bool {
840 if pgo := c.pgo; pgo != nil {
841 return pgo.Properties.PgoCompile
842 }
843 return false
844}
845
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800846func (c *Module) isNDKStubLibrary() bool {
847 if _, ok := c.compiler.(*stubDecorator); ok {
848 return true
849 }
850 return false
851}
852
Logan Chienf3511742017-10-31 18:04:35 +0800853func (c *Module) isVndkSp() bool {
854 if vndkdep := c.vndkdep; vndkdep != nil {
855 return vndkdep.isVndkSp()
856 }
857 return false
858}
859
860func (c *Module) isVndkExt() bool {
861 if vndkdep := c.vndkdep; vndkdep != nil {
862 return vndkdep.isVndkExt()
863 }
864 return false
865}
866
Ivan Lozano52767be2019-10-18 14:49:46 -0700867func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900868 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800869}
870
Logan Chienf3511742017-10-31 18:04:35 +0800871func (c *Module) getVndkExtendsModuleName() string {
872 if vndkdep := c.vndkdep; vndkdep != nil {
873 return vndkdep.getVndkExtendsModuleName()
874 }
875 return ""
876}
877
Justin Yun5f7f7e82019-11-18 19:52:14 +0900878// Returns true only when this module is configured to have core, product and vendor
Jiyong Park82e2bf32017-08-16 14:05:54 +0900879// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700880func (c *Module) HasVendorVariant() bool {
881 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900882}
883
Justin Yun5f7f7e82019-11-18 19:52:14 +0900884const (
885 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
886 // against the VNDK.
887 VendorVariationPrefix = "vendor."
888
889 // ProductVariationPrefix is the variant prefix used for /product code that compiles
890 // against the VNDK.
891 ProductVariationPrefix = "product."
892)
893
894// Returns true if the module is "product" variant. Usually these modules are installed in /product
895func (c *Module) inProduct() bool {
896 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
897}
898
899// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
900func (c *Module) inVendor() bool {
901 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
902}
903
Yifan Hong1b3348d2020-01-21 15:53:22 -0800904func (c *Module) InRamdisk() bool {
905 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
906}
907
Ivan Lozano52767be2019-10-18 14:49:46 -0700908func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800909 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900910}
911
Yifan Hong1b3348d2020-01-21 15:53:22 -0800912func (c *Module) OnlyInRamdisk() bool {
913 return c.ModuleBase.InstallInRamdisk()
914}
915
Ivan Lozano52767be2019-10-18 14:49:46 -0700916func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900917 return c.ModuleBase.InstallInRecovery()
918}
919
Jiyong Park25fc6a92018-11-18 18:02:45 +0900920func (c *Module) IsStubs() bool {
921 if library, ok := c.linker.(*libraryDecorator); ok {
922 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900923 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
924 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900925 }
926 return false
927}
928
929func (c *Module) HasStubsVariants() bool {
930 if library, ok := c.linker.(*libraryDecorator); ok {
931 return len(library.Properties.Stubs.Versions) > 0
932 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700933 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
934 return len(library.Properties.Stubs.Versions) > 0
935 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900936 return false
937}
938
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900939func (c *Module) bootstrap() bool {
940 return Bool(c.Properties.Bootstrap)
941}
942
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700943func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700944 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
945 if c.Target().NativeBridge == android.NativeBridgeEnabled {
946 return false
947 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700948 return c.linker != nil && c.linker.nativeCoverage()
949}
950
Inseob Kim8471cda2019-11-15 09:59:12 +0900951func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kimeec88e12020-01-22 11:11:29 +0900952 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
953 return true
954 }
955 if _, ok := c.linker.(*vendorSnapshotLibraryDecorator); ok {
956 return true
957 }
958 if _, ok := c.linker.(*vendorSnapshotBinaryDecorator); ok {
959 return true
960 }
961 return false
Inseob Kim8471cda2019-11-15 09:59:12 +0900962}
963
Jiyong Park73c54ee2019-10-22 20:31:18 +0900964func (c *Module) ExportedIncludeDirs() android.Paths {
965 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
966 return flagsProducer.exportedDirs()
967 }
Jiyong Park232e7852019-11-04 12:23:40 +0900968 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900969}
970
971func (c *Module) ExportedSystemIncludeDirs() android.Paths {
972 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
973 return flagsProducer.exportedSystemDirs()
974 }
Jiyong Park232e7852019-11-04 12:23:40 +0900975 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900976}
977
978func (c *Module) ExportedFlags() []string {
979 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
980 return flagsProducer.exportedFlags()
981 }
Jiyong Park232e7852019-11-04 12:23:40 +0900982 return nil
983}
984
985func (c *Module) ExportedDeps() android.Paths {
986 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
987 return flagsProducer.exportedDeps()
988 }
989 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900990}
991
Inseob Kimd110f872019-12-06 13:15:38 +0900992func (c *Module) ExportedGeneratedHeaders() android.Paths {
993 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
994 return flagsProducer.exportedGeneratedHeaders()
995 }
996 return nil
997}
998
Jiyong Parkf1194352019-02-25 11:05:47 +0900999func isBionic(name string) bool {
1000 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001001 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001002 return true
1003 }
1004 return false
1005}
1006
Martin Stjernholm279de572019-09-10 23:18:20 +01001007func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001008 if name == "libclang_rt.hwasan-aarch64-android" {
1009 return inList("hwaddress", config.SanitizeDevice())
1010 }
1011 return isBionic(name)
1012}
1013
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001014func (c *Module) XrefCcFiles() android.Paths {
1015 return c.kytheFiles
1016}
1017
Colin Crossca860ac2016-01-04 14:34:37 -08001018type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001019 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001020 moduleContextImpl
1021}
1022
Colin Cross37047f12016-12-13 17:06:13 -08001023type depsContext struct {
1024 android.BottomUpMutatorContext
1025 moduleContextImpl
1026}
1027
Colin Crossca860ac2016-01-04 14:34:37 -08001028type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001029 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001030 moduleContextImpl
1031}
1032
Justin Yun5f7f7e82019-11-18 19:52:14 +09001033func (ctx *moduleContext) ProductSpecific() bool {
1034 return ctx.ModuleContext.ProductSpecific() ||
1035 (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
1036}
1037
Jiyong Park2db76922017-11-08 16:03:48 +09001038func (ctx *moduleContext) SocSpecific() bool {
1039 return ctx.ModuleContext.SocSpecific() ||
Justin Yun5f7f7e82019-11-18 19:52:14 +09001040 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001041}
1042
Colin Crossca860ac2016-01-04 14:34:37 -08001043type moduleContextImpl struct {
1044 mod *Module
1045 ctx BaseModuleContext
1046}
1047
Colin Crossb98c8b02016-07-29 13:44:28 -07001048func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001049 return ctx.mod.toolchain(ctx.ctx)
1050}
1051
1052func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001053 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001054}
1055
1056func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001057 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001058}
1059
Jiyong Park1d1119f2019-07-29 21:27:18 +09001060func (ctx *moduleContextImpl) header() bool {
1061 return ctx.mod.header()
1062}
1063
Jooyung Han61c41542020-03-07 03:45:53 +09001064func (ctx *moduleContextImpl) canUseSdk() bool {
1065 return ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRamdisk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia()
1066}
1067
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001068func (ctx *moduleContextImpl) useSdk() bool {
Jooyung Han61c41542020-03-07 03:45:53 +09001069 if ctx.canUseSdk() {
Nan Zhang0007d812017-11-07 10:57:05 -08001070 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -07001071 }
1072 return false
Colin Crossca860ac2016-01-04 14:34:37 -08001073}
1074
1075func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001076 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001077 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001078 vndkVer := ctx.mod.VndkVersion()
1079 if inList(vndkVer, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
1080 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001081 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001082 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001083 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001084 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001085 }
1086 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001087}
1088
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001089func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001090 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001091}
Justin Yun8effde42017-06-23 19:24:43 +09001092
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001093func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001094 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001095}
1096
Inseob Kim9516ee92019-05-09 10:56:13 +09001097func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1098 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001099}
1100
Inseob Kim9516ee92019-05-09 10:56:13 +09001101func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1102 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001103}
1104
Inseob Kim9516ee92019-05-09 10:56:13 +09001105func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1106 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001107}
1108
Logan Chienf3511742017-10-31 18:04:35 +08001109func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001110 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001111}
1112
Yi Kong7e53c572018-02-14 18:16:12 +08001113func (ctx *moduleContextImpl) isPgoCompile() bool {
1114 return ctx.mod.isPgoCompile()
1115}
1116
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001117func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1118 return ctx.mod.isNDKStubLibrary()
1119}
1120
Justin Yun8effde42017-06-23 19:24:43 +09001121func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001122 return ctx.mod.isVndkSp()
1123}
1124
1125func (ctx *moduleContextImpl) isVndkExt() bool {
1126 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001127}
1128
Vic Yangefd249e2018-11-12 20:19:56 -08001129func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001130 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001131}
1132
Justin Yun5f7f7e82019-11-18 19:52:14 +09001133func (ctx *moduleContextImpl) inProduct() bool {
1134 return ctx.mod.inProduct()
1135}
1136
1137func (ctx *moduleContextImpl) inVendor() bool {
1138 return ctx.mod.inVendor()
1139}
1140
Yifan Hong1b3348d2020-01-21 15:53:22 -08001141func (ctx *moduleContextImpl) inRamdisk() bool {
1142 return ctx.mod.InRamdisk()
1143}
1144
Jiyong Parkf9332f12018-02-01 00:54:12 +09001145func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001146 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001147}
1148
Logan Chien2f2b8902018-07-10 15:01:19 +08001149// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001150func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001151 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1152 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001153 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001154
1155 if ctx.ctx.Fuchsia() {
1156 return false
1157 }
1158
Logan Chien2f2b8902018-07-10 15:01:19 +08001159 if sanitize := ctx.mod.sanitize; sanitize != nil {
1160 if !sanitize.isVariantOnProductionDevice() {
1161 return false
1162 }
1163 }
1164 if !ctx.ctx.Device() {
1165 // Host modules do not need ABI dumps.
1166 return false
1167 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001168 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001169 // Stubs do not need ABI dumps.
1170 return false
1171 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001172 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001173}
1174
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001175func (ctx *moduleContextImpl) selectedStl() string {
1176 if stl := ctx.mod.stl; stl != nil {
1177 return stl.Properties.SelectedStl
1178 }
1179 return ""
1180}
1181
Ivan Lozanobd721262018-11-27 14:33:03 -08001182func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1183 return ctx.mod.linker.useClangLld(actx)
1184}
1185
Colin Crossce75d2c2016-10-06 16:12:58 -07001186func (ctx *moduleContextImpl) baseModuleName() string {
1187 return ctx.mod.ModuleBase.BaseModuleName()
1188}
1189
Logan Chienf3511742017-10-31 18:04:35 +08001190func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1191 return ctx.mod.getVndkExtendsModuleName()
1192}
1193
Logan Chiene274fc92019-12-03 11:18:32 -08001194func (ctx *moduleContextImpl) isForPlatform() bool {
1195 return ctx.mod.IsForPlatform()
1196}
1197
Jiyong Park58e364a2019-01-19 19:24:06 +09001198func (ctx *moduleContextImpl) apexName() string {
1199 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001200}
1201
Jooyung Han61c41542020-03-07 03:45:53 +09001202func (ctx *moduleContextImpl) apexSdkVersion() int {
Jooyung Han74066602020-03-20 04:29:24 +09001203 return ctx.mod.apexSdkVersion
Jooyung Han61c41542020-03-07 03:45:53 +09001204}
1205
Jiyong Parkb0788572018-12-20 22:10:17 +09001206func (ctx *moduleContextImpl) hasStubsVariants() bool {
1207 return ctx.mod.HasStubsVariants()
1208}
1209
1210func (ctx *moduleContextImpl) isStubs() bool {
1211 return ctx.mod.IsStubs()
1212}
1213
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001214func (ctx *moduleContextImpl) bootstrap() bool {
1215 return ctx.mod.bootstrap()
1216}
1217
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001218func (ctx *moduleContextImpl) nativeCoverage() bool {
1219 return ctx.mod.nativeCoverage()
1220}
1221
Colin Cross635c3b02016-05-18 15:37:25 -07001222func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001223 return &Module{
1224 hod: hod,
1225 multilib: multilib,
1226 }
1227}
1228
Colin Cross635c3b02016-05-18 15:37:25 -07001229func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001230 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001231 module.features = []feature{
1232 &tidyFeature{},
1233 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001234 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001235 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001236 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001237 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001238 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001239 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001240 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001241 return module
1242}
1243
Colin Crossce75d2c2016-10-06 16:12:58 -07001244func (c *Module) Prebuilt() *android.Prebuilt {
1245 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1246 return p.prebuilt()
1247 }
1248 return nil
1249}
1250
1251func (c *Module) Name() string {
1252 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001253 if p, ok := c.linker.(interface {
1254 Name(string) string
1255 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001256 name = p.Name(name)
1257 }
1258 return name
1259}
1260
Alex Light3d673592019-01-18 14:37:31 -08001261func (c *Module) Symlinks() []string {
1262 if p, ok := c.installer.(interface {
1263 symlinkList() []string
1264 }); ok {
1265 return p.symlinkList()
1266 }
1267 return nil
1268}
1269
Jeff Gaston294356f2017-09-27 17:05:30 -07001270// orderDeps reorders dependencies into a list such that if module A depends on B, then
1271// A will precede B in the resultant list.
1272// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001273// Note that directSharedDeps should be the analogous static library for each shared lib dep
1274func 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 -07001275 // If A depends on B, then
1276 // Every list containing A will also contain B later in the list
1277 // So, after concatenating all lists, the final instance of B will have come from the same
1278 // original list as the final instance of A
1279 // So, the final instance of B will be later in the concatenation than the final A
1280 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1281 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001282 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001283 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001284 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1285 }
1286 for _, dep := range directSharedDeps {
1287 orderedAllDeps = append(orderedAllDeps, dep)
1288 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001289 }
1290
Colin Crossb6715442017-10-24 11:13:31 -07001291 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001292
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001293 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001294 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001295 // resultant list to only what the caller has chosen to include in directStaticDeps
1296 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001297
1298 return orderedAllDeps, orderedDeclaredDeps
1299}
1300
Ivan Lozano183a3212019-10-18 14:18:45 -07001301func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001302 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001303 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001304 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1305 staticDepFiles := []android.Path{}
1306 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001307 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1308 if dep.OutputFile().Valid() {
1309 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1310 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1311 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001312 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001313 sharedDepFiles := []android.Path{}
1314 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001315 if sharedDep.HasStaticVariant() {
1316 staticAnalogue := sharedDep.GetStaticVariant()
1317 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1318 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001319 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001320 }
1321
1322 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001323 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1324 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001325
1326 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001327}
1328
Roland Levillainf89cd092019-07-29 16:22:59 +01001329func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1330 test, ok := c.linker.(testPerSrc)
1331 return ok && test.isAllTestsVariation()
1332}
1333
Justin Yun5f7f7e82019-11-18 19:52:14 +09001334func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1335 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1336 // "current", it will append the VNDK version to the name suffix.
1337 var vndkVersion string
1338 var nameSuffix string
1339 if c.inProduct() {
1340 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1341 nameSuffix = productSuffix
1342 } else {
1343 vndkVersion = ctx.DeviceConfig().VndkVersion()
1344 nameSuffix = vendorSuffix
1345 }
1346 if vndkVersion == "current" {
1347 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1348 }
1349 if c.Properties.VndkVersion != vndkVersion {
1350 // add version suffix only if the module is using different vndk version than the
1351 // version in product or vendor partition.
1352 nameSuffix += "." + c.Properties.VndkVersion
1353 }
1354 return nameSuffix
1355}
1356
Colin Cross635c3b02016-05-18 15:37:25 -07001357func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001358 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001359 //
1360 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1361 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1362 // module and return early, as this module does not produce an output file per se.
1363 if c.IsTestPerSrcAllTestsVariation() {
1364 c.outputFile = android.OptionalPath{}
1365 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001366 }
1367
Jooyung Han38002912019-05-16 04:01:54 +09001368 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001369
Inseob Kim64c43952019-08-26 16:52:35 +09001370 c.Properties.SubName = ""
1371
1372 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1373 c.Properties.SubName += nativeBridgeSuffix
1374 }
1375
Justin Yun5f7f7e82019-11-18 19:52:14 +09001376 _, llndk := c.linker.(*llndkStubDecorator)
1377 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1378 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1379 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1380 // added for product variant only when we have vendor and product variants with core
1381 // variant. The suffix is not added for vendor-only or product-only module.
1382 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1383 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001384 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1385 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1386 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001387 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1388 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001389 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001390 c.Properties.SubName += recoverySuffix
1391 }
1392
Colin Crossca860ac2016-01-04 14:34:37 -08001393 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001394 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001395 moduleContextImpl: moduleContextImpl{
1396 mod: c,
1397 },
1398 }
1399 ctx.ctx = ctx
1400
Colin Crossf18e1102017-11-16 14:33:08 -08001401 deps := c.depsToPaths(ctx)
1402 if ctx.Failed() {
1403 return
1404 }
1405
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001406 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1407 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1408 }
1409
Colin Crossca860ac2016-01-04 14:34:37 -08001410 flags := Flags{
1411 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001412 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001413 }
Colin Crossca860ac2016-01-04 14:34:37 -08001414 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001415 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001416 }
1417 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001418 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001419 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001420 if c.stl != nil {
1421 flags = c.stl.flags(ctx, flags)
1422 }
Colin Cross16b23492016-01-06 14:41:07 -08001423 if c.sanitize != nil {
1424 flags = c.sanitize.flags(ctx, flags)
1425 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001426 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001427 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001428 }
Stephen Craneba090d12017-05-09 15:44:35 -07001429 if c.lto != nil {
1430 flags = c.lto.flags(ctx, flags)
1431 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001432 if c.pgo != nil {
1433 flags = c.pgo.flags(ctx, flags)
1434 }
Colin Crossca860ac2016-01-04 14:34:37 -08001435 for _, feature := range c.features {
1436 flags = feature.flags(ctx, flags)
1437 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001438 if ctx.Failed() {
1439 return
1440 }
1441
Colin Cross4af21ed2019-11-04 09:37:55 -08001442 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1443 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1444 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001445
Colin Cross4af21ed2019-11-04 09:37:55 -08001446 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001447
1448 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001449 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001450 }
1451 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001452 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001453 }
1454
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001455 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001456 // We need access to all the flags seen by a source file.
1457 if c.sabi != nil {
1458 flags = c.sabi.flags(ctx, flags)
1459 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001460
Colin Cross4af21ed2019-11-04 09:37:55 -08001461 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001462
Colin Crossca860ac2016-01-04 14:34:37 -08001463 // Optimization to reduce size of build.ninja
1464 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001465 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1466 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1467 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1468 flags.Local.CFlags = []string{"$cflags"}
1469 flags.Local.CppFlags = []string{"$cppflags"}
1470 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001471
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001472 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001473 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001474 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001475 if ctx.Failed() {
1476 return
1477 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001478 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001479 }
1480
Colin Crossca860ac2016-01-04 14:34:37 -08001481 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001482 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001483 if ctx.Failed() {
1484 return
1485 }
Colin Cross635c3b02016-05-18 15:37:25 -07001486 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001487
1488 // If a lib is directly included in any of the APEXes, unhide the stubs
1489 // variant having the latest version gets visible to make. In addition,
1490 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1491 // force anything in the make world to link against the stubs library.
1492 // (unless it is explicitly referenced via .bootstrap suffix or the
1493 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001494 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001495 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001496 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001497 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001498 c.Properties.HideFromMake = false // unhide
1499 // Note: this is still non-installable
1500 }
Inseob Kimac775b22020-03-03 22:06:32 +09001501
1502 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1503 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1504 if isSnapshotAware(ctx, c) {
1505 i.collectHeadersForSnapshot(ctx)
1506 }
1507 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001508 }
Colin Cross5049f022015-03-18 13:28:46 -07001509
Inseob Kim1f086e22019-05-09 13:29:15 +09001510 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001511 c.installer.install(ctx, c.outputFile.Path())
1512 if ctx.Failed() {
1513 return
Colin Crossca860ac2016-01-04 14:34:37 -08001514 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001515 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001516}
1517
Colin Cross0ea8ba82019-06-06 14:33:29 -07001518func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001519 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001520 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001521 }
Colin Crossca860ac2016-01-04 14:34:37 -08001522 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001523}
1524
Colin Crossca860ac2016-01-04 14:34:37 -08001525func (c *Module) begin(ctx BaseModuleContext) {
1526 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001527 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001528 }
Colin Crossca860ac2016-01-04 14:34:37 -08001529 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001530 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001531 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001532 if c.stl != nil {
1533 c.stl.begin(ctx)
1534 }
Colin Cross16b23492016-01-06 14:41:07 -08001535 if c.sanitize != nil {
1536 c.sanitize.begin(ctx)
1537 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001538 if c.coverage != nil {
1539 c.coverage.begin(ctx)
1540 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001541 if c.sabi != nil {
1542 c.sabi.begin(ctx)
1543 }
Justin Yun8effde42017-06-23 19:24:43 +09001544 if c.vndkdep != nil {
1545 c.vndkdep.begin(ctx)
1546 }
Stephen Craneba090d12017-05-09 15:44:35 -07001547 if c.lto != nil {
1548 c.lto.begin(ctx)
1549 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001550 if c.pgo != nil {
1551 c.pgo.begin(ctx)
1552 }
Colin Crossca860ac2016-01-04 14:34:37 -08001553 for _, feature := range c.features {
1554 feature.begin(ctx)
1555 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001556 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001557 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001558 if err != nil {
1559 ctx.PropertyErrorf("sdk_version", err.Error())
1560 }
Nan Zhang0007d812017-11-07 10:57:05 -08001561 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001562 }
Colin Crossca860ac2016-01-04 14:34:37 -08001563}
1564
Colin Cross37047f12016-12-13 17:06:13 -08001565func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001566 deps := Deps{}
1567
1568 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001569 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001570 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001571 // Add the PGO dependency (the clang_rt.profile runtime library), which
1572 // sometimes depends on symbols from libgcc, before libgcc gets added
1573 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001574 if c.pgo != nil {
1575 deps = c.pgo.deps(ctx, deps)
1576 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001577 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001578 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001579 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001580 if c.stl != nil {
1581 deps = c.stl.deps(ctx, deps)
1582 }
Colin Cross16b23492016-01-06 14:41:07 -08001583 if c.sanitize != nil {
1584 deps = c.sanitize.deps(ctx, deps)
1585 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001586 if c.coverage != nil {
1587 deps = c.coverage.deps(ctx, deps)
1588 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001589 if c.sabi != nil {
1590 deps = c.sabi.deps(ctx, deps)
1591 }
Justin Yun8effde42017-06-23 19:24:43 +09001592 if c.vndkdep != nil {
1593 deps = c.vndkdep.deps(ctx, deps)
1594 }
Stephen Craneba090d12017-05-09 15:44:35 -07001595 if c.lto != nil {
1596 deps = c.lto.deps(ctx, deps)
1597 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001598 for _, feature := range c.features {
1599 deps = feature.deps(ctx, deps)
1600 }
1601
Colin Crossb6715442017-10-24 11:13:31 -07001602 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1603 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1604 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1605 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1606 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1607 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001608 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001609
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001610 for _, lib := range deps.ReexportSharedLibHeaders {
1611 if !inList(lib, deps.SharedLibs) {
1612 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1613 }
1614 }
1615
1616 for _, lib := range deps.ReexportStaticLibHeaders {
1617 if !inList(lib, deps.StaticLibs) {
1618 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1619 }
1620 }
1621
Colin Cross5950f382016-12-13 12:50:57 -08001622 for _, lib := range deps.ReexportHeaderLibHeaders {
1623 if !inList(lib, deps.HeaderLibs) {
1624 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1625 }
1626 }
1627
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001628 for _, gen := range deps.ReexportGeneratedHeaders {
1629 if !inList(gen, deps.GeneratedHeaders) {
1630 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1631 }
1632 }
1633
Colin Crossc99deeb2016-04-11 15:06:20 -07001634 return deps
1635}
1636
Dan Albert7e9d2952016-08-04 13:02:36 -07001637func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001638 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001639 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001640 moduleContextImpl: moduleContextImpl{
1641 mod: c,
1642 },
1643 }
1644 ctx.ctx = ctx
1645
Colin Crossca860ac2016-01-04 14:34:37 -08001646 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001647}
1648
Jiyong Park7ed9de32018-10-15 22:25:07 +09001649// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001650func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001651 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1652 version := name[sharp+1:]
1653 libname := name[:sharp]
1654 return libname, version
1655 }
1656 return name, ""
1657}
1658
Colin Cross1e676be2016-10-12 14:38:15 -07001659func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001660 if !c.Enabled() {
1661 return
1662 }
1663
Colin Cross37047f12016-12-13 17:06:13 -08001664 ctx := &depsContext{
1665 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001666 moduleContextImpl: moduleContextImpl{
1667 mod: c,
1668 },
1669 }
1670 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001671
Colin Crossc99deeb2016-04-11 15:06:20 -07001672 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001673
Dan Albert914449f2016-06-17 16:45:24 -07001674 variantNdkLibs := []string{}
1675 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001676 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001677 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001678
Inseob Kimeec88e12020-01-22 11:11:29 +09001679 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001680 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001681 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001682 // 1. Name of an NDK library that refers to a prebuilt module.
1683 // For each of these, it adds the name of the prebuilt module (which will be in
1684 // prebuilts/ndk) to the list of nonvariant libs.
1685 // 2. Name of an NDK library that refers to an ndk_library module.
1686 // For each of these, it adds the name of the ndk_library module to the list of
1687 // variant libs.
1688 // 3. Anything else (so anything that isn't an NDK library).
1689 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001690 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001691 // The caller can then know to add the variantLibs dependencies differently from the
1692 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001693
Inseob Kim9516ee92019-05-09 10:56:13 +09001694 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001695 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1696
1697 rewriteVendorLibs := func(lib string) string {
1698 if isLlndkLibrary(lib, ctx.Config()) {
1699 return lib + llndkLibrarySuffix
1700 }
1701
1702 // only modules with BOARD_VNDK_VERSION uses snapshot.
1703 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1704 return lib
1705 }
1706
1707 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1708 return snapshot
1709 }
1710
1711 return lib
1712 }
1713
1714 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001715 variantLibs = []string{}
1716 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001717 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001718 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001719 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001720 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1721 if !inList(name, ndkMigratedLibs) {
1722 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001723 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001724 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001725 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001726 } else if ctx.useVndk() {
1727 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001728 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001729 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001730 if actx.OtherModuleExists(vendorPublicLib) {
1731 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1732 } else {
1733 // This can happen if vendor_public_library module is defined in a
1734 // namespace that isn't visible to the current module. In that case,
1735 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001736 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001737 }
Dan Albert914449f2016-06-17 16:45:24 -07001738 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001739 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001740 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001741 }
1742 }
Dan Albert914449f2016-06-17 16:45:24 -07001743 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001744 }
1745
Inseob Kimeec88e12020-01-22 11:11:29 +09001746 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1747 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1748 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1749 if ctx.useVndk() {
1750 for idx, lib := range deps.RuntimeLibs {
1751 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1752 }
1753 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001754 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001755
Jiyong Park7e636d02019-01-28 16:16:54 +09001756 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001757 if c.linker != nil {
1758 if library, ok := c.linker.(*libraryDecorator); ok {
1759 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001760 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001761 }
1762 }
1763 }
1764
Inseob Kimeec88e12020-01-22 11:11:29 +09001765 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1766 // only modules with BOARD_VNDK_VERSION uses snapshot.
1767 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1768 return lib
1769 }
1770
1771 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1772 return snapshot
1773 }
1774
1775 return lib
1776 }
1777
1778 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001779 for _, lib := range deps.HeaderLibs {
1780 depTag := headerDepTag
1781 if inList(lib, deps.ReexportHeaderLibHeaders) {
1782 depTag = headerExportDepTag
1783 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001784
1785 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1786
Jiyong Park7e636d02019-01-28 16:16:54 +09001787 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001788 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001789 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001790 } else {
1791 actx.AddVariationDependencies(nil, depTag, lib)
1792 }
1793 }
1794
1795 if buildStubs {
1796 // Stubs lib does not have dependency to other static/shared libraries.
1797 // Don't proceed.
1798 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001799 }
Colin Cross5950f382016-12-13 12:50:57 -08001800
Inseob Kimc0907f12019-02-08 21:00:45 +09001801 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001802 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001803
Jiyong Park5d1598f2019-02-25 22:14:17 +09001804 for _, lib := range deps.WholeStaticLibs {
1805 depTag := wholeStaticDepTag
1806 if impl, ok := syspropImplLibraries[lib]; ok {
1807 lib = impl
1808 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001809
1810 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1811
Jiyong Park5d1598f2019-02-25 22:14:17 +09001812 actx.AddVariationDependencies([]blueprint.Variation{
1813 {Mutator: "link", Variation: "static"},
1814 }, depTag, lib)
1815 }
1816
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001817 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001818 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001819 if inList(lib, deps.ReexportStaticLibHeaders) {
1820 depTag = staticExportDepTag
1821 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001822
1823 if impl, ok := syspropImplLibraries[lib]; ok {
1824 lib = impl
1825 }
1826
Inseob Kimeec88e12020-01-22 11:11:29 +09001827 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1828
Dan Willemsen59339a22018-07-22 21:18:45 -07001829 actx.AddVariationDependencies([]blueprint.Variation{
1830 {Mutator: "link", Variation: "static"},
1831 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001832 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001833
Jooyung Han74066602020-03-20 04:29:24 +09001834 // staticUnwinderDep is treated as staticDep for Q apexes
1835 // so that native libraries/binaries are linked with static unwinder
1836 // because Q libc doesn't have unwinder APIs
1837 if deps.StaticUnwinderIfLegacy {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001838 actx.AddVariationDependencies([]blueprint.Variation{
1839 {Mutator: "link", Variation: "static"},
1840 }, staticUnwinderDepTag, staticUnwinder(actx))
1841 }
1842
Inseob Kimeec88e12020-01-22 11:11:29 +09001843 for _, lib := range deps.LateStaticLibs {
1844 actx.AddVariationDependencies([]blueprint.Variation{
1845 {Mutator: "link", Variation: "static"},
1846 }, lateStaticDepTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
1847 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001848
Ivan Lozano183a3212019-10-18 14:18:45 -07001849 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001850 var variations []blueprint.Variation
1851 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han67a96cd2020-03-13 15:23:36 +09001852 versionVariantAvail := !c.InRecovery() && !c.InRamdisk()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001853 if version != "" && versionVariantAvail {
1854 // Version is explicitly specified. i.e. libFoo#30
1855 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001856 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001857 }
1858 actx.AddVariationDependencies(variations, depTag, name)
1859
Jooyung Han0c4e0162020-02-26 22:45:42 +09001860 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001861 // The stubs library will be used when the depending module is built for APEX and
1862 // the dependent module is not in the same APEX.
Jooyung Han0c4e0162020-02-26 22:45:42 +09001863 if version == "" && versionVariantAvail {
1864 for _, ver := range stubsVersionsFor(actx.Config())[name] {
1865 // Note that depTag.ExplicitlyVersioned is false in this case.
1866 actx.AddVariationDependencies([]blueprint.Variation{
1867 {Mutator: "link", Variation: "shared"},
1868 {Mutator: "version", Variation: ver},
1869 }, depTag, name)
1870 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001871 }
1872 }
1873
Jiyong Park7ed9de32018-10-15 22:25:07 +09001874 // shared lib names without the #version suffix
1875 var sharedLibNames []string
1876
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001877 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001878 depTag := SharedDepTag
Jiyong Parkd7536ba2020-01-16 17:14:23 +09001879 if c.static() {
1880 depTag = SharedFromStaticDepTag
1881 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001882 if inList(lib, deps.ReexportSharedLibHeaders) {
1883 depTag = sharedExportDepTag
1884 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001885
1886 if impl, ok := syspropImplLibraries[lib]; ok {
1887 lib = impl
1888 }
1889
Jiyong Park73c54ee2019-10-22 20:31:18 +09001890 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001891 sharedLibNames = append(sharedLibNames, name)
1892
Jiyong Park25fc6a92018-11-18 18:02:45 +09001893 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001894 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001895
Jiyong Park7ed9de32018-10-15 22:25:07 +09001896 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001897 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001898 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1899 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1900 // linking against both the stubs lib and the non-stubs lib at the same time.
1901 continue
1902 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001903 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001904 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001905
Dan Willemsen59339a22018-07-22 21:18:45 -07001906 actx.AddVariationDependencies([]blueprint.Variation{
1907 {Mutator: "link", Variation: "shared"},
1908 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001909
Colin Cross68861832016-07-08 10:41:41 -07001910 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001911
1912 for _, gen := range deps.GeneratedHeaders {
1913 depTag := genHeaderDepTag
1914 if inList(gen, deps.ReexportGeneratedHeaders) {
1915 depTag = genHeaderExportDepTag
1916 }
1917 actx.AddDependency(c, depTag, gen)
1918 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001919
Colin Cross42d48b72018-08-29 14:10:52 -07001920 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001921
1922 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001923 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001924 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001925 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001926 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001927 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001928 if deps.LinkerFlagsFile != "" {
1929 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1930 }
1931 if deps.DynamicLinker != "" {
1932 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001933 }
Dan Albert914449f2016-06-17 16:45:24 -07001934
1935 version := ctx.sdkVersion()
1936 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001937 {Mutator: "ndk_api", Variation: version},
1938 {Mutator: "link", Variation: "shared"},
1939 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001940 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001941 {Mutator: "ndk_api", Variation: version},
1942 {Mutator: "link", Variation: "shared"},
1943 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001944
1945 if vndkdep := c.vndkdep; vndkdep != nil {
1946 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08001947 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08001948 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07001949 {Mutator: "link", Variation: "shared"},
1950 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001951 }
1952 }
Colin Cross6362e272015-10-29 15:25:03 -07001953}
Colin Cross21b9a242015-03-24 14:15:58 -07001954
Colin Crosse40b4ea2018-10-02 22:25:58 -07001955func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001956 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1957 c.beginMutator(ctx)
1958 }
1959}
1960
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001961// Whether a module can link to another module, taking into
1962// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07001963func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
1964 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001965 // Host code is not restricted
1966 return
1967 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001968
1969 // VNDK is cc.Module supported only for now.
1970 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001971 // Though vendor code is limited by the vendor mutator,
1972 // each vendor-available module needs to check
1973 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07001974 if ccTo, ok := to.(*Module); ok {
1975 if ccFrom.vndkdep != nil {
1976 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
1977 }
1978 } else {
1979 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001980 }
1981 return
1982 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001983 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001984 // Platform code can link to anything
1985 return
1986 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08001987 if from.InRamdisk() {
1988 // Ramdisk code is not NDK
1989 return
1990 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001991 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09001992 // Recovery code is not NDK
1993 return
1994 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001995 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001996 // These are always allowed
1997 return
1998 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001999 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002000 // These are allowed, but they don't set sdk_version
2001 return
2002 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002003 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002004 // These aren't real libraries, but are the stub shared libraries that are included in
2005 // the NDK.
2006 return
2007 }
Logan Chien834b9a62019-01-14 15:39:03 +08002008
Ivan Lozano52767be2019-10-18 14:49:46 -07002009 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002010 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2011 // to link to libc++ (non-NDK and without sdk_version).
2012 return
2013 }
2014
Ivan Lozano52767be2019-10-18 14:49:46 -07002015 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002016 // NDK code linking to platform code is never okay.
2017 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002018 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002019 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002020 }
2021
2022 // At this point we know we have two NDK libraries, but we need to
2023 // check that we're not linking against anything built against a higher
2024 // API level, as it is only valid to link against older or equivalent
2025 // APIs.
2026
Inseob Kim01a28722018-04-11 09:48:45 +09002027 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002028 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002029 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002030 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002031 // Current can't be linked against by anything else.
2032 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002033 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002034 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002035 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002036 if err != nil {
2037 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002038 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002039 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002040 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002041 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002042 if err != nil {
2043 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002044 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002045 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002046 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002047
Inseob Kim01a28722018-04-11 09:48:45 +09002048 if toApi > fromApi {
2049 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002050 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002051 }
2052 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002053 }
Dan Albert202fe492017-12-15 13:56:59 -08002054
2055 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002056 fromStl := from.SelectedStl()
2057 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002058 if fromStl == "" || toStl == "" {
2059 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002060 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002061 // We can be permissive with the system "STL" since it is only the C++
2062 // ABI layer, but in the future we should make sure that everyone is
2063 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002064 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002065 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002066 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2067 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002068 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002069}
2070
Jiyong Park5fb8c102018-04-09 12:03:06 +09002071// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002072// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2073// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002074// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002075func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2076 check := func(child, parent android.Module) bool {
2077 to, ok := child.(*Module)
2078 if !ok {
2079 // follow thru cc.Defaults, etc.
2080 return true
2081 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002082
Jooyung Hana70f0672019-01-18 15:20:43 +09002083 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2084 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002085 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002086
2087 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002088 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002089 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002090 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002091
Jooyung Han0302a842019-10-30 18:43:49 +09002092 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002093 return false
2094 }
2095
2096 var stringPath []string
2097 for _, m := range ctx.GetWalkPath() {
2098 stringPath = append(stringPath, m.Name())
2099 }
2100 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2101 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2102 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2103 return false
2104 }
2105 if module, ok := ctx.Module().(*Module); ok {
2106 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002107 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002108 ctx.WalkDeps(check)
2109 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002110 }
2111 }
2112}
2113
Colin Crossc99deeb2016-04-11 15:06:20 -07002114// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002115func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002116 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002117
Ivan Lozano183a3212019-10-18 14:18:45 -07002118 directStaticDeps := []LinkableInterface{}
2119 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002120
Inseob Kim9516ee92019-05-09 10:56:13 +09002121 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2122
Inseob Kim69378442019-06-03 19:10:47 +09002123 reexportExporter := func(exporter exportedFlagsProducer) {
2124 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2125 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2126 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2127 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002128 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002129 }
2130
Colin Crossd11fcda2017-10-23 17:59:01 -07002131 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002132 depName := ctx.OtherModuleName(dep)
2133 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002134
Ivan Lozano52767be2019-10-18 14:49:46 -07002135 ccDep, ok := dep.(LinkableInterface)
2136 if !ok {
2137
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002138 // handling for a few module types that aren't cc Module but that are also supported
2139 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002140 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002141 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002142 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2143 genRule.GeneratedSourceFiles()...)
2144 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002145 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002146 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002147 // Support exported headers from a generated_sources dependency
2148 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002149 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002150 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002151 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Inseob Kimd110f872019-12-06 13:15:38 +09002152 genRule.GeneratedSourceFiles()...)
2153 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002154 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002155 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002156 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002157 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002158 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002159 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2160 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002161 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002162 // 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 +09002163 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002164
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002165 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002166 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002167 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002168 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002169 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002170 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002171 files := genRule.GeneratedSourceFiles()
2172 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002173 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002174 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002175 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 -07002176 }
2177 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002178 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002179 }
Colin Crossca860ac2016-01-04 14:34:37 -08002180 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002181 return
2182 }
2183
Colin Crossfe17f6f2019-03-28 19:30:56 -07002184 if depTag == android.ProtoPluginDepTag {
2185 return
2186 }
Jooyung Han67a96cd2020-03-13 15:23:36 +09002187 if depTag == llndkImplDep {
2188 return
2189 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002190
Colin Crossd11fcda2017-10-23 17:59:01 -07002191 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002192 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2193 return
2194 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002195 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han67a96cd2020-03-13 15:23:36 +09002196 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2197 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002198 return
2199 }
2200
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002201 // re-exporting flags
2202 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002203 // reusing objects only make sense for cc.Modules.
2204 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002205 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002206 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002207 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002208 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002209 return
2210 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002211 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002212
Jiyong Parke4bb9862019-02-01 00:31:10 +09002213 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002214 // staticVariants are a cc.Module specific concept.
2215 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002216 c.staticVariant = ccDep
2217 return
2218 }
2219 }
2220
Jooyung Han74066602020-03-20 04:29:24 +09002221 // For the dependency from platform to apex, use the latest stubs
2222 c.apexSdkVersion = android.FutureApiLevel
2223 if !c.IsForPlatform() {
2224 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion
2225 }
2226
2227 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2228 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2229 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2230 // (b/144430859)
2231 c.apexSdkVersion = android.FutureApiLevel
2232 }
2233
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002234 if depTag == staticUnwinderDepTag {
Jooyung Han74066602020-03-20 04:29:24 +09002235 // Use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
2236 if c.apexSdkVersion <= android.SdkVersion_Android10 {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002237 depTag = StaticDepTag
2238 } else {
2239 return
2240 }
2241 }
2242
Ivan Lozano183a3212019-10-18 14:18:45 -07002243 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
2244 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
2245 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002246 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07002247 if t, ok := depTag.(DependencyTag); ok {
2248 explicitlyVersioned = t.ExplicitlyVersioned
2249 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002250 depTag = t
2251 }
2252
Ivan Lozano183a3212019-10-18 14:18:45 -07002253 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002254 depIsStatic := false
2255 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002256 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002257 depIsStatic = true
2258 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002259 if ccDep.CcLibrary() && !depIsStatic {
2260 depIsStubs := ccDep.BuildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09002261 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002262 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002263 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002264
2265 var useThisDep bool
2266 if depIsStubs && explicitlyVersioned {
2267 // Always respect dependency to the versioned stubs (i.e. libX#10)
2268 useThisDep = true
2269 } else if !depHasStubs {
2270 // Use non-stub variant if that is the only choice
2271 // (i.e. depending on a lib without stubs.version property)
2272 useThisDep = true
2273 } else if c.IsForPlatform() {
2274 // If not building for APEX, use stubs only when it is from
2275 // an APEX (and not from platform)
2276 useThisDep = (depInPlatform != depIsStubs)
Yifan Hong1b3348d2020-01-21 15:53:22 -08002277 if c.InRamdisk() || c.InRecovery() || c.bootstrap() {
2278 // However, for ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002279 // always link to non-stub variant
2280 useThisDep = !depIsStubs
2281 }
2282 } else {
2283 // If building for APEX, use stubs only when it is not from
2284 // the same APEX
2285 useThisDep = (depInSameApex != depIsStubs)
2286 }
2287
Jooyung Han0c4e0162020-02-26 22:45:42 +09002288 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
2289 if useThisDep && depIsStubs && !explicitlyVersioned {
Jooyung Han74066602020-03-20 04:29:24 +09002290 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), c.apexSdkVersion)
Jooyung Han0c4e0162020-02-26 22:45:42 +09002291 if err != nil {
2292 ctx.OtherModuleErrorf(dep, err.Error())
2293 return
2294 }
2295 if versionToUse != ccDep.StubsVersion() {
2296 useThisDep = false
2297 }
2298 }
2299
Jiyong Park25fc6a92018-11-18 18:02:45 +09002300 if !useThisDep {
2301 return // stop processing this dep
2302 }
2303 }
Jooyung Han67a96cd2020-03-13 15:23:36 +09002304 if c.UseVndk() {
2305 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2306 // by default, use current version of LLNDK
2307 versionToUse := ""
2308 versions := stubsVersionsFor(ctx.Config())[depName]
2309 if c.ApexName() != "" && len(versions) > 0 {
2310 // if this is for use_vendor apex && dep has stubsVersions
2311 // apply the same rule of apex sdk enforcement to choose right version
2312 var err error
Jooyung Han74066602020-03-20 04:29:24 +09002313 versionToUse, err = c.ChooseSdkVersion(versions, c.apexSdkVersion)
Jooyung Han67a96cd2020-03-13 15:23:36 +09002314 if err != nil {
2315 ctx.OtherModuleErrorf(dep, err.Error())
2316 return
2317 }
2318 }
2319 if versionToUse != ccDep.StubsVersion() {
2320 return
2321 }
2322 }
2323 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002324
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002325 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2326
Ivan Lozano52767be2019-10-18 14:49:46 -07002327 // Exporting flags only makes sense for cc.Modules
2328 if _, ok := ccDep.(*Module); ok {
2329 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002330 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002331 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedGeneratedHeaders()...)
2332 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002333 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002334
Ivan Lozano52767be2019-10-18 14:49:46 -07002335 if t.ReexportFlags {
2336 reexportExporter(i)
2337 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2338 // Re-exported shared library headers must be included as well since they can help us with type information
2339 // about template instantiations (instantiated from their headers).
2340 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2341 // scripts.
2342 c.sabi.Properties.ReexportedIncludes = append(
2343 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2344 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002345 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002346 }
Logan Chienf3511742017-10-31 18:04:35 +08002347 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002348 }
2349
Colin Cross26c34ed2016-09-30 17:10:16 -07002350 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002351 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002352
Ivan Lozano52767be2019-10-18 14:49:46 -07002353 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002354 depFile := android.OptionalPath{}
2355
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002356 switch depTag {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002357 case ndkStubDepTag, SharedDepTag, SharedFromStaticDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002358 ptr = &depPaths.SharedLibs
2359 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002360 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002361 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002362
Jiyong Park64a44f22019-01-18 14:37:08 +09002363 case earlySharedDepTag:
2364 ptr = &depPaths.EarlySharedLibs
2365 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002366 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002367 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002368 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002369 ptr = &depPaths.LateSharedLibs
2370 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002371 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002372 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002373 ptr = nil
2374 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002375 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002376 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002377 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002378 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002379 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002380 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002381 return
2382 }
2383
Ivan Lozano52767be2019-10-18 14:49:46 -07002384 // Because the static library objects are included, this only makes sense
2385 // in the context of proper cc.Modules.
2386 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2387 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2388 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2389 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2390 for i := range missingDeps {
2391 missingDeps[i] += postfix
2392 }
2393 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002394 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002395 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2396 } else {
2397 ctx.ModuleErrorf(
2398 "non-cc.Modules cannot be included as whole static libraries.", depName)
2399 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002400 }
Colin Cross5950f382016-12-13 12:50:57 -08002401 case headerDepTag:
2402 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002403 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002404 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002405 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002406 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002407 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002408 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002409 case dynamicLinkerDepTag:
2410 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002411 }
2412
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002413 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002414 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002415 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002416 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002417 return
2418 }
2419
2420 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002421 // in static libraries act as if they were whole static libraries. The same goes for
2422 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002423 // This should only be done for cc.Modules
2424 if c, ok := ccDep.(*Module); ok {
2425 staticLib := c.linker.(libraryInterface)
2426 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2427 staticLib.objs().coverageFiles...)
2428 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2429 staticLib.objs().sAbiDumpFiles...)
2430 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002431 }
2432
Colin Cross26c34ed2016-09-30 17:10:16 -07002433 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002434 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002435 if !ctx.Config().AllowMissingDependencies() {
2436 ctx.ModuleErrorf("module %q missing output file", depName)
2437 } else {
2438 ctx.AddMissingDependencies([]string{depName})
2439 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002440 return
2441 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002442 *ptr = append(*ptr, linkFile.Path())
2443 }
2444
Colin Crossc99deeb2016-04-11 15:06:20 -07002445 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002446 dep := depFile
2447 if !dep.Valid() {
2448 dep = linkFile
2449 }
2450 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002451 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002452
Inseob Kimeec88e12020-01-22 11:11:29 +09002453 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2454
2455 baseLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002456 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002457 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002458 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kimeec88e12020-01-22 11:11:29 +09002459 return libName
2460 }
2461
2462 makeLibName := func(depName string) string {
2463 libName := baseLibName(depName)
Jooyung Han0302a842019-10-30 18:43:49 +09002464 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002465 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002466 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002467
Inseob Kimeec88e12020-01-22 11:11:29 +09002468 if c, ok := ccDep.(*Module); ok {
2469 // Use base module name for snapshots when exporting to Makefile.
Inseob Kim7ac1fa72020-03-14 01:30:34 +09002470 if c.isSnapshotPrebuilt() {
Inseob Kimeec88e12020-01-22 11:11:29 +09002471 baseName := c.BaseModuleName()
Inseob Kim7ac1fa72020-03-14 01:30:34 +09002472
2473 if c.IsVndk() {
2474 return baseName + ".vendor"
2475 }
2476
Inseob Kimeec88e12020-01-22 11:11:29 +09002477 if vendorSuffixModules[baseName] {
2478 return baseName + ".vendor"
2479 } else {
2480 return baseName
2481 }
2482 }
2483 }
2484
Yifan Hong1b3348d2020-01-21 15:53:22 -08002485 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002486 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2487 // core module instead.
2488 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002489 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002490 // The vendor module in Make will have been renamed to not conflict with the core
2491 // module, so update the dependency name here accordingly.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002492 return libName + c.getNameSuffixWithVndkVersion(ctx)
Jiyong Park374510b2018-03-19 18:23:01 +09002493 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002494 return libName + vendorPublicLibrarySuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08002495 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2496 return libName + ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002497 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002498 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002499 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002500 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002501 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002502 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002503 }
Logan Chien43d34c32017-12-20 01:17:32 +08002504 }
2505
2506 // Export the shared libs to Make.
2507 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002508 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002509 if ccDep.CcLibrary() {
2510 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002511 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002512 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002513 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002514 c.Properties.ApexesProvidingSharedLibs = append(
2515 c.Properties.ApexesProvidingSharedLibs, an)
2516 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002517 }
2518 }
2519
Jiyong Park27b188b2017-07-18 13:23:39 +09002520 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002521 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002522 c.Properties.AndroidMkSharedLibs = append(
2523 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002524 // Record baseLibName for snapshots.
2525 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002526 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002527 c.Properties.AndroidMkSharedLibs = append(
2528 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002529 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002530 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002531 c.Properties.AndroidMkStaticLibs = append(
2532 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002533 case runtimeDepTag:
2534 c.Properties.AndroidMkRuntimeLibs = append(
2535 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002536 // Record baseLibName for snapshots.
2537 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002538 case wholeStaticDepTag:
2539 c.Properties.AndroidMkWholeStaticLibs = append(
2540 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002541 }
Colin Crossca860ac2016-01-04 14:34:37 -08002542 })
2543
Jeff Gaston294356f2017-09-27 17:05:30 -07002544 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002545 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002546
Colin Crossdd84e052017-05-17 13:44:16 -07002547 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002548 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002549 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2550 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002551 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kimd110f872019-12-06 13:15:38 +09002552 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002553 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2554 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002555 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002556 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002557 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002558
2559 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002560 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002561 }
Colin Crossdd84e052017-05-17 13:44:16 -07002562
Colin Crossca860ac2016-01-04 14:34:37 -08002563 return depPaths
2564}
2565
2566func (c *Module) InstallInData() bool {
2567 if c.installer == nil {
2568 return false
2569 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002570 return c.installer.inData()
2571}
2572
2573func (c *Module) InstallInSanitizerDir() bool {
2574 if c.installer == nil {
2575 return false
2576 }
2577 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002578 return true
2579 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002580 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002581}
2582
Yifan Hong1b3348d2020-01-21 15:53:22 -08002583func (c *Module) InstallInRamdisk() bool {
2584 return c.InRamdisk()
2585}
2586
Jiyong Parkf9332f12018-02-01 00:54:12 +09002587func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002588 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002589}
2590
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002591func (c *Module) HostToolPath() android.OptionalPath {
2592 if c.installer == nil {
2593 return android.OptionalPath{}
2594 }
2595 return c.installer.hostToolPath()
2596}
2597
Nan Zhangd4e641b2017-07-12 12:55:28 -07002598func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2599 return c.outputFile
2600}
2601
Colin Cross41955e82019-05-29 14:40:35 -07002602func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2603 switch tag {
2604 case "":
2605 if c.outputFile.Valid() {
2606 return android.Paths{c.outputFile.Path()}, nil
2607 }
2608 return android.Paths{}, nil
2609 default:
2610 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002611 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002612}
2613
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002614func (c *Module) static() bool {
2615 if static, ok := c.linker.(interface {
2616 static() bool
2617 }); ok {
2618 return static.static()
2619 }
2620 return false
2621}
2622
Jiyong Park379de2f2018-12-19 02:47:14 +09002623func (c *Module) staticBinary() bool {
2624 if static, ok := c.linker.(interface {
2625 staticBinary() bool
2626 }); ok {
2627 return static.staticBinary()
2628 }
2629 return false
2630}
2631
Jiyong Park1d1119f2019-07-29 21:27:18 +09002632func (c *Module) header() bool {
2633 if h, ok := c.linker.(interface {
2634 header() bool
2635 }); ok {
2636 return h.header()
2637 }
2638 return false
2639}
2640
Jooyung Han38002912019-05-16 04:01:54 +09002641func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002642 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002643 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2644 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002645 return "native:vndk"
2646 }
Jooyung Han38002912019-05-16 04:01:54 +09002647 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002648 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002649 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002650 if Bool(c.VendorProperties.Vendor_available) {
2651 return "native:vndk"
2652 }
2653 return "native:vndk_private"
2654 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002655 if c.inProduct() {
2656 return "native:product"
2657 }
Jooyung Han38002912019-05-16 04:01:54 +09002658 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002659 } else if c.InRamdisk() {
2660 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002661 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002662 return "native:recovery"
2663 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2664 return "native:ndk:none:none"
2665 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2666 //family, link := getNdkStlFamilyAndLinkType(c)
2667 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002668 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002669 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002670 } else {
2671 return "native:platform"
2672 }
2673}
2674
Jiyong Park9d452992018-10-03 00:38:19 +09002675// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002676// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002677func (c *Module) IsInstallableToApex() bool {
2678 if shared, ok := c.linker.(interface {
2679 shared() bool
2680 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002681 // Stub libs and prebuilt libs in a versioned SDK are not
2682 // installable to APEX even though they are shared libs.
2683 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002684 } else if _, ok := c.linker.(testPerSrc); ok {
2685 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002686 }
2687 return false
2688}
2689
Jiyong Parka90ca002019-10-07 15:47:24 +09002690func (c *Module) AvailableFor(what string) bool {
2691 if linker, ok := c.linker.(interface {
2692 availableFor(string) bool
2693 }); ok {
2694 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2695 } else {
2696 return c.ApexModuleBase.AvailableFor(what)
2697 }
2698}
2699
Inseob Kim1f086e22019-05-09 13:29:15 +09002700func (c *Module) installable() bool {
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002701 ret := c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid()
2702
2703 // The platform variant doesn't need further condition. Apex variants however might not
2704 // be installable because it will likely to be included in the APEX and won't appear
2705 // in the system partition.
2706 if c.IsForPlatform() {
2707 return ret
2708 }
2709
2710 // Special case for modules that are configured to be installed to /data, which includes
2711 // test modules. For these modules, both APEX and non-APEX variants are considered as
2712 // installable. This is because even the APEX variants won't be included in the APEX, but
2713 // will anyway be installed to /data/*.
2714 // See b/146995717
2715 if c.InstallInData() {
2716 return ret
2717 }
2718
2719 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002720}
2721
Logan Chien41eabe62019-04-10 13:33:58 +08002722func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2723 if c.linker != nil {
2724 if library, ok := c.linker.(*libraryDecorator); ok {
2725 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2726 }
2727 }
2728}
2729
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002730func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002731 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002732 if cc, ok := dep.(*Module); ok {
Jiyong Park9f14b9b2020-03-01 17:29:06 +09002733 if cc.HasStubsVariants() {
2734 if depTag.Shared && depTag.Library {
2735 // dynamic dep to a stubs lib crosses APEX boundary
2736 return false
2737 }
2738 if IsRuntimeDepTag(depTag) {
2739 // runtime dep to a stubs lib also crosses APEX boundary
2740 return false
2741 }
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002742 }
2743 if depTag.FromStatic {
2744 // shared_lib dependency from a static lib is considered as crossing
2745 // the APEX boundary because the dependency doesn't actually is
2746 // linked; the dependency is used only during the compilation phase.
2747 return false
2748 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002749 }
2750 }
2751 return true
2752}
2753
Colin Cross2ba19d92015-05-07 15:44:20 -07002754//
Colin Crosscfad1192015-11-02 16:43:11 -08002755// Defaults
2756//
Colin Crossca860ac2016-01-04 14:34:37 -08002757type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002758 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002759 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002760 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002761}
2762
Patrice Arrudac249c712019-03-19 17:00:29 -07002763// cc_defaults provides a set of properties that can be inherited by other cc
2764// modules. A module can use the properties from a cc_defaults using
2765// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2766// merged (when possible) by prepending the default module's values to the
2767// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002768func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002769 return DefaultsFactory()
2770}
2771
Colin Cross36242852017-06-23 15:06:31 -07002772func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002773 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002774
Colin Cross36242852017-06-23 15:06:31 -07002775 module.AddProperties(props...)
2776 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002777 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002778 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002779 &BaseCompilerProperties{},
2780 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002781 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002782 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002783 &StaticProperties{},
2784 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002785 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002786 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002787 &TestProperties{},
2788 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002789 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002790 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002791 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002792 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002793 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002794 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002795 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002796 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002797 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002798 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002799 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002800 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002801 )
Colin Crosscfad1192015-11-02 16:43:11 -08002802
Jooyung Hancc372c52019-09-25 15:18:44 +09002803 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002804
2805 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002806}
2807
Jiyong Park6a43f042017-10-12 23:05:00 +09002808func squashVendorSrcs(m *Module) {
2809 if lib, ok := m.compiler.(*libraryDecorator); ok {
2810 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2811 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2812
2813 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2814 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2815 }
2816}
2817
Jiyong Parkf9332f12018-02-01 00:54:12 +09002818func squashRecoverySrcs(m *Module) {
2819 if lib, ok := m.compiler.(*libraryDecorator); ok {
2820 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2821 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2822
2823 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2824 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2825 }
2826}
2827
Colin Cross7228ecd2019-11-18 16:00:16 -08002828var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002829
Colin Cross7228ecd2019-11-18 16:00:16 -08002830func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002831 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002832 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002833 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002834
2835 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002836 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002837 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002838 }
Logan Chienf3511742017-10-31 18:04:35 +08002839
2840 if vndkdep := m.vndkdep; vndkdep != nil {
2841 if vndkdep.isVndk() {
Justin Yun98df0d12020-02-28 15:07:59 +09002842 if vendorSpecific || productSpecific {
Logan Chienf3511742017-10-31 18:04:35 +08002843 if !vndkdep.isVndkExt() {
2844 mctx.PropertyErrorf("vndk",
2845 "must set `extends: \"...\"` to vndk extension")
Justin Yun98df0d12020-02-28 15:07:59 +09002846 } else if m.VendorProperties.Vendor_available != nil {
2847 mctx.PropertyErrorf("vendor_available",
2848 "must not set at the same time as `vndk: {extends: \"...\"}`")
Logan Chienf3511742017-10-31 18:04:35 +08002849 }
2850 } else {
2851 if vndkdep.isVndkExt() {
2852 mctx.PropertyErrorf("vndk",
Justin Yun98df0d12020-02-28 15:07:59 +09002853 "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
Logan Chienf3511742017-10-31 18:04:35 +08002854 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002855 }
2856 if m.VendorProperties.Vendor_available == nil {
2857 mctx.PropertyErrorf("vndk",
2858 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08002859 }
2860 }
2861 } else {
2862 if vndkdep.isVndkSp() {
2863 mctx.PropertyErrorf("vndk",
2864 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08002865 }
2866 if vndkdep.isVndkExt() {
2867 mctx.PropertyErrorf("vndk",
2868 "must set `enabled: true` to set `extends: %q`",
2869 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002870 }
Justin Yun8effde42017-06-23 19:24:43 +09002871 }
2872 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002873
Jiyong Parkf9332f12018-02-01 00:54:12 +09002874 var coreVariantNeeded bool = false
Yifan Hong1b3348d2020-01-21 15:53:22 -08002875 var ramdiskVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002876 var recoveryVariantNeeded bool = false
2877
Inseob Kim64c43952019-08-26 16:52:35 +09002878 var vendorVariants []string
Justin Yun5f7f7e82019-11-18 19:52:14 +09002879 var productVariants []string
Inseob Kim64c43952019-08-26 16:52:35 +09002880
2881 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09002882 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
2883 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
2884 if boardVndkVersion == "current" {
2885 boardVndkVersion = platformVndkVersion
2886 }
2887 if productVndkVersion == "current" {
2888 productVndkVersion = platformVndkVersion
Inseob Kim64c43952019-08-26 16:52:35 +09002889 }
2890
Justin Yun5f7f7e82019-11-18 19:52:14 +09002891 if boardVndkVersion == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002892 // If the device isn't compiling against the VNDK, we always
2893 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002894 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002895 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002896 // LL-NDK stubs only exist in the vendor and product variants,
2897 // since the real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002898 vendorVariants = append(vendorVariants,
2899 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002900 boardVndkVersion,
2901 )
2902 productVariants = append(productVariants,
2903 platformVndkVersion,
2904 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002905 )
Jiyong Park2a454122017-10-19 15:59:33 +09002906 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2907 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002908 vendorVariants = append(vendorVariants,
2909 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002910 boardVndkVersion,
2911 )
2912 productVariants = append(productVariants,
2913 platformVndkVersion,
2914 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002915 )
Inseob Kimeec88e12020-01-22 11:11:29 +09002916 } else if m.isSnapshotPrebuilt() {
Justin Yun71549282017-11-17 12:10:28 +09002917 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2918 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kimeec88e12020-01-22 11:11:29 +09002919 if snapshot, ok := m.linker.(interface {
2920 version() string
2921 }); ok {
2922 vendorVariants = append(vendorVariants, snapshot.version())
2923 } else {
2924 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
2925 }
Justin Yun98df0d12020-02-28 15:07:59 +09002926 } else if m.HasVendorVariant() && !m.isVndkExt() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002927 // This will be available in /system, /vendor and /product
2928 // or a /system directory that is available to vendor and product.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002929 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002930 vendorVariants = append(vendorVariants, platformVndkVersion)
Justin Yun5f7f7e82019-11-18 19:52:14 +09002931 productVariants = append(productVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09002932 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
2933 // code is PLATFORM_VNDK_VERSION.
2934 // On the other hand, vendor_available modules which are not VNDK should
2935 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002936 // vendor_available modules are also available to /product.
Inseob Kimbc093672019-11-01 11:29:44 +09002937 if !m.IsVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002938 vendorVariants = append(vendorVariants, boardVndkVersion)
2939 productVariants = append(productVariants, productVndkVersion)
Inseob Kim64c43952019-08-26 16:52:35 +09002940 }
Logan Chienf3511742017-10-31 18:04:35 +08002941 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002942 // This will be available in /vendor (or /odm) only
Justin Yun5f7f7e82019-11-18 19:52:14 +09002943 vendorVariants = append(vendorVariants, boardVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002944 } else {
2945 // This is either in /system (or similar: /data), or is a
2946 // modules built with the NDK. Modules built with the NDK
2947 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002948 coreVariantNeeded = true
2949 }
2950
Justin Yun5f7f7e82019-11-18 19:52:14 +09002951 if boardVndkVersion != "" && productVndkVersion != "" {
2952 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
2953 // The module has "product_specific: true" that does not create core variant.
2954 coreVariantNeeded = false
2955 productVariants = append(productVariants, productVndkVersion)
2956 }
2957 } else {
2958 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
2959 // restriction to use system libs.
2960 // No product variants defined in this case.
2961 productVariants = []string{}
2962 }
2963
Yifan Hong1b3348d2020-01-21 15:53:22 -08002964 if Bool(m.Properties.Ramdisk_available) {
2965 ramdiskVariantNeeded = true
2966 }
2967
2968 if m.ModuleBase.InstallInRamdisk() {
2969 ramdiskVariantNeeded = true
2970 coreVariantNeeded = false
2971 }
2972
Jiyong Parkf9332f12018-02-01 00:54:12 +09002973 if Bool(m.Properties.Recovery_available) {
2974 recoveryVariantNeeded = true
2975 }
2976
2977 if m.ModuleBase.InstallInRecovery() {
2978 recoveryVariantNeeded = true
2979 coreVariantNeeded = false
2980 }
2981
Inseob Kim64c43952019-08-26 16:52:35 +09002982 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002983 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
2984 }
2985
2986 for _, variant := range android.FirstUniqueStrings(productVariants) {
2987 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09002988 }
Colin Cross7228ecd2019-11-18 16:00:16 -08002989
Yifan Hong1b3348d2020-01-21 15:53:22 -08002990 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Colin Cross7228ecd2019-11-18 16:00:16 -08002991 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
2992 m.Properties.CoreVariantNeeded = coreVariantNeeded
2993}
2994
2995func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
2996 return c.Properties.CoreVariantNeeded
2997}
2998
Yifan Hong1b3348d2020-01-21 15:53:22 -08002999func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
3000 return c.Properties.RamdiskVariantNeeded
3001}
3002
Colin Cross7228ecd2019-11-18 16:00:16 -08003003func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
3004 return c.Properties.RecoveryVariantNeeded
3005}
3006
3007func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003008 return c.Properties.ExtraVariants
Colin Cross7228ecd2019-11-18 16:00:16 -08003009}
3010
3011func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
3012 m := module.(*Module)
Yifan Hong1b3348d2020-01-21 15:53:22 -08003013 if variant == android.RamdiskVariation {
3014 m.MakeAsPlatform()
3015 } else if variant == android.RecoveryVariation {
Colin Cross7228ecd2019-11-18 16:00:16 -08003016 m.MakeAsPlatform()
3017 squashRecoverySrcs(m)
3018 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003019 m.Properties.ImageVariationPrefix = VendorVariationPrefix
Colin Cross7228ecd2019-11-18 16:00:16 -08003020 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
3021 squashVendorSrcs(m)
Inseob Kimeec88e12020-01-22 11:11:29 +09003022
3023 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
3024 // Hide other vendor variants to avoid collision.
3025 vndkVersion := ctx.DeviceConfig().VndkVersion()
3026 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
3027 m.Properties.HideFromMake = true
3028 m.SkipInstall()
3029 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09003030 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
3031 m.Properties.ImageVariationPrefix = ProductVariationPrefix
3032 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
3033 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003034 }
3035}
3036
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003037func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08003038 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003039 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
3040 }
Colin Cross6510f912017-11-29 00:27:14 -08003041 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003042}
3043
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003044func kytheExtractAllFactory() android.Singleton {
3045 return &kytheExtractAllSingleton{}
3046}
3047
3048type kytheExtractAllSingleton struct {
3049}
3050
3051func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3052 var xrefTargets android.Paths
3053 ctx.VisitAllModules(func(module android.Module) {
3054 if ccModule, ok := module.(xref); ok {
3055 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3056 }
3057 })
3058 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3059 if len(xrefTargets) > 0 {
3060 ctx.Build(pctx, android.BuildParams{
3061 Rule: blueprint.Phony,
3062 Output: android.PathForPhony(ctx, "xref_cxx"),
3063 Inputs: xrefTargets,
3064 //Default: true,
3065 })
3066 }
3067}
3068
Colin Cross06a931b2015-10-28 17:23:31 -07003069var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003070var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003071var BoolPtr = proptools.BoolPtr
3072var String = proptools.String
3073var StringPtr = proptools.StringPtr