blob: 4310a36c285c1035383fa1270fb073101dddad23 [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"`
Paul Duffin0cb37b92020-03-04 14:52:46 +0000253
254 Installable *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700255}
256
257type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900258 // whether this module should be allowed to be directly depended by other
259 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900260 // In addition, this module should be allowed to be directly depended by
261 // product modules with `product_specific: true`.
262 // If set to true, three variants will be built separately, one like
263 // normal, another limited to the set of libraries and headers
264 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700265 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900266 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700267 // so it shouldn't have any unversioned runtime dependencies, or
268 // make assumptions about the system that may not be true in the
269 // future.
270 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900271 // If set to false, this module becomes inaccessible from /vendor or /product
272 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900273 //
274 // Default value is true when vndk: {enabled: true} or vendor: true.
275 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700276 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900277 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700278 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900279
280 // whether this module is capable of being loaded with other instance
281 // (possibly an older version) of the same module in the same process.
282 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
283 // can be double loaded in a vendor process if the library is also a
284 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
285 // explicitly marked as `double_loadable: true` by the owner, or the dependency
286 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
287 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800288}
289
Colin Crossca860ac2016-01-04 14:34:37 -0800290type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800291 static() bool
292 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900293 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700294 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700295 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800296 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700297 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800298 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900299 isLlndk(config android.Config) bool
300 isLlndkPublic(config android.Config) bool
301 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900302 isVndk() bool
303 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800304 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900305 inProduct() bool
306 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800307 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900308 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800309 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700310 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700311 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800312 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800313 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800314 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800315 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800316 isForPlatform() bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900317 apexName() string
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)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000376 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800377 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700378 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700379 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900380 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800381}
382
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800383type xref interface {
384 XrefCcFiles() android.Paths
385}
386
Colin Crossc99deeb2016-04-11 15:06:20 -0700387var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700388 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
389 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
390 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
391 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
392 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800393 staticUnwinderDepTag = DependencyTag{Name: "static unwinder", Library: true}
Ivan Lozano183a3212019-10-18 14:18:45 -0700394 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
395 headerDepTag = DependencyTag{Name: "header", Library: true}
396 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
397 genSourceDepTag = DependencyTag{Name: "gen source"}
398 genHeaderDepTag = DependencyTag{Name: "gen header"}
399 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
400 objDepTag = DependencyTag{Name: "obj"}
401 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
402 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
403 reuseObjTag = DependencyTag{Name: "reuse objects"}
404 staticVariantTag = DependencyTag{Name: "static variant"}
405 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
406 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
407 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
408 runtimeDepTag = DependencyTag{Name: "runtime lib"}
409 coverageDepTag = DependencyTag{Name: "coverage"}
410 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700411)
412
Roland Levillainf89cd092019-07-29 16:22:59 +0100413func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700414 ccDepTag, ok := depTag.(DependencyTag)
415 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100416}
417
418func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700419 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100420 return ok && ccDepTag == runtimeDepTag
421}
422
423func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700424 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100425 return ok && ccDepTag == testPerSrcDepTag
426}
427
Colin Crossca860ac2016-01-04 14:34:37 -0800428// Module contains the properties and members used by all C/C++ module types, and implements
429// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
430// to construct the output file. Behavior can be customized with a Customizer interface
431type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700432 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700433 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900434 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900435 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700436
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700437 Properties BaseProperties
438 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700439
Colin Crossca860ac2016-01-04 14:34:37 -0800440 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700441 hod android.HostOrDeviceSupported
442 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700443
Paul Duffina0843f62019-12-13 19:50:38 +0000444 // Allowable SdkMemberTypes of this module type.
445 sdkMemberTypes []android.SdkMemberType
446
Colin Crossca860ac2016-01-04 14:34:37 -0800447 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700448 features []feature
449 compiler compiler
450 linker linker
451 installer installer
452 stl *stl
453 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800454 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800455 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900456 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700457 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700458 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800459
Colin Cross635c3b02016-05-18 15:37:25 -0700460 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800461
Colin Crossb98c8b02016-07-29 13:44:28 -0700462 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700463
464 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800465
466 // Flags used to compile this module
467 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700468
469 // 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 -0800470 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700471 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800472 depsInLinkOrder android.Paths
473
474 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700475 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900476
477 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800478 // Kythe (source file indexer) paths for this compilation module
479 kytheFiles android.Paths
Colin Crossc472d572015-03-17 15:06:21 -0700480}
481
Ivan Lozano52767be2019-10-18 14:49:46 -0700482func (c *Module) Toc() android.OptionalPath {
483 if c.linker != nil {
484 if library, ok := c.linker.(libraryInterface); ok {
485 return library.toc()
486 }
487 }
488 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
489}
490
491func (c *Module) ApiLevel() string {
492 if c.linker != nil {
493 if stub, ok := c.linker.(*stubDecorator); ok {
494 return stub.properties.ApiLevel
495 }
496 }
497 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
498}
499
500func (c *Module) Static() bool {
501 if c.linker != nil {
502 if library, ok := c.linker.(libraryInterface); ok {
503 return library.static()
504 }
505 }
506 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
507}
508
509func (c *Module) Shared() bool {
510 if c.linker != nil {
511 if library, ok := c.linker.(libraryInterface); ok {
512 return library.shared()
513 }
514 }
515 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
516}
517
518func (c *Module) SelectedStl() string {
519 return c.stl.Properties.SelectedStl
520}
521
522func (c *Module) ToolchainLibrary() bool {
523 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
524 return true
525 }
526 return false
527}
528
529func (c *Module) NdkPrebuiltStl() bool {
530 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
531 return true
532 }
533 return false
534}
535
536func (c *Module) StubDecorator() bool {
537 if _, ok := c.linker.(*stubDecorator); ok {
538 return true
539 }
540 return false
541}
542
543func (c *Module) SdkVersion() string {
544 return String(c.Properties.Sdk_version)
545}
546
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800547func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700548 if c.linker != nil {
549 if library, ok := c.linker.(exportedFlagsProducer); ok {
550 return library.exportedDirs()
551 }
552 }
553 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
554}
555
556func (c *Module) HasStaticVariant() bool {
557 if c.staticVariant != nil {
558 return true
559 }
560 return false
561}
562
563func (c *Module) GetStaticVariant() LinkableInterface {
564 return c.staticVariant
565}
566
567func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
568 c.depsInLinkOrder = depsInLinkOrder
569}
570
571func (c *Module) GetDepsInLinkOrder() []android.Path {
572 return c.depsInLinkOrder
573}
574
575func (c *Module) StubsVersions() []string {
576 if c.linker != nil {
577 if library, ok := c.linker.(*libraryDecorator); ok {
578 return library.Properties.Stubs.Versions
579 }
580 }
581 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
582}
583
584func (c *Module) CcLibrary() bool {
585 if c.linker != nil {
586 if _, ok := c.linker.(*libraryDecorator); ok {
587 return true
588 }
589 }
590 return false
591}
592
593func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700594 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700595 return true
596 }
597 return false
598}
599
Ivan Lozano2b262972019-11-21 12:30:50 -0800600func (c *Module) NonCcVariants() bool {
601 return false
602}
603
Ivan Lozano183a3212019-10-18 14:18:45 -0700604func (c *Module) SetBuildStubs() {
605 if c.linker != nil {
606 if library, ok := c.linker.(*libraryDecorator); ok {
607 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700608 c.Properties.HideFromMake = true
609 c.sanitize = nil
610 c.stl = nil
611 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700612 return
613 }
614 }
615 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
616}
617
Ivan Lozano52767be2019-10-18 14:49:46 -0700618func (c *Module) BuildStubs() bool {
619 if c.linker != nil {
620 if library, ok := c.linker.(*libraryDecorator); ok {
621 return library.buildStubs()
622 }
623 }
624 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
625}
626
Ivan Lozano183a3212019-10-18 14:18:45 -0700627func (c *Module) SetStubsVersions(version string) {
628 if c.linker != nil {
629 if library, ok := c.linker.(*libraryDecorator); ok {
630 library.MutatedProperties.StubsVersion = version
631 return
632 }
633 }
634 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
635}
636
Jooyung Han03b51852020-02-26 22:45:42 +0900637func (c *Module) StubsVersion() string {
638 if c.linker != nil {
639 if library, ok := c.linker.(*libraryDecorator); ok {
640 return library.MutatedProperties.StubsVersion
641 }
642 }
643 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
644}
645
Ivan Lozano183a3212019-10-18 14:18:45 -0700646func (c *Module) SetStatic() {
647 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700648 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700649 library.setStatic()
650 return
651 }
652 }
653 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
654}
655
656func (c *Module) SetShared() {
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.setShared()
660 return
661 }
662 }
663 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
664}
665
666func (c *Module) BuildStaticVariant() bool {
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 return library.buildStatic()
670 }
671 }
672 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
673}
674
675func (c *Module) BuildSharedVariant() bool {
676 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700677 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700678 return library.buildShared()
679 }
680 }
681 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
682}
683
684func (c *Module) Module() android.Module {
685 return c
686}
687
Jiyong Parkc20eee32018-09-05 22:36:17 +0900688func (c *Module) OutputFile() android.OptionalPath {
689 return c.outputFile
690}
691
Ivan Lozano183a3212019-10-18 14:18:45 -0700692var _ LinkableInterface = (*Module)(nil)
693
Jiyong Park719b4462019-01-13 00:39:51 +0900694func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900695 if c.linker != nil {
696 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900697 }
698 return nil
699}
700
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900701func (c *Module) CoverageOutputFile() android.OptionalPath {
702 if c.linker != nil {
703 return c.linker.coverageOutputFilePath()
704 }
705 return android.OptionalPath{}
706}
707
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900708func (c *Module) RelativeInstallPath() string {
709 if c.installer != nil {
710 return c.installer.relativeInstallPath()
711 }
712 return ""
713}
714
Jooyung Han344d5432019-08-23 11:17:39 +0900715func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900716 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900717}
718
Colin Cross36242852017-06-23 15:06:31 -0700719func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700720 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800721 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700722 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800723 }
724 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700725 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800726 }
727 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700728 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800729 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700730 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700731 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700732 }
Colin Cross16b23492016-01-06 14:41:07 -0800733 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700734 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800735 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800736 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700737 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800738 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800739 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700740 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800741 }
Justin Yun8effde42017-06-23 19:24:43 +0900742 if c.vndkdep != nil {
743 c.AddProperties(c.vndkdep.props()...)
744 }
Stephen Craneba090d12017-05-09 15:44:35 -0700745 if c.lto != nil {
746 c.AddProperties(c.lto.props()...)
747 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700748 if c.pgo != nil {
749 c.AddProperties(c.pgo.props()...)
750 }
Colin Crossca860ac2016-01-04 14:34:37 -0800751 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700752 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800753 }
Colin Crossc472d572015-03-17 15:06:21 -0700754
Colin Crossa9d8bee2018-10-02 13:59:46 -0700755 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
756 switch class {
757 case android.Device:
758 return ctx.Config().DevicePrefer32BitExecutables()
759 case android.HostCross:
760 // Windows builds always prefer 32-bit
761 return true
762 default:
763 return false
764 }
765 })
Colin Cross36242852017-06-23 15:06:31 -0700766 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900767 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900768 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900769 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900770
Colin Cross36242852017-06-23 15:06:31 -0700771 return c
Colin Crossc472d572015-03-17 15:06:21 -0700772}
773
Colin Crossb916a382016-07-29 17:28:03 -0700774// Returns true for dependency roots (binaries)
775// TODO(ccross): also handle dlopenable libraries
776func (c *Module) isDependencyRoot() bool {
777 if root, ok := c.linker.(interface {
778 isDependencyRoot() bool
779 }); ok {
780 return root.isDependencyRoot()
781 }
782 return false
783}
784
Justin Yun5f7f7e82019-11-18 19:52:14 +0900785// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
786// "product" and "vendor" variant modules return true for this function.
787// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
788// "soc_specific: true" and more vendor installed modules are included here.
789// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
790// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700791func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900792 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700793}
794
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800795func (c *Module) isCoverageVariant() bool {
796 return c.coverage.Properties.IsCoverageVariant
797}
798
Peter Collingbournead84f972019-12-17 16:46:18 -0800799func (c *Module) IsNdk() bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800800 return inList(c.Name(), ndkMigratedLibs)
801}
802
Inseob Kim9516ee92019-05-09 10:56:13 +0900803func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800804 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900805 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800806}
807
Inseob Kim9516ee92019-05-09 10:56:13 +0900808func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800809 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900810 name := c.BaseModuleName()
811 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800812}
813
Inseob Kim9516ee92019-05-09 10:56:13 +0900814func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800815 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900816 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800817}
818
Ivan Lozano52767be2019-10-18 14:49:46 -0700819func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800820 if vndkdep := c.vndkdep; vndkdep != nil {
821 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900822 }
823 return false
824}
825
Yi Kong7e53c572018-02-14 18:16:12 +0800826func (c *Module) isPgoCompile() bool {
827 if pgo := c.pgo; pgo != nil {
828 return pgo.Properties.PgoCompile
829 }
830 return false
831}
832
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800833func (c *Module) isNDKStubLibrary() bool {
834 if _, ok := c.compiler.(*stubDecorator); ok {
835 return true
836 }
837 return false
838}
839
Logan Chienf3511742017-10-31 18:04:35 +0800840func (c *Module) isVndkSp() bool {
841 if vndkdep := c.vndkdep; vndkdep != nil {
842 return vndkdep.isVndkSp()
843 }
844 return false
845}
846
847func (c *Module) isVndkExt() bool {
848 if vndkdep := c.vndkdep; vndkdep != nil {
849 return vndkdep.isVndkExt()
850 }
851 return false
852}
853
Ivan Lozano52767be2019-10-18 14:49:46 -0700854func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900855 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800856}
857
Logan Chienf3511742017-10-31 18:04:35 +0800858func (c *Module) getVndkExtendsModuleName() string {
859 if vndkdep := c.vndkdep; vndkdep != nil {
860 return vndkdep.getVndkExtendsModuleName()
861 }
862 return ""
863}
864
Justin Yun5f7f7e82019-11-18 19:52:14 +0900865// Returns true only when this module is configured to have core, product and vendor
Jiyong Park82e2bf32017-08-16 14:05:54 +0900866// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700867func (c *Module) HasVendorVariant() bool {
868 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900869}
870
Justin Yun5f7f7e82019-11-18 19:52:14 +0900871const (
872 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
873 // against the VNDK.
874 VendorVariationPrefix = "vendor."
875
876 // ProductVariationPrefix is the variant prefix used for /product code that compiles
877 // against the VNDK.
878 ProductVariationPrefix = "product."
879)
880
881// Returns true if the module is "product" variant. Usually these modules are installed in /product
882func (c *Module) inProduct() bool {
883 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
884}
885
886// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
887func (c *Module) inVendor() bool {
888 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
889}
890
Yifan Hong1b3348d2020-01-21 15:53:22 -0800891func (c *Module) InRamdisk() bool {
892 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
893}
894
Ivan Lozano52767be2019-10-18 14:49:46 -0700895func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800896 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900897}
898
Yifan Hong1b3348d2020-01-21 15:53:22 -0800899func (c *Module) OnlyInRamdisk() bool {
900 return c.ModuleBase.InstallInRamdisk()
901}
902
Ivan Lozano52767be2019-10-18 14:49:46 -0700903func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900904 return c.ModuleBase.InstallInRecovery()
905}
906
Jiyong Park25fc6a92018-11-18 18:02:45 +0900907func (c *Module) IsStubs() bool {
908 if library, ok := c.linker.(*libraryDecorator); ok {
909 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900910 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
911 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900912 }
913 return false
914}
915
916func (c *Module) HasStubsVariants() bool {
917 if library, ok := c.linker.(*libraryDecorator); ok {
918 return len(library.Properties.Stubs.Versions) > 0
919 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700920 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
921 return len(library.Properties.Stubs.Versions) > 0
922 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900923 return false
924}
925
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900926func (c *Module) bootstrap() bool {
927 return Bool(c.Properties.Bootstrap)
928}
929
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700930func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700931 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
932 if c.Target().NativeBridge == android.NativeBridgeEnabled {
933 return false
934 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700935 return c.linker != nil && c.linker.nativeCoverage()
936}
937
Inseob Kim8471cda2019-11-15 09:59:12 +0900938func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kimeec88e12020-01-22 11:11:29 +0900939 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
940 return true
941 }
942 if _, ok := c.linker.(*vendorSnapshotLibraryDecorator); ok {
943 return true
944 }
945 if _, ok := c.linker.(*vendorSnapshotBinaryDecorator); ok {
946 return true
947 }
948 return false
Inseob Kim8471cda2019-11-15 09:59:12 +0900949}
950
Jiyong Park73c54ee2019-10-22 20:31:18 +0900951func (c *Module) ExportedIncludeDirs() android.Paths {
952 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
953 return flagsProducer.exportedDirs()
954 }
Jiyong Park232e7852019-11-04 12:23:40 +0900955 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900956}
957
958func (c *Module) ExportedSystemIncludeDirs() android.Paths {
959 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
960 return flagsProducer.exportedSystemDirs()
961 }
Jiyong Park232e7852019-11-04 12:23:40 +0900962 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900963}
964
965func (c *Module) ExportedFlags() []string {
966 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
967 return flagsProducer.exportedFlags()
968 }
Jiyong Park232e7852019-11-04 12:23:40 +0900969 return nil
970}
971
972func (c *Module) ExportedDeps() android.Paths {
973 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
974 return flagsProducer.exportedDeps()
975 }
976 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900977}
978
Inseob Kimd110f872019-12-06 13:15:38 +0900979func (c *Module) ExportedGeneratedHeaders() android.Paths {
980 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
981 return flagsProducer.exportedGeneratedHeaders()
982 }
983 return nil
984}
985
Jiyong Parkf1194352019-02-25 11:05:47 +0900986func isBionic(name string) bool {
987 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +0000988 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +0900989 return true
990 }
991 return false
992}
993
Martin Stjernholm279de572019-09-10 23:18:20 +0100994func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700995 if name == "libclang_rt.hwasan-aarch64-android" {
996 return inList("hwaddress", config.SanitizeDevice())
997 }
998 return isBionic(name)
999}
1000
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001001func (c *Module) XrefCcFiles() android.Paths {
1002 return c.kytheFiles
1003}
1004
Colin Crossca860ac2016-01-04 14:34:37 -08001005type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001006 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001007 moduleContextImpl
1008}
1009
Colin Cross37047f12016-12-13 17:06:13 -08001010type depsContext struct {
1011 android.BottomUpMutatorContext
1012 moduleContextImpl
1013}
1014
Colin Crossca860ac2016-01-04 14:34:37 -08001015type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001016 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001017 moduleContextImpl
1018}
1019
Justin Yun5f7f7e82019-11-18 19:52:14 +09001020func (ctx *moduleContext) ProductSpecific() bool {
1021 return ctx.ModuleContext.ProductSpecific() ||
1022 (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
1023}
1024
Jiyong Park2db76922017-11-08 16:03:48 +09001025func (ctx *moduleContext) SocSpecific() bool {
1026 return ctx.ModuleContext.SocSpecific() ||
Justin Yun5f7f7e82019-11-18 19:52:14 +09001027 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001028}
1029
Colin Crossca860ac2016-01-04 14:34:37 -08001030type moduleContextImpl struct {
1031 mod *Module
1032 ctx BaseModuleContext
1033}
1034
Colin Crossb98c8b02016-07-29 13:44:28 -07001035func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001036 return ctx.mod.toolchain(ctx.ctx)
1037}
1038
1039func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001040 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001041}
1042
1043func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001044 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001045}
1046
Jiyong Park1d1119f2019-07-29 21:27:18 +09001047func (ctx *moduleContextImpl) header() bool {
1048 return ctx.mod.header()
1049}
1050
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001051func (ctx *moduleContextImpl) useSdk() bool {
Yifan Hong1b3348d2020-01-21 15:53:22 -08001052 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRamdisk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -08001053 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -07001054 }
1055 return false
Colin Crossca860ac2016-01-04 14:34:37 -08001056}
1057
1058func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001059 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001060 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001061 vndkVer := ctx.mod.VndkVersion()
1062 if inList(vndkVer, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
1063 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001064 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001065 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001066 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001067 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001068 }
1069 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001070}
1071
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001072func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001073 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001074}
Justin Yun8effde42017-06-23 19:24:43 +09001075
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001076func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001077 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001078}
1079
Inseob Kim9516ee92019-05-09 10:56:13 +09001080func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1081 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001082}
1083
Inseob Kim9516ee92019-05-09 10:56:13 +09001084func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1085 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001086}
1087
Inseob Kim9516ee92019-05-09 10:56:13 +09001088func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1089 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001090}
1091
Logan Chienf3511742017-10-31 18:04:35 +08001092func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001093 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001094}
1095
Yi Kong7e53c572018-02-14 18:16:12 +08001096func (ctx *moduleContextImpl) isPgoCompile() bool {
1097 return ctx.mod.isPgoCompile()
1098}
1099
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001100func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1101 return ctx.mod.isNDKStubLibrary()
1102}
1103
Justin Yun8effde42017-06-23 19:24:43 +09001104func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001105 return ctx.mod.isVndkSp()
1106}
1107
1108func (ctx *moduleContextImpl) isVndkExt() bool {
1109 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001110}
1111
Vic Yangefd249e2018-11-12 20:19:56 -08001112func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001113 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001114}
1115
Justin Yun5f7f7e82019-11-18 19:52:14 +09001116func (ctx *moduleContextImpl) inProduct() bool {
1117 return ctx.mod.inProduct()
1118}
1119
1120func (ctx *moduleContextImpl) inVendor() bool {
1121 return ctx.mod.inVendor()
1122}
1123
Yifan Hong1b3348d2020-01-21 15:53:22 -08001124func (ctx *moduleContextImpl) inRamdisk() bool {
1125 return ctx.mod.InRamdisk()
1126}
1127
Jiyong Parkf9332f12018-02-01 00:54:12 +09001128func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001129 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001130}
1131
Logan Chien2f2b8902018-07-10 15:01:19 +08001132// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001133func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001134 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1135 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001136 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001137
1138 if ctx.ctx.Fuchsia() {
1139 return false
1140 }
1141
Logan Chien2f2b8902018-07-10 15:01:19 +08001142 if sanitize := ctx.mod.sanitize; sanitize != nil {
1143 if !sanitize.isVariantOnProductionDevice() {
1144 return false
1145 }
1146 }
1147 if !ctx.ctx.Device() {
1148 // Host modules do not need ABI dumps.
1149 return false
1150 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001151 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001152 // Stubs do not need ABI dumps.
1153 return false
1154 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001155 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001156}
1157
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001158func (ctx *moduleContextImpl) selectedStl() string {
1159 if stl := ctx.mod.stl; stl != nil {
1160 return stl.Properties.SelectedStl
1161 }
1162 return ""
1163}
1164
Ivan Lozanobd721262018-11-27 14:33:03 -08001165func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1166 return ctx.mod.linker.useClangLld(actx)
1167}
1168
Colin Crossce75d2c2016-10-06 16:12:58 -07001169func (ctx *moduleContextImpl) baseModuleName() string {
1170 return ctx.mod.ModuleBase.BaseModuleName()
1171}
1172
Logan Chienf3511742017-10-31 18:04:35 +08001173func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1174 return ctx.mod.getVndkExtendsModuleName()
1175}
1176
Logan Chiene274fc92019-12-03 11:18:32 -08001177func (ctx *moduleContextImpl) isForPlatform() bool {
1178 return ctx.mod.IsForPlatform()
1179}
1180
Jiyong Park58e364a2019-01-19 19:24:06 +09001181func (ctx *moduleContextImpl) apexName() string {
1182 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001183}
1184
Jiyong Parkb0788572018-12-20 22:10:17 +09001185func (ctx *moduleContextImpl) hasStubsVariants() bool {
1186 return ctx.mod.HasStubsVariants()
1187}
1188
1189func (ctx *moduleContextImpl) isStubs() bool {
1190 return ctx.mod.IsStubs()
1191}
1192
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001193func (ctx *moduleContextImpl) bootstrap() bool {
1194 return ctx.mod.bootstrap()
1195}
1196
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001197func (ctx *moduleContextImpl) nativeCoverage() bool {
1198 return ctx.mod.nativeCoverage()
1199}
1200
Colin Cross635c3b02016-05-18 15:37:25 -07001201func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001202 return &Module{
1203 hod: hod,
1204 multilib: multilib,
1205 }
1206}
1207
Colin Cross635c3b02016-05-18 15:37:25 -07001208func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001209 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001210 module.features = []feature{
1211 &tidyFeature{},
1212 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001213 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001214 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001215 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001216 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001217 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001218 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001219 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001220 return module
1221}
1222
Colin Crossce75d2c2016-10-06 16:12:58 -07001223func (c *Module) Prebuilt() *android.Prebuilt {
1224 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1225 return p.prebuilt()
1226 }
1227 return nil
1228}
1229
1230func (c *Module) Name() string {
1231 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001232 if p, ok := c.linker.(interface {
1233 Name(string) string
1234 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001235 name = p.Name(name)
1236 }
1237 return name
1238}
1239
Alex Light3d673592019-01-18 14:37:31 -08001240func (c *Module) Symlinks() []string {
1241 if p, ok := c.installer.(interface {
1242 symlinkList() []string
1243 }); ok {
1244 return p.symlinkList()
1245 }
1246 return nil
1247}
1248
Jeff Gaston294356f2017-09-27 17:05:30 -07001249// orderDeps reorders dependencies into a list such that if module A depends on B, then
1250// A will precede B in the resultant list.
1251// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001252// Note that directSharedDeps should be the analogous static library for each shared lib dep
1253func 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 -07001254 // If A depends on B, then
1255 // Every list containing A will also contain B later in the list
1256 // So, after concatenating all lists, the final instance of B will have come from the same
1257 // original list as the final instance of A
1258 // So, the final instance of B will be later in the concatenation than the final A
1259 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1260 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001261 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001262 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001263 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1264 }
1265 for _, dep := range directSharedDeps {
1266 orderedAllDeps = append(orderedAllDeps, dep)
1267 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001268 }
1269
Colin Crossb6715442017-10-24 11:13:31 -07001270 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001271
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001272 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001273 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001274 // resultant list to only what the caller has chosen to include in directStaticDeps
1275 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001276
1277 return orderedAllDeps, orderedDeclaredDeps
1278}
1279
Ivan Lozano183a3212019-10-18 14:18:45 -07001280func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001281 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001282 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001283 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1284 staticDepFiles := []android.Path{}
1285 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001286 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1287 if dep.OutputFile().Valid() {
1288 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1289 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1290 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001291 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001292 sharedDepFiles := []android.Path{}
1293 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001294 if sharedDep.HasStaticVariant() {
1295 staticAnalogue := sharedDep.GetStaticVariant()
1296 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1297 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001298 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001299 }
1300
1301 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001302 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1303 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001304
1305 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001306}
1307
Roland Levillainf89cd092019-07-29 16:22:59 +01001308func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1309 test, ok := c.linker.(testPerSrc)
1310 return ok && test.isAllTestsVariation()
1311}
1312
Justin Yun5f7f7e82019-11-18 19:52:14 +09001313func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1314 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1315 // "current", it will append the VNDK version to the name suffix.
1316 var vndkVersion string
1317 var nameSuffix string
1318 if c.inProduct() {
1319 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1320 nameSuffix = productSuffix
1321 } else {
1322 vndkVersion = ctx.DeviceConfig().VndkVersion()
1323 nameSuffix = vendorSuffix
1324 }
1325 if vndkVersion == "current" {
1326 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1327 }
1328 if c.Properties.VndkVersion != vndkVersion {
1329 // add version suffix only if the module is using different vndk version than the
1330 // version in product or vendor partition.
1331 nameSuffix += "." + c.Properties.VndkVersion
1332 }
1333 return nameSuffix
1334}
1335
Colin Cross635c3b02016-05-18 15:37:25 -07001336func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001337 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001338 //
1339 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1340 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1341 // module and return early, as this module does not produce an output file per se.
1342 if c.IsTestPerSrcAllTestsVariation() {
1343 c.outputFile = android.OptionalPath{}
1344 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001345 }
1346
Jooyung Han38002912019-05-16 04:01:54 +09001347 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001348
Inseob Kim64c43952019-08-26 16:52:35 +09001349 c.Properties.SubName = ""
1350
1351 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1352 c.Properties.SubName += nativeBridgeSuffix
1353 }
1354
Justin Yun5f7f7e82019-11-18 19:52:14 +09001355 _, llndk := c.linker.(*llndkStubDecorator)
1356 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1357 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1358 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1359 // added for product variant only when we have vendor and product variants with core
1360 // variant. The suffix is not added for vendor-only or product-only module.
1361 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1362 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001363 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1364 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1365 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001366 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1367 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001368 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001369 c.Properties.SubName += recoverySuffix
1370 }
1371
Colin Crossca860ac2016-01-04 14:34:37 -08001372 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001373 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001374 moduleContextImpl: moduleContextImpl{
1375 mod: c,
1376 },
1377 }
1378 ctx.ctx = ctx
1379
Colin Crossf18e1102017-11-16 14:33:08 -08001380 deps := c.depsToPaths(ctx)
1381 if ctx.Failed() {
1382 return
1383 }
1384
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001385 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1386 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1387 }
1388
Colin Crossca860ac2016-01-04 14:34:37 -08001389 flags := Flags{
1390 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001391 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001392 }
Colin Crossca860ac2016-01-04 14:34:37 -08001393 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001394 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001395 }
1396 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001397 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001398 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001399 if c.stl != nil {
1400 flags = c.stl.flags(ctx, flags)
1401 }
Colin Cross16b23492016-01-06 14:41:07 -08001402 if c.sanitize != nil {
1403 flags = c.sanitize.flags(ctx, flags)
1404 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001405 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001406 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001407 }
Stephen Craneba090d12017-05-09 15:44:35 -07001408 if c.lto != nil {
1409 flags = c.lto.flags(ctx, flags)
1410 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001411 if c.pgo != nil {
1412 flags = c.pgo.flags(ctx, flags)
1413 }
Colin Crossca860ac2016-01-04 14:34:37 -08001414 for _, feature := range c.features {
1415 flags = feature.flags(ctx, flags)
1416 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001417 if ctx.Failed() {
1418 return
1419 }
1420
Colin Cross4af21ed2019-11-04 09:37:55 -08001421 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1422 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1423 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001424
Colin Cross4af21ed2019-11-04 09:37:55 -08001425 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001426
1427 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001428 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001429 }
1430 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001431 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001432 }
1433
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001434 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001435 // We need access to all the flags seen by a source file.
1436 if c.sabi != nil {
1437 flags = c.sabi.flags(ctx, flags)
1438 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001439
Colin Cross4af21ed2019-11-04 09:37:55 -08001440 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001441
Colin Crossca860ac2016-01-04 14:34:37 -08001442 // Optimization to reduce size of build.ninja
1443 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001444 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1445 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1446 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1447 flags.Local.CFlags = []string{"$cflags"}
1448 flags.Local.CppFlags = []string{"$cppflags"}
1449 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001450
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001451 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001452 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001453 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001454 if ctx.Failed() {
1455 return
1456 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001457 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001458 }
1459
Colin Crossca860ac2016-01-04 14:34:37 -08001460 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001461 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001462 if ctx.Failed() {
1463 return
1464 }
Colin Cross635c3b02016-05-18 15:37:25 -07001465 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001466
1467 // If a lib is directly included in any of the APEXes, unhide the stubs
1468 // variant having the latest version gets visible to make. In addition,
1469 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1470 // force anything in the make world to link against the stubs library.
1471 // (unless it is explicitly referenced via .bootstrap suffix or the
1472 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001473 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001474 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001475 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001476 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001477 c.Properties.HideFromMake = false // unhide
1478 // Note: this is still non-installable
1479 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001480
1481 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1482 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1483 if isSnapshotAware(ctx, c) {
1484 i.collectHeadersForSnapshot(ctx)
1485 }
1486 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001487 }
Colin Cross5049f022015-03-18 13:28:46 -07001488
Inseob Kim1f086e22019-05-09 13:29:15 +09001489 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001490 c.installer.install(ctx, c.outputFile.Path())
1491 if ctx.Failed() {
1492 return
Colin Crossca860ac2016-01-04 14:34:37 -08001493 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001494 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1495 // If the module has been specifically configure to not be installed then
1496 // skip the installation as otherwise it will break when running inside make
1497 // as the output path to install will not be specified. Not all uninstallable
1498 // modules can skip installation as some are needed for resolving make side
1499 // dependencies.
1500 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001501 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001502}
1503
Colin Cross0ea8ba82019-06-06 14:33:29 -07001504func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001505 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001506 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001507 }
Colin Crossca860ac2016-01-04 14:34:37 -08001508 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001509}
1510
Colin Crossca860ac2016-01-04 14:34:37 -08001511func (c *Module) begin(ctx BaseModuleContext) {
1512 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001513 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001514 }
Colin Crossca860ac2016-01-04 14:34:37 -08001515 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001516 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001517 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001518 if c.stl != nil {
1519 c.stl.begin(ctx)
1520 }
Colin Cross16b23492016-01-06 14:41:07 -08001521 if c.sanitize != nil {
1522 c.sanitize.begin(ctx)
1523 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001524 if c.coverage != nil {
1525 c.coverage.begin(ctx)
1526 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001527 if c.sabi != nil {
1528 c.sabi.begin(ctx)
1529 }
Justin Yun8effde42017-06-23 19:24:43 +09001530 if c.vndkdep != nil {
1531 c.vndkdep.begin(ctx)
1532 }
Stephen Craneba090d12017-05-09 15:44:35 -07001533 if c.lto != nil {
1534 c.lto.begin(ctx)
1535 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001536 if c.pgo != nil {
1537 c.pgo.begin(ctx)
1538 }
Colin Crossca860ac2016-01-04 14:34:37 -08001539 for _, feature := range c.features {
1540 feature.begin(ctx)
1541 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001542 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001543 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001544 if err != nil {
1545 ctx.PropertyErrorf("sdk_version", err.Error())
1546 }
Nan Zhang0007d812017-11-07 10:57:05 -08001547 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001548 }
Colin Crossca860ac2016-01-04 14:34:37 -08001549}
1550
Colin Cross37047f12016-12-13 17:06:13 -08001551func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001552 deps := Deps{}
1553
1554 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001555 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001556 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001557 // Add the PGO dependency (the clang_rt.profile runtime library), which
1558 // sometimes depends on symbols from libgcc, before libgcc gets added
1559 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001560 if c.pgo != nil {
1561 deps = c.pgo.deps(ctx, deps)
1562 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001563 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001564 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001565 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001566 if c.stl != nil {
1567 deps = c.stl.deps(ctx, deps)
1568 }
Colin Cross16b23492016-01-06 14:41:07 -08001569 if c.sanitize != nil {
1570 deps = c.sanitize.deps(ctx, deps)
1571 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001572 if c.coverage != nil {
1573 deps = c.coverage.deps(ctx, deps)
1574 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001575 if c.sabi != nil {
1576 deps = c.sabi.deps(ctx, deps)
1577 }
Justin Yun8effde42017-06-23 19:24:43 +09001578 if c.vndkdep != nil {
1579 deps = c.vndkdep.deps(ctx, deps)
1580 }
Stephen Craneba090d12017-05-09 15:44:35 -07001581 if c.lto != nil {
1582 deps = c.lto.deps(ctx, deps)
1583 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001584 for _, feature := range c.features {
1585 deps = feature.deps(ctx, deps)
1586 }
1587
Colin Crossb6715442017-10-24 11:13:31 -07001588 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1589 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1590 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1591 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1592 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1593 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001594 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001595
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001596 for _, lib := range deps.ReexportSharedLibHeaders {
1597 if !inList(lib, deps.SharedLibs) {
1598 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1599 }
1600 }
1601
1602 for _, lib := range deps.ReexportStaticLibHeaders {
1603 if !inList(lib, deps.StaticLibs) {
1604 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1605 }
1606 }
1607
Colin Cross5950f382016-12-13 12:50:57 -08001608 for _, lib := range deps.ReexportHeaderLibHeaders {
1609 if !inList(lib, deps.HeaderLibs) {
1610 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1611 }
1612 }
1613
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001614 for _, gen := range deps.ReexportGeneratedHeaders {
1615 if !inList(gen, deps.GeneratedHeaders) {
1616 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1617 }
1618 }
1619
Colin Crossc99deeb2016-04-11 15:06:20 -07001620 return deps
1621}
1622
Dan Albert7e9d2952016-08-04 13:02:36 -07001623func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001624 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001625 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001626 moduleContextImpl: moduleContextImpl{
1627 mod: c,
1628 },
1629 }
1630 ctx.ctx = ctx
1631
Colin Crossca860ac2016-01-04 14:34:37 -08001632 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001633}
1634
Jiyong Park7ed9de32018-10-15 22:25:07 +09001635// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001636func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001637 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1638 version := name[sharp+1:]
1639 libname := name[:sharp]
1640 return libname, version
1641 }
1642 return name, ""
1643}
1644
Colin Cross1e676be2016-10-12 14:38:15 -07001645func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001646 if !c.Enabled() {
1647 return
1648 }
1649
Colin Cross37047f12016-12-13 17:06:13 -08001650 ctx := &depsContext{
1651 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001652 moduleContextImpl: moduleContextImpl{
1653 mod: c,
1654 },
1655 }
1656 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001657
Colin Crossc99deeb2016-04-11 15:06:20 -07001658 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001659
Dan Albert914449f2016-06-17 16:45:24 -07001660 variantNdkLibs := []string{}
1661 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001662 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001663 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001664
Inseob Kimeec88e12020-01-22 11:11:29 +09001665 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001666 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001667 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001668 // 1. Name of an NDK library that refers to a prebuilt module.
1669 // For each of these, it adds the name of the prebuilt module (which will be in
1670 // prebuilts/ndk) to the list of nonvariant libs.
1671 // 2. Name of an NDK library that refers to an ndk_library module.
1672 // For each of these, it adds the name of the ndk_library module to the list of
1673 // variant libs.
1674 // 3. Anything else (so anything that isn't an NDK library).
1675 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001676 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001677 // The caller can then know to add the variantLibs dependencies differently from the
1678 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001679
Inseob Kim9516ee92019-05-09 10:56:13 +09001680 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001681 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1682
1683 rewriteVendorLibs := func(lib string) string {
1684 if isLlndkLibrary(lib, ctx.Config()) {
1685 return lib + llndkLibrarySuffix
1686 }
1687
1688 // only modules with BOARD_VNDK_VERSION uses snapshot.
1689 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1690 return lib
1691 }
1692
1693 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1694 return snapshot
1695 }
1696
1697 return lib
1698 }
1699
1700 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001701 variantLibs = []string{}
1702 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001703 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001704 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001705 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001706 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1707 if !inList(name, ndkMigratedLibs) {
1708 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001709 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001710 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001711 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001712 } else if ctx.useVndk() {
1713 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001714 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001715 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001716 if actx.OtherModuleExists(vendorPublicLib) {
1717 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1718 } else {
1719 // This can happen if vendor_public_library module is defined in a
1720 // namespace that isn't visible to the current module. In that case,
1721 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001722 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001723 }
Dan Albert914449f2016-06-17 16:45:24 -07001724 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001725 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001726 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001727 }
1728 }
Dan Albert914449f2016-06-17 16:45:24 -07001729 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001730 }
1731
Inseob Kimeec88e12020-01-22 11:11:29 +09001732 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1733 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1734 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1735 if ctx.useVndk() {
1736 for idx, lib := range deps.RuntimeLibs {
1737 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1738 }
1739 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001740 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001741
Jiyong Park7e636d02019-01-28 16:16:54 +09001742 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001743 if c.linker != nil {
1744 if library, ok := c.linker.(*libraryDecorator); ok {
1745 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001746 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001747 }
1748 }
1749 }
1750
Inseob Kimeec88e12020-01-22 11:11:29 +09001751 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1752 // only modules with BOARD_VNDK_VERSION uses snapshot.
1753 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1754 return lib
1755 }
1756
1757 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1758 return snapshot
1759 }
1760
1761 return lib
1762 }
1763
1764 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001765 for _, lib := range deps.HeaderLibs {
1766 depTag := headerDepTag
1767 if inList(lib, deps.ReexportHeaderLibHeaders) {
1768 depTag = headerExportDepTag
1769 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001770
1771 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1772
Jiyong Park7e636d02019-01-28 16:16:54 +09001773 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001774 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001775 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001776 } else {
1777 actx.AddVariationDependencies(nil, depTag, lib)
1778 }
1779 }
1780
1781 if buildStubs {
1782 // Stubs lib does not have dependency to other static/shared libraries.
1783 // Don't proceed.
1784 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001785 }
Colin Cross5950f382016-12-13 12:50:57 -08001786
Inseob Kimc0907f12019-02-08 21:00:45 +09001787 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001788 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001789
Jiyong Park5d1598f2019-02-25 22:14:17 +09001790 for _, lib := range deps.WholeStaticLibs {
1791 depTag := wholeStaticDepTag
1792 if impl, ok := syspropImplLibraries[lib]; ok {
1793 lib = impl
1794 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001795
1796 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1797
Jiyong Park5d1598f2019-02-25 22:14:17 +09001798 actx.AddVariationDependencies([]blueprint.Variation{
1799 {Mutator: "link", Variation: "static"},
1800 }, depTag, lib)
1801 }
1802
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001803 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001804 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001805 if inList(lib, deps.ReexportStaticLibHeaders) {
1806 depTag = staticExportDepTag
1807 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001808
1809 if impl, ok := syspropImplLibraries[lib]; ok {
1810 lib = impl
1811 }
1812
Inseob Kimeec88e12020-01-22 11:11:29 +09001813 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1814
Dan Willemsen59339a22018-07-22 21:18:45 -07001815 actx.AddVariationDependencies([]blueprint.Variation{
1816 {Mutator: "link", Variation: "static"},
1817 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001818 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001819
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001820 if deps.StaticUnwinderIfLegacy && ctx.Config().UnbundledBuild() {
1821 actx.AddVariationDependencies([]blueprint.Variation{
1822 {Mutator: "link", Variation: "static"},
1823 }, staticUnwinderDepTag, staticUnwinder(actx))
1824 }
1825
Inseob Kimeec88e12020-01-22 11:11:29 +09001826 for _, lib := range deps.LateStaticLibs {
1827 actx.AddVariationDependencies([]blueprint.Variation{
1828 {Mutator: "link", Variation: "static"},
1829 }, lateStaticDepTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
1830 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001831
Ivan Lozano183a3212019-10-18 14:18:45 -07001832 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001833 var variations []blueprint.Variation
1834 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Yifan Hong1b3348d2020-01-21 15:53:22 -08001835 versionVariantAvail := !ctx.useVndk() && !c.InRecovery() && !c.InRamdisk()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001836 if version != "" && versionVariantAvail {
1837 // Version is explicitly specified. i.e. libFoo#30
1838 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001839 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001840 }
1841 actx.AddVariationDependencies(variations, depTag, name)
1842
Jooyung Han03b51852020-02-26 22:45:42 +09001843 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001844 // The stubs library will be used when the depending module is built for APEX and
1845 // the dependent module is not in the same APEX.
Jooyung Han03b51852020-02-26 22:45:42 +09001846 if version == "" && versionVariantAvail {
1847 for _, ver := range stubsVersionsFor(actx.Config())[name] {
1848 // Note that depTag.ExplicitlyVersioned is false in this case.
1849 actx.AddVariationDependencies([]blueprint.Variation{
1850 {Mutator: "link", Variation: "shared"},
1851 {Mutator: "version", Variation: ver},
1852 }, depTag, name)
1853 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001854 }
1855 }
1856
Jiyong Park7ed9de32018-10-15 22:25:07 +09001857 // shared lib names without the #version suffix
1858 var sharedLibNames []string
1859
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001860 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001861 depTag := SharedDepTag
Jiyong Parkd7536ba2020-01-16 17:14:23 +09001862 if c.static() {
1863 depTag = SharedFromStaticDepTag
1864 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001865 if inList(lib, deps.ReexportSharedLibHeaders) {
1866 depTag = sharedExportDepTag
1867 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001868
1869 if impl, ok := syspropImplLibraries[lib]; ok {
1870 lib = impl
1871 }
1872
Jiyong Park73c54ee2019-10-22 20:31:18 +09001873 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001874 sharedLibNames = append(sharedLibNames, name)
1875
Jiyong Park25fc6a92018-11-18 18:02:45 +09001876 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001877 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001878
Jiyong Park7ed9de32018-10-15 22:25:07 +09001879 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001880 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001881 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1882 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1883 // linking against both the stubs lib and the non-stubs lib at the same time.
1884 continue
1885 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001886 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001887 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001888
Dan Willemsen59339a22018-07-22 21:18:45 -07001889 actx.AddVariationDependencies([]blueprint.Variation{
1890 {Mutator: "link", Variation: "shared"},
1891 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001892
Colin Cross68861832016-07-08 10:41:41 -07001893 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001894
1895 for _, gen := range deps.GeneratedHeaders {
1896 depTag := genHeaderDepTag
1897 if inList(gen, deps.ReexportGeneratedHeaders) {
1898 depTag = genHeaderExportDepTag
1899 }
1900 actx.AddDependency(c, depTag, gen)
1901 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001902
Colin Cross42d48b72018-08-29 14:10:52 -07001903 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001904
1905 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001906 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001907 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001908 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001909 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001910 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001911 if deps.LinkerFlagsFile != "" {
1912 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1913 }
1914 if deps.DynamicLinker != "" {
1915 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001916 }
Dan Albert914449f2016-06-17 16:45:24 -07001917
1918 version := ctx.sdkVersion()
1919 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001920 {Mutator: "ndk_api", Variation: version},
1921 {Mutator: "link", Variation: "shared"},
1922 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001923 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001924 {Mutator: "ndk_api", Variation: version},
1925 {Mutator: "link", Variation: "shared"},
1926 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001927
1928 if vndkdep := c.vndkdep; vndkdep != nil {
1929 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08001930 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08001931 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07001932 {Mutator: "link", Variation: "shared"},
1933 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001934 }
1935 }
Colin Cross6362e272015-10-29 15:25:03 -07001936}
Colin Cross21b9a242015-03-24 14:15:58 -07001937
Colin Crosse40b4ea2018-10-02 22:25:58 -07001938func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001939 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1940 c.beginMutator(ctx)
1941 }
1942}
1943
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001944// Whether a module can link to another module, taking into
1945// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07001946func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
1947 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001948 // Host code is not restricted
1949 return
1950 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001951
1952 // VNDK is cc.Module supported only for now.
1953 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001954 // Though vendor code is limited by the vendor mutator,
1955 // each vendor-available module needs to check
1956 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07001957 if ccTo, ok := to.(*Module); ok {
1958 if ccFrom.vndkdep != nil {
1959 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
1960 }
1961 } else {
1962 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001963 }
1964 return
1965 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001966 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001967 // Platform code can link to anything
1968 return
1969 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08001970 if from.InRamdisk() {
1971 // Ramdisk code is not NDK
1972 return
1973 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001974 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09001975 // Recovery code is not NDK
1976 return
1977 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001978 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001979 // These are always allowed
1980 return
1981 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001982 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001983 // These are allowed, but they don't set sdk_version
1984 return
1985 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001986 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001987 // These aren't real libraries, but are the stub shared libraries that are included in
1988 // the NDK.
1989 return
1990 }
Logan Chien834b9a62019-01-14 15:39:03 +08001991
Ivan Lozano52767be2019-10-18 14:49:46 -07001992 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08001993 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1994 // to link to libc++ (non-NDK and without sdk_version).
1995 return
1996 }
1997
Ivan Lozano52767be2019-10-18 14:49:46 -07001998 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001999 // NDK code linking to platform code is never okay.
2000 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002001 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002002 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002003 }
2004
2005 // At this point we know we have two NDK libraries, but we need to
2006 // check that we're not linking against anything built against a higher
2007 // API level, as it is only valid to link against older or equivalent
2008 // APIs.
2009
Inseob Kim01a28722018-04-11 09:48:45 +09002010 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002011 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002012 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002013 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002014 // Current can't be linked against by anything else.
2015 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002016 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002017 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002018 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002019 if err != nil {
2020 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002021 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002022 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002023 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002024 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002025 if err != nil {
2026 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002027 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002028 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002029 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002030
Inseob Kim01a28722018-04-11 09:48:45 +09002031 if toApi > fromApi {
2032 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002033 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002034 }
2035 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002036 }
Dan Albert202fe492017-12-15 13:56:59 -08002037
2038 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002039 fromStl := from.SelectedStl()
2040 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002041 if fromStl == "" || toStl == "" {
2042 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002043 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002044 // We can be permissive with the system "STL" since it is only the C++
2045 // ABI layer, but in the future we should make sure that everyone is
2046 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002047 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002048 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002049 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2050 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002051 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002052}
2053
Jiyong Park5fb8c102018-04-09 12:03:06 +09002054// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002055// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2056// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002057// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002058func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2059 check := func(child, parent android.Module) bool {
2060 to, ok := child.(*Module)
2061 if !ok {
2062 // follow thru cc.Defaults, etc.
2063 return true
2064 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002065
Jooyung Hana70f0672019-01-18 15:20:43 +09002066 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2067 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002068 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002069
2070 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002071 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002072 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002073 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002074
Jooyung Han0302a842019-10-30 18:43:49 +09002075 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002076 return false
2077 }
2078
2079 var stringPath []string
2080 for _, m := range ctx.GetWalkPath() {
2081 stringPath = append(stringPath, m.Name())
2082 }
2083 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2084 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2085 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2086 return false
2087 }
2088 if module, ok := ctx.Module().(*Module); ok {
2089 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002090 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002091 ctx.WalkDeps(check)
2092 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002093 }
2094 }
2095}
2096
Colin Crossc99deeb2016-04-11 15:06:20 -07002097// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002098func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002099 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002100
Ivan Lozano183a3212019-10-18 14:18:45 -07002101 directStaticDeps := []LinkableInterface{}
2102 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002103
Inseob Kim9516ee92019-05-09 10:56:13 +09002104 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2105
Inseob Kim69378442019-06-03 19:10:47 +09002106 reexportExporter := func(exporter exportedFlagsProducer) {
2107 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2108 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2109 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2110 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002111 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002112 }
2113
Colin Crossd11fcda2017-10-23 17:59:01 -07002114 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002115 depName := ctx.OtherModuleName(dep)
2116 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002117
Ivan Lozano52767be2019-10-18 14:49:46 -07002118 ccDep, ok := dep.(LinkableInterface)
2119 if !ok {
2120
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002121 // handling for a few module types that aren't cc Module but that are also supported
2122 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002123 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002124 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002125 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2126 genRule.GeneratedSourceFiles()...)
2127 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002128 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002129 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002130 // Support exported headers from a generated_sources dependency
2131 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002132 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002133 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002134 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Inseob Kimd110f872019-12-06 13:15:38 +09002135 genRule.GeneratedSourceFiles()...)
2136 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002137 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002138 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002139 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002140 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002141 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002142 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2143 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002144 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002145 // 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 +09002146 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002147
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002148 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002149 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002150 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002151 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002152 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002153 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002154 files := genRule.GeneratedSourceFiles()
2155 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002156 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002157 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002158 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 -07002159 }
2160 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002161 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002162 }
Colin Crossca860ac2016-01-04 14:34:37 -08002163 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002164 return
2165 }
2166
Colin Crossfe17f6f2019-03-28 19:30:56 -07002167 if depTag == android.ProtoPluginDepTag {
2168 return
2169 }
2170
Colin Crossd11fcda2017-10-23 17:59:01 -07002171 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002172 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2173 return
2174 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002175 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002176 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002177 return
2178 }
2179
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002180 // re-exporting flags
2181 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002182 // reusing objects only make sense for cc.Modules.
2183 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002184 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002185 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002186 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002187 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002188 return
2189 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002190 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002191
Jiyong Parke4bb9862019-02-01 00:31:10 +09002192 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002193 // staticVariants are a cc.Module specific concept.
2194 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002195 c.staticVariant = ccDep
2196 return
2197 }
2198 }
2199
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002200 if depTag == staticUnwinderDepTag {
Jooyung Han03b51852020-02-26 22:45:42 +09002201 // Use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
2202 if c.ShouldSupportAndroid10() {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002203 depTag = StaticDepTag
2204 } else {
2205 return
2206 }
2207 }
2208
Ivan Lozano183a3212019-10-18 14:18:45 -07002209 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
2210 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
2211 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002212 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07002213 if t, ok := depTag.(DependencyTag); ok {
2214 explicitlyVersioned = t.ExplicitlyVersioned
2215 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002216 depTag = t
2217 }
2218
Ivan Lozano183a3212019-10-18 14:18:45 -07002219 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002220 depIsStatic := false
2221 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002222 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002223 depIsStatic = true
2224 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002225 if ccDep.CcLibrary() && !depIsStatic {
2226 depIsStubs := ccDep.BuildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09002227 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002228 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002229 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002230
2231 var useThisDep bool
2232 if depIsStubs && explicitlyVersioned {
2233 // Always respect dependency to the versioned stubs (i.e. libX#10)
2234 useThisDep = true
2235 } else if !depHasStubs {
2236 // Use non-stub variant if that is the only choice
2237 // (i.e. depending on a lib without stubs.version property)
2238 useThisDep = true
2239 } else if c.IsForPlatform() {
2240 // If not building for APEX, use stubs only when it is from
2241 // an APEX (and not from platform)
2242 useThisDep = (depInPlatform != depIsStubs)
Yifan Hong1b3348d2020-01-21 15:53:22 -08002243 if c.InRamdisk() || c.InRecovery() || c.bootstrap() {
2244 // However, for ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002245 // always link to non-stub variant
2246 useThisDep = !depIsStubs
2247 }
2248 } else {
2249 // If building for APEX, use stubs only when it is not from
2250 // the same APEX
2251 useThisDep = (depInSameApex != depIsStubs)
2252 }
2253
Jooyung Han03b51852020-02-26 22:45:42 +09002254 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
2255 if useThisDep && depIsStubs && !explicitlyVersioned {
2256 useLatest := c.IsForPlatform() || (c.ShouldSupportAndroid10() && !ctx.Config().UnbundledBuild())
2257 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), useLatest)
2258 if err != nil {
2259 ctx.OtherModuleErrorf(dep, err.Error())
2260 return
2261 }
2262 if versionToUse != ccDep.StubsVersion() {
2263 useThisDep = false
2264 }
2265 }
2266
Jiyong Park25fc6a92018-11-18 18:02:45 +09002267 if !useThisDep {
2268 return // stop processing this dep
2269 }
2270 }
2271
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002272 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2273
Ivan Lozano52767be2019-10-18 14:49:46 -07002274 // Exporting flags only makes sense for cc.Modules
2275 if _, ok := ccDep.(*Module); ok {
2276 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002277 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002278 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedGeneratedHeaders()...)
2279 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002280 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002281
Ivan Lozano52767be2019-10-18 14:49:46 -07002282 if t.ReexportFlags {
2283 reexportExporter(i)
2284 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2285 // Re-exported shared library headers must be included as well since they can help us with type information
2286 // about template instantiations (instantiated from their headers).
2287 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2288 // scripts.
2289 c.sabi.Properties.ReexportedIncludes = append(
2290 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2291 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002292 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002293 }
Logan Chienf3511742017-10-31 18:04:35 +08002294 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002295 }
2296
Colin Cross26c34ed2016-09-30 17:10:16 -07002297 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002298 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002299
Ivan Lozano52767be2019-10-18 14:49:46 -07002300 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002301 depFile := android.OptionalPath{}
2302
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002303 switch depTag {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002304 case ndkStubDepTag, SharedDepTag, SharedFromStaticDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002305 ptr = &depPaths.SharedLibs
2306 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002307 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002308 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002309
Jiyong Park64a44f22019-01-18 14:37:08 +09002310 case earlySharedDepTag:
2311 ptr = &depPaths.EarlySharedLibs
2312 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002313 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002314 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002315 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002316 ptr = &depPaths.LateSharedLibs
2317 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002318 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002319 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002320 ptr = nil
2321 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002322 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002323 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002324 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002325 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002326 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002327 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002328 return
2329 }
2330
Ivan Lozano52767be2019-10-18 14:49:46 -07002331 // Because the static library objects are included, this only makes sense
2332 // in the context of proper cc.Modules.
2333 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2334 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2335 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2336 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2337 for i := range missingDeps {
2338 missingDeps[i] += postfix
2339 }
2340 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002341 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002342 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2343 } else {
2344 ctx.ModuleErrorf(
2345 "non-cc.Modules cannot be included as whole static libraries.", depName)
2346 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002347 }
Colin Cross5950f382016-12-13 12:50:57 -08002348 case headerDepTag:
2349 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002350 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002351 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002352 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002353 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002354 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002355 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002356 case dynamicLinkerDepTag:
2357 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002358 }
2359
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002360 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002361 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
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)
Dan Willemsen581341d2017-02-09 16:16:31 -08002364 return
2365 }
2366
2367 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002368 // in static libraries act as if they were whole static libraries. The same goes for
2369 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002370 // This should only be done for cc.Modules
2371 if c, ok := ccDep.(*Module); ok {
2372 staticLib := c.linker.(libraryInterface)
2373 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2374 staticLib.objs().coverageFiles...)
2375 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2376 staticLib.objs().sAbiDumpFiles...)
2377 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002378 }
2379
Colin Cross26c34ed2016-09-30 17:10:16 -07002380 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002381 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002382 if !ctx.Config().AllowMissingDependencies() {
2383 ctx.ModuleErrorf("module %q missing output file", depName)
2384 } else {
2385 ctx.AddMissingDependencies([]string{depName})
2386 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002387 return
2388 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002389 *ptr = append(*ptr, linkFile.Path())
2390 }
2391
Colin Crossc99deeb2016-04-11 15:06:20 -07002392 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002393 dep := depFile
2394 if !dep.Valid() {
2395 dep = linkFile
2396 }
2397 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002398 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002399
Inseob Kimeec88e12020-01-22 11:11:29 +09002400 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2401
2402 baseLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002403 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002404 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002405 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kimeec88e12020-01-22 11:11:29 +09002406 return libName
2407 }
2408
2409 makeLibName := func(depName string) string {
2410 libName := baseLibName(depName)
Jooyung Han0302a842019-10-30 18:43:49 +09002411 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002412 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002413 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002414
Inseob Kimeec88e12020-01-22 11:11:29 +09002415 if c, ok := ccDep.(*Module); ok {
2416 // Use base module name for snapshots when exporting to Makefile.
2417 if c.isSnapshotPrebuilt() && !c.IsVndk() {
2418 baseName := c.BaseModuleName()
2419 if vendorSuffixModules[baseName] {
2420 return baseName + ".vendor"
2421 } else {
2422 return baseName
2423 }
2424 }
2425 }
2426
Yifan Hong1b3348d2020-01-21 15:53:22 -08002427 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002428 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2429 // core module instead.
2430 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002431 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002432 // The vendor module in Make will have been renamed to not conflict with the core
2433 // module, so update the dependency name here accordingly.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002434 return libName + c.getNameSuffixWithVndkVersion(ctx)
Jiyong Park374510b2018-03-19 18:23:01 +09002435 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002436 return libName + vendorPublicLibrarySuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08002437 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2438 return libName + ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002439 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002440 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002441 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002442 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002443 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002444 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002445 }
Logan Chien43d34c32017-12-20 01:17:32 +08002446 }
2447
2448 // Export the shared libs to Make.
2449 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002450 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002451 if ccDep.CcLibrary() {
2452 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002453 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002454 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002455 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002456 c.Properties.ApexesProvidingSharedLibs = append(
2457 c.Properties.ApexesProvidingSharedLibs, an)
2458 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002459 }
2460 }
2461
Jiyong Park27b188b2017-07-18 13:23:39 +09002462 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002463 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002464 c.Properties.AndroidMkSharedLibs = append(
2465 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002466 // Record baseLibName for snapshots.
2467 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002468 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002469 c.Properties.AndroidMkSharedLibs = append(
2470 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002471 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002472 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002473 c.Properties.AndroidMkStaticLibs = append(
2474 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002475 case runtimeDepTag:
2476 c.Properties.AndroidMkRuntimeLibs = append(
2477 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002478 // Record baseLibName for snapshots.
2479 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002480 case wholeStaticDepTag:
2481 c.Properties.AndroidMkWholeStaticLibs = append(
2482 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002483 }
Colin Crossca860ac2016-01-04 14:34:37 -08002484 })
2485
Jeff Gaston294356f2017-09-27 17:05:30 -07002486 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002487 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002488
Colin Crossdd84e052017-05-17 13:44:16 -07002489 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002490 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002491 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2492 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002493 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kimd110f872019-12-06 13:15:38 +09002494 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002495 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2496 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002497 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002498 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002499 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002500
2501 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002502 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002503 }
Colin Crossdd84e052017-05-17 13:44:16 -07002504
Colin Crossca860ac2016-01-04 14:34:37 -08002505 return depPaths
2506}
2507
2508func (c *Module) InstallInData() bool {
2509 if c.installer == nil {
2510 return false
2511 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002512 return c.installer.inData()
2513}
2514
2515func (c *Module) InstallInSanitizerDir() bool {
2516 if c.installer == nil {
2517 return false
2518 }
2519 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002520 return true
2521 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002522 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002523}
2524
Yifan Hong1b3348d2020-01-21 15:53:22 -08002525func (c *Module) InstallInRamdisk() bool {
2526 return c.InRamdisk()
2527}
2528
Jiyong Parkf9332f12018-02-01 00:54:12 +09002529func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002530 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002531}
2532
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002533func (c *Module) HostToolPath() android.OptionalPath {
2534 if c.installer == nil {
2535 return android.OptionalPath{}
2536 }
2537 return c.installer.hostToolPath()
2538}
2539
Nan Zhangd4e641b2017-07-12 12:55:28 -07002540func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2541 return c.outputFile
2542}
2543
Colin Cross41955e82019-05-29 14:40:35 -07002544func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2545 switch tag {
2546 case "":
2547 if c.outputFile.Valid() {
2548 return android.Paths{c.outputFile.Path()}, nil
2549 }
2550 return android.Paths{}, nil
2551 default:
2552 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002553 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002554}
2555
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002556func (c *Module) static() bool {
2557 if static, ok := c.linker.(interface {
2558 static() bool
2559 }); ok {
2560 return static.static()
2561 }
2562 return false
2563}
2564
Jiyong Park379de2f2018-12-19 02:47:14 +09002565func (c *Module) staticBinary() bool {
2566 if static, ok := c.linker.(interface {
2567 staticBinary() bool
2568 }); ok {
2569 return static.staticBinary()
2570 }
2571 return false
2572}
2573
Jiyong Park1d1119f2019-07-29 21:27:18 +09002574func (c *Module) header() bool {
2575 if h, ok := c.linker.(interface {
2576 header() bool
2577 }); ok {
2578 return h.header()
2579 }
2580 return false
2581}
2582
Jooyung Han38002912019-05-16 04:01:54 +09002583func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002584 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002585 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2586 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002587 return "native:vndk"
2588 }
Jooyung Han38002912019-05-16 04:01:54 +09002589 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002590 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002591 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002592 if Bool(c.VendorProperties.Vendor_available) {
2593 return "native:vndk"
2594 }
2595 return "native:vndk_private"
2596 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002597 if c.inProduct() {
2598 return "native:product"
2599 }
Jooyung Han38002912019-05-16 04:01:54 +09002600 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002601 } else if c.InRamdisk() {
2602 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002603 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002604 return "native:recovery"
2605 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2606 return "native:ndk:none:none"
2607 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2608 //family, link := getNdkStlFamilyAndLinkType(c)
2609 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002610 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002611 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002612 } else {
2613 return "native:platform"
2614 }
2615}
2616
Jiyong Park9d452992018-10-03 00:38:19 +09002617// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002618// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002619func (c *Module) IsInstallableToApex() bool {
2620 if shared, ok := c.linker.(interface {
2621 shared() bool
2622 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002623 // Stub libs and prebuilt libs in a versioned SDK are not
2624 // installable to APEX even though they are shared libs.
2625 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002626 } else if _, ok := c.linker.(testPerSrc); ok {
2627 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002628 }
2629 return false
2630}
2631
Jiyong Parka90ca002019-10-07 15:47:24 +09002632func (c *Module) AvailableFor(what string) bool {
2633 if linker, ok := c.linker.(interface {
2634 availableFor(string) bool
2635 }); ok {
2636 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2637 } else {
2638 return c.ApexModuleBase.AvailableFor(what)
2639 }
2640}
2641
Paul Duffin0cb37b92020-03-04 14:52:46 +00002642// Return true if the module is ever installable.
2643func (c *Module) EverInstallable() bool {
2644 return c.installer != nil &&
2645 // Check to see whether the module is actually ever installable.
2646 c.installer.everInstallable()
2647}
2648
Inseob Kim1f086e22019-05-09 13:29:15 +09002649func (c *Module) installable() bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00002650 ret := c.EverInstallable() &&
2651 // Check to see whether the module has been configured to not be installed.
2652 proptools.BoolDefault(c.Properties.Installable, true) &&
2653 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002654
2655 // The platform variant doesn't need further condition. Apex variants however might not
2656 // be installable because it will likely to be included in the APEX and won't appear
2657 // in the system partition.
2658 if c.IsForPlatform() {
2659 return ret
2660 }
2661
2662 // Special case for modules that are configured to be installed to /data, which includes
2663 // test modules. For these modules, both APEX and non-APEX variants are considered as
2664 // installable. This is because even the APEX variants won't be included in the APEX, but
2665 // will anyway be installed to /data/*.
2666 // See b/146995717
2667 if c.InstallInData() {
2668 return ret
2669 }
2670
2671 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002672}
2673
Logan Chien41eabe62019-04-10 13:33:58 +08002674func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2675 if c.linker != nil {
2676 if library, ok := c.linker.(*libraryDecorator); ok {
2677 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2678 }
2679 }
2680}
2681
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002682func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002683 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002684 if cc, ok := dep.(*Module); ok {
Jiyong Park323a4c32020-03-01 17:29:06 +09002685 if cc.HasStubsVariants() {
2686 if depTag.Shared && depTag.Library {
2687 // dynamic dep to a stubs lib crosses APEX boundary
2688 return false
2689 }
2690 if IsRuntimeDepTag(depTag) {
2691 // runtime dep to a stubs lib also crosses APEX boundary
2692 return false
2693 }
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002694 }
2695 if depTag.FromStatic {
2696 // shared_lib dependency from a static lib is considered as crossing
2697 // the APEX boundary because the dependency doesn't actually is
2698 // linked; the dependency is used only during the compilation phase.
2699 return false
2700 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002701 }
2702 }
2703 return true
2704}
2705
Colin Cross2ba19d92015-05-07 15:44:20 -07002706//
Colin Crosscfad1192015-11-02 16:43:11 -08002707// Defaults
2708//
Colin Crossca860ac2016-01-04 14:34:37 -08002709type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002710 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002711 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002712 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002713}
2714
Patrice Arrudac249c712019-03-19 17:00:29 -07002715// cc_defaults provides a set of properties that can be inherited by other cc
2716// modules. A module can use the properties from a cc_defaults using
2717// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2718// merged (when possible) by prepending the default module's values to the
2719// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002720func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002721 return DefaultsFactory()
2722}
2723
Colin Cross36242852017-06-23 15:06:31 -07002724func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002725 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002726
Colin Cross36242852017-06-23 15:06:31 -07002727 module.AddProperties(props...)
2728 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002729 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002730 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002731 &BaseCompilerProperties{},
2732 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002733 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002734 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002735 &StaticProperties{},
2736 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002737 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002738 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002739 &TestProperties{},
2740 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002741 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002742 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002743 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002744 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002745 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002746 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002747 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002748 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002749 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002750 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002751 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002752 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002753 )
Colin Crosscfad1192015-11-02 16:43:11 -08002754
Jooyung Hancc372c52019-09-25 15:18:44 +09002755 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002756
2757 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002758}
2759
Jiyong Park6a43f042017-10-12 23:05:00 +09002760func squashVendorSrcs(m *Module) {
2761 if lib, ok := m.compiler.(*libraryDecorator); ok {
2762 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2763 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2764
2765 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2766 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2767 }
2768}
2769
Jiyong Parkf9332f12018-02-01 00:54:12 +09002770func squashRecoverySrcs(m *Module) {
2771 if lib, ok := m.compiler.(*libraryDecorator); ok {
2772 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2773 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2774
2775 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2776 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2777 }
2778}
2779
Colin Cross7228ecd2019-11-18 16:00:16 -08002780var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002781
Colin Cross7228ecd2019-11-18 16:00:16 -08002782func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002783 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002784 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002785 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002786
2787 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002788 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002789 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002790 }
Logan Chienf3511742017-10-31 18:04:35 +08002791
2792 if vndkdep := m.vndkdep; vndkdep != nil {
2793 if vndkdep.isVndk() {
Justin Yun0ecf0b22020-02-28 15:07:59 +09002794 if vendorSpecific || productSpecific {
Logan Chienf3511742017-10-31 18:04:35 +08002795 if !vndkdep.isVndkExt() {
2796 mctx.PropertyErrorf("vndk",
2797 "must set `extends: \"...\"` to vndk extension")
Justin Yun0ecf0b22020-02-28 15:07:59 +09002798 } else if m.VendorProperties.Vendor_available != nil {
2799 mctx.PropertyErrorf("vendor_available",
2800 "must not set at the same time as `vndk: {extends: \"...\"}`")
Logan Chienf3511742017-10-31 18:04:35 +08002801 }
2802 } else {
2803 if vndkdep.isVndkExt() {
2804 mctx.PropertyErrorf("vndk",
Justin Yun0ecf0b22020-02-28 15:07:59 +09002805 "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
Logan Chienf3511742017-10-31 18:04:35 +08002806 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002807 }
2808 if m.VendorProperties.Vendor_available == nil {
2809 mctx.PropertyErrorf("vndk",
2810 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08002811 }
2812 }
2813 } else {
2814 if vndkdep.isVndkSp() {
2815 mctx.PropertyErrorf("vndk",
2816 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08002817 }
2818 if vndkdep.isVndkExt() {
2819 mctx.PropertyErrorf("vndk",
2820 "must set `enabled: true` to set `extends: %q`",
2821 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002822 }
Justin Yun8effde42017-06-23 19:24:43 +09002823 }
2824 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002825
Jiyong Parkf9332f12018-02-01 00:54:12 +09002826 var coreVariantNeeded bool = false
Yifan Hong1b3348d2020-01-21 15:53:22 -08002827 var ramdiskVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002828 var recoveryVariantNeeded bool = false
2829
Inseob Kim64c43952019-08-26 16:52:35 +09002830 var vendorVariants []string
Justin Yun5f7f7e82019-11-18 19:52:14 +09002831 var productVariants []string
Inseob Kim64c43952019-08-26 16:52:35 +09002832
2833 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09002834 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
2835 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
2836 if boardVndkVersion == "current" {
2837 boardVndkVersion = platformVndkVersion
2838 }
2839 if productVndkVersion == "current" {
2840 productVndkVersion = platformVndkVersion
Inseob Kim64c43952019-08-26 16:52:35 +09002841 }
2842
Justin Yun5f7f7e82019-11-18 19:52:14 +09002843 if boardVndkVersion == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002844 // If the device isn't compiling against the VNDK, we always
2845 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002846 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002847 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002848 // LL-NDK stubs only exist in the vendor and product variants,
2849 // since the real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002850 vendorVariants = append(vendorVariants,
2851 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002852 boardVndkVersion,
2853 )
2854 productVariants = append(productVariants,
2855 platformVndkVersion,
2856 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002857 )
Jiyong Park2a454122017-10-19 15:59:33 +09002858 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2859 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002860 vendorVariants = append(vendorVariants,
2861 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002862 boardVndkVersion,
2863 )
2864 productVariants = append(productVariants,
2865 platformVndkVersion,
2866 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002867 )
Inseob Kimeec88e12020-01-22 11:11:29 +09002868 } else if m.isSnapshotPrebuilt() {
Justin Yun71549282017-11-17 12:10:28 +09002869 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2870 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kimeec88e12020-01-22 11:11:29 +09002871 if snapshot, ok := m.linker.(interface {
2872 version() string
2873 }); ok {
2874 vendorVariants = append(vendorVariants, snapshot.version())
2875 } else {
2876 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
2877 }
Justin Yun0ecf0b22020-02-28 15:07:59 +09002878 } else if m.HasVendorVariant() && !m.isVndkExt() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002879 // This will be available in /system, /vendor and /product
2880 // or a /system directory that is available to vendor and product.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002881 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002882 vendorVariants = append(vendorVariants, platformVndkVersion)
Justin Yun5f7f7e82019-11-18 19:52:14 +09002883 productVariants = append(productVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09002884 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
2885 // code is PLATFORM_VNDK_VERSION.
2886 // On the other hand, vendor_available modules which are not VNDK should
2887 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002888 // vendor_available modules are also available to /product.
Inseob Kimbc093672019-11-01 11:29:44 +09002889 if !m.IsVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002890 vendorVariants = append(vendorVariants, boardVndkVersion)
2891 productVariants = append(productVariants, productVndkVersion)
Inseob Kim64c43952019-08-26 16:52:35 +09002892 }
Logan Chienf3511742017-10-31 18:04:35 +08002893 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002894 // This will be available in /vendor (or /odm) only
Justin Yun5f7f7e82019-11-18 19:52:14 +09002895 vendorVariants = append(vendorVariants, boardVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002896 } else {
2897 // This is either in /system (or similar: /data), or is a
2898 // modules built with the NDK. Modules built with the NDK
2899 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002900 coreVariantNeeded = true
2901 }
2902
Justin Yun5f7f7e82019-11-18 19:52:14 +09002903 if boardVndkVersion != "" && productVndkVersion != "" {
2904 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
2905 // The module has "product_specific: true" that does not create core variant.
2906 coreVariantNeeded = false
2907 productVariants = append(productVariants, productVndkVersion)
2908 }
2909 } else {
2910 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
2911 // restriction to use system libs.
2912 // No product variants defined in this case.
2913 productVariants = []string{}
2914 }
2915
Yifan Hong1b3348d2020-01-21 15:53:22 -08002916 if Bool(m.Properties.Ramdisk_available) {
2917 ramdiskVariantNeeded = true
2918 }
2919
2920 if m.ModuleBase.InstallInRamdisk() {
2921 ramdiskVariantNeeded = true
2922 coreVariantNeeded = false
2923 }
2924
Jiyong Parkf9332f12018-02-01 00:54:12 +09002925 if Bool(m.Properties.Recovery_available) {
2926 recoveryVariantNeeded = true
2927 }
2928
2929 if m.ModuleBase.InstallInRecovery() {
2930 recoveryVariantNeeded = true
2931 coreVariantNeeded = false
2932 }
2933
Inseob Kim64c43952019-08-26 16:52:35 +09002934 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002935 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
2936 }
2937
2938 for _, variant := range android.FirstUniqueStrings(productVariants) {
2939 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09002940 }
Colin Cross7228ecd2019-11-18 16:00:16 -08002941
Yifan Hong1b3348d2020-01-21 15:53:22 -08002942 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Colin Cross7228ecd2019-11-18 16:00:16 -08002943 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
2944 m.Properties.CoreVariantNeeded = coreVariantNeeded
2945}
2946
2947func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
2948 return c.Properties.CoreVariantNeeded
2949}
2950
Yifan Hong1b3348d2020-01-21 15:53:22 -08002951func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
2952 return c.Properties.RamdiskVariantNeeded
2953}
2954
Colin Cross7228ecd2019-11-18 16:00:16 -08002955func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
2956 return c.Properties.RecoveryVariantNeeded
2957}
2958
2959func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002960 return c.Properties.ExtraVariants
Colin Cross7228ecd2019-11-18 16:00:16 -08002961}
2962
2963func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
2964 m := module.(*Module)
Yifan Hong1b3348d2020-01-21 15:53:22 -08002965 if variant == android.RamdiskVariation {
2966 m.MakeAsPlatform()
2967 } else if variant == android.RecoveryVariation {
Colin Cross7228ecd2019-11-18 16:00:16 -08002968 m.MakeAsPlatform()
2969 squashRecoverySrcs(m)
2970 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002971 m.Properties.ImageVariationPrefix = VendorVariationPrefix
Colin Cross7228ecd2019-11-18 16:00:16 -08002972 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
2973 squashVendorSrcs(m)
Inseob Kimeec88e12020-01-22 11:11:29 +09002974
2975 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
2976 // Hide other vendor variants to avoid collision.
2977 vndkVersion := ctx.DeviceConfig().VndkVersion()
2978 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
2979 m.Properties.HideFromMake = true
2980 m.SkipInstall()
2981 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002982 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
2983 m.Properties.ImageVariationPrefix = ProductVariationPrefix
2984 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
2985 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002986 }
2987}
2988
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002989func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002990 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002991 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2992 }
Colin Cross6510f912017-11-29 00:27:14 -08002993 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002994}
2995
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002996func kytheExtractAllFactory() android.Singleton {
2997 return &kytheExtractAllSingleton{}
2998}
2999
3000type kytheExtractAllSingleton struct {
3001}
3002
3003func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3004 var xrefTargets android.Paths
3005 ctx.VisitAllModules(func(module android.Module) {
3006 if ccModule, ok := module.(xref); ok {
3007 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3008 }
3009 })
3010 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3011 if len(xrefTargets) > 0 {
3012 ctx.Build(pctx, android.BuildParams{
3013 Rule: blueprint.Phony,
3014 Output: android.PathForPhony(ctx, "xref_cxx"),
3015 Inputs: xrefTargets,
3016 //Default: true,
3017 })
3018 }
3019}
3020
Colin Cross06a931b2015-10-28 17:23:31 -07003021var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003022var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003023var BoolPtr = proptools.BoolPtr
3024var String = proptools.String
3025var StringPtr = proptools.StringPtr