blob: cc54f7a566420d99dbb73caab6a2d5d3d568e02e [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -07001// Copyright 2015 Google Inc. All rights reserved.
Colin Cross3f40fa42015-01-30 17:27:36 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17// This file contains the module types for compiling C/C++ for Android, and converts the properties
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
Colin Cross41955e82019-05-29 14:40:35 -070022 "fmt"
Logan Chien41eabe62019-04-10 13:33:58 +080023 "io"
Dan Albert9e10cd42016-08-03 14:12:14 -070024 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080025 "strings"
26
Colin Cross97ba0732015-03-23 17:50:24 -070027 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070028 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070029
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070031 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070032 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080033)
34
Colin Cross463a90e2015-06-17 14:20:06 -070035func init() {
Paul Duffin036e7002019-12-19 19:16:28 +000036 RegisterCCBuildComponents(android.InitRegistrationContext)
Colin Cross463a90e2015-06-17 14:20:06 -070037
Paul Duffin036e7002019-12-19 19:16:28 +000038 pctx.Import("android/soong/cc/config")
39}
40
41func RegisterCCBuildComponents(ctx android.RegistrationContext) {
42 ctx.RegisterModuleType("cc_defaults", defaultsFactory)
43
44 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Inseob Kim64c43952019-08-26 16:52:35 +090045 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070046 ctx.BottomUp("link", LinkageMutator).Parallel()
Jooyung Hanb90e4912019-12-09 18:21:48 +090047 ctx.BottomUp("ndk_api", NdkApiMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +010048 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090049 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070050 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimac1e9862019-12-09 18:15:47 +090051 ctx.BottomUp("sysprop_cc", SyspropMutator).Parallel()
Inseob Kimeec88e12020-01-22 11:11:29 +090052 ctx.BottomUp("vendor_snapshot", VendorSnapshotMutator).Parallel()
53 ctx.BottomUp("vendor_snapshot_source", VendorSnapshotSourceMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070054 })
Colin Cross16b23492016-01-06 14:41:07 -080055
Paul Duffin036e7002019-12-19 19:16:28 +000056 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Cross1e676be2016-10-12 14:38:15 -070057 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
58 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080059
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070060 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
61 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
62
Mitch Phillipsbfeade62019-05-01 14:42:05 -070063 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
64 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
65
Jiyong Park1d1119f2019-07-29 21:27:18 +090066 // cfi mutator shouldn't run before sanitizers that return true for
67 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000068 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
69 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
70
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080071 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
72 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
73
Colin Cross1e676be2016-10-12 14:38:15 -070074 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
75 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080076
Colin Cross0b908332019-06-19 23:00:20 -070077 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090078 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080079
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080080 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080081 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070082
83 ctx.TopDown("lto_deps", ltoDepsMutator)
84 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090085
86 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070087 })
Colin Crossb98c8b02016-07-29 13:44:28 -070088
Sasha Smundak2a4549e2018-11-05 16:49:08 -080089 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070090}
91
Colin Crossca860ac2016-01-04 14:34:37 -080092type Deps struct {
93 SharedLibs, LateSharedLibs []string
94 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080095 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080096 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070097
Peter Collingbournedc4f9862020-02-12 17:13:25 -080098 StaticUnwinderIfLegacy bool
99
Colin Cross5950f382016-12-13 12:50:57 -0800100 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700101
Colin Cross81413472016-04-11 14:37:39 -0700102 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700103
Dan Willemsenb40aab62016-04-20 14:21:14 -0700104 GeneratedSources []string
105 GeneratedHeaders []string
Inseob Kimd110f872019-12-06 13:15:38 +0900106 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700107
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700108 ReexportGeneratedHeaders []string
109
Colin Cross97ba0732015-03-23 17:50:24 -0700110 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700111
112 // Used for host bionic
113 LinkerFlagsFile string
114 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700115}
116
Colin Crossca860ac2016-01-04 14:34:37 -0800117type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700118 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900119 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700120 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900121 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700122 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700123 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700124
Colin Cross26c34ed2016-09-30 17:10:16 -0700125 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700126 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800127 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700128 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700129
Colin Cross26c34ed2016-09-30 17:10:16 -0700130 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700131 GeneratedSources android.Paths
132 GeneratedHeaders android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900133 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700134
Inseob Kimd110f872019-12-06 13:15:38 +0900135 Flags []string
136 IncludeDirs android.Paths
137 SystemIncludeDirs android.Paths
138 ReexportedDirs android.Paths
139 ReexportedSystemDirs android.Paths
140 ReexportedFlags []string
141 ReexportedGeneratedHeaders android.Paths
142 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700143
Colin Cross26c34ed2016-09-30 17:10:16 -0700144 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700145 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700146
147 // Path to the file container flags to use with the linker
148 LinkerFlagsFile android.OptionalPath
149
150 // Path to the dynamic linker binary
151 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700152}
153
Colin Cross4af21ed2019-11-04 09:37:55 -0800154// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
155// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
156// command line so they can be overridden by the local module flags).
157type LocalOrGlobalFlags struct {
158 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700159 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800160 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700161 CFlags []string // Flags that apply to C and C++ source files
162 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
163 ConlyFlags []string // Flags that apply to C source files
164 CppFlags []string // Flags that apply to C++ source files
165 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700166 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800167}
168
169type Flags struct {
170 Local LocalOrGlobalFlags
171 Global LocalOrGlobalFlags
172
173 aidlFlags []string // Flags that apply to aidl source files
174 rsFlags []string // Flags that apply to renderscript source files
175 libFlags []string // Flags to add libraries early to the link order
176 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
177 TidyFlags []string // Flags that apply to clang-tidy
178 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700179
Colin Crossc3199482017-03-30 15:03:04 -0700180 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800181 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700182 SystemIncludeFlags []string
183
Colin Crossb98c8b02016-07-29 13:44:28 -0700184 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700185 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800186 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800187 SAbiDump bool
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800188 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800189
190 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800191 DynamicLinker string
192
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700193 CFlagsDeps android.Paths // Files depended on by compiler flags
194 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800195
Dan Willemsen98ab3112019-08-27 21:20:40 -0700196 AssemblerWithCpp bool
197 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800198
Colin Cross19878da2019-03-28 14:45:07 -0700199 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700200 protoC bool // Whether to use C instead of C++
201 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700202
203 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700204}
205
Colin Crossca860ac2016-01-04 14:34:37 -0800206// Properties used to compile all C or C++ modules
207type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700208 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800209 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700210
211 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800212 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700213
Jiyong Parkde866cb2018-12-07 23:08:36 +0900214 AndroidMkSharedLibs []string `blueprint:"mutated"`
215 AndroidMkStaticLibs []string `blueprint:"mutated"`
216 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
217 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
218 HideFromMake bool `blueprint:"mutated"`
219 PreventInstall bool `blueprint:"mutated"`
220 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700221
Justin Yun5f7f7e82019-11-18 19:52:14 +0900222 ImageVariationPrefix string `blueprint:"mutated"`
223 VndkVersion string `blueprint:"mutated"`
224 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800225
226 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
227 // file
228 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900229
Yifan Hong1b3348d2020-01-21 15:53:22 -0800230 // Make this module available when building for ramdisk
231 Ramdisk_available *bool
232
Jiyong Parkf9332f12018-02-01 00:54:12 +0900233 // Make this module available when building for recovery
234 Recovery_available *bool
235
Colin Crossae6c5202019-11-20 13:35:50 -0800236 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800237 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800238 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800239 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900240 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900241
242 // Allows this module to use non-APEX version of libraries. Useful
243 // for building binaries that are started before APEXes are activated.
244 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900245
246 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
247 // see soong/cc/config/vndk.go
248 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900249
250 // Used by vendor snapshot to record dependencies from snapshot modules.
251 SnapshotSharedLibs []string `blueprint:"mutated"`
252 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700253}
254
255type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900256 // whether this module should be allowed to be directly depended by other
257 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900258 // In addition, this module should be allowed to be directly depended by
259 // product modules with `product_specific: true`.
260 // If set to true, three variants will be built separately, one like
261 // normal, another limited to the set of libraries and headers
262 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700263 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900264 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700265 // so it shouldn't have any unversioned runtime dependencies, or
266 // make assumptions about the system that may not be true in the
267 // future.
268 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900269 // If set to false, this module becomes inaccessible from /vendor or /product
270 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900271 //
272 // Default value is true when vndk: {enabled: true} or vendor: true.
273 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700274 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900275 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700276 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900277
278 // whether this module is capable of being loaded with other instance
279 // (possibly an older version) of the same module in the same process.
280 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
281 // can be double loaded in a vendor process if the library is also a
282 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
283 // explicitly marked as `double_loadable: true` by the owner, or the dependency
284 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
285 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800286}
287
Colin Crossca860ac2016-01-04 14:34:37 -0800288type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800289 static() bool
290 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900291 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700292 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700293 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800294 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700295 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800296 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900297 isLlndk(config android.Config) bool
298 isLlndkPublic(config android.Config) bool
299 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900300 isVndk() bool
301 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800302 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900303 inProduct() bool
304 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800305 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900306 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800307 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700308 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700309 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800310 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800311 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800312 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800313 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800314 isForPlatform() bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900315 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900316 hasStubsVariants() bool
317 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900318 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800319 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700320 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800321}
322
323type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700324 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800325 ModuleContextIntf
326}
327
328type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700329 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800330 ModuleContextIntf
331}
332
Colin Cross37047f12016-12-13 17:06:13 -0800333type DepsContext interface {
334 android.BottomUpMutatorContext
335 ModuleContextIntf
336}
337
Colin Crossca860ac2016-01-04 14:34:37 -0800338type feature interface {
339 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800340 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800341 flags(ctx ModuleContext, flags Flags) Flags
342 props() []interface{}
343}
344
345type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700346 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800347 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800348 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700349 compilerProps() []interface{}
350
Colin Cross76fada02016-07-27 10:31:13 -0700351 appendCflags([]string)
352 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700353 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800354}
355
356type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700357 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800358 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700359 linkerFlags(ctx ModuleContext, flags Flags) Flags
360 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800361 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700362
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700363 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700364 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900365 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700366
367 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900368 coverageOutputFilePath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800369}
370
371type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700372 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700373 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800374 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700375 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700376 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900377 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800378}
379
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800380type xref interface {
381 XrefCcFiles() android.Paths
382}
383
Colin Crossc99deeb2016-04-11 15:06:20 -0700384var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700385 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
386 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
387 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
388 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
389 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800390 staticUnwinderDepTag = DependencyTag{Name: "static unwinder", Library: true}
Ivan Lozano183a3212019-10-18 14:18:45 -0700391 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
392 headerDepTag = DependencyTag{Name: "header", Library: true}
393 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
394 genSourceDepTag = DependencyTag{Name: "gen source"}
395 genHeaderDepTag = DependencyTag{Name: "gen header"}
396 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
397 objDepTag = DependencyTag{Name: "obj"}
398 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
399 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
400 reuseObjTag = DependencyTag{Name: "reuse objects"}
401 staticVariantTag = DependencyTag{Name: "static variant"}
402 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
403 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
404 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
405 runtimeDepTag = DependencyTag{Name: "runtime lib"}
406 coverageDepTag = DependencyTag{Name: "coverage"}
407 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700408)
409
Roland Levillainf89cd092019-07-29 16:22:59 +0100410func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700411 ccDepTag, ok := depTag.(DependencyTag)
412 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100413}
414
415func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700416 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100417 return ok && ccDepTag == runtimeDepTag
418}
419
420func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700421 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100422 return ok && ccDepTag == testPerSrcDepTag
423}
424
Colin Crossca860ac2016-01-04 14:34:37 -0800425// Module contains the properties and members used by all C/C++ module types, and implements
426// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
427// to construct the output file. Behavior can be customized with a Customizer interface
428type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700429 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700430 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900431 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900432 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700433
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700434 Properties BaseProperties
435 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700436
Colin Crossca860ac2016-01-04 14:34:37 -0800437 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700438 hod android.HostOrDeviceSupported
439 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700440
Paul Duffina0843f62019-12-13 19:50:38 +0000441 // Allowable SdkMemberTypes of this module type.
442 sdkMemberTypes []android.SdkMemberType
443
Colin Crossca860ac2016-01-04 14:34:37 -0800444 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700445 features []feature
446 compiler compiler
447 linker linker
448 installer installer
449 stl *stl
450 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800451 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800452 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900453 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700454 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700455 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800456
Colin Cross635c3b02016-05-18 15:37:25 -0700457 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800458
Colin Crossb98c8b02016-07-29 13:44:28 -0700459 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700460
461 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800462
463 // Flags used to compile this module
464 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700465
466 // 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 -0800467 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700468 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800469 depsInLinkOrder android.Paths
470
471 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700472 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900473
474 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800475 // Kythe (source file indexer) paths for this compilation module
476 kytheFiles android.Paths
Colin Crossc472d572015-03-17 15:06:21 -0700477}
478
Ivan Lozano52767be2019-10-18 14:49:46 -0700479func (c *Module) Toc() android.OptionalPath {
480 if c.linker != nil {
481 if library, ok := c.linker.(libraryInterface); ok {
482 return library.toc()
483 }
484 }
485 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
486}
487
488func (c *Module) ApiLevel() string {
489 if c.linker != nil {
490 if stub, ok := c.linker.(*stubDecorator); ok {
491 return stub.properties.ApiLevel
492 }
493 }
494 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
495}
496
497func (c *Module) Static() bool {
498 if c.linker != nil {
499 if library, ok := c.linker.(libraryInterface); ok {
500 return library.static()
501 }
502 }
503 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
504}
505
506func (c *Module) Shared() bool {
507 if c.linker != nil {
508 if library, ok := c.linker.(libraryInterface); ok {
509 return library.shared()
510 }
511 }
512 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
513}
514
515func (c *Module) SelectedStl() string {
516 return c.stl.Properties.SelectedStl
517}
518
519func (c *Module) ToolchainLibrary() bool {
520 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
521 return true
522 }
523 return false
524}
525
526func (c *Module) NdkPrebuiltStl() bool {
527 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
528 return true
529 }
530 return false
531}
532
533func (c *Module) StubDecorator() bool {
534 if _, ok := c.linker.(*stubDecorator); ok {
535 return true
536 }
537 return false
538}
539
540func (c *Module) SdkVersion() string {
541 return String(c.Properties.Sdk_version)
542}
543
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800544func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700545 if c.linker != nil {
546 if library, ok := c.linker.(exportedFlagsProducer); ok {
547 return library.exportedDirs()
548 }
549 }
550 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
551}
552
553func (c *Module) HasStaticVariant() bool {
554 if c.staticVariant != nil {
555 return true
556 }
557 return false
558}
559
560func (c *Module) GetStaticVariant() LinkableInterface {
561 return c.staticVariant
562}
563
564func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
565 c.depsInLinkOrder = depsInLinkOrder
566}
567
568func (c *Module) GetDepsInLinkOrder() []android.Path {
569 return c.depsInLinkOrder
570}
571
572func (c *Module) StubsVersions() []string {
573 if c.linker != nil {
574 if library, ok := c.linker.(*libraryDecorator); ok {
575 return library.Properties.Stubs.Versions
576 }
577 }
578 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
579}
580
581func (c *Module) CcLibrary() bool {
582 if c.linker != nil {
583 if _, ok := c.linker.(*libraryDecorator); ok {
584 return true
585 }
586 }
587 return false
588}
589
590func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700591 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700592 return true
593 }
594 return false
595}
596
Ivan Lozano2b262972019-11-21 12:30:50 -0800597func (c *Module) NonCcVariants() bool {
598 return false
599}
600
Ivan Lozano183a3212019-10-18 14:18:45 -0700601func (c *Module) SetBuildStubs() {
602 if c.linker != nil {
603 if library, ok := c.linker.(*libraryDecorator); ok {
604 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700605 c.Properties.HideFromMake = true
606 c.sanitize = nil
607 c.stl = nil
608 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700609 return
610 }
611 }
612 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
613}
614
Ivan Lozano52767be2019-10-18 14:49:46 -0700615func (c *Module) BuildStubs() bool {
616 if c.linker != nil {
617 if library, ok := c.linker.(*libraryDecorator); ok {
618 return library.buildStubs()
619 }
620 }
621 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
622}
623
Ivan Lozano183a3212019-10-18 14:18:45 -0700624func (c *Module) SetStubsVersions(version string) {
625 if c.linker != nil {
626 if library, ok := c.linker.(*libraryDecorator); ok {
627 library.MutatedProperties.StubsVersion = version
628 return
629 }
630 }
631 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
632}
633
634func (c *Module) SetStatic() {
635 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700636 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700637 library.setStatic()
638 return
639 }
640 }
641 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
642}
643
644func (c *Module) SetShared() {
645 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700646 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700647 library.setShared()
648 return
649 }
650 }
651 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
652}
653
654func (c *Module) BuildStaticVariant() bool {
655 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700656 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700657 return library.buildStatic()
658 }
659 }
660 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
661}
662
663func (c *Module) BuildSharedVariant() bool {
664 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700665 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700666 return library.buildShared()
667 }
668 }
669 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
670}
671
672func (c *Module) Module() android.Module {
673 return c
674}
675
Jiyong Parkc20eee32018-09-05 22:36:17 +0900676func (c *Module) OutputFile() android.OptionalPath {
677 return c.outputFile
678}
679
Ivan Lozano183a3212019-10-18 14:18:45 -0700680var _ LinkableInterface = (*Module)(nil)
681
Jiyong Park719b4462019-01-13 00:39:51 +0900682func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900683 if c.linker != nil {
684 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900685 }
686 return nil
687}
688
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900689func (c *Module) CoverageOutputFile() android.OptionalPath {
690 if c.linker != nil {
691 return c.linker.coverageOutputFilePath()
692 }
693 return android.OptionalPath{}
694}
695
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900696func (c *Module) RelativeInstallPath() string {
697 if c.installer != nil {
698 return c.installer.relativeInstallPath()
699 }
700 return ""
701}
702
Jooyung Han344d5432019-08-23 11:17:39 +0900703func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900704 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900705}
706
Colin Cross36242852017-06-23 15:06:31 -0700707func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700708 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800709 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700710 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800711 }
712 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700713 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800714 }
715 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700716 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800717 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700718 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700719 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700720 }
Colin Cross16b23492016-01-06 14:41:07 -0800721 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700722 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800723 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800724 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700725 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800726 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800727 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700728 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800729 }
Justin Yun8effde42017-06-23 19:24:43 +0900730 if c.vndkdep != nil {
731 c.AddProperties(c.vndkdep.props()...)
732 }
Stephen Craneba090d12017-05-09 15:44:35 -0700733 if c.lto != nil {
734 c.AddProperties(c.lto.props()...)
735 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700736 if c.pgo != nil {
737 c.AddProperties(c.pgo.props()...)
738 }
Colin Crossca860ac2016-01-04 14:34:37 -0800739 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700740 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800741 }
Colin Crossc472d572015-03-17 15:06:21 -0700742
Colin Crossa9d8bee2018-10-02 13:59:46 -0700743 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
744 switch class {
745 case android.Device:
746 return ctx.Config().DevicePrefer32BitExecutables()
747 case android.HostCross:
748 // Windows builds always prefer 32-bit
749 return true
750 default:
751 return false
752 }
753 })
Colin Cross36242852017-06-23 15:06:31 -0700754 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900755 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900756 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900757 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900758
Colin Cross36242852017-06-23 15:06:31 -0700759 return c
Colin Crossc472d572015-03-17 15:06:21 -0700760}
761
Colin Crossb916a382016-07-29 17:28:03 -0700762// Returns true for dependency roots (binaries)
763// TODO(ccross): also handle dlopenable libraries
764func (c *Module) isDependencyRoot() bool {
765 if root, ok := c.linker.(interface {
766 isDependencyRoot() bool
767 }); ok {
768 return root.isDependencyRoot()
769 }
770 return false
771}
772
Justin Yun5f7f7e82019-11-18 19:52:14 +0900773// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
774// "product" and "vendor" variant modules return true for this function.
775// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
776// "soc_specific: true" and more vendor installed modules are included here.
777// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
778// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700779func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900780 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700781}
782
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800783func (c *Module) isCoverageVariant() bool {
784 return c.coverage.Properties.IsCoverageVariant
785}
786
Peter Collingbournead84f972019-12-17 16:46:18 -0800787func (c *Module) IsNdk() bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800788 return inList(c.Name(), ndkMigratedLibs)
789}
790
Inseob Kim9516ee92019-05-09 10:56:13 +0900791func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800792 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900793 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800794}
795
Inseob Kim9516ee92019-05-09 10:56:13 +0900796func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800797 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900798 name := c.BaseModuleName()
799 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800800}
801
Inseob Kim9516ee92019-05-09 10:56:13 +0900802func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800803 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900804 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800805}
806
Ivan Lozano52767be2019-10-18 14:49:46 -0700807func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800808 if vndkdep := c.vndkdep; vndkdep != nil {
809 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900810 }
811 return false
812}
813
Yi Kong7e53c572018-02-14 18:16:12 +0800814func (c *Module) isPgoCompile() bool {
815 if pgo := c.pgo; pgo != nil {
816 return pgo.Properties.PgoCompile
817 }
818 return false
819}
820
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800821func (c *Module) isNDKStubLibrary() bool {
822 if _, ok := c.compiler.(*stubDecorator); ok {
823 return true
824 }
825 return false
826}
827
Logan Chienf3511742017-10-31 18:04:35 +0800828func (c *Module) isVndkSp() bool {
829 if vndkdep := c.vndkdep; vndkdep != nil {
830 return vndkdep.isVndkSp()
831 }
832 return false
833}
834
835func (c *Module) isVndkExt() bool {
836 if vndkdep := c.vndkdep; vndkdep != nil {
837 return vndkdep.isVndkExt()
838 }
839 return false
840}
841
Ivan Lozano52767be2019-10-18 14:49:46 -0700842func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900843 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800844}
845
Logan Chienf3511742017-10-31 18:04:35 +0800846func (c *Module) getVndkExtendsModuleName() string {
847 if vndkdep := c.vndkdep; vndkdep != nil {
848 return vndkdep.getVndkExtendsModuleName()
849 }
850 return ""
851}
852
Justin Yun5f7f7e82019-11-18 19:52:14 +0900853// Returns true only when this module is configured to have core, product and vendor
Jiyong Park82e2bf32017-08-16 14:05:54 +0900854// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700855func (c *Module) HasVendorVariant() bool {
856 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900857}
858
Justin Yun5f7f7e82019-11-18 19:52:14 +0900859const (
860 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
861 // against the VNDK.
862 VendorVariationPrefix = "vendor."
863
864 // ProductVariationPrefix is the variant prefix used for /product code that compiles
865 // against the VNDK.
866 ProductVariationPrefix = "product."
867)
868
869// Returns true if the module is "product" variant. Usually these modules are installed in /product
870func (c *Module) inProduct() bool {
871 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
872}
873
874// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
875func (c *Module) inVendor() bool {
876 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
877}
878
Yifan Hong1b3348d2020-01-21 15:53:22 -0800879func (c *Module) InRamdisk() bool {
880 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
881}
882
Ivan Lozano52767be2019-10-18 14:49:46 -0700883func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800884 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900885}
886
Yifan Hong1b3348d2020-01-21 15:53:22 -0800887func (c *Module) OnlyInRamdisk() bool {
888 return c.ModuleBase.InstallInRamdisk()
889}
890
Ivan Lozano52767be2019-10-18 14:49:46 -0700891func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900892 return c.ModuleBase.InstallInRecovery()
893}
894
Jiyong Park25fc6a92018-11-18 18:02:45 +0900895func (c *Module) IsStubs() bool {
896 if library, ok := c.linker.(*libraryDecorator); ok {
897 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900898 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
899 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900900 }
901 return false
902}
903
904func (c *Module) HasStubsVariants() bool {
905 if library, ok := c.linker.(*libraryDecorator); ok {
906 return len(library.Properties.Stubs.Versions) > 0
907 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700908 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
909 return len(library.Properties.Stubs.Versions) > 0
910 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900911 return false
912}
913
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900914func (c *Module) bootstrap() bool {
915 return Bool(c.Properties.Bootstrap)
916}
917
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700918func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700919 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
920 if c.Target().NativeBridge == android.NativeBridgeEnabled {
921 return false
922 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700923 return c.linker != nil && c.linker.nativeCoverage()
924}
925
Inseob Kim8471cda2019-11-15 09:59:12 +0900926func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kimeec88e12020-01-22 11:11:29 +0900927 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
928 return true
929 }
930 if _, ok := c.linker.(*vendorSnapshotLibraryDecorator); ok {
931 return true
932 }
933 if _, ok := c.linker.(*vendorSnapshotBinaryDecorator); ok {
934 return true
935 }
936 return false
Inseob Kim8471cda2019-11-15 09:59:12 +0900937}
938
Jiyong Park73c54ee2019-10-22 20:31:18 +0900939func (c *Module) ExportedIncludeDirs() android.Paths {
940 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
941 return flagsProducer.exportedDirs()
942 }
Jiyong Park232e7852019-11-04 12:23:40 +0900943 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900944}
945
946func (c *Module) ExportedSystemIncludeDirs() android.Paths {
947 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
948 return flagsProducer.exportedSystemDirs()
949 }
Jiyong Park232e7852019-11-04 12:23:40 +0900950 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900951}
952
953func (c *Module) ExportedFlags() []string {
954 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
955 return flagsProducer.exportedFlags()
956 }
Jiyong Park232e7852019-11-04 12:23:40 +0900957 return nil
958}
959
960func (c *Module) ExportedDeps() android.Paths {
961 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
962 return flagsProducer.exportedDeps()
963 }
964 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900965}
966
Inseob Kimd110f872019-12-06 13:15:38 +0900967func (c *Module) ExportedGeneratedHeaders() android.Paths {
968 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
969 return flagsProducer.exportedGeneratedHeaders()
970 }
971 return nil
972}
973
Jiyong Parkf1194352019-02-25 11:05:47 +0900974func isBionic(name string) bool {
975 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +0000976 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +0900977 return true
978 }
979 return false
980}
981
Martin Stjernholm279de572019-09-10 23:18:20 +0100982func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700983 if name == "libclang_rt.hwasan-aarch64-android" {
984 return inList("hwaddress", config.SanitizeDevice())
985 }
986 return isBionic(name)
987}
988
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800989func (c *Module) XrefCcFiles() android.Paths {
990 return c.kytheFiles
991}
992
Colin Crossca860ac2016-01-04 14:34:37 -0800993type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700994 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800995 moduleContextImpl
996}
997
Colin Cross37047f12016-12-13 17:06:13 -0800998type depsContext struct {
999 android.BottomUpMutatorContext
1000 moduleContextImpl
1001}
1002
Colin Crossca860ac2016-01-04 14:34:37 -08001003type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001004 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001005 moduleContextImpl
1006}
1007
Justin Yun5f7f7e82019-11-18 19:52:14 +09001008func (ctx *moduleContext) ProductSpecific() bool {
1009 return ctx.ModuleContext.ProductSpecific() ||
1010 (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
1011}
1012
Jiyong Park2db76922017-11-08 16:03:48 +09001013func (ctx *moduleContext) SocSpecific() bool {
1014 return ctx.ModuleContext.SocSpecific() ||
Justin Yun5f7f7e82019-11-18 19:52:14 +09001015 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001016}
1017
Colin Crossca860ac2016-01-04 14:34:37 -08001018type moduleContextImpl struct {
1019 mod *Module
1020 ctx BaseModuleContext
1021}
1022
Colin Crossb98c8b02016-07-29 13:44:28 -07001023func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001024 return ctx.mod.toolchain(ctx.ctx)
1025}
1026
1027func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001028 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001029}
1030
1031func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001032 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001033}
1034
Jiyong Park1d1119f2019-07-29 21:27:18 +09001035func (ctx *moduleContextImpl) header() bool {
1036 return ctx.mod.header()
1037}
1038
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001039func (ctx *moduleContextImpl) useSdk() bool {
Yifan Hong1b3348d2020-01-21 15:53:22 -08001040 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRamdisk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -08001041 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -07001042 }
1043 return false
Colin Crossca860ac2016-01-04 14:34:37 -08001044}
1045
1046func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001047 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001048 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001049 vndkVer := ctx.mod.VndkVersion()
1050 if inList(vndkVer, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
1051 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001052 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001053 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001054 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001055 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001056 }
1057 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001058}
1059
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001060func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001061 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001062}
Justin Yun8effde42017-06-23 19:24:43 +09001063
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001064func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001065 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001066}
1067
Inseob Kim9516ee92019-05-09 10:56:13 +09001068func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1069 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001070}
1071
Inseob Kim9516ee92019-05-09 10:56:13 +09001072func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1073 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001074}
1075
Inseob Kim9516ee92019-05-09 10:56:13 +09001076func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1077 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001078}
1079
Logan Chienf3511742017-10-31 18:04:35 +08001080func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001081 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001082}
1083
Yi Kong7e53c572018-02-14 18:16:12 +08001084func (ctx *moduleContextImpl) isPgoCompile() bool {
1085 return ctx.mod.isPgoCompile()
1086}
1087
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001088func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1089 return ctx.mod.isNDKStubLibrary()
1090}
1091
Justin Yun8effde42017-06-23 19:24:43 +09001092func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001093 return ctx.mod.isVndkSp()
1094}
1095
1096func (ctx *moduleContextImpl) isVndkExt() bool {
1097 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001098}
1099
Vic Yangefd249e2018-11-12 20:19:56 -08001100func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001101 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001102}
1103
Justin Yun5f7f7e82019-11-18 19:52:14 +09001104func (ctx *moduleContextImpl) inProduct() bool {
1105 return ctx.mod.inProduct()
1106}
1107
1108func (ctx *moduleContextImpl) inVendor() bool {
1109 return ctx.mod.inVendor()
1110}
1111
Yifan Hong1b3348d2020-01-21 15:53:22 -08001112func (ctx *moduleContextImpl) inRamdisk() bool {
1113 return ctx.mod.InRamdisk()
1114}
1115
Jiyong Parkf9332f12018-02-01 00:54:12 +09001116func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001117 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001118}
1119
Logan Chien2f2b8902018-07-10 15:01:19 +08001120// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001121func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001122 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1123 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001124 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001125
1126 if ctx.ctx.Fuchsia() {
1127 return false
1128 }
1129
Logan Chien2f2b8902018-07-10 15:01:19 +08001130 if sanitize := ctx.mod.sanitize; sanitize != nil {
1131 if !sanitize.isVariantOnProductionDevice() {
1132 return false
1133 }
1134 }
1135 if !ctx.ctx.Device() {
1136 // Host modules do not need ABI dumps.
1137 return false
1138 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001139 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001140 // Stubs do not need ABI dumps.
1141 return false
1142 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001143 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001144}
1145
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001146func (ctx *moduleContextImpl) selectedStl() string {
1147 if stl := ctx.mod.stl; stl != nil {
1148 return stl.Properties.SelectedStl
1149 }
1150 return ""
1151}
1152
Ivan Lozanobd721262018-11-27 14:33:03 -08001153func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1154 return ctx.mod.linker.useClangLld(actx)
1155}
1156
Colin Crossce75d2c2016-10-06 16:12:58 -07001157func (ctx *moduleContextImpl) baseModuleName() string {
1158 return ctx.mod.ModuleBase.BaseModuleName()
1159}
1160
Logan Chienf3511742017-10-31 18:04:35 +08001161func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1162 return ctx.mod.getVndkExtendsModuleName()
1163}
1164
Logan Chiene274fc92019-12-03 11:18:32 -08001165func (ctx *moduleContextImpl) isForPlatform() bool {
1166 return ctx.mod.IsForPlatform()
1167}
1168
Jiyong Park58e364a2019-01-19 19:24:06 +09001169func (ctx *moduleContextImpl) apexName() string {
1170 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001171}
1172
Jiyong Parkb0788572018-12-20 22:10:17 +09001173func (ctx *moduleContextImpl) hasStubsVariants() bool {
1174 return ctx.mod.HasStubsVariants()
1175}
1176
1177func (ctx *moduleContextImpl) isStubs() bool {
1178 return ctx.mod.IsStubs()
1179}
1180
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001181func (ctx *moduleContextImpl) bootstrap() bool {
1182 return ctx.mod.bootstrap()
1183}
1184
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001185func (ctx *moduleContextImpl) nativeCoverage() bool {
1186 return ctx.mod.nativeCoverage()
1187}
1188
Colin Cross635c3b02016-05-18 15:37:25 -07001189func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001190 return &Module{
1191 hod: hod,
1192 multilib: multilib,
1193 }
1194}
1195
Colin Cross635c3b02016-05-18 15:37:25 -07001196func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001197 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001198 module.features = []feature{
1199 &tidyFeature{},
1200 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001201 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001202 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001203 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001204 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001205 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001206 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001207 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001208 return module
1209}
1210
Colin Crossce75d2c2016-10-06 16:12:58 -07001211func (c *Module) Prebuilt() *android.Prebuilt {
1212 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1213 return p.prebuilt()
1214 }
1215 return nil
1216}
1217
1218func (c *Module) Name() string {
1219 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001220 if p, ok := c.linker.(interface {
1221 Name(string) string
1222 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001223 name = p.Name(name)
1224 }
1225 return name
1226}
1227
Alex Light3d673592019-01-18 14:37:31 -08001228func (c *Module) Symlinks() []string {
1229 if p, ok := c.installer.(interface {
1230 symlinkList() []string
1231 }); ok {
1232 return p.symlinkList()
1233 }
1234 return nil
1235}
1236
Jeff Gaston294356f2017-09-27 17:05:30 -07001237// orderDeps reorders dependencies into a list such that if module A depends on B, then
1238// A will precede B in the resultant list.
1239// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001240// Note that directSharedDeps should be the analogous static library for each shared lib dep
1241func 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 -07001242 // If A depends on B, then
1243 // Every list containing A will also contain B later in the list
1244 // So, after concatenating all lists, the final instance of B will have come from the same
1245 // original list as the final instance of A
1246 // So, the final instance of B will be later in the concatenation than the final A
1247 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1248 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001249 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001250 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001251 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1252 }
1253 for _, dep := range directSharedDeps {
1254 orderedAllDeps = append(orderedAllDeps, dep)
1255 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001256 }
1257
Colin Crossb6715442017-10-24 11:13:31 -07001258 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001259
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001260 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001261 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001262 // resultant list to only what the caller has chosen to include in directStaticDeps
1263 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001264
1265 return orderedAllDeps, orderedDeclaredDeps
1266}
1267
Ivan Lozano183a3212019-10-18 14:18:45 -07001268func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001269 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001270 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001271 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1272 staticDepFiles := []android.Path{}
1273 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001274 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1275 if dep.OutputFile().Valid() {
1276 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1277 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1278 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001279 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001280 sharedDepFiles := []android.Path{}
1281 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001282 if sharedDep.HasStaticVariant() {
1283 staticAnalogue := sharedDep.GetStaticVariant()
1284 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1285 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001286 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001287 }
1288
1289 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001290 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1291 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001292
1293 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001294}
1295
Roland Levillainf89cd092019-07-29 16:22:59 +01001296func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1297 test, ok := c.linker.(testPerSrc)
1298 return ok && test.isAllTestsVariation()
1299}
1300
Justin Yun5f7f7e82019-11-18 19:52:14 +09001301func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1302 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1303 // "current", it will append the VNDK version to the name suffix.
1304 var vndkVersion string
1305 var nameSuffix string
1306 if c.inProduct() {
1307 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1308 nameSuffix = productSuffix
1309 } else {
1310 vndkVersion = ctx.DeviceConfig().VndkVersion()
1311 nameSuffix = vendorSuffix
1312 }
1313 if vndkVersion == "current" {
1314 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1315 }
1316 if c.Properties.VndkVersion != vndkVersion {
1317 // add version suffix only if the module is using different vndk version than the
1318 // version in product or vendor partition.
1319 nameSuffix += "." + c.Properties.VndkVersion
1320 }
1321 return nameSuffix
1322}
1323
Colin Cross635c3b02016-05-18 15:37:25 -07001324func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001325 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001326 //
1327 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1328 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1329 // module and return early, as this module does not produce an output file per se.
1330 if c.IsTestPerSrcAllTestsVariation() {
1331 c.outputFile = android.OptionalPath{}
1332 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001333 }
1334
Jooyung Han38002912019-05-16 04:01:54 +09001335 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001336
Inseob Kim64c43952019-08-26 16:52:35 +09001337 c.Properties.SubName = ""
1338
1339 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1340 c.Properties.SubName += nativeBridgeSuffix
1341 }
1342
Justin Yun5f7f7e82019-11-18 19:52:14 +09001343 _, llndk := c.linker.(*llndkStubDecorator)
1344 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1345 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1346 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1347 // added for product variant only when we have vendor and product variants with core
1348 // variant. The suffix is not added for vendor-only or product-only module.
1349 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1350 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001351 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1352 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1353 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001354 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1355 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001356 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001357 c.Properties.SubName += recoverySuffix
1358 }
1359
Colin Crossca860ac2016-01-04 14:34:37 -08001360 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001361 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001362 moduleContextImpl: moduleContextImpl{
1363 mod: c,
1364 },
1365 }
1366 ctx.ctx = ctx
1367
Colin Crossf18e1102017-11-16 14:33:08 -08001368 deps := c.depsToPaths(ctx)
1369 if ctx.Failed() {
1370 return
1371 }
1372
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001373 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1374 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1375 }
1376
Colin Crossca860ac2016-01-04 14:34:37 -08001377 flags := Flags{
1378 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001379 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001380 }
Colin Crossca860ac2016-01-04 14:34:37 -08001381 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001382 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001383 }
1384 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001385 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001386 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001387 if c.stl != nil {
1388 flags = c.stl.flags(ctx, flags)
1389 }
Colin Cross16b23492016-01-06 14:41:07 -08001390 if c.sanitize != nil {
1391 flags = c.sanitize.flags(ctx, flags)
1392 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001393 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001394 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001395 }
Stephen Craneba090d12017-05-09 15:44:35 -07001396 if c.lto != nil {
1397 flags = c.lto.flags(ctx, flags)
1398 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001399 if c.pgo != nil {
1400 flags = c.pgo.flags(ctx, flags)
1401 }
Colin Crossca860ac2016-01-04 14:34:37 -08001402 for _, feature := range c.features {
1403 flags = feature.flags(ctx, flags)
1404 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001405 if ctx.Failed() {
1406 return
1407 }
1408
Colin Cross4af21ed2019-11-04 09:37:55 -08001409 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1410 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1411 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001412
Colin Cross4af21ed2019-11-04 09:37:55 -08001413 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001414
1415 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001416 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001417 }
1418 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001419 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001420 }
1421
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001422 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001423 // We need access to all the flags seen by a source file.
1424 if c.sabi != nil {
1425 flags = c.sabi.flags(ctx, flags)
1426 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001427
Colin Cross4af21ed2019-11-04 09:37:55 -08001428 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001429
Colin Crossca860ac2016-01-04 14:34:37 -08001430 // Optimization to reduce size of build.ninja
1431 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001432 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1433 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1434 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1435 flags.Local.CFlags = []string{"$cflags"}
1436 flags.Local.CppFlags = []string{"$cppflags"}
1437 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001438
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001439 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001440 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001441 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001442 if ctx.Failed() {
1443 return
1444 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001445 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001446 }
1447
Colin Crossca860ac2016-01-04 14:34:37 -08001448 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001449 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001450 if ctx.Failed() {
1451 return
1452 }
Colin Cross635c3b02016-05-18 15:37:25 -07001453 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001454
1455 // If a lib is directly included in any of the APEXes, unhide the stubs
1456 // variant having the latest version gets visible to make. In addition,
1457 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1458 // force anything in the make world to link against the stubs library.
1459 // (unless it is explicitly referenced via .bootstrap suffix or the
1460 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001461 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001462 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001463 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001464 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001465 c.Properties.HideFromMake = false // unhide
1466 // Note: this is still non-installable
1467 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001468 }
Colin Cross5049f022015-03-18 13:28:46 -07001469
Inseob Kim1f086e22019-05-09 13:29:15 +09001470 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001471 c.installer.install(ctx, c.outputFile.Path())
1472 if ctx.Failed() {
1473 return
Colin Crossca860ac2016-01-04 14:34:37 -08001474 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001475 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001476}
1477
Colin Cross0ea8ba82019-06-06 14:33:29 -07001478func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001479 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001480 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001481 }
Colin Crossca860ac2016-01-04 14:34:37 -08001482 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001483}
1484
Colin Crossca860ac2016-01-04 14:34:37 -08001485func (c *Module) begin(ctx BaseModuleContext) {
1486 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001487 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001488 }
Colin Crossca860ac2016-01-04 14:34:37 -08001489 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001490 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001491 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001492 if c.stl != nil {
1493 c.stl.begin(ctx)
1494 }
Colin Cross16b23492016-01-06 14:41:07 -08001495 if c.sanitize != nil {
1496 c.sanitize.begin(ctx)
1497 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001498 if c.coverage != nil {
1499 c.coverage.begin(ctx)
1500 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001501 if c.sabi != nil {
1502 c.sabi.begin(ctx)
1503 }
Justin Yun8effde42017-06-23 19:24:43 +09001504 if c.vndkdep != nil {
1505 c.vndkdep.begin(ctx)
1506 }
Stephen Craneba090d12017-05-09 15:44:35 -07001507 if c.lto != nil {
1508 c.lto.begin(ctx)
1509 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001510 if c.pgo != nil {
1511 c.pgo.begin(ctx)
1512 }
Colin Crossca860ac2016-01-04 14:34:37 -08001513 for _, feature := range c.features {
1514 feature.begin(ctx)
1515 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001516 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001517 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001518 if err != nil {
1519 ctx.PropertyErrorf("sdk_version", err.Error())
1520 }
Nan Zhang0007d812017-11-07 10:57:05 -08001521 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001522 }
Colin Crossca860ac2016-01-04 14:34:37 -08001523}
1524
Colin Cross37047f12016-12-13 17:06:13 -08001525func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001526 deps := Deps{}
1527
1528 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001529 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001530 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001531 // Add the PGO dependency (the clang_rt.profile runtime library), which
1532 // sometimes depends on symbols from libgcc, before libgcc gets added
1533 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001534 if c.pgo != nil {
1535 deps = c.pgo.deps(ctx, deps)
1536 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001537 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001538 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001539 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001540 if c.stl != nil {
1541 deps = c.stl.deps(ctx, deps)
1542 }
Colin Cross16b23492016-01-06 14:41:07 -08001543 if c.sanitize != nil {
1544 deps = c.sanitize.deps(ctx, deps)
1545 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001546 if c.coverage != nil {
1547 deps = c.coverage.deps(ctx, deps)
1548 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001549 if c.sabi != nil {
1550 deps = c.sabi.deps(ctx, deps)
1551 }
Justin Yun8effde42017-06-23 19:24:43 +09001552 if c.vndkdep != nil {
1553 deps = c.vndkdep.deps(ctx, deps)
1554 }
Stephen Craneba090d12017-05-09 15:44:35 -07001555 if c.lto != nil {
1556 deps = c.lto.deps(ctx, deps)
1557 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001558 for _, feature := range c.features {
1559 deps = feature.deps(ctx, deps)
1560 }
1561
Colin Crossb6715442017-10-24 11:13:31 -07001562 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1563 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1564 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1565 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1566 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1567 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001568 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001569
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001570 for _, lib := range deps.ReexportSharedLibHeaders {
1571 if !inList(lib, deps.SharedLibs) {
1572 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1573 }
1574 }
1575
1576 for _, lib := range deps.ReexportStaticLibHeaders {
1577 if !inList(lib, deps.StaticLibs) {
1578 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1579 }
1580 }
1581
Colin Cross5950f382016-12-13 12:50:57 -08001582 for _, lib := range deps.ReexportHeaderLibHeaders {
1583 if !inList(lib, deps.HeaderLibs) {
1584 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1585 }
1586 }
1587
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001588 for _, gen := range deps.ReexportGeneratedHeaders {
1589 if !inList(gen, deps.GeneratedHeaders) {
1590 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1591 }
1592 }
1593
Colin Crossc99deeb2016-04-11 15:06:20 -07001594 return deps
1595}
1596
Dan Albert7e9d2952016-08-04 13:02:36 -07001597func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001598 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001599 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001600 moduleContextImpl: moduleContextImpl{
1601 mod: c,
1602 },
1603 }
1604 ctx.ctx = ctx
1605
Colin Crossca860ac2016-01-04 14:34:37 -08001606 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001607}
1608
Jiyong Park7ed9de32018-10-15 22:25:07 +09001609// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001610func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001611 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1612 version := name[sharp+1:]
1613 libname := name[:sharp]
1614 return libname, version
1615 }
1616 return name, ""
1617}
1618
Colin Cross1e676be2016-10-12 14:38:15 -07001619func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001620 if !c.Enabled() {
1621 return
1622 }
1623
Colin Cross37047f12016-12-13 17:06:13 -08001624 ctx := &depsContext{
1625 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001626 moduleContextImpl: moduleContextImpl{
1627 mod: c,
1628 },
1629 }
1630 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001631
Colin Crossc99deeb2016-04-11 15:06:20 -07001632 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001633
Dan Albert914449f2016-06-17 16:45:24 -07001634 variantNdkLibs := []string{}
1635 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001636 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001637 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001638
Inseob Kimeec88e12020-01-22 11:11:29 +09001639 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001640 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001641 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001642 // 1. Name of an NDK library that refers to a prebuilt module.
1643 // For each of these, it adds the name of the prebuilt module (which will be in
1644 // prebuilts/ndk) to the list of nonvariant libs.
1645 // 2. Name of an NDK library that refers to an ndk_library module.
1646 // For each of these, it adds the name of the ndk_library module to the list of
1647 // variant libs.
1648 // 3. Anything else (so anything that isn't an NDK library).
1649 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001650 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001651 // The caller can then know to add the variantLibs dependencies differently from the
1652 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001653
Inseob Kim9516ee92019-05-09 10:56:13 +09001654 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001655 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1656
1657 rewriteVendorLibs := func(lib string) string {
1658 if isLlndkLibrary(lib, ctx.Config()) {
1659 return lib + llndkLibrarySuffix
1660 }
1661
1662 // only modules with BOARD_VNDK_VERSION uses snapshot.
1663 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1664 return lib
1665 }
1666
1667 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1668 return snapshot
1669 }
1670
1671 return lib
1672 }
1673
1674 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001675 variantLibs = []string{}
1676 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001677 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001678 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001679 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001680 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1681 if !inList(name, ndkMigratedLibs) {
1682 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001683 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001684 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001685 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001686 } else if ctx.useVndk() {
1687 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001688 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001689 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001690 if actx.OtherModuleExists(vendorPublicLib) {
1691 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1692 } else {
1693 // This can happen if vendor_public_library module is defined in a
1694 // namespace that isn't visible to the current module. In that case,
1695 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001696 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001697 }
Dan Albert914449f2016-06-17 16:45:24 -07001698 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001699 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001700 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001701 }
1702 }
Dan Albert914449f2016-06-17 16:45:24 -07001703 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001704 }
1705
Inseob Kimeec88e12020-01-22 11:11:29 +09001706 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1707 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1708 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1709 if ctx.useVndk() {
1710 for idx, lib := range deps.RuntimeLibs {
1711 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1712 }
1713 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001714 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001715
Jiyong Park7e636d02019-01-28 16:16:54 +09001716 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001717 if c.linker != nil {
1718 if library, ok := c.linker.(*libraryDecorator); ok {
1719 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001720 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001721 }
1722 }
1723 }
1724
Inseob Kimeec88e12020-01-22 11:11:29 +09001725 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1726 // only modules with BOARD_VNDK_VERSION uses snapshot.
1727 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1728 return lib
1729 }
1730
1731 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1732 return snapshot
1733 }
1734
1735 return lib
1736 }
1737
1738 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001739 for _, lib := range deps.HeaderLibs {
1740 depTag := headerDepTag
1741 if inList(lib, deps.ReexportHeaderLibHeaders) {
1742 depTag = headerExportDepTag
1743 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001744
1745 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1746
Jiyong Park7e636d02019-01-28 16:16:54 +09001747 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001748 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001749 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001750 } else {
1751 actx.AddVariationDependencies(nil, depTag, lib)
1752 }
1753 }
1754
1755 if buildStubs {
1756 // Stubs lib does not have dependency to other static/shared libraries.
1757 // Don't proceed.
1758 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001759 }
Colin Cross5950f382016-12-13 12:50:57 -08001760
Inseob Kimc0907f12019-02-08 21:00:45 +09001761 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001762 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001763
Jiyong Park5d1598f2019-02-25 22:14:17 +09001764 for _, lib := range deps.WholeStaticLibs {
1765 depTag := wholeStaticDepTag
1766 if impl, ok := syspropImplLibraries[lib]; ok {
1767 lib = impl
1768 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001769
1770 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1771
Jiyong Park5d1598f2019-02-25 22:14:17 +09001772 actx.AddVariationDependencies([]blueprint.Variation{
1773 {Mutator: "link", Variation: "static"},
1774 }, depTag, lib)
1775 }
1776
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001777 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001778 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001779 if inList(lib, deps.ReexportStaticLibHeaders) {
1780 depTag = staticExportDepTag
1781 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001782
1783 if impl, ok := syspropImplLibraries[lib]; ok {
1784 lib = impl
1785 }
1786
Inseob Kimeec88e12020-01-22 11:11:29 +09001787 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1788
Dan Willemsen59339a22018-07-22 21:18:45 -07001789 actx.AddVariationDependencies([]blueprint.Variation{
1790 {Mutator: "link", Variation: "static"},
1791 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001792 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001793
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001794 if deps.StaticUnwinderIfLegacy && ctx.Config().UnbundledBuild() {
1795 actx.AddVariationDependencies([]blueprint.Variation{
1796 {Mutator: "link", Variation: "static"},
1797 }, staticUnwinderDepTag, staticUnwinder(actx))
1798 }
1799
Inseob Kimeec88e12020-01-22 11:11:29 +09001800 for _, lib := range deps.LateStaticLibs {
1801 actx.AddVariationDependencies([]blueprint.Variation{
1802 {Mutator: "link", Variation: "static"},
1803 }, lateStaticDepTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
1804 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001805
Ivan Lozano183a3212019-10-18 14:18:45 -07001806 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001807 var variations []blueprint.Variation
1808 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Yifan Hong1b3348d2020-01-21 15:53:22 -08001809 versionVariantAvail := !ctx.useVndk() && !c.InRecovery() && !c.InRamdisk()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001810 if version != "" && versionVariantAvail {
1811 // Version is explicitly specified. i.e. libFoo#30
1812 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001813 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001814 }
1815 actx.AddVariationDependencies(variations, depTag, name)
1816
1817 // If the version is not specified, add dependency to the latest stubs library.
1818 // The stubs library will be used when the depending module is built for APEX and
1819 // the dependent module is not in the same APEX.
Jiyong Park73c54ee2019-10-22 20:31:18 +09001820 latestVersion := LatestStubsVersionFor(actx.Config(), name)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001821 if version == "" && latestVersion != "" && versionVariantAvail {
1822 actx.AddVariationDependencies([]blueprint.Variation{
1823 {Mutator: "link", Variation: "shared"},
1824 {Mutator: "version", Variation: latestVersion},
1825 }, depTag, name)
Ivan Lozano183a3212019-10-18 14:18:45 -07001826 // Note that depTag.ExplicitlyVersioned is false in this case.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001827 }
1828 }
1829
Jiyong Park7ed9de32018-10-15 22:25:07 +09001830 // shared lib names without the #version suffix
1831 var sharedLibNames []string
1832
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001833 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001834 depTag := SharedDepTag
Jiyong Parkd7536ba2020-01-16 17:14:23 +09001835 if c.static() {
1836 depTag = SharedFromStaticDepTag
1837 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001838 if inList(lib, deps.ReexportSharedLibHeaders) {
1839 depTag = sharedExportDepTag
1840 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001841
1842 if impl, ok := syspropImplLibraries[lib]; ok {
1843 lib = impl
1844 }
1845
Jiyong Park73c54ee2019-10-22 20:31:18 +09001846 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001847 sharedLibNames = append(sharedLibNames, name)
1848
Jiyong Park25fc6a92018-11-18 18:02:45 +09001849 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001850 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001851
Jiyong Park7ed9de32018-10-15 22:25:07 +09001852 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001853 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001854 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1855 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1856 // linking against both the stubs lib and the non-stubs lib at the same time.
1857 continue
1858 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001859 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001860 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001861
Dan Willemsen59339a22018-07-22 21:18:45 -07001862 actx.AddVariationDependencies([]blueprint.Variation{
1863 {Mutator: "link", Variation: "shared"},
1864 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001865
Colin Cross68861832016-07-08 10:41:41 -07001866 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001867
1868 for _, gen := range deps.GeneratedHeaders {
1869 depTag := genHeaderDepTag
1870 if inList(gen, deps.ReexportGeneratedHeaders) {
1871 depTag = genHeaderExportDepTag
1872 }
1873 actx.AddDependency(c, depTag, gen)
1874 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001875
Colin Cross42d48b72018-08-29 14:10:52 -07001876 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001877
1878 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001879 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001880 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001881 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001882 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001883 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001884 if deps.LinkerFlagsFile != "" {
1885 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1886 }
1887 if deps.DynamicLinker != "" {
1888 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001889 }
Dan Albert914449f2016-06-17 16:45:24 -07001890
1891 version := ctx.sdkVersion()
1892 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001893 {Mutator: "ndk_api", Variation: version},
1894 {Mutator: "link", Variation: "shared"},
1895 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001896 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001897 {Mutator: "ndk_api", Variation: version},
1898 {Mutator: "link", Variation: "shared"},
1899 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001900
1901 if vndkdep := c.vndkdep; vndkdep != nil {
1902 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08001903 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08001904 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07001905 {Mutator: "link", Variation: "shared"},
1906 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001907 }
1908 }
Colin Cross6362e272015-10-29 15:25:03 -07001909}
Colin Cross21b9a242015-03-24 14:15:58 -07001910
Colin Crosse40b4ea2018-10-02 22:25:58 -07001911func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001912 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1913 c.beginMutator(ctx)
1914 }
1915}
1916
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001917// Whether a module can link to another module, taking into
1918// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07001919func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
1920 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001921 // Host code is not restricted
1922 return
1923 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001924
1925 // VNDK is cc.Module supported only for now.
1926 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001927 // Though vendor code is limited by the vendor mutator,
1928 // each vendor-available module needs to check
1929 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07001930 if ccTo, ok := to.(*Module); ok {
1931 if ccFrom.vndkdep != nil {
1932 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
1933 }
1934 } else {
1935 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001936 }
1937 return
1938 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001939 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001940 // Platform code can link to anything
1941 return
1942 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08001943 if from.InRamdisk() {
1944 // Ramdisk code is not NDK
1945 return
1946 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001947 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09001948 // Recovery code is not NDK
1949 return
1950 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001951 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001952 // These are always allowed
1953 return
1954 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001955 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001956 // These are allowed, but they don't set sdk_version
1957 return
1958 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001959 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001960 // These aren't real libraries, but are the stub shared libraries that are included in
1961 // the NDK.
1962 return
1963 }
Logan Chien834b9a62019-01-14 15:39:03 +08001964
Ivan Lozano52767be2019-10-18 14:49:46 -07001965 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08001966 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1967 // to link to libc++ (non-NDK and without sdk_version).
1968 return
1969 }
1970
Ivan Lozano52767be2019-10-18 14:49:46 -07001971 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001972 // NDK code linking to platform code is never okay.
1973 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001974 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001975 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001976 }
1977
1978 // At this point we know we have two NDK libraries, but we need to
1979 // check that we're not linking against anything built against a higher
1980 // API level, as it is only valid to link against older or equivalent
1981 // APIs.
1982
Inseob Kim01a28722018-04-11 09:48:45 +09001983 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07001984 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001985 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07001986 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001987 // Current can't be linked against by anything else.
1988 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001989 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09001990 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07001991 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001992 if err != nil {
1993 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001994 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001995 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001996 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001997 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001998 if err != nil {
1999 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002000 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002001 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002002 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002003
Inseob Kim01a28722018-04-11 09:48:45 +09002004 if toApi > fromApi {
2005 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002006 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002007 }
2008 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002009 }
Dan Albert202fe492017-12-15 13:56:59 -08002010
2011 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002012 fromStl := from.SelectedStl()
2013 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002014 if fromStl == "" || toStl == "" {
2015 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002016 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002017 // We can be permissive with the system "STL" since it is only the C++
2018 // ABI layer, but in the future we should make sure that everyone is
2019 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002020 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002021 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002022 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2023 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002024 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002025}
2026
Jiyong Park5fb8c102018-04-09 12:03:06 +09002027// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002028// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2029// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002030// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002031func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2032 check := func(child, parent android.Module) bool {
2033 to, ok := child.(*Module)
2034 if !ok {
2035 // follow thru cc.Defaults, etc.
2036 return true
2037 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002038
Jooyung Hana70f0672019-01-18 15:20:43 +09002039 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2040 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002041 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002042
2043 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002044 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002045 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002046 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002047
Jooyung Han0302a842019-10-30 18:43:49 +09002048 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002049 return false
2050 }
2051
2052 var stringPath []string
2053 for _, m := range ctx.GetWalkPath() {
2054 stringPath = append(stringPath, m.Name())
2055 }
2056 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2057 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2058 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2059 return false
2060 }
2061 if module, ok := ctx.Module().(*Module); ok {
2062 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002063 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002064 ctx.WalkDeps(check)
2065 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002066 }
2067 }
2068}
2069
Colin Crossc99deeb2016-04-11 15:06:20 -07002070// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002071func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002072 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002073
Ivan Lozano183a3212019-10-18 14:18:45 -07002074 directStaticDeps := []LinkableInterface{}
2075 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002076
Inseob Kim9516ee92019-05-09 10:56:13 +09002077 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2078
Inseob Kim69378442019-06-03 19:10:47 +09002079 reexportExporter := func(exporter exportedFlagsProducer) {
2080 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2081 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2082 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2083 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002084 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002085 }
2086
Colin Crossd11fcda2017-10-23 17:59:01 -07002087 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002088 depName := ctx.OtherModuleName(dep)
2089 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002090
Ivan Lozano52767be2019-10-18 14:49:46 -07002091 ccDep, ok := dep.(LinkableInterface)
2092 if !ok {
2093
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002094 // handling for a few module types that aren't cc Module but that are also supported
2095 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002096 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002097 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002098 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2099 genRule.GeneratedSourceFiles()...)
2100 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002101 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002102 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002103 // Support exported headers from a generated_sources dependency
2104 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002105 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002106 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002107 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Inseob Kimd110f872019-12-06 13:15:38 +09002108 genRule.GeneratedSourceFiles()...)
2109 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002110 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002111 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002112 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002113 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002114 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002115 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2116 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002117 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002118 // 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 +09002119 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002120
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002121 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002122 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002123 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002124 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002125 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002126 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002127 files := genRule.GeneratedSourceFiles()
2128 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002129 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002130 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002131 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 -07002132 }
2133 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002134 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002135 }
Colin Crossca860ac2016-01-04 14:34:37 -08002136 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002137 return
2138 }
2139
Colin Crossfe17f6f2019-03-28 19:30:56 -07002140 if depTag == android.ProtoPluginDepTag {
2141 return
2142 }
2143
Colin Crossd11fcda2017-10-23 17:59:01 -07002144 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002145 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2146 return
2147 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002148 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002149 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002150 return
2151 }
2152
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002153 // re-exporting flags
2154 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002155 // reusing objects only make sense for cc.Modules.
2156 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002157 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002158 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002159 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002160 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002161 return
2162 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002163 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002164
Jiyong Parke4bb9862019-02-01 00:31:10 +09002165 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002166 // staticVariants are a cc.Module specific concept.
2167 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002168 c.staticVariant = ccDep
2169 return
2170 }
2171 }
2172
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002173 if depTag == staticUnwinderDepTag {
2174 if c.ApexProperties.Info.LegacyAndroid10Support {
2175 depTag = StaticDepTag
2176 } else {
2177 return
2178 }
2179 }
2180
Ivan Lozano183a3212019-10-18 14:18:45 -07002181 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
2182 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
2183 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002184 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07002185 if t, ok := depTag.(DependencyTag); ok {
2186 explicitlyVersioned = t.ExplicitlyVersioned
2187 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002188 depTag = t
2189 }
2190
Ivan Lozano183a3212019-10-18 14:18:45 -07002191 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002192 depIsStatic := false
2193 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002194 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002195 depIsStatic = true
2196 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002197 if ccDep.CcLibrary() && !depIsStatic {
2198 depIsStubs := ccDep.BuildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09002199 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002200 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002201 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002202
2203 var useThisDep bool
2204 if depIsStubs && explicitlyVersioned {
2205 // Always respect dependency to the versioned stubs (i.e. libX#10)
2206 useThisDep = true
2207 } else if !depHasStubs {
2208 // Use non-stub variant if that is the only choice
2209 // (i.e. depending on a lib without stubs.version property)
2210 useThisDep = true
2211 } else if c.IsForPlatform() {
2212 // If not building for APEX, use stubs only when it is from
2213 // an APEX (and not from platform)
2214 useThisDep = (depInPlatform != depIsStubs)
Yifan Hong1b3348d2020-01-21 15:53:22 -08002215 if c.InRamdisk() || c.InRecovery() || c.bootstrap() {
2216 // However, for ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002217 // always link to non-stub variant
2218 useThisDep = !depIsStubs
2219 }
2220 } else {
2221 // If building for APEX, use stubs only when it is not from
2222 // the same APEX
2223 useThisDep = (depInSameApex != depIsStubs)
2224 }
2225
2226 if !useThisDep {
2227 return // stop processing this dep
2228 }
2229 }
2230
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002231 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2232
Ivan Lozano52767be2019-10-18 14:49:46 -07002233 // Exporting flags only makes sense for cc.Modules
2234 if _, ok := ccDep.(*Module); ok {
2235 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002236 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002237 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedGeneratedHeaders()...)
2238 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002239 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002240
Ivan Lozano52767be2019-10-18 14:49:46 -07002241 if t.ReexportFlags {
2242 reexportExporter(i)
2243 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2244 // Re-exported shared library headers must be included as well since they can help us with type information
2245 // about template instantiations (instantiated from their headers).
2246 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2247 // scripts.
2248 c.sabi.Properties.ReexportedIncludes = append(
2249 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2250 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002251 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002252 }
Logan Chienf3511742017-10-31 18:04:35 +08002253 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002254 }
2255
Colin Cross26c34ed2016-09-30 17:10:16 -07002256 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002257 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002258
Ivan Lozano52767be2019-10-18 14:49:46 -07002259 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002260 depFile := android.OptionalPath{}
2261
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002262 switch depTag {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002263 case ndkStubDepTag, SharedDepTag, SharedFromStaticDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002264 ptr = &depPaths.SharedLibs
2265 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002266 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002267 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002268
Jiyong Park64a44f22019-01-18 14:37:08 +09002269 case earlySharedDepTag:
2270 ptr = &depPaths.EarlySharedLibs
2271 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002272 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002273 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002274 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002275 ptr = &depPaths.LateSharedLibs
2276 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002277 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002278 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002279 ptr = nil
2280 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002281 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002282 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002283 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002284 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002285 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002286 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002287 return
2288 }
2289
Ivan Lozano52767be2019-10-18 14:49:46 -07002290 // Because the static library objects are included, this only makes sense
2291 // in the context of proper cc.Modules.
2292 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2293 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2294 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2295 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2296 for i := range missingDeps {
2297 missingDeps[i] += postfix
2298 }
2299 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002300 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002301 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2302 } else {
2303 ctx.ModuleErrorf(
2304 "non-cc.Modules cannot be included as whole static libraries.", depName)
2305 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002306 }
Colin Cross5950f382016-12-13 12:50:57 -08002307 case headerDepTag:
2308 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002309 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002310 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002311 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002312 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002313 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002314 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002315 case dynamicLinkerDepTag:
2316 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002317 }
2318
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002319 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002320 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002321 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002322 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002323 return
2324 }
2325
2326 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002327 // in static libraries act as if they were whole static libraries. The same goes for
2328 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002329 // This should only be done for cc.Modules
2330 if c, ok := ccDep.(*Module); ok {
2331 staticLib := c.linker.(libraryInterface)
2332 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2333 staticLib.objs().coverageFiles...)
2334 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2335 staticLib.objs().sAbiDumpFiles...)
2336 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002337 }
2338
Colin Cross26c34ed2016-09-30 17:10:16 -07002339 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002340 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002341 if !ctx.Config().AllowMissingDependencies() {
2342 ctx.ModuleErrorf("module %q missing output file", depName)
2343 } else {
2344 ctx.AddMissingDependencies([]string{depName})
2345 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002346 return
2347 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002348 *ptr = append(*ptr, linkFile.Path())
2349 }
2350
Colin Crossc99deeb2016-04-11 15:06:20 -07002351 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002352 dep := depFile
2353 if !dep.Valid() {
2354 dep = linkFile
2355 }
2356 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002357 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002358
Inseob Kimeec88e12020-01-22 11:11:29 +09002359 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2360
2361 baseLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002362 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002363 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002364 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kimeec88e12020-01-22 11:11:29 +09002365 return libName
2366 }
2367
2368 makeLibName := func(depName string) string {
2369 libName := baseLibName(depName)
Jooyung Han0302a842019-10-30 18:43:49 +09002370 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002371 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002372 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002373
Inseob Kimeec88e12020-01-22 11:11:29 +09002374 if c, ok := ccDep.(*Module); ok {
2375 // Use base module name for snapshots when exporting to Makefile.
2376 if c.isSnapshotPrebuilt() && !c.IsVndk() {
2377 baseName := c.BaseModuleName()
2378 if vendorSuffixModules[baseName] {
2379 return baseName + ".vendor"
2380 } else {
2381 return baseName
2382 }
2383 }
2384 }
2385
Yifan Hong1b3348d2020-01-21 15:53:22 -08002386 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002387 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2388 // core module instead.
2389 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002390 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002391 // The vendor module in Make will have been renamed to not conflict with the core
2392 // module, so update the dependency name here accordingly.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002393 return libName + c.getNameSuffixWithVndkVersion(ctx)
Jiyong Park374510b2018-03-19 18:23:01 +09002394 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002395 return libName + vendorPublicLibrarySuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08002396 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2397 return libName + ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002398 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002399 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002400 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002401 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002402 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002403 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002404 }
Logan Chien43d34c32017-12-20 01:17:32 +08002405 }
2406
2407 // Export the shared libs to Make.
2408 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002409 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002410 if ccDep.CcLibrary() {
2411 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002412 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002413 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002414 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002415 c.Properties.ApexesProvidingSharedLibs = append(
2416 c.Properties.ApexesProvidingSharedLibs, an)
2417 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002418 }
2419 }
2420
Jiyong Park27b188b2017-07-18 13:23:39 +09002421 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002422 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002423 c.Properties.AndroidMkSharedLibs = append(
2424 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002425 // Record baseLibName for snapshots.
2426 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002427 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002428 c.Properties.AndroidMkSharedLibs = append(
2429 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002430 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002431 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002432 c.Properties.AndroidMkStaticLibs = append(
2433 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002434 case runtimeDepTag:
2435 c.Properties.AndroidMkRuntimeLibs = append(
2436 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002437 // Record baseLibName for snapshots.
2438 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002439 case wholeStaticDepTag:
2440 c.Properties.AndroidMkWholeStaticLibs = append(
2441 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002442 }
Colin Crossca860ac2016-01-04 14:34:37 -08002443 })
2444
Jeff Gaston294356f2017-09-27 17:05:30 -07002445 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002446 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002447
Colin Crossdd84e052017-05-17 13:44:16 -07002448 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002449 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002450 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2451 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002452 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kimd110f872019-12-06 13:15:38 +09002453 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002454 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2455 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002456 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002457 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002458 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002459
2460 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002461 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002462 }
Colin Crossdd84e052017-05-17 13:44:16 -07002463
Colin Crossca860ac2016-01-04 14:34:37 -08002464 return depPaths
2465}
2466
2467func (c *Module) InstallInData() bool {
2468 if c.installer == nil {
2469 return false
2470 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002471 return c.installer.inData()
2472}
2473
2474func (c *Module) InstallInSanitizerDir() bool {
2475 if c.installer == nil {
2476 return false
2477 }
2478 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002479 return true
2480 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002481 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002482}
2483
Yifan Hong1b3348d2020-01-21 15:53:22 -08002484func (c *Module) InstallInRamdisk() bool {
2485 return c.InRamdisk()
2486}
2487
Jiyong Parkf9332f12018-02-01 00:54:12 +09002488func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002489 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002490}
2491
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002492func (c *Module) HostToolPath() android.OptionalPath {
2493 if c.installer == nil {
2494 return android.OptionalPath{}
2495 }
2496 return c.installer.hostToolPath()
2497}
2498
Nan Zhangd4e641b2017-07-12 12:55:28 -07002499func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2500 return c.outputFile
2501}
2502
Colin Cross41955e82019-05-29 14:40:35 -07002503func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2504 switch tag {
2505 case "":
2506 if c.outputFile.Valid() {
2507 return android.Paths{c.outputFile.Path()}, nil
2508 }
2509 return android.Paths{}, nil
2510 default:
2511 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002512 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002513}
2514
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002515func (c *Module) static() bool {
2516 if static, ok := c.linker.(interface {
2517 static() bool
2518 }); ok {
2519 return static.static()
2520 }
2521 return false
2522}
2523
Jiyong Park379de2f2018-12-19 02:47:14 +09002524func (c *Module) staticBinary() bool {
2525 if static, ok := c.linker.(interface {
2526 staticBinary() bool
2527 }); ok {
2528 return static.staticBinary()
2529 }
2530 return false
2531}
2532
Jiyong Park1d1119f2019-07-29 21:27:18 +09002533func (c *Module) header() bool {
2534 if h, ok := c.linker.(interface {
2535 header() bool
2536 }); ok {
2537 return h.header()
2538 }
2539 return false
2540}
2541
Jooyung Han38002912019-05-16 04:01:54 +09002542func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002543 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002544 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2545 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002546 return "native:vndk"
2547 }
Jooyung Han38002912019-05-16 04:01:54 +09002548 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002549 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002550 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002551 if Bool(c.VendorProperties.Vendor_available) {
2552 return "native:vndk"
2553 }
2554 return "native:vndk_private"
2555 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002556 if c.inProduct() {
2557 return "native:product"
2558 }
Jooyung Han38002912019-05-16 04:01:54 +09002559 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002560 } else if c.InRamdisk() {
2561 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002562 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002563 return "native:recovery"
2564 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2565 return "native:ndk:none:none"
2566 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2567 //family, link := getNdkStlFamilyAndLinkType(c)
2568 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002569 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002570 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002571 } else {
2572 return "native:platform"
2573 }
2574}
2575
Jiyong Park9d452992018-10-03 00:38:19 +09002576// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002577// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002578func (c *Module) IsInstallableToApex() bool {
2579 if shared, ok := c.linker.(interface {
2580 shared() bool
2581 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002582 // Stub libs and prebuilt libs in a versioned SDK are not
2583 // installable to APEX even though they are shared libs.
2584 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002585 } else if _, ok := c.linker.(testPerSrc); ok {
2586 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002587 }
2588 return false
2589}
2590
Jiyong Parka90ca002019-10-07 15:47:24 +09002591func (c *Module) AvailableFor(what string) bool {
2592 if linker, ok := c.linker.(interface {
2593 availableFor(string) bool
2594 }); ok {
2595 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2596 } else {
2597 return c.ApexModuleBase.AvailableFor(what)
2598 }
2599}
2600
Inseob Kim1f086e22019-05-09 13:29:15 +09002601func (c *Module) installable() bool {
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002602 ret := c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid()
2603
2604 // The platform variant doesn't need further condition. Apex variants however might not
2605 // be installable because it will likely to be included in the APEX and won't appear
2606 // in the system partition.
2607 if c.IsForPlatform() {
2608 return ret
2609 }
2610
2611 // Special case for modules that are configured to be installed to /data, which includes
2612 // test modules. For these modules, both APEX and non-APEX variants are considered as
2613 // installable. This is because even the APEX variants won't be included in the APEX, but
2614 // will anyway be installed to /data/*.
2615 // See b/146995717
2616 if c.InstallInData() {
2617 return ret
2618 }
2619
2620 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002621}
2622
Logan Chien41eabe62019-04-10 13:33:58 +08002623func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2624 if c.linker != nil {
2625 if library, ok := c.linker.(*libraryDecorator); ok {
2626 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2627 }
2628 }
2629}
2630
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002631func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002632 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002633 if cc, ok := dep.(*Module); ok {
Jiyong Park323a4c32020-03-01 17:29:06 +09002634 if cc.HasStubsVariants() {
2635 if depTag.Shared && depTag.Library {
2636 // dynamic dep to a stubs lib crosses APEX boundary
2637 return false
2638 }
2639 if IsRuntimeDepTag(depTag) {
2640 // runtime dep to a stubs lib also crosses APEX boundary
2641 return false
2642 }
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002643 }
2644 if depTag.FromStatic {
2645 // shared_lib dependency from a static lib is considered as crossing
2646 // the APEX boundary because the dependency doesn't actually is
2647 // linked; the dependency is used only during the compilation phase.
2648 return false
2649 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002650 }
2651 }
2652 return true
2653}
2654
Colin Cross2ba19d92015-05-07 15:44:20 -07002655//
Colin Crosscfad1192015-11-02 16:43:11 -08002656// Defaults
2657//
Colin Crossca860ac2016-01-04 14:34:37 -08002658type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002659 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002660 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002661 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002662}
2663
Patrice Arrudac249c712019-03-19 17:00:29 -07002664// cc_defaults provides a set of properties that can be inherited by other cc
2665// modules. A module can use the properties from a cc_defaults using
2666// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2667// merged (when possible) by prepending the default module's values to the
2668// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002669func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002670 return DefaultsFactory()
2671}
2672
Colin Cross36242852017-06-23 15:06:31 -07002673func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002674 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002675
Colin Cross36242852017-06-23 15:06:31 -07002676 module.AddProperties(props...)
2677 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002678 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002679 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002680 &BaseCompilerProperties{},
2681 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002682 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002683 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002684 &StaticProperties{},
2685 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002686 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002687 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002688 &TestProperties{},
2689 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002690 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002691 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002692 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002693 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002694 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002695 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002696 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002697 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002698 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002699 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002700 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002701 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002702 )
Colin Crosscfad1192015-11-02 16:43:11 -08002703
Jooyung Hancc372c52019-09-25 15:18:44 +09002704 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002705
2706 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002707}
2708
Jiyong Park6a43f042017-10-12 23:05:00 +09002709func squashVendorSrcs(m *Module) {
2710 if lib, ok := m.compiler.(*libraryDecorator); ok {
2711 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2712 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2713
2714 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2715 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2716 }
2717}
2718
Jiyong Parkf9332f12018-02-01 00:54:12 +09002719func squashRecoverySrcs(m *Module) {
2720 if lib, ok := m.compiler.(*libraryDecorator); ok {
2721 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2722 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2723
2724 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2725 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2726 }
2727}
2728
Colin Cross7228ecd2019-11-18 16:00:16 -08002729var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002730
Colin Cross7228ecd2019-11-18 16:00:16 -08002731func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002732 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002733 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002734 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002735
2736 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002737 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002738 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002739 }
Logan Chienf3511742017-10-31 18:04:35 +08002740
2741 if vndkdep := m.vndkdep; vndkdep != nil {
2742 if vndkdep.isVndk() {
Justin Yun0ecf0b22020-02-28 15:07:59 +09002743 if vendorSpecific || productSpecific {
Logan Chienf3511742017-10-31 18:04:35 +08002744 if !vndkdep.isVndkExt() {
2745 mctx.PropertyErrorf("vndk",
2746 "must set `extends: \"...\"` to vndk extension")
Justin Yun0ecf0b22020-02-28 15:07:59 +09002747 } else if m.VendorProperties.Vendor_available != nil {
2748 mctx.PropertyErrorf("vendor_available",
2749 "must not set at the same time as `vndk: {extends: \"...\"}`")
Logan Chienf3511742017-10-31 18:04:35 +08002750 }
2751 } else {
2752 if vndkdep.isVndkExt() {
2753 mctx.PropertyErrorf("vndk",
Justin Yun0ecf0b22020-02-28 15:07:59 +09002754 "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
Logan Chienf3511742017-10-31 18:04:35 +08002755 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002756 }
2757 if m.VendorProperties.Vendor_available == nil {
2758 mctx.PropertyErrorf("vndk",
2759 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08002760 }
2761 }
2762 } else {
2763 if vndkdep.isVndkSp() {
2764 mctx.PropertyErrorf("vndk",
2765 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08002766 }
2767 if vndkdep.isVndkExt() {
2768 mctx.PropertyErrorf("vndk",
2769 "must set `enabled: true` to set `extends: %q`",
2770 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002771 }
Justin Yun8effde42017-06-23 19:24:43 +09002772 }
2773 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002774
Jiyong Parkf9332f12018-02-01 00:54:12 +09002775 var coreVariantNeeded bool = false
Yifan Hong1b3348d2020-01-21 15:53:22 -08002776 var ramdiskVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002777 var recoveryVariantNeeded bool = false
2778
Inseob Kim64c43952019-08-26 16:52:35 +09002779 var vendorVariants []string
Justin Yun5f7f7e82019-11-18 19:52:14 +09002780 var productVariants []string
Inseob Kim64c43952019-08-26 16:52:35 +09002781
2782 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09002783 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
2784 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
2785 if boardVndkVersion == "current" {
2786 boardVndkVersion = platformVndkVersion
2787 }
2788 if productVndkVersion == "current" {
2789 productVndkVersion = platformVndkVersion
Inseob Kim64c43952019-08-26 16:52:35 +09002790 }
2791
Justin Yun5f7f7e82019-11-18 19:52:14 +09002792 if boardVndkVersion == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002793 // If the device isn't compiling against the VNDK, we always
2794 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002795 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002796 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002797 // LL-NDK stubs only exist in the vendor and product variants,
2798 // since the real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002799 vendorVariants = append(vendorVariants,
2800 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002801 boardVndkVersion,
2802 )
2803 productVariants = append(productVariants,
2804 platformVndkVersion,
2805 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002806 )
Jiyong Park2a454122017-10-19 15:59:33 +09002807 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2808 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002809 vendorVariants = append(vendorVariants,
2810 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002811 boardVndkVersion,
2812 )
2813 productVariants = append(productVariants,
2814 platformVndkVersion,
2815 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002816 )
Inseob Kimeec88e12020-01-22 11:11:29 +09002817 } else if m.isSnapshotPrebuilt() {
Justin Yun71549282017-11-17 12:10:28 +09002818 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2819 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kimeec88e12020-01-22 11:11:29 +09002820 if snapshot, ok := m.linker.(interface {
2821 version() string
2822 }); ok {
2823 vendorVariants = append(vendorVariants, snapshot.version())
2824 } else {
2825 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
2826 }
Justin Yun0ecf0b22020-02-28 15:07:59 +09002827 } else if m.HasVendorVariant() && !m.isVndkExt() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002828 // This will be available in /system, /vendor and /product
2829 // or a /system directory that is available to vendor and product.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002830 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002831 vendorVariants = append(vendorVariants, platformVndkVersion)
Justin Yun5f7f7e82019-11-18 19:52:14 +09002832 productVariants = append(productVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09002833 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
2834 // code is PLATFORM_VNDK_VERSION.
2835 // On the other hand, vendor_available modules which are not VNDK should
2836 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002837 // vendor_available modules are also available to /product.
Inseob Kimbc093672019-11-01 11:29:44 +09002838 if !m.IsVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002839 vendorVariants = append(vendorVariants, boardVndkVersion)
2840 productVariants = append(productVariants, productVndkVersion)
Inseob Kim64c43952019-08-26 16:52:35 +09002841 }
Logan Chienf3511742017-10-31 18:04:35 +08002842 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002843 // This will be available in /vendor (or /odm) only
Justin Yun5f7f7e82019-11-18 19:52:14 +09002844 vendorVariants = append(vendorVariants, boardVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002845 } else {
2846 // This is either in /system (or similar: /data), or is a
2847 // modules built with the NDK. Modules built with the NDK
2848 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002849 coreVariantNeeded = true
2850 }
2851
Justin Yun5f7f7e82019-11-18 19:52:14 +09002852 if boardVndkVersion != "" && productVndkVersion != "" {
2853 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
2854 // The module has "product_specific: true" that does not create core variant.
2855 coreVariantNeeded = false
2856 productVariants = append(productVariants, productVndkVersion)
2857 }
2858 } else {
2859 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
2860 // restriction to use system libs.
2861 // No product variants defined in this case.
2862 productVariants = []string{}
2863 }
2864
Yifan Hong1b3348d2020-01-21 15:53:22 -08002865 if Bool(m.Properties.Ramdisk_available) {
2866 ramdiskVariantNeeded = true
2867 }
2868
2869 if m.ModuleBase.InstallInRamdisk() {
2870 ramdiskVariantNeeded = true
2871 coreVariantNeeded = false
2872 }
2873
Jiyong Parkf9332f12018-02-01 00:54:12 +09002874 if Bool(m.Properties.Recovery_available) {
2875 recoveryVariantNeeded = true
2876 }
2877
2878 if m.ModuleBase.InstallInRecovery() {
2879 recoveryVariantNeeded = true
2880 coreVariantNeeded = false
2881 }
2882
Inseob Kim64c43952019-08-26 16:52:35 +09002883 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002884 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
2885 }
2886
2887 for _, variant := range android.FirstUniqueStrings(productVariants) {
2888 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09002889 }
Colin Cross7228ecd2019-11-18 16:00:16 -08002890
Yifan Hong1b3348d2020-01-21 15:53:22 -08002891 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Colin Cross7228ecd2019-11-18 16:00:16 -08002892 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
2893 m.Properties.CoreVariantNeeded = coreVariantNeeded
2894}
2895
2896func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
2897 return c.Properties.CoreVariantNeeded
2898}
2899
Yifan Hong1b3348d2020-01-21 15:53:22 -08002900func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
2901 return c.Properties.RamdiskVariantNeeded
2902}
2903
Colin Cross7228ecd2019-11-18 16:00:16 -08002904func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
2905 return c.Properties.RecoveryVariantNeeded
2906}
2907
2908func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002909 return c.Properties.ExtraVariants
Colin Cross7228ecd2019-11-18 16:00:16 -08002910}
2911
2912func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
2913 m := module.(*Module)
Yifan Hong1b3348d2020-01-21 15:53:22 -08002914 if variant == android.RamdiskVariation {
2915 m.MakeAsPlatform()
2916 } else if variant == android.RecoveryVariation {
Colin Cross7228ecd2019-11-18 16:00:16 -08002917 m.MakeAsPlatform()
2918 squashRecoverySrcs(m)
2919 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002920 m.Properties.ImageVariationPrefix = VendorVariationPrefix
Colin Cross7228ecd2019-11-18 16:00:16 -08002921 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
2922 squashVendorSrcs(m)
Inseob Kimeec88e12020-01-22 11:11:29 +09002923
2924 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
2925 // Hide other vendor variants to avoid collision.
2926 vndkVersion := ctx.DeviceConfig().VndkVersion()
2927 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
2928 m.Properties.HideFromMake = true
2929 m.SkipInstall()
2930 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002931 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
2932 m.Properties.ImageVariationPrefix = ProductVariationPrefix
2933 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
2934 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002935 }
2936}
2937
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002938func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002939 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002940 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2941 }
Colin Cross6510f912017-11-29 00:27:14 -08002942 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002943}
2944
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002945func kytheExtractAllFactory() android.Singleton {
2946 return &kytheExtractAllSingleton{}
2947}
2948
2949type kytheExtractAllSingleton struct {
2950}
2951
2952func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2953 var xrefTargets android.Paths
2954 ctx.VisitAllModules(func(module android.Module) {
2955 if ccModule, ok := module.(xref); ok {
2956 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
2957 }
2958 })
2959 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
2960 if len(xrefTargets) > 0 {
2961 ctx.Build(pctx, android.BuildParams{
2962 Rule: blueprint.Phony,
2963 Output: android.PathForPhony(ctx, "xref_cxx"),
2964 Inputs: xrefTargets,
2965 //Default: true,
2966 })
2967 }
2968}
2969
Colin Cross06a931b2015-10-28 17:23:31 -07002970var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002971var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002972var BoolPtr = proptools.BoolPtr
2973var String = proptools.String
2974var StringPtr = proptools.StringPtr