blob: 62e861f3012a50a08a7f728a76594e2df896346e [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
Colin Crossc472d572015-03-17 15:06:21 -0700479}
480
Ivan Lozano52767be2019-10-18 14:49:46 -0700481func (c *Module) Toc() android.OptionalPath {
482 if c.linker != nil {
483 if library, ok := c.linker.(libraryInterface); ok {
484 return library.toc()
485 }
486 }
487 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
488}
489
490func (c *Module) ApiLevel() string {
491 if c.linker != nil {
492 if stub, ok := c.linker.(*stubDecorator); ok {
493 return stub.properties.ApiLevel
494 }
495 }
496 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
497}
498
499func (c *Module) Static() bool {
500 if c.linker != nil {
501 if library, ok := c.linker.(libraryInterface); ok {
502 return library.static()
503 }
504 }
505 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
506}
507
508func (c *Module) Shared() bool {
509 if c.linker != nil {
510 if library, ok := c.linker.(libraryInterface); ok {
511 return library.shared()
512 }
513 }
514 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
515}
516
517func (c *Module) SelectedStl() string {
518 return c.stl.Properties.SelectedStl
519}
520
521func (c *Module) ToolchainLibrary() bool {
522 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
523 return true
524 }
525 return false
526}
527
528func (c *Module) NdkPrebuiltStl() bool {
529 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
530 return true
531 }
532 return false
533}
534
535func (c *Module) StubDecorator() bool {
536 if _, ok := c.linker.(*stubDecorator); ok {
537 return true
538 }
539 return false
540}
541
542func (c *Module) SdkVersion() string {
543 return String(c.Properties.Sdk_version)
544}
545
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800546func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700547 if c.linker != nil {
548 if library, ok := c.linker.(exportedFlagsProducer); ok {
549 return library.exportedDirs()
550 }
551 }
552 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
553}
554
555func (c *Module) HasStaticVariant() bool {
556 if c.staticVariant != nil {
557 return true
558 }
559 return false
560}
561
562func (c *Module) GetStaticVariant() LinkableInterface {
563 return c.staticVariant
564}
565
566func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
567 c.depsInLinkOrder = depsInLinkOrder
568}
569
570func (c *Module) GetDepsInLinkOrder() []android.Path {
571 return c.depsInLinkOrder
572}
573
574func (c *Module) StubsVersions() []string {
575 if c.linker != nil {
576 if library, ok := c.linker.(*libraryDecorator); ok {
577 return library.Properties.Stubs.Versions
578 }
579 }
580 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
581}
582
583func (c *Module) CcLibrary() bool {
584 if c.linker != nil {
585 if _, ok := c.linker.(*libraryDecorator); ok {
586 return true
587 }
588 }
589 return false
590}
591
592func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700593 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700594 return true
595 }
596 return false
597}
598
Ivan Lozano2b262972019-11-21 12:30:50 -0800599func (c *Module) NonCcVariants() bool {
600 return false
601}
602
Ivan Lozano183a3212019-10-18 14:18:45 -0700603func (c *Module) SetBuildStubs() {
604 if c.linker != nil {
605 if library, ok := c.linker.(*libraryDecorator); ok {
606 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700607 c.Properties.HideFromMake = true
608 c.sanitize = nil
609 c.stl = nil
610 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700611 return
612 }
Jooyung Han67a96cd2020-03-13 15:23:36 +0900613 if _, ok := c.linker.(*llndkStubDecorator); ok {
614 c.Properties.HideFromMake = true
615 return
616 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700617 }
618 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
619}
620
Ivan Lozano52767be2019-10-18 14:49:46 -0700621func (c *Module) BuildStubs() bool {
622 if c.linker != nil {
623 if library, ok := c.linker.(*libraryDecorator); ok {
624 return library.buildStubs()
625 }
626 }
627 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
628}
629
Ivan Lozano183a3212019-10-18 14:18:45 -0700630func (c *Module) SetStubsVersions(version string) {
631 if c.linker != nil {
632 if library, ok := c.linker.(*libraryDecorator); ok {
633 library.MutatedProperties.StubsVersion = version
634 return
635 }
Jooyung Han67a96cd2020-03-13 15:23:36 +0900636 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
637 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
638 return
639 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700640 }
641 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
642}
643
Jooyung Han0c4e0162020-02-26 22:45:42 +0900644func (c *Module) StubsVersion() string {
645 if c.linker != nil {
646 if library, ok := c.linker.(*libraryDecorator); ok {
647 return library.MutatedProperties.StubsVersion
648 }
Jooyung Han67a96cd2020-03-13 15:23:36 +0900649 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
650 return llndk.libraryDecorator.MutatedProperties.StubsVersion
651 }
Jooyung Han0c4e0162020-02-26 22:45:42 +0900652 }
653 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
654}
655
Ivan Lozano183a3212019-10-18 14:18:45 -0700656func (c *Module) SetStatic() {
657 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700658 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700659 library.setStatic()
660 return
661 }
662 }
663 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
664}
665
666func (c *Module) SetShared() {
667 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700668 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700669 library.setShared()
670 return
671 }
672 }
673 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
674}
675
676func (c *Module) BuildStaticVariant() bool {
677 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700678 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700679 return library.buildStatic()
680 }
681 }
682 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
683}
684
685func (c *Module) BuildSharedVariant() bool {
686 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700687 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700688 return library.buildShared()
689 }
690 }
691 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
692}
693
694func (c *Module) Module() android.Module {
695 return c
696}
697
Jiyong Parkc20eee32018-09-05 22:36:17 +0900698func (c *Module) OutputFile() android.OptionalPath {
699 return c.outputFile
700}
701
Ivan Lozano183a3212019-10-18 14:18:45 -0700702var _ LinkableInterface = (*Module)(nil)
703
Jiyong Park719b4462019-01-13 00:39:51 +0900704func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900705 if c.linker != nil {
706 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900707 }
708 return nil
709}
710
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900711func (c *Module) CoverageOutputFile() android.OptionalPath {
712 if c.linker != nil {
713 return c.linker.coverageOutputFilePath()
714 }
715 return android.OptionalPath{}
716}
717
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900718func (c *Module) RelativeInstallPath() string {
719 if c.installer != nil {
720 return c.installer.relativeInstallPath()
721 }
722 return ""
723}
724
Jooyung Han344d5432019-08-23 11:17:39 +0900725func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900726 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900727}
728
Colin Cross36242852017-06-23 15:06:31 -0700729func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700730 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800731 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700732 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800733 }
734 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700735 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800736 }
737 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700738 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800739 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700740 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700741 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700742 }
Colin Cross16b23492016-01-06 14:41:07 -0800743 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700744 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800745 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800746 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700747 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800748 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800749 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700750 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800751 }
Justin Yun8effde42017-06-23 19:24:43 +0900752 if c.vndkdep != nil {
753 c.AddProperties(c.vndkdep.props()...)
754 }
Stephen Craneba090d12017-05-09 15:44:35 -0700755 if c.lto != nil {
756 c.AddProperties(c.lto.props()...)
757 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700758 if c.pgo != nil {
759 c.AddProperties(c.pgo.props()...)
760 }
Colin Crossca860ac2016-01-04 14:34:37 -0800761 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700762 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800763 }
Colin Crossc472d572015-03-17 15:06:21 -0700764
Colin Crossa9d8bee2018-10-02 13:59:46 -0700765 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
766 switch class {
767 case android.Device:
768 return ctx.Config().DevicePrefer32BitExecutables()
769 case android.HostCross:
770 // Windows builds always prefer 32-bit
771 return true
772 default:
773 return false
774 }
775 })
Colin Cross36242852017-06-23 15:06:31 -0700776 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900777 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900778 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900779 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900780
Colin Cross36242852017-06-23 15:06:31 -0700781 return c
Colin Crossc472d572015-03-17 15:06:21 -0700782}
783
Colin Crossb916a382016-07-29 17:28:03 -0700784// Returns true for dependency roots (binaries)
785// TODO(ccross): also handle dlopenable libraries
786func (c *Module) isDependencyRoot() bool {
787 if root, ok := c.linker.(interface {
788 isDependencyRoot() bool
789 }); ok {
790 return root.isDependencyRoot()
791 }
792 return false
793}
794
Justin Yun5f7f7e82019-11-18 19:52:14 +0900795// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
796// "product" and "vendor" variant modules return true for this function.
797// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
798// "soc_specific: true" and more vendor installed modules are included here.
799// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
800// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700801func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900802 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700803}
804
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800805func (c *Module) isCoverageVariant() bool {
806 return c.coverage.Properties.IsCoverageVariant
807}
808
Peter Collingbournead84f972019-12-17 16:46:18 -0800809func (c *Module) IsNdk() bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800810 return inList(c.Name(), ndkMigratedLibs)
811}
812
Inseob Kim9516ee92019-05-09 10:56:13 +0900813func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800814 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900815 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800816}
817
Inseob Kim9516ee92019-05-09 10:56:13 +0900818func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800819 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900820 name := c.BaseModuleName()
821 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800822}
823
Inseob Kim9516ee92019-05-09 10:56:13 +0900824func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800825 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900826 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800827}
828
Ivan Lozano52767be2019-10-18 14:49:46 -0700829func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800830 if vndkdep := c.vndkdep; vndkdep != nil {
831 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900832 }
833 return false
834}
835
Yi Kong7e53c572018-02-14 18:16:12 +0800836func (c *Module) isPgoCompile() bool {
837 if pgo := c.pgo; pgo != nil {
838 return pgo.Properties.PgoCompile
839 }
840 return false
841}
842
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800843func (c *Module) isNDKStubLibrary() bool {
844 if _, ok := c.compiler.(*stubDecorator); ok {
845 return true
846 }
847 return false
848}
849
Logan Chienf3511742017-10-31 18:04:35 +0800850func (c *Module) isVndkSp() bool {
851 if vndkdep := c.vndkdep; vndkdep != nil {
852 return vndkdep.isVndkSp()
853 }
854 return false
855}
856
857func (c *Module) isVndkExt() bool {
858 if vndkdep := c.vndkdep; vndkdep != nil {
859 return vndkdep.isVndkExt()
860 }
861 return false
862}
863
Ivan Lozano52767be2019-10-18 14:49:46 -0700864func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900865 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800866}
867
Logan Chienf3511742017-10-31 18:04:35 +0800868func (c *Module) getVndkExtendsModuleName() string {
869 if vndkdep := c.vndkdep; vndkdep != nil {
870 return vndkdep.getVndkExtendsModuleName()
871 }
872 return ""
873}
874
Justin Yun5f7f7e82019-11-18 19:52:14 +0900875// Returns true only when this module is configured to have core, product and vendor
Jiyong Park82e2bf32017-08-16 14:05:54 +0900876// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700877func (c *Module) HasVendorVariant() bool {
878 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900879}
880
Justin Yun5f7f7e82019-11-18 19:52:14 +0900881const (
882 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
883 // against the VNDK.
884 VendorVariationPrefix = "vendor."
885
886 // ProductVariationPrefix is the variant prefix used for /product code that compiles
887 // against the VNDK.
888 ProductVariationPrefix = "product."
889)
890
891// Returns true if the module is "product" variant. Usually these modules are installed in /product
892func (c *Module) inProduct() bool {
893 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
894}
895
896// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
897func (c *Module) inVendor() bool {
898 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
899}
900
Yifan Hong1b3348d2020-01-21 15:53:22 -0800901func (c *Module) InRamdisk() bool {
902 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
903}
904
Ivan Lozano52767be2019-10-18 14:49:46 -0700905func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800906 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900907}
908
Yifan Hong1b3348d2020-01-21 15:53:22 -0800909func (c *Module) OnlyInRamdisk() bool {
910 return c.ModuleBase.InstallInRamdisk()
911}
912
Ivan Lozano52767be2019-10-18 14:49:46 -0700913func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900914 return c.ModuleBase.InstallInRecovery()
915}
916
Jiyong Park25fc6a92018-11-18 18:02:45 +0900917func (c *Module) IsStubs() bool {
918 if library, ok := c.linker.(*libraryDecorator); ok {
919 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900920 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
921 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900922 }
923 return false
924}
925
926func (c *Module) HasStubsVariants() bool {
927 if library, ok := c.linker.(*libraryDecorator); ok {
928 return len(library.Properties.Stubs.Versions) > 0
929 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700930 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
931 return len(library.Properties.Stubs.Versions) > 0
932 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900933 return false
934}
935
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900936func (c *Module) bootstrap() bool {
937 return Bool(c.Properties.Bootstrap)
938}
939
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700940func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700941 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
942 if c.Target().NativeBridge == android.NativeBridgeEnabled {
943 return false
944 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700945 return c.linker != nil && c.linker.nativeCoverage()
946}
947
Inseob Kim8471cda2019-11-15 09:59:12 +0900948func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kimeec88e12020-01-22 11:11:29 +0900949 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
950 return true
951 }
952 if _, ok := c.linker.(*vendorSnapshotLibraryDecorator); ok {
953 return true
954 }
955 if _, ok := c.linker.(*vendorSnapshotBinaryDecorator); ok {
956 return true
957 }
958 return false
Inseob Kim8471cda2019-11-15 09:59:12 +0900959}
960
Jiyong Park73c54ee2019-10-22 20:31:18 +0900961func (c *Module) ExportedIncludeDirs() android.Paths {
962 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
963 return flagsProducer.exportedDirs()
964 }
Jiyong Park232e7852019-11-04 12:23:40 +0900965 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900966}
967
968func (c *Module) ExportedSystemIncludeDirs() android.Paths {
969 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
970 return flagsProducer.exportedSystemDirs()
971 }
Jiyong Park232e7852019-11-04 12:23:40 +0900972 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900973}
974
975func (c *Module) ExportedFlags() []string {
976 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
977 return flagsProducer.exportedFlags()
978 }
Jiyong Park232e7852019-11-04 12:23:40 +0900979 return nil
980}
981
982func (c *Module) ExportedDeps() android.Paths {
983 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
984 return flagsProducer.exportedDeps()
985 }
986 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900987}
988
Inseob Kimd110f872019-12-06 13:15:38 +0900989func (c *Module) ExportedGeneratedHeaders() android.Paths {
990 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
991 return flagsProducer.exportedGeneratedHeaders()
992 }
993 return nil
994}
995
Jiyong Parkf1194352019-02-25 11:05:47 +0900996func isBionic(name string) bool {
997 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +0000998 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +0900999 return true
1000 }
1001 return false
1002}
1003
Martin Stjernholm279de572019-09-10 23:18:20 +01001004func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001005 if name == "libclang_rt.hwasan-aarch64-android" {
1006 return inList("hwaddress", config.SanitizeDevice())
1007 }
1008 return isBionic(name)
1009}
1010
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001011func (c *Module) XrefCcFiles() android.Paths {
1012 return c.kytheFiles
1013}
1014
Colin Crossca860ac2016-01-04 14:34:37 -08001015type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001016 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001017 moduleContextImpl
1018}
1019
Colin Cross37047f12016-12-13 17:06:13 -08001020type depsContext struct {
1021 android.BottomUpMutatorContext
1022 moduleContextImpl
1023}
1024
Colin Crossca860ac2016-01-04 14:34:37 -08001025type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001026 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001027 moduleContextImpl
1028}
1029
Justin Yun5f7f7e82019-11-18 19:52:14 +09001030func (ctx *moduleContext) ProductSpecific() bool {
1031 return ctx.ModuleContext.ProductSpecific() ||
1032 (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
1033}
1034
Jiyong Park2db76922017-11-08 16:03:48 +09001035func (ctx *moduleContext) SocSpecific() bool {
1036 return ctx.ModuleContext.SocSpecific() ||
Justin Yun5f7f7e82019-11-18 19:52:14 +09001037 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001038}
1039
Colin Crossca860ac2016-01-04 14:34:37 -08001040type moduleContextImpl struct {
1041 mod *Module
1042 ctx BaseModuleContext
1043}
1044
Colin Crossb98c8b02016-07-29 13:44:28 -07001045func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001046 return ctx.mod.toolchain(ctx.ctx)
1047}
1048
1049func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001050 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001051}
1052
1053func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001054 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001055}
1056
Jiyong Park1d1119f2019-07-29 21:27:18 +09001057func (ctx *moduleContextImpl) header() bool {
1058 return ctx.mod.header()
1059}
1060
Jooyung Han61c41542020-03-07 03:45:53 +09001061func (ctx *moduleContextImpl) canUseSdk() bool {
1062 return ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRamdisk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia()
1063}
1064
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001065func (ctx *moduleContextImpl) useSdk() bool {
Jooyung Han61c41542020-03-07 03:45:53 +09001066 if ctx.canUseSdk() {
Nan Zhang0007d812017-11-07 10:57:05 -08001067 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -07001068 }
1069 return false
Colin Crossca860ac2016-01-04 14:34:37 -08001070}
1071
1072func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001073 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001074 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001075 vndkVer := ctx.mod.VndkVersion()
1076 if inList(vndkVer, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
1077 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001078 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001079 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001080 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001081 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001082 }
1083 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001084}
1085
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001086func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001087 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001088}
Justin Yun8effde42017-06-23 19:24:43 +09001089
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001090func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001091 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001092}
1093
Inseob Kim9516ee92019-05-09 10:56:13 +09001094func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1095 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001096}
1097
Inseob Kim9516ee92019-05-09 10:56:13 +09001098func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1099 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001100}
1101
Inseob Kim9516ee92019-05-09 10:56:13 +09001102func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1103 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001104}
1105
Logan Chienf3511742017-10-31 18:04:35 +08001106func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001107 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001108}
1109
Yi Kong7e53c572018-02-14 18:16:12 +08001110func (ctx *moduleContextImpl) isPgoCompile() bool {
1111 return ctx.mod.isPgoCompile()
1112}
1113
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001114func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1115 return ctx.mod.isNDKStubLibrary()
1116}
1117
Justin Yun8effde42017-06-23 19:24:43 +09001118func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001119 return ctx.mod.isVndkSp()
1120}
1121
1122func (ctx *moduleContextImpl) isVndkExt() bool {
1123 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001124}
1125
Vic Yangefd249e2018-11-12 20:19:56 -08001126func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001127 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001128}
1129
Justin Yun5f7f7e82019-11-18 19:52:14 +09001130func (ctx *moduleContextImpl) inProduct() bool {
1131 return ctx.mod.inProduct()
1132}
1133
1134func (ctx *moduleContextImpl) inVendor() bool {
1135 return ctx.mod.inVendor()
1136}
1137
Yifan Hong1b3348d2020-01-21 15:53:22 -08001138func (ctx *moduleContextImpl) inRamdisk() bool {
1139 return ctx.mod.InRamdisk()
1140}
1141
Jiyong Parkf9332f12018-02-01 00:54:12 +09001142func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001143 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001144}
1145
Logan Chien2f2b8902018-07-10 15:01:19 +08001146// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001147func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001148 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1149 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001150 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001151
1152 if ctx.ctx.Fuchsia() {
1153 return false
1154 }
1155
Logan Chien2f2b8902018-07-10 15:01:19 +08001156 if sanitize := ctx.mod.sanitize; sanitize != nil {
1157 if !sanitize.isVariantOnProductionDevice() {
1158 return false
1159 }
1160 }
1161 if !ctx.ctx.Device() {
1162 // Host modules do not need ABI dumps.
1163 return false
1164 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001165 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001166 // Stubs do not need ABI dumps.
1167 return false
1168 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001169 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001170}
1171
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001172func (ctx *moduleContextImpl) selectedStl() string {
1173 if stl := ctx.mod.stl; stl != nil {
1174 return stl.Properties.SelectedStl
1175 }
1176 return ""
1177}
1178
Ivan Lozanobd721262018-11-27 14:33:03 -08001179func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1180 return ctx.mod.linker.useClangLld(actx)
1181}
1182
Colin Crossce75d2c2016-10-06 16:12:58 -07001183func (ctx *moduleContextImpl) baseModuleName() string {
1184 return ctx.mod.ModuleBase.BaseModuleName()
1185}
1186
Logan Chienf3511742017-10-31 18:04:35 +08001187func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1188 return ctx.mod.getVndkExtendsModuleName()
1189}
1190
Logan Chiene274fc92019-12-03 11:18:32 -08001191func (ctx *moduleContextImpl) isForPlatform() bool {
1192 return ctx.mod.IsForPlatform()
1193}
1194
Jiyong Park58e364a2019-01-19 19:24:06 +09001195func (ctx *moduleContextImpl) apexName() string {
1196 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001197}
1198
Jooyung Han61c41542020-03-07 03:45:53 +09001199func (ctx *moduleContextImpl) apexSdkVersion() int {
1200 return ctx.mod.ApexProperties.Info.MinSdkVersion
1201}
1202
Jiyong Parkb0788572018-12-20 22:10:17 +09001203func (ctx *moduleContextImpl) hasStubsVariants() bool {
1204 return ctx.mod.HasStubsVariants()
1205}
1206
1207func (ctx *moduleContextImpl) isStubs() bool {
1208 return ctx.mod.IsStubs()
1209}
1210
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001211func (ctx *moduleContextImpl) bootstrap() bool {
1212 return ctx.mod.bootstrap()
1213}
1214
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001215func (ctx *moduleContextImpl) nativeCoverage() bool {
1216 return ctx.mod.nativeCoverage()
1217}
1218
Colin Cross635c3b02016-05-18 15:37:25 -07001219func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001220 return &Module{
1221 hod: hod,
1222 multilib: multilib,
1223 }
1224}
1225
Colin Cross635c3b02016-05-18 15:37:25 -07001226func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001227 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001228 module.features = []feature{
1229 &tidyFeature{},
1230 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001231 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001232 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001233 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001234 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001235 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001236 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001237 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001238 return module
1239}
1240
Colin Crossce75d2c2016-10-06 16:12:58 -07001241func (c *Module) Prebuilt() *android.Prebuilt {
1242 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1243 return p.prebuilt()
1244 }
1245 return nil
1246}
1247
1248func (c *Module) Name() string {
1249 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001250 if p, ok := c.linker.(interface {
1251 Name(string) string
1252 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001253 name = p.Name(name)
1254 }
1255 return name
1256}
1257
Alex Light3d673592019-01-18 14:37:31 -08001258func (c *Module) Symlinks() []string {
1259 if p, ok := c.installer.(interface {
1260 symlinkList() []string
1261 }); ok {
1262 return p.symlinkList()
1263 }
1264 return nil
1265}
1266
Jeff Gaston294356f2017-09-27 17:05:30 -07001267// orderDeps reorders dependencies into a list such that if module A depends on B, then
1268// A will precede B in the resultant list.
1269// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001270// Note that directSharedDeps should be the analogous static library for each shared lib dep
1271func 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 -07001272 // If A depends on B, then
1273 // Every list containing A will also contain B later in the list
1274 // So, after concatenating all lists, the final instance of B will have come from the same
1275 // original list as the final instance of A
1276 // So, the final instance of B will be later in the concatenation than the final A
1277 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1278 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001279 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001280 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001281 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1282 }
1283 for _, dep := range directSharedDeps {
1284 orderedAllDeps = append(orderedAllDeps, dep)
1285 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001286 }
1287
Colin Crossb6715442017-10-24 11:13:31 -07001288 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001289
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001290 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001291 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001292 // resultant list to only what the caller has chosen to include in directStaticDeps
1293 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001294
1295 return orderedAllDeps, orderedDeclaredDeps
1296}
1297
Ivan Lozano183a3212019-10-18 14:18:45 -07001298func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001299 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001300 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001301 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1302 staticDepFiles := []android.Path{}
1303 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001304 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1305 if dep.OutputFile().Valid() {
1306 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1307 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1308 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001309 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001310 sharedDepFiles := []android.Path{}
1311 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001312 if sharedDep.HasStaticVariant() {
1313 staticAnalogue := sharedDep.GetStaticVariant()
1314 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1315 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001316 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001317 }
1318
1319 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001320 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1321 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001322
1323 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001324}
1325
Roland Levillainf89cd092019-07-29 16:22:59 +01001326func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1327 test, ok := c.linker.(testPerSrc)
1328 return ok && test.isAllTestsVariation()
1329}
1330
Justin Yun5f7f7e82019-11-18 19:52:14 +09001331func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1332 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1333 // "current", it will append the VNDK version to the name suffix.
1334 var vndkVersion string
1335 var nameSuffix string
1336 if c.inProduct() {
1337 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1338 nameSuffix = productSuffix
1339 } else {
1340 vndkVersion = ctx.DeviceConfig().VndkVersion()
1341 nameSuffix = vendorSuffix
1342 }
1343 if vndkVersion == "current" {
1344 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1345 }
1346 if c.Properties.VndkVersion != vndkVersion {
1347 // add version suffix only if the module is using different vndk version than the
1348 // version in product or vendor partition.
1349 nameSuffix += "." + c.Properties.VndkVersion
1350 }
1351 return nameSuffix
1352}
1353
Colin Cross635c3b02016-05-18 15:37:25 -07001354func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001355 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001356 //
1357 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1358 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1359 // module and return early, as this module does not produce an output file per se.
1360 if c.IsTestPerSrcAllTestsVariation() {
1361 c.outputFile = android.OptionalPath{}
1362 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001363 }
1364
Jooyung Han38002912019-05-16 04:01:54 +09001365 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001366
Inseob Kim64c43952019-08-26 16:52:35 +09001367 c.Properties.SubName = ""
1368
1369 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1370 c.Properties.SubName += nativeBridgeSuffix
1371 }
1372
Justin Yun5f7f7e82019-11-18 19:52:14 +09001373 _, llndk := c.linker.(*llndkStubDecorator)
1374 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1375 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1376 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1377 // added for product variant only when we have vendor and product variants with core
1378 // variant. The suffix is not added for vendor-only or product-only module.
1379 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1380 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001381 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1382 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1383 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001384 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1385 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001386 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001387 c.Properties.SubName += recoverySuffix
1388 }
1389
Colin Crossca860ac2016-01-04 14:34:37 -08001390 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001391 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001392 moduleContextImpl: moduleContextImpl{
1393 mod: c,
1394 },
1395 }
1396 ctx.ctx = ctx
1397
Colin Crossf18e1102017-11-16 14:33:08 -08001398 deps := c.depsToPaths(ctx)
1399 if ctx.Failed() {
1400 return
1401 }
1402
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001403 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1404 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1405 }
1406
Colin Crossca860ac2016-01-04 14:34:37 -08001407 flags := Flags{
1408 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001409 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001410 }
Colin Crossca860ac2016-01-04 14:34:37 -08001411 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001412 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001413 }
1414 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001415 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001416 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001417 if c.stl != nil {
1418 flags = c.stl.flags(ctx, flags)
1419 }
Colin Cross16b23492016-01-06 14:41:07 -08001420 if c.sanitize != nil {
1421 flags = c.sanitize.flags(ctx, flags)
1422 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001423 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001424 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001425 }
Stephen Craneba090d12017-05-09 15:44:35 -07001426 if c.lto != nil {
1427 flags = c.lto.flags(ctx, flags)
1428 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001429 if c.pgo != nil {
1430 flags = c.pgo.flags(ctx, flags)
1431 }
Colin Crossca860ac2016-01-04 14:34:37 -08001432 for _, feature := range c.features {
1433 flags = feature.flags(ctx, flags)
1434 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001435 if ctx.Failed() {
1436 return
1437 }
1438
Colin Cross4af21ed2019-11-04 09:37:55 -08001439 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1440 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1441 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001442
Colin Cross4af21ed2019-11-04 09:37:55 -08001443 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001444
1445 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001446 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001447 }
1448 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001449 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001450 }
1451
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001452 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001453 // We need access to all the flags seen by a source file.
1454 if c.sabi != nil {
1455 flags = c.sabi.flags(ctx, flags)
1456 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001457
Colin Cross4af21ed2019-11-04 09:37:55 -08001458 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001459
Colin Crossca860ac2016-01-04 14:34:37 -08001460 // Optimization to reduce size of build.ninja
1461 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001462 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1463 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1464 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1465 flags.Local.CFlags = []string{"$cflags"}
1466 flags.Local.CppFlags = []string{"$cppflags"}
1467 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001468
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001469 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001470 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001471 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001472 if ctx.Failed() {
1473 return
1474 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001475 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001476 }
1477
Colin Crossca860ac2016-01-04 14:34:37 -08001478 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001479 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001480 if ctx.Failed() {
1481 return
1482 }
Colin Cross635c3b02016-05-18 15:37:25 -07001483 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001484
1485 // If a lib is directly included in any of the APEXes, unhide the stubs
1486 // variant having the latest version gets visible to make. In addition,
1487 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1488 // force anything in the make world to link against the stubs library.
1489 // (unless it is explicitly referenced via .bootstrap suffix or the
1490 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001491 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001492 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001493 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001494 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001495 c.Properties.HideFromMake = false // unhide
1496 // Note: this is still non-installable
1497 }
Inseob Kimac775b22020-03-03 22:06:32 +09001498
1499 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1500 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1501 if isSnapshotAware(ctx, c) {
1502 i.collectHeadersForSnapshot(ctx)
1503 }
1504 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001505 }
Colin Cross5049f022015-03-18 13:28:46 -07001506
Inseob Kim1f086e22019-05-09 13:29:15 +09001507 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001508 c.installer.install(ctx, c.outputFile.Path())
1509 if ctx.Failed() {
1510 return
Colin Crossca860ac2016-01-04 14:34:37 -08001511 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001512 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001513}
1514
Colin Cross0ea8ba82019-06-06 14:33:29 -07001515func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001516 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001517 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001518 }
Colin Crossca860ac2016-01-04 14:34:37 -08001519 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001520}
1521
Colin Crossca860ac2016-01-04 14:34:37 -08001522func (c *Module) begin(ctx BaseModuleContext) {
1523 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001524 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001525 }
Colin Crossca860ac2016-01-04 14:34:37 -08001526 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001527 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001528 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001529 if c.stl != nil {
1530 c.stl.begin(ctx)
1531 }
Colin Cross16b23492016-01-06 14:41:07 -08001532 if c.sanitize != nil {
1533 c.sanitize.begin(ctx)
1534 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001535 if c.coverage != nil {
1536 c.coverage.begin(ctx)
1537 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001538 if c.sabi != nil {
1539 c.sabi.begin(ctx)
1540 }
Justin Yun8effde42017-06-23 19:24:43 +09001541 if c.vndkdep != nil {
1542 c.vndkdep.begin(ctx)
1543 }
Stephen Craneba090d12017-05-09 15:44:35 -07001544 if c.lto != nil {
1545 c.lto.begin(ctx)
1546 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001547 if c.pgo != nil {
1548 c.pgo.begin(ctx)
1549 }
Colin Crossca860ac2016-01-04 14:34:37 -08001550 for _, feature := range c.features {
1551 feature.begin(ctx)
1552 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001553 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001554 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001555 if err != nil {
1556 ctx.PropertyErrorf("sdk_version", err.Error())
1557 }
Nan Zhang0007d812017-11-07 10:57:05 -08001558 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001559 }
Colin Crossca860ac2016-01-04 14:34:37 -08001560}
1561
Colin Cross37047f12016-12-13 17:06:13 -08001562func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001563 deps := Deps{}
1564
1565 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001566 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001567 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001568 // Add the PGO dependency (the clang_rt.profile runtime library), which
1569 // sometimes depends on symbols from libgcc, before libgcc gets added
1570 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001571 if c.pgo != nil {
1572 deps = c.pgo.deps(ctx, deps)
1573 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001574 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001575 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001576 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001577 if c.stl != nil {
1578 deps = c.stl.deps(ctx, deps)
1579 }
Colin Cross16b23492016-01-06 14:41:07 -08001580 if c.sanitize != nil {
1581 deps = c.sanitize.deps(ctx, deps)
1582 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001583 if c.coverage != nil {
1584 deps = c.coverage.deps(ctx, deps)
1585 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001586 if c.sabi != nil {
1587 deps = c.sabi.deps(ctx, deps)
1588 }
Justin Yun8effde42017-06-23 19:24:43 +09001589 if c.vndkdep != nil {
1590 deps = c.vndkdep.deps(ctx, deps)
1591 }
Stephen Craneba090d12017-05-09 15:44:35 -07001592 if c.lto != nil {
1593 deps = c.lto.deps(ctx, deps)
1594 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001595 for _, feature := range c.features {
1596 deps = feature.deps(ctx, deps)
1597 }
1598
Colin Crossb6715442017-10-24 11:13:31 -07001599 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1600 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1601 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1602 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1603 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1604 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001605 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001606
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001607 for _, lib := range deps.ReexportSharedLibHeaders {
1608 if !inList(lib, deps.SharedLibs) {
1609 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1610 }
1611 }
1612
1613 for _, lib := range deps.ReexportStaticLibHeaders {
1614 if !inList(lib, deps.StaticLibs) {
1615 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1616 }
1617 }
1618
Colin Cross5950f382016-12-13 12:50:57 -08001619 for _, lib := range deps.ReexportHeaderLibHeaders {
1620 if !inList(lib, deps.HeaderLibs) {
1621 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1622 }
1623 }
1624
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001625 for _, gen := range deps.ReexportGeneratedHeaders {
1626 if !inList(gen, deps.GeneratedHeaders) {
1627 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1628 }
1629 }
1630
Colin Crossc99deeb2016-04-11 15:06:20 -07001631 return deps
1632}
1633
Dan Albert7e9d2952016-08-04 13:02:36 -07001634func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001635 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001636 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001637 moduleContextImpl: moduleContextImpl{
1638 mod: c,
1639 },
1640 }
1641 ctx.ctx = ctx
1642
Colin Crossca860ac2016-01-04 14:34:37 -08001643 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001644}
1645
Jiyong Park7ed9de32018-10-15 22:25:07 +09001646// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001647func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001648 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1649 version := name[sharp+1:]
1650 libname := name[:sharp]
1651 return libname, version
1652 }
1653 return name, ""
1654}
1655
Colin Cross1e676be2016-10-12 14:38:15 -07001656func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001657 if !c.Enabled() {
1658 return
1659 }
1660
Colin Cross37047f12016-12-13 17:06:13 -08001661 ctx := &depsContext{
1662 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001663 moduleContextImpl: moduleContextImpl{
1664 mod: c,
1665 },
1666 }
1667 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001668
Colin Crossc99deeb2016-04-11 15:06:20 -07001669 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001670
Dan Albert914449f2016-06-17 16:45:24 -07001671 variantNdkLibs := []string{}
1672 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001673 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001674 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001675
Inseob Kimeec88e12020-01-22 11:11:29 +09001676 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001677 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001678 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001679 // 1. Name of an NDK library that refers to a prebuilt module.
1680 // For each of these, it adds the name of the prebuilt module (which will be in
1681 // prebuilts/ndk) to the list of nonvariant libs.
1682 // 2. Name of an NDK library that refers to an ndk_library module.
1683 // For each of these, it adds the name of the ndk_library module to the list of
1684 // variant libs.
1685 // 3. Anything else (so anything that isn't an NDK library).
1686 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001687 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001688 // The caller can then know to add the variantLibs dependencies differently from the
1689 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001690
Inseob Kim9516ee92019-05-09 10:56:13 +09001691 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001692 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1693
1694 rewriteVendorLibs := func(lib string) string {
1695 if isLlndkLibrary(lib, ctx.Config()) {
1696 return lib + llndkLibrarySuffix
1697 }
1698
1699 // only modules with BOARD_VNDK_VERSION uses snapshot.
1700 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1701 return lib
1702 }
1703
1704 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1705 return snapshot
1706 }
1707
1708 return lib
1709 }
1710
1711 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001712 variantLibs = []string{}
1713 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001714 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001715 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001716 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001717 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1718 if !inList(name, ndkMigratedLibs) {
1719 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001720 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001721 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001722 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001723 } else if ctx.useVndk() {
1724 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001725 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001726 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001727 if actx.OtherModuleExists(vendorPublicLib) {
1728 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1729 } else {
1730 // This can happen if vendor_public_library module is defined in a
1731 // namespace that isn't visible to the current module. In that case,
1732 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001733 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001734 }
Dan Albert914449f2016-06-17 16:45:24 -07001735 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001736 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001737 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001738 }
1739 }
Dan Albert914449f2016-06-17 16:45:24 -07001740 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001741 }
1742
Inseob Kimeec88e12020-01-22 11:11:29 +09001743 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1744 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1745 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1746 if ctx.useVndk() {
1747 for idx, lib := range deps.RuntimeLibs {
1748 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1749 }
1750 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001751 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001752
Jiyong Park7e636d02019-01-28 16:16:54 +09001753 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001754 if c.linker != nil {
1755 if library, ok := c.linker.(*libraryDecorator); ok {
1756 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001757 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001758 }
1759 }
1760 }
1761
Inseob Kimeec88e12020-01-22 11:11:29 +09001762 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1763 // only modules with BOARD_VNDK_VERSION uses snapshot.
1764 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1765 return lib
1766 }
1767
1768 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1769 return snapshot
1770 }
1771
1772 return lib
1773 }
1774
1775 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001776 for _, lib := range deps.HeaderLibs {
1777 depTag := headerDepTag
1778 if inList(lib, deps.ReexportHeaderLibHeaders) {
1779 depTag = headerExportDepTag
1780 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001781
1782 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1783
Jiyong Park7e636d02019-01-28 16:16:54 +09001784 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001785 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001786 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001787 } else {
1788 actx.AddVariationDependencies(nil, depTag, lib)
1789 }
1790 }
1791
1792 if buildStubs {
1793 // Stubs lib does not have dependency to other static/shared libraries.
1794 // Don't proceed.
1795 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001796 }
Colin Cross5950f382016-12-13 12:50:57 -08001797
Inseob Kimc0907f12019-02-08 21:00:45 +09001798 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001799 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001800
Jiyong Park5d1598f2019-02-25 22:14:17 +09001801 for _, lib := range deps.WholeStaticLibs {
1802 depTag := wholeStaticDepTag
1803 if impl, ok := syspropImplLibraries[lib]; ok {
1804 lib = impl
1805 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001806
1807 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1808
Jiyong Park5d1598f2019-02-25 22:14:17 +09001809 actx.AddVariationDependencies([]blueprint.Variation{
1810 {Mutator: "link", Variation: "static"},
1811 }, depTag, lib)
1812 }
1813
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001814 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001815 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001816 if inList(lib, deps.ReexportStaticLibHeaders) {
1817 depTag = staticExportDepTag
1818 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001819
1820 if impl, ok := syspropImplLibraries[lib]; ok {
1821 lib = impl
1822 }
1823
Inseob Kimeec88e12020-01-22 11:11:29 +09001824 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1825
Dan Willemsen59339a22018-07-22 21:18:45 -07001826 actx.AddVariationDependencies([]blueprint.Variation{
1827 {Mutator: "link", Variation: "static"},
1828 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001829 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001830
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001831 if deps.StaticUnwinderIfLegacy && ctx.Config().UnbundledBuild() {
1832 actx.AddVariationDependencies([]blueprint.Variation{
1833 {Mutator: "link", Variation: "static"},
1834 }, staticUnwinderDepTag, staticUnwinder(actx))
1835 }
1836
Inseob Kimeec88e12020-01-22 11:11:29 +09001837 for _, lib := range deps.LateStaticLibs {
1838 actx.AddVariationDependencies([]blueprint.Variation{
1839 {Mutator: "link", Variation: "static"},
1840 }, lateStaticDepTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
1841 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001842
Ivan Lozano183a3212019-10-18 14:18:45 -07001843 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001844 var variations []blueprint.Variation
1845 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han67a96cd2020-03-13 15:23:36 +09001846 versionVariantAvail := !c.InRecovery() && !c.InRamdisk()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001847 if version != "" && versionVariantAvail {
1848 // Version is explicitly specified. i.e. libFoo#30
1849 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001850 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001851 }
1852 actx.AddVariationDependencies(variations, depTag, name)
1853
Jooyung Han0c4e0162020-02-26 22:45:42 +09001854 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001855 // The stubs library will be used when the depending module is built for APEX and
1856 // the dependent module is not in the same APEX.
Jooyung Han0c4e0162020-02-26 22:45:42 +09001857 if version == "" && versionVariantAvail {
1858 for _, ver := range stubsVersionsFor(actx.Config())[name] {
1859 // Note that depTag.ExplicitlyVersioned is false in this case.
1860 actx.AddVariationDependencies([]blueprint.Variation{
1861 {Mutator: "link", Variation: "shared"},
1862 {Mutator: "version", Variation: ver},
1863 }, depTag, name)
1864 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001865 }
1866 }
1867
Jiyong Park7ed9de32018-10-15 22:25:07 +09001868 // shared lib names without the #version suffix
1869 var sharedLibNames []string
1870
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001871 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001872 depTag := SharedDepTag
Jiyong Parkd7536ba2020-01-16 17:14:23 +09001873 if c.static() {
1874 depTag = SharedFromStaticDepTag
1875 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001876 if inList(lib, deps.ReexportSharedLibHeaders) {
1877 depTag = sharedExportDepTag
1878 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001879
1880 if impl, ok := syspropImplLibraries[lib]; ok {
1881 lib = impl
1882 }
1883
Jiyong Park73c54ee2019-10-22 20:31:18 +09001884 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001885 sharedLibNames = append(sharedLibNames, name)
1886
Jiyong Park25fc6a92018-11-18 18:02:45 +09001887 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001888 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001889
Jiyong Park7ed9de32018-10-15 22:25:07 +09001890 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001891 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001892 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1893 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1894 // linking against both the stubs lib and the non-stubs lib at the same time.
1895 continue
1896 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001897 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001898 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001899
Dan Willemsen59339a22018-07-22 21:18:45 -07001900 actx.AddVariationDependencies([]blueprint.Variation{
1901 {Mutator: "link", Variation: "shared"},
1902 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001903
Colin Cross68861832016-07-08 10:41:41 -07001904 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001905
1906 for _, gen := range deps.GeneratedHeaders {
1907 depTag := genHeaderDepTag
1908 if inList(gen, deps.ReexportGeneratedHeaders) {
1909 depTag = genHeaderExportDepTag
1910 }
1911 actx.AddDependency(c, depTag, gen)
1912 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001913
Colin Cross42d48b72018-08-29 14:10:52 -07001914 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001915
1916 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001917 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001918 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001919 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001920 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001921 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001922 if deps.LinkerFlagsFile != "" {
1923 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1924 }
1925 if deps.DynamicLinker != "" {
1926 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001927 }
Dan Albert914449f2016-06-17 16:45:24 -07001928
1929 version := ctx.sdkVersion()
1930 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001931 {Mutator: "ndk_api", Variation: version},
1932 {Mutator: "link", Variation: "shared"},
1933 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001934 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001935 {Mutator: "ndk_api", Variation: version},
1936 {Mutator: "link", Variation: "shared"},
1937 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001938
1939 if vndkdep := c.vndkdep; vndkdep != nil {
1940 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08001941 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08001942 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07001943 {Mutator: "link", Variation: "shared"},
1944 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001945 }
1946 }
Colin Cross6362e272015-10-29 15:25:03 -07001947}
Colin Cross21b9a242015-03-24 14:15:58 -07001948
Colin Crosse40b4ea2018-10-02 22:25:58 -07001949func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001950 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1951 c.beginMutator(ctx)
1952 }
1953}
1954
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001955// Whether a module can link to another module, taking into
1956// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07001957func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
1958 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001959 // Host code is not restricted
1960 return
1961 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001962
1963 // VNDK is cc.Module supported only for now.
1964 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001965 // Though vendor code is limited by the vendor mutator,
1966 // each vendor-available module needs to check
1967 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07001968 if ccTo, ok := to.(*Module); ok {
1969 if ccFrom.vndkdep != nil {
1970 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
1971 }
1972 } else {
1973 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001974 }
1975 return
1976 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001977 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001978 // Platform code can link to anything
1979 return
1980 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08001981 if from.InRamdisk() {
1982 // Ramdisk code is not NDK
1983 return
1984 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001985 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09001986 // Recovery code is not NDK
1987 return
1988 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001989 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001990 // These are always allowed
1991 return
1992 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001993 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001994 // These are allowed, but they don't set sdk_version
1995 return
1996 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001997 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001998 // These aren't real libraries, but are the stub shared libraries that are included in
1999 // the NDK.
2000 return
2001 }
Logan Chien834b9a62019-01-14 15:39:03 +08002002
Ivan Lozano52767be2019-10-18 14:49:46 -07002003 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002004 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2005 // to link to libc++ (non-NDK and without sdk_version).
2006 return
2007 }
2008
Ivan Lozano52767be2019-10-18 14:49:46 -07002009 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002010 // NDK code linking to platform code is never okay.
2011 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002012 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002013 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002014 }
2015
2016 // At this point we know we have two NDK libraries, but we need to
2017 // check that we're not linking against anything built against a higher
2018 // API level, as it is only valid to link against older or equivalent
2019 // APIs.
2020
Inseob Kim01a28722018-04-11 09:48:45 +09002021 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002022 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002023 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002024 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002025 // Current can't be linked against by anything else.
2026 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002027 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002028 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002029 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002030 if err != nil {
2031 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002032 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002033 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002034 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002035 toApi, err := strconv.Atoi(to.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 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002040 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002041
Inseob Kim01a28722018-04-11 09:48:45 +09002042 if toApi > fromApi {
2043 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002044 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002045 }
2046 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002047 }
Dan Albert202fe492017-12-15 13:56:59 -08002048
2049 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002050 fromStl := from.SelectedStl()
2051 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002052 if fromStl == "" || toStl == "" {
2053 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002054 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002055 // We can be permissive with the system "STL" since it is only the C++
2056 // ABI layer, but in the future we should make sure that everyone is
2057 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002058 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002059 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002060 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2061 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002062 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002063}
2064
Jiyong Park5fb8c102018-04-09 12:03:06 +09002065// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002066// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2067// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002068// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002069func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2070 check := func(child, parent android.Module) bool {
2071 to, ok := child.(*Module)
2072 if !ok {
2073 // follow thru cc.Defaults, etc.
2074 return true
2075 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002076
Jooyung Hana70f0672019-01-18 15:20:43 +09002077 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2078 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002079 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002080
2081 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002082 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002083 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002084 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002085
Jooyung Han0302a842019-10-30 18:43:49 +09002086 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002087 return false
2088 }
2089
2090 var stringPath []string
2091 for _, m := range ctx.GetWalkPath() {
2092 stringPath = append(stringPath, m.Name())
2093 }
2094 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2095 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2096 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2097 return false
2098 }
2099 if module, ok := ctx.Module().(*Module); ok {
2100 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002101 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002102 ctx.WalkDeps(check)
2103 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002104 }
2105 }
2106}
2107
Colin Crossc99deeb2016-04-11 15:06:20 -07002108// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002109func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002110 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002111
Ivan Lozano183a3212019-10-18 14:18:45 -07002112 directStaticDeps := []LinkableInterface{}
2113 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002114
Inseob Kim9516ee92019-05-09 10:56:13 +09002115 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2116
Inseob Kim69378442019-06-03 19:10:47 +09002117 reexportExporter := func(exporter exportedFlagsProducer) {
2118 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2119 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2120 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2121 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002122 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002123 }
2124
Colin Crossd11fcda2017-10-23 17:59:01 -07002125 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002126 depName := ctx.OtherModuleName(dep)
2127 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002128
Ivan Lozano52767be2019-10-18 14:49:46 -07002129 ccDep, ok := dep.(LinkableInterface)
2130 if !ok {
2131
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002132 // handling for a few module types that aren't cc Module but that are also supported
2133 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002134 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002135 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002136 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2137 genRule.GeneratedSourceFiles()...)
2138 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002139 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002140 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002141 // Support exported headers from a generated_sources dependency
2142 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002143 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002144 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002145 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Inseob Kimd110f872019-12-06 13:15:38 +09002146 genRule.GeneratedSourceFiles()...)
2147 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002148 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002149 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002150 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002151 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002152 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002153 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2154 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002155 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002156 // 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 +09002157 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002158
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002159 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002160 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002161 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002162 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002163 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002164 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002165 files := genRule.GeneratedSourceFiles()
2166 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002167 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002168 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002169 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 -07002170 }
2171 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002172 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002173 }
Colin Crossca860ac2016-01-04 14:34:37 -08002174 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002175 return
2176 }
2177
Colin Crossfe17f6f2019-03-28 19:30:56 -07002178 if depTag == android.ProtoPluginDepTag {
2179 return
2180 }
Jooyung Han67a96cd2020-03-13 15:23:36 +09002181 if depTag == llndkImplDep {
2182 return
2183 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002184
Colin Crossd11fcda2017-10-23 17:59:01 -07002185 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002186 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2187 return
2188 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002189 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han67a96cd2020-03-13 15:23:36 +09002190 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2191 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002192 return
2193 }
2194
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002195 // re-exporting flags
2196 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002197 // reusing objects only make sense for cc.Modules.
2198 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002199 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002200 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002201 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002202 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002203 return
2204 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002205 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002206
Jiyong Parke4bb9862019-02-01 00:31:10 +09002207 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002208 // staticVariants are a cc.Module specific concept.
2209 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002210 c.staticVariant = ccDep
2211 return
2212 }
2213 }
2214
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002215 if depTag == staticUnwinderDepTag {
Jooyung Han0c4e0162020-02-26 22:45:42 +09002216 // Use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
2217 if c.ShouldSupportAndroid10() {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002218 depTag = StaticDepTag
2219 } else {
2220 return
2221 }
2222 }
2223
Ivan Lozano183a3212019-10-18 14:18:45 -07002224 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
2225 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
2226 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002227 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07002228 if t, ok := depTag.(DependencyTag); ok {
2229 explicitlyVersioned = t.ExplicitlyVersioned
2230 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002231 depTag = t
2232 }
2233
Ivan Lozano183a3212019-10-18 14:18:45 -07002234 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002235 depIsStatic := false
2236 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002237 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002238 depIsStatic = true
2239 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002240 if ccDep.CcLibrary() && !depIsStatic {
2241 depIsStubs := ccDep.BuildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09002242 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002243 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002244 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002245
2246 var useThisDep bool
2247 if depIsStubs && explicitlyVersioned {
2248 // Always respect dependency to the versioned stubs (i.e. libX#10)
2249 useThisDep = true
2250 } else if !depHasStubs {
2251 // Use non-stub variant if that is the only choice
2252 // (i.e. depending on a lib without stubs.version property)
2253 useThisDep = true
2254 } else if c.IsForPlatform() {
2255 // If not building for APEX, use stubs only when it is from
2256 // an APEX (and not from platform)
2257 useThisDep = (depInPlatform != depIsStubs)
Yifan Hong1b3348d2020-01-21 15:53:22 -08002258 if c.InRamdisk() || c.InRecovery() || c.bootstrap() {
2259 // However, for ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002260 // always link to non-stub variant
2261 useThisDep = !depIsStubs
2262 }
2263 } else {
2264 // If building for APEX, use stubs only when it is not from
2265 // the same APEX
2266 useThisDep = (depInSameApex != depIsStubs)
2267 }
2268
Jooyung Han0c4e0162020-02-26 22:45:42 +09002269 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
2270 if useThisDep && depIsStubs && !explicitlyVersioned {
2271 useLatest := c.IsForPlatform() || (c.ShouldSupportAndroid10() && !ctx.Config().UnbundledBuild())
2272 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), useLatest)
2273 if err != nil {
2274 ctx.OtherModuleErrorf(dep, err.Error())
2275 return
2276 }
2277 if versionToUse != ccDep.StubsVersion() {
2278 useThisDep = false
2279 }
2280 }
2281
Jiyong Park25fc6a92018-11-18 18:02:45 +09002282 if !useThisDep {
2283 return // stop processing this dep
2284 }
2285 }
Jooyung Han67a96cd2020-03-13 15:23:36 +09002286 if c.UseVndk() {
2287 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2288 // by default, use current version of LLNDK
2289 versionToUse := ""
2290 versions := stubsVersionsFor(ctx.Config())[depName]
2291 if c.ApexName() != "" && len(versions) > 0 {
2292 // if this is for use_vendor apex && dep has stubsVersions
2293 // apply the same rule of apex sdk enforcement to choose right version
2294 var err error
2295 useLatest := c.ShouldSupportAndroid10() && !ctx.Config().UnbundledBuild()
2296 versionToUse, err = c.ChooseSdkVersion(versions, useLatest)
2297 if err != nil {
2298 ctx.OtherModuleErrorf(dep, err.Error())
2299 return
2300 }
2301 }
2302 if versionToUse != ccDep.StubsVersion() {
2303 return
2304 }
2305 }
2306 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002307
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002308 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2309
Ivan Lozano52767be2019-10-18 14:49:46 -07002310 // Exporting flags only makes sense for cc.Modules
2311 if _, ok := ccDep.(*Module); ok {
2312 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002313 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002314 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedGeneratedHeaders()...)
2315 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002316 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002317
Ivan Lozano52767be2019-10-18 14:49:46 -07002318 if t.ReexportFlags {
2319 reexportExporter(i)
2320 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2321 // Re-exported shared library headers must be included as well since they can help us with type information
2322 // about template instantiations (instantiated from their headers).
2323 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2324 // scripts.
2325 c.sabi.Properties.ReexportedIncludes = append(
2326 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2327 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002328 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002329 }
Logan Chienf3511742017-10-31 18:04:35 +08002330 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002331 }
2332
Colin Cross26c34ed2016-09-30 17:10:16 -07002333 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002334 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002335
Ivan Lozano52767be2019-10-18 14:49:46 -07002336 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002337 depFile := android.OptionalPath{}
2338
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002339 switch depTag {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002340 case ndkStubDepTag, SharedDepTag, SharedFromStaticDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002341 ptr = &depPaths.SharedLibs
2342 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002343 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002344 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002345
Jiyong Park64a44f22019-01-18 14:37:08 +09002346 case earlySharedDepTag:
2347 ptr = &depPaths.EarlySharedLibs
2348 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002349 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002350 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002351 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002352 ptr = &depPaths.LateSharedLibs
2353 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002354 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002355 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002356 ptr = nil
2357 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002358 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002359 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002360 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002361 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002362 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002363 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002364 return
2365 }
2366
Ivan Lozano52767be2019-10-18 14:49:46 -07002367 // Because the static library objects are included, this only makes sense
2368 // in the context of proper cc.Modules.
2369 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2370 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2371 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2372 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2373 for i := range missingDeps {
2374 missingDeps[i] += postfix
2375 }
2376 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002377 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002378 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2379 } else {
2380 ctx.ModuleErrorf(
2381 "non-cc.Modules cannot be included as whole static libraries.", depName)
2382 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002383 }
Colin Cross5950f382016-12-13 12:50:57 -08002384 case headerDepTag:
2385 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002386 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002387 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002388 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002389 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002390 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002391 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002392 case dynamicLinkerDepTag:
2393 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002394 }
2395
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002396 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002397 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002398 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002399 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002400 return
2401 }
2402
2403 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002404 // in static libraries act as if they were whole static libraries. The same goes for
2405 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002406 // This should only be done for cc.Modules
2407 if c, ok := ccDep.(*Module); ok {
2408 staticLib := c.linker.(libraryInterface)
2409 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2410 staticLib.objs().coverageFiles...)
2411 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2412 staticLib.objs().sAbiDumpFiles...)
2413 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002414 }
2415
Colin Cross26c34ed2016-09-30 17:10:16 -07002416 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002417 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002418 if !ctx.Config().AllowMissingDependencies() {
2419 ctx.ModuleErrorf("module %q missing output file", depName)
2420 } else {
2421 ctx.AddMissingDependencies([]string{depName})
2422 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002423 return
2424 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002425 *ptr = append(*ptr, linkFile.Path())
2426 }
2427
Colin Crossc99deeb2016-04-11 15:06:20 -07002428 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002429 dep := depFile
2430 if !dep.Valid() {
2431 dep = linkFile
2432 }
2433 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002434 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002435
Inseob Kimeec88e12020-01-22 11:11:29 +09002436 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2437
2438 baseLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002439 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002440 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002441 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kimeec88e12020-01-22 11:11:29 +09002442 return libName
2443 }
2444
2445 makeLibName := func(depName string) string {
2446 libName := baseLibName(depName)
Jooyung Han0302a842019-10-30 18:43:49 +09002447 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002448 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002449 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002450
Inseob Kimeec88e12020-01-22 11:11:29 +09002451 if c, ok := ccDep.(*Module); ok {
2452 // Use base module name for snapshots when exporting to Makefile.
Inseob Kim7ac1fa72020-03-14 01:30:34 +09002453 if c.isSnapshotPrebuilt() {
Inseob Kimeec88e12020-01-22 11:11:29 +09002454 baseName := c.BaseModuleName()
Inseob Kim7ac1fa72020-03-14 01:30:34 +09002455
2456 if c.IsVndk() {
2457 return baseName + ".vendor"
2458 }
2459
Inseob Kimeec88e12020-01-22 11:11:29 +09002460 if vendorSuffixModules[baseName] {
2461 return baseName + ".vendor"
2462 } else {
2463 return baseName
2464 }
2465 }
2466 }
2467
Yifan Hong1b3348d2020-01-21 15:53:22 -08002468 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002469 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2470 // core module instead.
2471 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002472 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002473 // The vendor module in Make will have been renamed to not conflict with the core
2474 // module, so update the dependency name here accordingly.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002475 return libName + c.getNameSuffixWithVndkVersion(ctx)
Jiyong Park374510b2018-03-19 18:23:01 +09002476 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002477 return libName + vendorPublicLibrarySuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08002478 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2479 return libName + ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002480 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002481 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002482 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002483 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002484 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002485 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002486 }
Logan Chien43d34c32017-12-20 01:17:32 +08002487 }
2488
2489 // Export the shared libs to Make.
2490 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002491 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002492 if ccDep.CcLibrary() {
2493 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002494 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002495 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002496 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002497 c.Properties.ApexesProvidingSharedLibs = append(
2498 c.Properties.ApexesProvidingSharedLibs, an)
2499 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002500 }
2501 }
2502
Jiyong Park27b188b2017-07-18 13:23:39 +09002503 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002504 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002505 c.Properties.AndroidMkSharedLibs = append(
2506 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002507 // Record baseLibName for snapshots.
2508 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002509 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002510 c.Properties.AndroidMkSharedLibs = append(
2511 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002512 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002513 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002514 c.Properties.AndroidMkStaticLibs = append(
2515 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002516 case runtimeDepTag:
2517 c.Properties.AndroidMkRuntimeLibs = append(
2518 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002519 // Record baseLibName for snapshots.
2520 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002521 case wholeStaticDepTag:
2522 c.Properties.AndroidMkWholeStaticLibs = append(
2523 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002524 }
Colin Crossca860ac2016-01-04 14:34:37 -08002525 })
2526
Jeff Gaston294356f2017-09-27 17:05:30 -07002527 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002528 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002529
Colin Crossdd84e052017-05-17 13:44:16 -07002530 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002531 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002532 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2533 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002534 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kimd110f872019-12-06 13:15:38 +09002535 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002536 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2537 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002538 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002539 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002540 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002541
2542 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002543 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002544 }
Colin Crossdd84e052017-05-17 13:44:16 -07002545
Colin Crossca860ac2016-01-04 14:34:37 -08002546 return depPaths
2547}
2548
2549func (c *Module) InstallInData() bool {
2550 if c.installer == nil {
2551 return false
2552 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002553 return c.installer.inData()
2554}
2555
2556func (c *Module) InstallInSanitizerDir() bool {
2557 if c.installer == nil {
2558 return false
2559 }
2560 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002561 return true
2562 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002563 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002564}
2565
Yifan Hong1b3348d2020-01-21 15:53:22 -08002566func (c *Module) InstallInRamdisk() bool {
2567 return c.InRamdisk()
2568}
2569
Jiyong Parkf9332f12018-02-01 00:54:12 +09002570func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002571 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002572}
2573
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002574func (c *Module) HostToolPath() android.OptionalPath {
2575 if c.installer == nil {
2576 return android.OptionalPath{}
2577 }
2578 return c.installer.hostToolPath()
2579}
2580
Nan Zhangd4e641b2017-07-12 12:55:28 -07002581func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2582 return c.outputFile
2583}
2584
Colin Cross41955e82019-05-29 14:40:35 -07002585func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2586 switch tag {
2587 case "":
2588 if c.outputFile.Valid() {
2589 return android.Paths{c.outputFile.Path()}, nil
2590 }
2591 return android.Paths{}, nil
2592 default:
2593 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002594 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002595}
2596
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002597func (c *Module) static() bool {
2598 if static, ok := c.linker.(interface {
2599 static() bool
2600 }); ok {
2601 return static.static()
2602 }
2603 return false
2604}
2605
Jiyong Park379de2f2018-12-19 02:47:14 +09002606func (c *Module) staticBinary() bool {
2607 if static, ok := c.linker.(interface {
2608 staticBinary() bool
2609 }); ok {
2610 return static.staticBinary()
2611 }
2612 return false
2613}
2614
Jiyong Park1d1119f2019-07-29 21:27:18 +09002615func (c *Module) header() bool {
2616 if h, ok := c.linker.(interface {
2617 header() bool
2618 }); ok {
2619 return h.header()
2620 }
2621 return false
2622}
2623
Jooyung Han38002912019-05-16 04:01:54 +09002624func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002625 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002626 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2627 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002628 return "native:vndk"
2629 }
Jooyung Han38002912019-05-16 04:01:54 +09002630 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002631 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002632 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002633 if Bool(c.VendorProperties.Vendor_available) {
2634 return "native:vndk"
2635 }
2636 return "native:vndk_private"
2637 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002638 if c.inProduct() {
2639 return "native:product"
2640 }
Jooyung Han38002912019-05-16 04:01:54 +09002641 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002642 } else if c.InRamdisk() {
2643 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002644 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002645 return "native:recovery"
2646 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2647 return "native:ndk:none:none"
2648 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2649 //family, link := getNdkStlFamilyAndLinkType(c)
2650 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002651 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002652 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002653 } else {
2654 return "native:platform"
2655 }
2656}
2657
Jiyong Park9d452992018-10-03 00:38:19 +09002658// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002659// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002660func (c *Module) IsInstallableToApex() bool {
2661 if shared, ok := c.linker.(interface {
2662 shared() bool
2663 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002664 // Stub libs and prebuilt libs in a versioned SDK are not
2665 // installable to APEX even though they are shared libs.
2666 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002667 } else if _, ok := c.linker.(testPerSrc); ok {
2668 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002669 }
2670 return false
2671}
2672
Jiyong Parka90ca002019-10-07 15:47:24 +09002673func (c *Module) AvailableFor(what string) bool {
2674 if linker, ok := c.linker.(interface {
2675 availableFor(string) bool
2676 }); ok {
2677 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2678 } else {
2679 return c.ApexModuleBase.AvailableFor(what)
2680 }
2681}
2682
Inseob Kim1f086e22019-05-09 13:29:15 +09002683func (c *Module) installable() bool {
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002684 ret := c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid()
2685
2686 // The platform variant doesn't need further condition. Apex variants however might not
2687 // be installable because it will likely to be included in the APEX and won't appear
2688 // in the system partition.
2689 if c.IsForPlatform() {
2690 return ret
2691 }
2692
2693 // Special case for modules that are configured to be installed to /data, which includes
2694 // test modules. For these modules, both APEX and non-APEX variants are considered as
2695 // installable. This is because even the APEX variants won't be included in the APEX, but
2696 // will anyway be installed to /data/*.
2697 // See b/146995717
2698 if c.InstallInData() {
2699 return ret
2700 }
2701
2702 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002703}
2704
Logan Chien41eabe62019-04-10 13:33:58 +08002705func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2706 if c.linker != nil {
2707 if library, ok := c.linker.(*libraryDecorator); ok {
2708 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2709 }
2710 }
2711}
2712
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002713func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002714 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002715 if cc, ok := dep.(*Module); ok {
Jiyong Park9f14b9b2020-03-01 17:29:06 +09002716 if cc.HasStubsVariants() {
2717 if depTag.Shared && depTag.Library {
2718 // dynamic dep to a stubs lib crosses APEX boundary
2719 return false
2720 }
2721 if IsRuntimeDepTag(depTag) {
2722 // runtime dep to a stubs lib also crosses APEX boundary
2723 return false
2724 }
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002725 }
2726 if depTag.FromStatic {
2727 // shared_lib dependency from a static lib is considered as crossing
2728 // the APEX boundary because the dependency doesn't actually is
2729 // linked; the dependency is used only during the compilation phase.
2730 return false
2731 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002732 }
2733 }
2734 return true
2735}
2736
Colin Cross2ba19d92015-05-07 15:44:20 -07002737//
Colin Crosscfad1192015-11-02 16:43:11 -08002738// Defaults
2739//
Colin Crossca860ac2016-01-04 14:34:37 -08002740type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002741 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002742 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002743 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002744}
2745
Patrice Arrudac249c712019-03-19 17:00:29 -07002746// cc_defaults provides a set of properties that can be inherited by other cc
2747// modules. A module can use the properties from a cc_defaults using
2748// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2749// merged (when possible) by prepending the default module's values to the
2750// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002751func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002752 return DefaultsFactory()
2753}
2754
Colin Cross36242852017-06-23 15:06:31 -07002755func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002756 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002757
Colin Cross36242852017-06-23 15:06:31 -07002758 module.AddProperties(props...)
2759 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002760 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002761 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002762 &BaseCompilerProperties{},
2763 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002764 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002765 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002766 &StaticProperties{},
2767 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002768 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002769 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002770 &TestProperties{},
2771 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002772 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002773 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002774 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002775 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002776 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002777 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002778 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002779 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002780 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002781 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002782 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002783 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002784 )
Colin Crosscfad1192015-11-02 16:43:11 -08002785
Jooyung Hancc372c52019-09-25 15:18:44 +09002786 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002787
2788 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002789}
2790
Jiyong Park6a43f042017-10-12 23:05:00 +09002791func squashVendorSrcs(m *Module) {
2792 if lib, ok := m.compiler.(*libraryDecorator); ok {
2793 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2794 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2795
2796 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2797 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2798 }
2799}
2800
Jiyong Parkf9332f12018-02-01 00:54:12 +09002801func squashRecoverySrcs(m *Module) {
2802 if lib, ok := m.compiler.(*libraryDecorator); ok {
2803 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2804 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2805
2806 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2807 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2808 }
2809}
2810
Colin Cross7228ecd2019-11-18 16:00:16 -08002811var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002812
Colin Cross7228ecd2019-11-18 16:00:16 -08002813func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002814 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002815 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002816 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002817
2818 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002819 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002820 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002821 }
Logan Chienf3511742017-10-31 18:04:35 +08002822
2823 if vndkdep := m.vndkdep; vndkdep != nil {
2824 if vndkdep.isVndk() {
Justin Yun98df0d12020-02-28 15:07:59 +09002825 if vendorSpecific || productSpecific {
Logan Chienf3511742017-10-31 18:04:35 +08002826 if !vndkdep.isVndkExt() {
2827 mctx.PropertyErrorf("vndk",
2828 "must set `extends: \"...\"` to vndk extension")
Justin Yun98df0d12020-02-28 15:07:59 +09002829 } else if m.VendorProperties.Vendor_available != nil {
2830 mctx.PropertyErrorf("vendor_available",
2831 "must not set at the same time as `vndk: {extends: \"...\"}`")
Logan Chienf3511742017-10-31 18:04:35 +08002832 }
2833 } else {
2834 if vndkdep.isVndkExt() {
2835 mctx.PropertyErrorf("vndk",
Justin Yun98df0d12020-02-28 15:07:59 +09002836 "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
Logan Chienf3511742017-10-31 18:04:35 +08002837 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002838 }
2839 if m.VendorProperties.Vendor_available == nil {
2840 mctx.PropertyErrorf("vndk",
2841 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08002842 }
2843 }
2844 } else {
2845 if vndkdep.isVndkSp() {
2846 mctx.PropertyErrorf("vndk",
2847 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08002848 }
2849 if vndkdep.isVndkExt() {
2850 mctx.PropertyErrorf("vndk",
2851 "must set `enabled: true` to set `extends: %q`",
2852 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002853 }
Justin Yun8effde42017-06-23 19:24:43 +09002854 }
2855 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002856
Jiyong Parkf9332f12018-02-01 00:54:12 +09002857 var coreVariantNeeded bool = false
Yifan Hong1b3348d2020-01-21 15:53:22 -08002858 var ramdiskVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002859 var recoveryVariantNeeded bool = false
2860
Inseob Kim64c43952019-08-26 16:52:35 +09002861 var vendorVariants []string
Justin Yun5f7f7e82019-11-18 19:52:14 +09002862 var productVariants []string
Inseob Kim64c43952019-08-26 16:52:35 +09002863
2864 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09002865 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
2866 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
2867 if boardVndkVersion == "current" {
2868 boardVndkVersion = platformVndkVersion
2869 }
2870 if productVndkVersion == "current" {
2871 productVndkVersion = platformVndkVersion
Inseob Kim64c43952019-08-26 16:52:35 +09002872 }
2873
Justin Yun5f7f7e82019-11-18 19:52:14 +09002874 if boardVndkVersion == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002875 // If the device isn't compiling against the VNDK, we always
2876 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002877 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002878 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002879 // LL-NDK stubs only exist in the vendor and product variants,
2880 // since the real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002881 vendorVariants = append(vendorVariants,
2882 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002883 boardVndkVersion,
2884 )
2885 productVariants = append(productVariants,
2886 platformVndkVersion,
2887 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002888 )
Jiyong Park2a454122017-10-19 15:59:33 +09002889 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2890 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002891 vendorVariants = append(vendorVariants,
2892 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002893 boardVndkVersion,
2894 )
2895 productVariants = append(productVariants,
2896 platformVndkVersion,
2897 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002898 )
Inseob Kimeec88e12020-01-22 11:11:29 +09002899 } else if m.isSnapshotPrebuilt() {
Justin Yun71549282017-11-17 12:10:28 +09002900 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2901 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kimeec88e12020-01-22 11:11:29 +09002902 if snapshot, ok := m.linker.(interface {
2903 version() string
2904 }); ok {
2905 vendorVariants = append(vendorVariants, snapshot.version())
2906 } else {
2907 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
2908 }
Justin Yun98df0d12020-02-28 15:07:59 +09002909 } else if m.HasVendorVariant() && !m.isVndkExt() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002910 // This will be available in /system, /vendor and /product
2911 // or a /system directory that is available to vendor and product.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002912 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002913 vendorVariants = append(vendorVariants, platformVndkVersion)
Justin Yun5f7f7e82019-11-18 19:52:14 +09002914 productVariants = append(productVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09002915 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
2916 // code is PLATFORM_VNDK_VERSION.
2917 // On the other hand, vendor_available modules which are not VNDK should
2918 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002919 // vendor_available modules are also available to /product.
Inseob Kimbc093672019-11-01 11:29:44 +09002920 if !m.IsVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002921 vendorVariants = append(vendorVariants, boardVndkVersion)
2922 productVariants = append(productVariants, productVndkVersion)
Inseob Kim64c43952019-08-26 16:52:35 +09002923 }
Logan Chienf3511742017-10-31 18:04:35 +08002924 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002925 // This will be available in /vendor (or /odm) only
Justin Yun5f7f7e82019-11-18 19:52:14 +09002926 vendorVariants = append(vendorVariants, boardVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002927 } else {
2928 // This is either in /system (or similar: /data), or is a
2929 // modules built with the NDK. Modules built with the NDK
2930 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002931 coreVariantNeeded = true
2932 }
2933
Justin Yun5f7f7e82019-11-18 19:52:14 +09002934 if boardVndkVersion != "" && productVndkVersion != "" {
2935 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
2936 // The module has "product_specific: true" that does not create core variant.
2937 coreVariantNeeded = false
2938 productVariants = append(productVariants, productVndkVersion)
2939 }
2940 } else {
2941 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
2942 // restriction to use system libs.
2943 // No product variants defined in this case.
2944 productVariants = []string{}
2945 }
2946
Yifan Hong1b3348d2020-01-21 15:53:22 -08002947 if Bool(m.Properties.Ramdisk_available) {
2948 ramdiskVariantNeeded = true
2949 }
2950
2951 if m.ModuleBase.InstallInRamdisk() {
2952 ramdiskVariantNeeded = true
2953 coreVariantNeeded = false
2954 }
2955
Jiyong Parkf9332f12018-02-01 00:54:12 +09002956 if Bool(m.Properties.Recovery_available) {
2957 recoveryVariantNeeded = true
2958 }
2959
2960 if m.ModuleBase.InstallInRecovery() {
2961 recoveryVariantNeeded = true
2962 coreVariantNeeded = false
2963 }
2964
Inseob Kim64c43952019-08-26 16:52:35 +09002965 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002966 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
2967 }
2968
2969 for _, variant := range android.FirstUniqueStrings(productVariants) {
2970 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09002971 }
Colin Cross7228ecd2019-11-18 16:00:16 -08002972
Yifan Hong1b3348d2020-01-21 15:53:22 -08002973 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Colin Cross7228ecd2019-11-18 16:00:16 -08002974 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
2975 m.Properties.CoreVariantNeeded = coreVariantNeeded
2976}
2977
2978func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
2979 return c.Properties.CoreVariantNeeded
2980}
2981
Yifan Hong1b3348d2020-01-21 15:53:22 -08002982func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
2983 return c.Properties.RamdiskVariantNeeded
2984}
2985
Colin Cross7228ecd2019-11-18 16:00:16 -08002986func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
2987 return c.Properties.RecoveryVariantNeeded
2988}
2989
2990func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002991 return c.Properties.ExtraVariants
Colin Cross7228ecd2019-11-18 16:00:16 -08002992}
2993
2994func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
2995 m := module.(*Module)
Yifan Hong1b3348d2020-01-21 15:53:22 -08002996 if variant == android.RamdiskVariation {
2997 m.MakeAsPlatform()
2998 } else if variant == android.RecoveryVariation {
Colin Cross7228ecd2019-11-18 16:00:16 -08002999 m.MakeAsPlatform()
3000 squashRecoverySrcs(m)
3001 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003002 m.Properties.ImageVariationPrefix = VendorVariationPrefix
Colin Cross7228ecd2019-11-18 16:00:16 -08003003 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
3004 squashVendorSrcs(m)
Inseob Kimeec88e12020-01-22 11:11:29 +09003005
3006 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
3007 // Hide other vendor variants to avoid collision.
3008 vndkVersion := ctx.DeviceConfig().VndkVersion()
3009 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
3010 m.Properties.HideFromMake = true
3011 m.SkipInstall()
3012 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09003013 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
3014 m.Properties.ImageVariationPrefix = ProductVariationPrefix
3015 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
3016 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003017 }
3018}
3019
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003020func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08003021 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003022 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
3023 }
Colin Cross6510f912017-11-29 00:27:14 -08003024 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003025}
3026
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003027func kytheExtractAllFactory() android.Singleton {
3028 return &kytheExtractAllSingleton{}
3029}
3030
3031type kytheExtractAllSingleton struct {
3032}
3033
3034func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3035 var xrefTargets android.Paths
3036 ctx.VisitAllModules(func(module android.Module) {
3037 if ccModule, ok := module.(xref); ok {
3038 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3039 }
3040 })
3041 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3042 if len(xrefTargets) > 0 {
3043 ctx.Build(pctx, android.BuildParams{
3044 Rule: blueprint.Phony,
3045 Output: android.PathForPhony(ctx, "xref_cxx"),
3046 Inputs: xrefTargets,
3047 //Default: true,
3048 })
3049 }
3050}
3051
Colin Cross06a931b2015-10-28 17:23:31 -07003052var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003053var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003054var BoolPtr = proptools.BoolPtr
3055var String = proptools.String
3056var StringPtr = proptools.StringPtr