blob: caefea4f65f3bfe94cb3b775446c66c897bfd544 [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) {
Colin Crossc511bc52020-04-07 16:50:32 +000045 ctx.BottomUp("sdk", sdkMutator).Parallel()
Inseob Kim64c43952019-08-26 16:52:35 +090046 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070047 ctx.BottomUp("link", LinkageMutator).Parallel()
Jooyung Hanb90e4912019-12-09 18:21:48 +090048 ctx.BottomUp("ndk_api", NdkApiMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +010049 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Colin Crossd1f898e2020-08-18 18:35:15 -070050 ctx.BottomUp("version_selector", versionSelectorMutator).Parallel()
51 ctx.BottomUp("version", versionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070052 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimac1e9862019-12-09 18:15:47 +090053 ctx.BottomUp("sysprop_cc", SyspropMutator).Parallel()
Inseob Kimeec88e12020-01-22 11:11:29 +090054 ctx.BottomUp("vendor_snapshot", VendorSnapshotMutator).Parallel()
55 ctx.BottomUp("vendor_snapshot_source", VendorSnapshotSourceMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070056 })
Colin Cross16b23492016-01-06 14:41:07 -080057
Paul Duffin036e7002019-12-19 19:16:28 +000058 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Cross1e676be2016-10-12 14:38:15 -070059 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
60 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080061
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070062 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
63 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
64
Mitch Phillipsbfeade62019-05-01 14:42:05 -070065 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
66 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
67
Jiyong Park1d1119f2019-07-29 21:27:18 +090068 // cfi mutator shouldn't run before sanitizers that return true for
69 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000070 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
71 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
72
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080073 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
74 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
75
Colin Cross1e676be2016-10-12 14:38:15 -070076 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
77 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080078
Colin Cross0b908332019-06-19 23:00:20 -070079 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090080 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080081
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080082 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080083 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070084
85 ctx.TopDown("lto_deps", ltoDepsMutator)
86 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090087
88 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070089 })
Colin Crossb98c8b02016-07-29 13:44:28 -070090
Sasha Smundak2a4549e2018-11-05 16:49:08 -080091 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070092}
93
Colin Crossca860ac2016-01-04 14:34:37 -080094type Deps struct {
95 SharedLibs, LateSharedLibs []string
96 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080097 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080098 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070099
Chris Parsons79d66a52020-06-05 17:26:16 -0400100 // Used for data dependencies adjacent to tests
101 DataLibs []string
102
Yo Chiang219968c2020-09-22 18:45:04 +0800103 // Used by DepsMutator to pass system_shared_libs information to check_elf_file.py.
104 SystemSharedLibs []string
105
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800106 StaticUnwinderIfLegacy bool
107
Colin Cross5950f382016-12-13 12:50:57 -0800108 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700109
Colin Cross81413472016-04-11 14:37:39 -0700110 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700111
Dan Willemsenb40aab62016-04-20 14:21:14 -0700112 GeneratedSources []string
113 GeneratedHeaders []string
Inseob Kimd110f872019-12-06 13:15:38 +0900114 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700115
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700116 ReexportGeneratedHeaders []string
117
Colin Cross97ba0732015-03-23 17:50:24 -0700118 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700119
120 // Used for host bionic
121 LinkerFlagsFile string
122 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700123}
124
Colin Crossca860ac2016-01-04 14:34:37 -0800125type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700126 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900127 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700128 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900129 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700130 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700131 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700132
Colin Cross26c34ed2016-09-30 17:10:16 -0700133 // Paths to .o files
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100134 Objs Objects
135 // Paths to .o files in dependencies that provide them. Note that these lists
136 // aren't complete since prebuilt modules don't provide the .o files.
Dan Willemsen581341d2017-02-09 16:16:31 -0800137 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700138 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700139
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100140 // Paths to .a files in prebuilts. Complements WholeStaticLibObjs to contain
141 // the libs from all whole_static_lib dependencies.
142 WholeStaticLibsFromPrebuilts android.Paths
143
Colin Cross26c34ed2016-09-30 17:10:16 -0700144 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700145 GeneratedSources android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900146 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700147
Inseob Kimd110f872019-12-06 13:15:38 +0900148 Flags []string
149 IncludeDirs android.Paths
150 SystemIncludeDirs android.Paths
151 ReexportedDirs android.Paths
152 ReexportedSystemDirs android.Paths
153 ReexportedFlags []string
154 ReexportedGeneratedHeaders android.Paths
155 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700156
Colin Cross26c34ed2016-09-30 17:10:16 -0700157 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700158 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700159
160 // Path to the file container flags to use with the linker
161 LinkerFlagsFile android.OptionalPath
162
163 // Path to the dynamic linker binary
164 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700165}
166
Colin Cross4af21ed2019-11-04 09:37:55 -0800167// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
168// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
169// command line so they can be overridden by the local module flags).
170type LocalOrGlobalFlags struct {
171 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700172 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800173 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700174 CFlags []string // Flags that apply to C and C++ source files
175 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
176 ConlyFlags []string // Flags that apply to C source files
177 CppFlags []string // Flags that apply to C++ source files
178 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700179 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800180}
181
182type Flags struct {
183 Local LocalOrGlobalFlags
184 Global LocalOrGlobalFlags
185
186 aidlFlags []string // Flags that apply to aidl source files
187 rsFlags []string // Flags that apply to renderscript source files
188 libFlags []string // Flags to add libraries early to the link order
189 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
190 TidyFlags []string // Flags that apply to clang-tidy
191 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700192
Colin Crossc3199482017-03-30 15:03:04 -0700193 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800194 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700195 SystemIncludeFlags []string
196
Oliver Nguyen04526782020-04-21 12:40:27 -0700197 Toolchain config.Toolchain
198 Tidy bool
199 GcovCoverage bool
200 SAbiDump bool
201 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800202
203 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800204 DynamicLinker string
205
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700206 CFlagsDeps android.Paths // Files depended on by compiler flags
207 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800208
Dan Willemsen98ab3112019-08-27 21:20:40 -0700209 AssemblerWithCpp bool
210 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800211
Colin Cross19878da2019-03-28 14:45:07 -0700212 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700213 protoC bool // Whether to use C instead of C++
214 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700215
216 Yacc *YaccProperties
Matthias Maennich22fd4d12020-07-15 10:58:56 +0200217 Lex *LexProperties
Colin Crossc472d572015-03-17 15:06:21 -0700218}
219
Colin Crossca860ac2016-01-04 14:34:37 -0800220// Properties used to compile all C or C++ modules
221type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700222 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800223 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700224
Colin Crossc511bc52020-04-07 16:50:32 +0000225 // Minimum sdk version supported when compiling against the ndk. Setting this property causes
226 // two variants to be built, one for the platform and one for apps.
Nan Zhang0007d812017-11-07 10:57:05 -0800227 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700228
Jooyung Han379660c2020-04-21 15:24:00 +0900229 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
230 Min_sdk_version *string
231
Colin Crossc511bc52020-04-07 16:50:32 +0000232 // If true, always create an sdk variant and don't create a platform variant.
233 Sdk_variant_only *bool
234
Jiyong Parkde866cb2018-12-07 23:08:36 +0900235 AndroidMkSharedLibs []string `blueprint:"mutated"`
236 AndroidMkStaticLibs []string `blueprint:"mutated"`
237 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
238 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
Bill Peckhama46de702020-04-21 17:23:37 -0700239 AndroidMkHeaderLibs []string `blueprint:"mutated"`
Jiyong Parkde866cb2018-12-07 23:08:36 +0900240 HideFromMake bool `blueprint:"mutated"`
241 PreventInstall bool `blueprint:"mutated"`
242 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700243
Yo Chiang219968c2020-09-22 18:45:04 +0800244 // Set by DepsMutator.
245 AndroidMkSystemSharedLibs []string `blueprint:"mutated"`
246
Justin Yun5f7f7e82019-11-18 19:52:14 +0900247 ImageVariationPrefix string `blueprint:"mutated"`
248 VndkVersion string `blueprint:"mutated"`
249 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800250
251 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
252 // file
253 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900254
Yifan Hong1b3348d2020-01-21 15:53:22 -0800255 // Make this module available when building for ramdisk
256 Ramdisk_available *bool
257
Jiyong Parkf9332f12018-02-01 00:54:12 +0900258 // Make this module available when building for recovery
259 Recovery_available *bool
260
Colin Crossae6c5202019-11-20 13:35:50 -0800261 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800262 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800263 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800264 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900265 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900266
267 // Allows this module to use non-APEX version of libraries. Useful
268 // for building binaries that are started before APEXes are activated.
269 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900270
271 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
272 // see soong/cc/config/vndk.go
273 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900274
275 // Used by vendor snapshot to record dependencies from snapshot modules.
276 SnapshotSharedLibs []string `blueprint:"mutated"`
277 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Paul Duffin0cb37b92020-03-04 14:52:46 +0000278
279 Installable *bool
Colin Crossc511bc52020-04-07 16:50:32 +0000280
281 // Set by factories of module types that can only be referenced from variants compiled against
282 // the SDK.
283 AlwaysSdk bool `blueprint:"mutated"`
284
285 // Variant is an SDK variant created by sdkMutator
286 IsSdkVariant bool `blueprint:"mutated"`
287 // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK
288 // variant to have a ".sdk" suffix.
289 SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"`
Bill Peckham945441c2020-08-31 16:07:58 -0700290
291 // Normally Soong uses the directory structure to decide which modules
292 // should be included (framework) or excluded (non-framework) from the
293 // vendor snapshot, but this property allows a partner to exclude a
294 // module normally thought of as a framework module from the vendor
295 // snapshot.
296 Exclude_from_vendor_snapshot *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700297}
298
299type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900300 // whether this module should be allowed to be directly depended by other
301 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900302 // In addition, this module should be allowed to be directly depended by
303 // product modules with `product_specific: true`.
304 // If set to true, three variants will be built separately, one like
305 // normal, another limited to the set of libraries and headers
306 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700307 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900308 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700309 // so it shouldn't have any unversioned runtime dependencies, or
310 // make assumptions about the system that may not be true in the
311 // future.
312 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900313 // If set to false, this module becomes inaccessible from /vendor or /product
314 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900315 //
316 // Default value is true when vndk: {enabled: true} or vendor: true.
317 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700318 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900319 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700320 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900321
322 // whether this module is capable of being loaded with other instance
323 // (possibly an older version) of the same module in the same process.
324 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
325 // can be double loaded in a vendor process if the library is also a
326 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
327 // explicitly marked as `double_loadable: true` by the owner, or the dependency
328 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
329 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800330}
331
Colin Crossca860ac2016-01-04 14:34:37 -0800332type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800333 static() bool
334 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900335 header() bool
Inseob Kim7f283f42020-06-01 21:53:49 +0900336 binary() bool
Inseob Kim1042d292020-06-01 23:23:05 +0900337 object() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700338 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900339 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700340 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800341 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700342 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800343 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900344 isLlndk(config android.Config) bool
345 isLlndkPublic(config android.Config) bool
346 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900347 isVndk() bool
348 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800349 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900350 inProduct() bool
351 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800352 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900353 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800354 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700355 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700356 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800357 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800358 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800359 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800360 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800361 isForPlatform() bool
Colin Crosse07f2312020-08-13 11:24:56 -0700362 apexVariationName() string
Dan Albertc8060532020-07-22 22:32:17 -0700363 apexSdkVersion() android.ApiLevel
Jiyong Parkb0788572018-12-20 22:10:17 +0900364 hasStubsVariants() bool
365 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900366 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800367 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700368 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800369}
370
371type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700372 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800373 ModuleContextIntf
374}
375
376type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700377 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800378 ModuleContextIntf
379}
380
Colin Cross37047f12016-12-13 17:06:13 -0800381type DepsContext interface {
382 android.BottomUpMutatorContext
383 ModuleContextIntf
384}
385
Colin Crossca860ac2016-01-04 14:34:37 -0800386type feature interface {
387 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800388 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800389 flags(ctx ModuleContext, flags Flags) Flags
390 props() []interface{}
391}
392
393type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700394 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800395 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800396 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700397 compilerProps() []interface{}
398
Colin Cross76fada02016-07-27 10:31:13 -0700399 appendCflags([]string)
400 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700401 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800402}
403
404type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700405 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800406 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700407 linkerFlags(ctx ModuleContext, flags Flags) Flags
408 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800409 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700410
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700411 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700412 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900413 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700414
415 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900416 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000417
418 // Get the deps that have been explicitly specified in the properties.
419 // Only updates the
420 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
421}
422
423type specifiedDeps struct {
424 sharedLibs []string
Martin Stjernholm10566a02020-03-24 01:19:52 +0000425 systemSharedLibs []string // Note nil and [] are semantically distinct.
Colin Crossca860ac2016-01-04 14:34:37 -0800426}
427
428type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700429 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700430 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000431 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800432 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700433 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700434 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900435 relativeInstallPath() string
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +0100436 makeUninstallable(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800437}
438
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800439type xref interface {
440 XrefCcFiles() android.Paths
441}
442
Colin Cross6e511a92020-07-27 21:26:48 -0700443type libraryDependencyKind int
444
445const (
446 headerLibraryDependency = iota
447 sharedLibraryDependency
448 staticLibraryDependency
449)
450
451func (k libraryDependencyKind) String() string {
452 switch k {
453 case headerLibraryDependency:
454 return "headerLibraryDependency"
455 case sharedLibraryDependency:
456 return "sharedLibraryDependency"
457 case staticLibraryDependency:
458 return "staticLibraryDependency"
459 default:
460 panic(fmt.Errorf("unknown libraryDependencyKind %d", k))
461 }
462}
463
464type libraryDependencyOrder int
465
466const (
467 earlyLibraryDependency = -1
468 normalLibraryDependency = 0
469 lateLibraryDependency = 1
470)
471
472func (o libraryDependencyOrder) String() string {
473 switch o {
474 case earlyLibraryDependency:
475 return "earlyLibraryDependency"
476 case normalLibraryDependency:
477 return "normalLibraryDependency"
478 case lateLibraryDependency:
479 return "lateLibraryDependency"
480 default:
481 panic(fmt.Errorf("unknown libraryDependencyOrder %d", o))
482 }
483}
484
485// libraryDependencyTag is used to tag dependencies on libraries. Unlike many dependency
486// tags that have a set of predefined tag objects that are reused for each dependency, a
487// libraryDependencyTag is designed to contain extra metadata and is constructed as needed.
488// That means that comparing a libraryDependencyTag for equality will only be equal if all
489// of the metadata is equal. Most usages will want to type assert to libraryDependencyTag and
490// then check individual metadata fields instead.
491type libraryDependencyTag struct {
492 blueprint.BaseDependencyTag
493
494 // These are exported so that fmt.Printf("%#v") can call their String methods.
495 Kind libraryDependencyKind
496 Order libraryDependencyOrder
497
498 wholeStatic bool
499
500 reexportFlags bool
501 explicitlyVersioned bool
502 dataLib bool
503 ndk bool
504
505 staticUnwinder bool
506
507 makeSuffix string
508}
509
510// header returns true if the libraryDependencyTag is tagging a header lib dependency.
511func (d libraryDependencyTag) header() bool {
512 return d.Kind == headerLibraryDependency
513}
514
515// shared returns true if the libraryDependencyTag is tagging a shared lib dependency.
516func (d libraryDependencyTag) shared() bool {
517 return d.Kind == sharedLibraryDependency
518}
519
520// shared returns true if the libraryDependencyTag is tagging a static lib dependency.
521func (d libraryDependencyTag) static() bool {
522 return d.Kind == staticLibraryDependency
523}
524
525// dependencyTag is used for tagging miscellanous dependency types that don't fit into
526// libraryDependencyTag. Each tag object is created globally and reused for multiple
527// dependencies (although since the object contains no references, assigning a tag to a
528// variable and modifying it will not modify the original). Users can compare the tag
529// returned by ctx.OtherModuleDependencyTag against the global original
530type dependencyTag struct {
531 blueprint.BaseDependencyTag
532 name string
533}
534
Colin Crossc99deeb2016-04-11 15:06:20 -0700535var (
Colin Cross6e511a92020-07-27 21:26:48 -0700536 genSourceDepTag = dependencyTag{name: "gen source"}
537 genHeaderDepTag = dependencyTag{name: "gen header"}
538 genHeaderExportDepTag = dependencyTag{name: "gen header export"}
539 objDepTag = dependencyTag{name: "obj"}
540 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
541 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
542 reuseObjTag = dependencyTag{name: "reuse objects"}
543 staticVariantTag = dependencyTag{name: "static variant"}
544 vndkExtDepTag = dependencyTag{name: "vndk extends"}
545 dataLibDepTag = dependencyTag{name: "data lib"}
546 runtimeDepTag = dependencyTag{name: "runtime lib"}
547 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700548)
549
Roland Levillainf89cd092019-07-29 16:22:59 +0100550func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700551 ccLibDepTag, ok := depTag.(libraryDependencyTag)
552 return ok && ccLibDepTag.shared()
553}
554
555func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
556 ccLibDepTag, ok := depTag.(libraryDependencyTag)
557 return ok && ccLibDepTag.static()
Roland Levillainf89cd092019-07-29 16:22:59 +0100558}
559
560func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700561 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100562 return ok && ccDepTag == runtimeDepTag
563}
564
565func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700566 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100567 return ok && ccDepTag == testPerSrcDepTag
568}
569
Colin Crossca860ac2016-01-04 14:34:37 -0800570// Module contains the properties and members used by all C/C++ module types, and implements
571// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
572// to construct the output file. Behavior can be customized with a Customizer interface
573type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700574 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700575 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900576 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900577 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700578
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700579 Properties BaseProperties
580 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700581
Colin Crossca860ac2016-01-04 14:34:37 -0800582 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700583 hod android.HostOrDeviceSupported
584 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700585
Paul Duffina0843f62019-12-13 19:50:38 +0000586 // Allowable SdkMemberTypes of this module type.
587 sdkMemberTypes []android.SdkMemberType
588
Colin Crossca860ac2016-01-04 14:34:37 -0800589 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700590 features []feature
591 compiler compiler
592 linker linker
593 installer installer
594 stl *stl
595 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800596 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800597 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900598 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700599 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700600 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800601
Colin Cross635c3b02016-05-18 15:37:25 -0700602 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800603
Colin Crossb98c8b02016-07-29 13:44:28 -0700604 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700605
606 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800607
608 // Flags used to compile this module
609 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700610
611 // 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 -0800612 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700613 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800614 depsInLinkOrder android.Paths
615
616 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700617 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900618
619 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800620 // Kythe (source file indexer) paths for this compilation module
621 kytheFiles android.Paths
Jooyung Han75568392020-03-20 04:29:24 +0900622
623 // For apex variants, this is set as apex.min_sdk_version
Dan Albertc8060532020-07-22 22:32:17 -0700624 apexSdkVersion android.ApiLevel
Colin Crossc472d572015-03-17 15:06:21 -0700625}
626
Ivan Lozano52767be2019-10-18 14:49:46 -0700627func (c *Module) Toc() android.OptionalPath {
628 if c.linker != nil {
629 if library, ok := c.linker.(libraryInterface); ok {
630 return library.toc()
631 }
632 }
633 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
634}
635
636func (c *Module) ApiLevel() string {
637 if c.linker != nil {
638 if stub, ok := c.linker.(*stubDecorator); ok {
Dan Albert1a246272020-07-06 14:49:35 -0700639 return stub.apiLevel.String()
Ivan Lozano52767be2019-10-18 14:49:46 -0700640 }
641 }
642 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
643}
644
645func (c *Module) Static() bool {
646 if c.linker != nil {
647 if library, ok := c.linker.(libraryInterface); ok {
648 return library.static()
649 }
650 }
651 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
652}
653
654func (c *Module) Shared() bool {
655 if c.linker != nil {
656 if library, ok := c.linker.(libraryInterface); ok {
657 return library.shared()
658 }
659 }
660 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
661}
662
663func (c *Module) SelectedStl() string {
Colin Crossc511bc52020-04-07 16:50:32 +0000664 if c.stl != nil {
665 return c.stl.Properties.SelectedStl
666 }
667 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700668}
669
670func (c *Module) ToolchainLibrary() bool {
671 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
672 return true
673 }
674 return false
675}
676
677func (c *Module) NdkPrebuiltStl() bool {
678 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
679 return true
680 }
681 return false
682}
683
684func (c *Module) StubDecorator() bool {
685 if _, ok := c.linker.(*stubDecorator); ok {
686 return true
687 }
688 return false
689}
690
691func (c *Module) SdkVersion() string {
692 return String(c.Properties.Sdk_version)
693}
694
Artur Satayev480e25b2020-04-27 18:53:18 +0100695func (c *Module) MinSdkVersion() string {
696 return String(c.Properties.Min_sdk_version)
697}
698
Dan Albert92fe7402020-07-15 13:33:30 -0700699func (c *Module) SplitPerApiLevel() bool {
700 if linker, ok := c.linker.(*objectLinker); ok {
701 return linker.isCrt()
702 }
703 return false
704}
705
Colin Crossc511bc52020-04-07 16:50:32 +0000706func (c *Module) AlwaysSdk() bool {
707 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
708}
709
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800710func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700711 if c.linker != nil {
712 if library, ok := c.linker.(exportedFlagsProducer); ok {
713 return library.exportedDirs()
714 }
715 }
716 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
717}
718
719func (c *Module) HasStaticVariant() bool {
720 if c.staticVariant != nil {
721 return true
722 }
723 return false
724}
725
726func (c *Module) GetStaticVariant() LinkableInterface {
727 return c.staticVariant
728}
729
730func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
731 c.depsInLinkOrder = depsInLinkOrder
732}
733
734func (c *Module) GetDepsInLinkOrder() []android.Path {
735 return c.depsInLinkOrder
736}
737
738func (c *Module) StubsVersions() []string {
739 if c.linker != nil {
740 if library, ok := c.linker.(*libraryDecorator); ok {
741 return library.Properties.Stubs.Versions
742 }
Colin Crossd48fe732020-09-23 20:37:24 -0700743 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
744 return library.Properties.Stubs.Versions
745 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700746 }
747 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
748}
749
750func (c *Module) CcLibrary() bool {
751 if c.linker != nil {
752 if _, ok := c.linker.(*libraryDecorator); ok {
753 return true
754 }
Colin Crossd48fe732020-09-23 20:37:24 -0700755 if _, ok := c.linker.(*prebuiltLibraryLinker); ok {
756 return true
757 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700758 }
759 return false
760}
761
762func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700763 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700764 return true
765 }
766 return false
767}
768
Ivan Lozano2b262972019-11-21 12:30:50 -0800769func (c *Module) NonCcVariants() bool {
770 return false
771}
772
Ivan Lozano183a3212019-10-18 14:18:45 -0700773func (c *Module) SetBuildStubs() {
774 if c.linker != nil {
775 if library, ok := c.linker.(*libraryDecorator); ok {
776 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700777 c.Properties.HideFromMake = true
778 c.sanitize = nil
779 c.stl = nil
780 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700781 return
782 }
Colin Crossd48fe732020-09-23 20:37:24 -0700783 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
784 library.MutatedProperties.BuildStubs = true
785 c.Properties.HideFromMake = true
786 c.sanitize = nil
787 c.stl = nil
788 c.Properties.PreventInstall = true
789 return
790 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000791 if _, ok := c.linker.(*llndkStubDecorator); ok {
792 c.Properties.HideFromMake = true
793 return
794 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700795 }
796 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
797}
798
Ivan Lozano52767be2019-10-18 14:49:46 -0700799func (c *Module) BuildStubs() bool {
800 if c.linker != nil {
801 if library, ok := c.linker.(*libraryDecorator); ok {
802 return library.buildStubs()
803 }
Colin Crossd48fe732020-09-23 20:37:24 -0700804 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
805 return library.buildStubs()
806 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700807 }
808 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
809}
810
Colin Crossd1f898e2020-08-18 18:35:15 -0700811func (c *Module) SetAllStubsVersions(versions []string) {
812 if library, ok := c.linker.(*libraryDecorator); ok {
813 library.MutatedProperties.AllStubsVersions = versions
814 return
815 }
Colin Crossd48fe732020-09-23 20:37:24 -0700816 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
817 library.MutatedProperties.AllStubsVersions = versions
818 return
819 }
Colin Crossd1f898e2020-08-18 18:35:15 -0700820 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
821 llndk.libraryDecorator.MutatedProperties.AllStubsVersions = versions
822 return
823 }
824}
825
826func (c *Module) AllStubsVersions() []string {
827 if library, ok := c.linker.(*libraryDecorator); ok {
828 return library.MutatedProperties.AllStubsVersions
829 }
Colin Crossd48fe732020-09-23 20:37:24 -0700830 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
831 return library.MutatedProperties.AllStubsVersions
832 }
Colin Crossd1f898e2020-08-18 18:35:15 -0700833 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
834 return llndk.libraryDecorator.MutatedProperties.AllStubsVersions
835 }
836 return nil
837}
838
839func (c *Module) SetStubsVersion(version string) {
Ivan Lozano183a3212019-10-18 14:18:45 -0700840 if c.linker != nil {
841 if library, ok := c.linker.(*libraryDecorator); ok {
842 library.MutatedProperties.StubsVersion = version
843 return
844 }
Colin Crossd48fe732020-09-23 20:37:24 -0700845 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
846 library.MutatedProperties.StubsVersion = version
847 return
848 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000849 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
850 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
851 return
852 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700853 }
Colin Crossd1f898e2020-08-18 18:35:15 -0700854 panic(fmt.Errorf("SetStubsVersion called on non-library module: %q", c.BaseModuleName()))
Ivan Lozano183a3212019-10-18 14:18:45 -0700855}
856
Jooyung Han03b51852020-02-26 22:45:42 +0900857func (c *Module) StubsVersion() string {
858 if c.linker != nil {
859 if library, ok := c.linker.(*libraryDecorator); ok {
860 return library.MutatedProperties.StubsVersion
861 }
Colin Crossd48fe732020-09-23 20:37:24 -0700862 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
863 return library.MutatedProperties.StubsVersion
864 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000865 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
866 return llndk.libraryDecorator.MutatedProperties.StubsVersion
867 }
Jooyung Han03b51852020-02-26 22:45:42 +0900868 }
869 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
870}
871
Ivan Lozano183a3212019-10-18 14:18:45 -0700872func (c *Module) SetStatic() {
873 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700874 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700875 library.setStatic()
876 return
877 }
878 }
879 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
880}
881
882func (c *Module) SetShared() {
883 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700884 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700885 library.setShared()
886 return
887 }
888 }
889 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
890}
891
892func (c *Module) BuildStaticVariant() bool {
893 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700894 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700895 return library.buildStatic()
896 }
897 }
898 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
899}
900
901func (c *Module) BuildSharedVariant() bool {
902 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700903 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700904 return library.buildShared()
905 }
906 }
907 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
908}
909
910func (c *Module) Module() android.Module {
911 return c
912}
913
Jiyong Parkc20eee32018-09-05 22:36:17 +0900914func (c *Module) OutputFile() android.OptionalPath {
915 return c.outputFile
916}
917
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400918func (c *Module) CoverageFiles() android.Paths {
919 if c.linker != nil {
920 if library, ok := c.linker.(libraryInterface); ok {
921 return library.objs().coverageFiles
922 }
923 }
924 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
925}
926
Ivan Lozano183a3212019-10-18 14:18:45 -0700927var _ LinkableInterface = (*Module)(nil)
928
Jiyong Park719b4462019-01-13 00:39:51 +0900929func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900930 if c.linker != nil {
931 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900932 }
933 return nil
934}
935
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900936func (c *Module) CoverageOutputFile() android.OptionalPath {
937 if c.linker != nil {
938 return c.linker.coverageOutputFilePath()
939 }
940 return android.OptionalPath{}
941}
942
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900943func (c *Module) RelativeInstallPath() string {
944 if c.installer != nil {
945 return c.installer.relativeInstallPath()
946 }
947 return ""
948}
949
Jooyung Han344d5432019-08-23 11:17:39 +0900950func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900951 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900952}
953
Colin Cross36242852017-06-23 15:06:31 -0700954func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700955 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800956 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700957 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800958 }
959 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700960 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800961 }
962 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700963 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800964 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700965 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700966 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700967 }
Colin Cross16b23492016-01-06 14:41:07 -0800968 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700969 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800970 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800971 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700972 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800973 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800974 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700975 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800976 }
Justin Yun8effde42017-06-23 19:24:43 +0900977 if c.vndkdep != nil {
978 c.AddProperties(c.vndkdep.props()...)
979 }
Stephen Craneba090d12017-05-09 15:44:35 -0700980 if c.lto != nil {
981 c.AddProperties(c.lto.props()...)
982 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700983 if c.pgo != nil {
984 c.AddProperties(c.pgo.props()...)
985 }
Colin Crossca860ac2016-01-04 14:34:37 -0800986 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700987 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800988 }
Colin Crossc472d572015-03-17 15:06:21 -0700989
Jiyong Park1613e552020-09-14 19:43:17 +0900990 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, os android.OsType) bool {
Elliott Hughes79ae3412020-04-17 15:49:49 -0700991 // Windows builds always prefer 32-bit
Jiyong Park1613e552020-09-14 19:43:17 +0900992 return os == android.Windows
Colin Crossa9d8bee2018-10-02 13:59:46 -0700993 })
Colin Cross36242852017-06-23 15:06:31 -0700994 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900995 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900996 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900997 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900998
Colin Cross36242852017-06-23 15:06:31 -0700999 return c
Colin Crossc472d572015-03-17 15:06:21 -07001000}
1001
Colin Crossb916a382016-07-29 17:28:03 -07001002// Returns true for dependency roots (binaries)
1003// TODO(ccross): also handle dlopenable libraries
1004func (c *Module) isDependencyRoot() bool {
1005 if root, ok := c.linker.(interface {
1006 isDependencyRoot() bool
1007 }); ok {
1008 return root.isDependencyRoot()
1009 }
1010 return false
1011}
1012
Justin Yun5f7f7e82019-11-18 19:52:14 +09001013// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
1014// "product" and "vendor" variant modules return true for this function.
1015// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
1016// "soc_specific: true" and more vendor installed modules are included here.
1017// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
1018// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -07001019func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +09001020 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001021}
1022
Colin Crossc511bc52020-04-07 16:50:32 +00001023func (c *Module) canUseSdk() bool {
1024 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery()
1025}
1026
1027func (c *Module) UseSdk() bool {
1028 if c.canUseSdk() {
Dan Albert92fe7402020-07-15 13:33:30 -07001029 return String(c.Properties.Sdk_version) != "" || c.SplitPerApiLevel()
Colin Crossc511bc52020-04-07 16:50:32 +00001030 }
1031 return false
1032}
1033
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001034func (c *Module) isCoverageVariant() bool {
1035 return c.coverage.Properties.IsCoverageVariant
1036}
1037
Peter Collingbournead84f972019-12-17 16:46:18 -08001038func (c *Module) IsNdk() bool {
Colin Crossf0913fb2020-07-29 12:59:39 -07001039 return inList(c.BaseModuleName(), ndkKnownLibs)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001040}
1041
Inseob Kim9516ee92019-05-09 10:56:13 +09001042func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001043 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +09001044 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001045}
1046
Inseob Kim9516ee92019-05-09 10:56:13 +09001047func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001048 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +09001049 name := c.BaseModuleName()
1050 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001051}
1052
Inseob Kim9516ee92019-05-09 10:56:13 +09001053func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001054 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +09001055 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001056}
1057
Ivan Lozano52767be2019-10-18 14:49:46 -07001058func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001059 if vndkdep := c.vndkdep; vndkdep != nil {
1060 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +09001061 }
1062 return false
1063}
1064
Yi Kong7e53c572018-02-14 18:16:12 +08001065func (c *Module) isPgoCompile() bool {
1066 if pgo := c.pgo; pgo != nil {
1067 return pgo.Properties.PgoCompile
1068 }
1069 return false
1070}
1071
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001072func (c *Module) isNDKStubLibrary() bool {
1073 if _, ok := c.compiler.(*stubDecorator); ok {
1074 return true
1075 }
1076 return false
1077}
1078
Logan Chienf3511742017-10-31 18:04:35 +08001079func (c *Module) isVndkSp() bool {
1080 if vndkdep := c.vndkdep; vndkdep != nil {
1081 return vndkdep.isVndkSp()
1082 }
1083 return false
1084}
1085
1086func (c *Module) isVndkExt() bool {
1087 if vndkdep := c.vndkdep; vndkdep != nil {
1088 return vndkdep.isVndkExt()
1089 }
1090 return false
1091}
1092
Ivan Lozano52767be2019-10-18 14:49:46 -07001093func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +09001094 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -08001095}
1096
Logan Chienf3511742017-10-31 18:04:35 +08001097func (c *Module) getVndkExtendsModuleName() string {
1098 if vndkdep := c.vndkdep; vndkdep != nil {
1099 return vndkdep.getVndkExtendsModuleName()
1100 }
1101 return ""
1102}
1103
Jiyong Park25fc6a92018-11-18 18:02:45 +09001104func (c *Module) IsStubs() bool {
1105 if library, ok := c.linker.(*libraryDecorator); ok {
1106 return library.buildStubs()
Colin Crossd48fe732020-09-23 20:37:24 -07001107 } else if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
1108 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +09001109 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
1110 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001111 }
1112 return false
1113}
1114
1115func (c *Module) HasStubsVariants() bool {
1116 if library, ok := c.linker.(*libraryDecorator); ok {
1117 return len(library.Properties.Stubs.Versions) > 0
1118 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001119 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
1120 return len(library.Properties.Stubs.Versions) > 0
1121 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001122 return false
1123}
1124
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001125func (c *Module) bootstrap() bool {
1126 return Bool(c.Properties.Bootstrap)
1127}
1128
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001129func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001130 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1131 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1132 return false
1133 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001134 return c.linker != nil && c.linker.nativeCoverage()
1135}
1136
Inseob Kim8471cda2019-11-15 09:59:12 +09001137func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kim1042d292020-06-01 23:23:05 +09001138 if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
1139 return p.isSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001140 }
1141 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001142}
1143
Jiyong Park73c54ee2019-10-22 20:31:18 +09001144func (c *Module) ExportedIncludeDirs() android.Paths {
1145 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1146 return flagsProducer.exportedDirs()
1147 }
Jiyong Park232e7852019-11-04 12:23:40 +09001148 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001149}
1150
1151func (c *Module) ExportedSystemIncludeDirs() android.Paths {
1152 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1153 return flagsProducer.exportedSystemDirs()
1154 }
Jiyong Park232e7852019-11-04 12:23:40 +09001155 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001156}
1157
1158func (c *Module) ExportedFlags() []string {
1159 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1160 return flagsProducer.exportedFlags()
1161 }
Jiyong Park232e7852019-11-04 12:23:40 +09001162 return nil
1163}
1164
1165func (c *Module) ExportedDeps() android.Paths {
1166 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1167 return flagsProducer.exportedDeps()
1168 }
1169 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001170}
1171
Inseob Kimd110f872019-12-06 13:15:38 +09001172func (c *Module) ExportedGeneratedHeaders() android.Paths {
1173 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1174 return flagsProducer.exportedGeneratedHeaders()
1175 }
1176 return nil
1177}
1178
Bill Peckham945441c2020-08-31 16:07:58 -07001179func (c *Module) ExcludeFromVendorSnapshot() bool {
1180 return Bool(c.Properties.Exclude_from_vendor_snapshot)
1181}
1182
Jiyong Parkf1194352019-02-25 11:05:47 +09001183func isBionic(name string) bool {
1184 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001185 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001186 return true
1187 }
1188 return false
1189}
1190
Martin Stjernholm279de572019-09-10 23:18:20 +01001191func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001192 if name == "libclang_rt.hwasan-aarch64-android" {
Jooyung Han8ce8db92020-05-15 19:05:05 +09001193 return true
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001194 }
1195 return isBionic(name)
1196}
1197
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001198func (c *Module) XrefCcFiles() android.Paths {
1199 return c.kytheFiles
1200}
1201
Colin Crossca860ac2016-01-04 14:34:37 -08001202type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001203 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001204 moduleContextImpl
1205}
1206
Colin Cross37047f12016-12-13 17:06:13 -08001207type depsContext struct {
1208 android.BottomUpMutatorContext
1209 moduleContextImpl
1210}
1211
Colin Crossca860ac2016-01-04 14:34:37 -08001212type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001213 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001214 moduleContextImpl
1215}
1216
1217type moduleContextImpl struct {
1218 mod *Module
1219 ctx BaseModuleContext
1220}
1221
Colin Crossb98c8b02016-07-29 13:44:28 -07001222func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001223 return ctx.mod.toolchain(ctx.ctx)
1224}
1225
1226func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001227 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001228}
1229
1230func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001231 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001232}
1233
Jiyong Park1d1119f2019-07-29 21:27:18 +09001234func (ctx *moduleContextImpl) header() bool {
1235 return ctx.mod.header()
1236}
1237
Inseob Kim7f283f42020-06-01 21:53:49 +09001238func (ctx *moduleContextImpl) binary() bool {
1239 return ctx.mod.binary()
1240}
1241
Inseob Kim1042d292020-06-01 23:23:05 +09001242func (ctx *moduleContextImpl) object() bool {
1243 return ctx.mod.object()
1244}
1245
Jooyung Hanccce2f22020-03-07 03:45:53 +09001246func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001247 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001248}
1249
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001250func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001251 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001252}
1253
1254func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001255 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001256 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001257 vndkVer := ctx.mod.VndkVersion()
Jooyung Han03302ee2020-04-08 09:22:26 +09001258 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001259 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001260 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001261 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001262 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001263 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001264 }
1265 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001266}
1267
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001268func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001269 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001270}
Justin Yun8effde42017-06-23 19:24:43 +09001271
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001272func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001273 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001274}
1275
Inseob Kim9516ee92019-05-09 10:56:13 +09001276func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1277 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001278}
1279
Inseob Kim9516ee92019-05-09 10:56:13 +09001280func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1281 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001282}
1283
Inseob Kim9516ee92019-05-09 10:56:13 +09001284func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1285 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001286}
1287
Logan Chienf3511742017-10-31 18:04:35 +08001288func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001289 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001290}
1291
Yi Kong7e53c572018-02-14 18:16:12 +08001292func (ctx *moduleContextImpl) isPgoCompile() bool {
1293 return ctx.mod.isPgoCompile()
1294}
1295
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001296func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1297 return ctx.mod.isNDKStubLibrary()
1298}
1299
Justin Yun8effde42017-06-23 19:24:43 +09001300func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001301 return ctx.mod.isVndkSp()
1302}
1303
1304func (ctx *moduleContextImpl) isVndkExt() bool {
1305 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001306}
1307
Vic Yangefd249e2018-11-12 20:19:56 -08001308func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001309 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001310}
1311
Logan Chien2f2b8902018-07-10 15:01:19 +08001312// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001313func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001314 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1315 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001316 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001317
Hsin-Yi Chenf81bb652020-04-07 21:42:19 +08001318 // Coverage builds have extra symbols.
1319 if ctx.mod.isCoverageVariant() {
1320 return false
1321 }
1322
Doug Hornc32c6b02019-01-17 14:44:05 -08001323 if ctx.ctx.Fuchsia() {
1324 return false
1325 }
1326
Logan Chien2f2b8902018-07-10 15:01:19 +08001327 if sanitize := ctx.mod.sanitize; sanitize != nil {
1328 if !sanitize.isVariantOnProductionDevice() {
1329 return false
1330 }
1331 }
1332 if !ctx.ctx.Device() {
1333 // Host modules do not need ABI dumps.
1334 return false
1335 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001336 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001337 // Stubs do not need ABI dumps.
1338 return false
1339 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001340 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001341}
1342
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001343func (ctx *moduleContextImpl) selectedStl() string {
1344 if stl := ctx.mod.stl; stl != nil {
1345 return stl.Properties.SelectedStl
1346 }
1347 return ""
1348}
1349
Ivan Lozanobd721262018-11-27 14:33:03 -08001350func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1351 return ctx.mod.linker.useClangLld(actx)
1352}
1353
Colin Crossce75d2c2016-10-06 16:12:58 -07001354func (ctx *moduleContextImpl) baseModuleName() string {
1355 return ctx.mod.ModuleBase.BaseModuleName()
1356}
1357
Logan Chienf3511742017-10-31 18:04:35 +08001358func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1359 return ctx.mod.getVndkExtendsModuleName()
1360}
1361
Logan Chiene274fc92019-12-03 11:18:32 -08001362func (ctx *moduleContextImpl) isForPlatform() bool {
1363 return ctx.mod.IsForPlatform()
1364}
1365
Colin Crosse07f2312020-08-13 11:24:56 -07001366func (ctx *moduleContextImpl) apexVariationName() string {
1367 return ctx.mod.ApexVariationName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001368}
1369
Dan Albertc8060532020-07-22 22:32:17 -07001370func (ctx *moduleContextImpl) apexSdkVersion() android.ApiLevel {
Jooyung Han75568392020-03-20 04:29:24 +09001371 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001372}
1373
Jiyong Parkb0788572018-12-20 22:10:17 +09001374func (ctx *moduleContextImpl) hasStubsVariants() bool {
1375 return ctx.mod.HasStubsVariants()
1376}
1377
1378func (ctx *moduleContextImpl) isStubs() bool {
1379 return ctx.mod.IsStubs()
1380}
1381
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001382func (ctx *moduleContextImpl) bootstrap() bool {
1383 return ctx.mod.bootstrap()
1384}
1385
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001386func (ctx *moduleContextImpl) nativeCoverage() bool {
1387 return ctx.mod.nativeCoverage()
1388}
1389
Colin Cross635c3b02016-05-18 15:37:25 -07001390func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001391 return &Module{
1392 hod: hod,
1393 multilib: multilib,
1394 }
1395}
1396
Colin Cross635c3b02016-05-18 15:37:25 -07001397func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001398 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001399 module.features = []feature{
1400 &tidyFeature{},
1401 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001402 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001403 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001404 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001405 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001406 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001407 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001408 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001409 return module
1410}
1411
Colin Crossce75d2c2016-10-06 16:12:58 -07001412func (c *Module) Prebuilt() *android.Prebuilt {
1413 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1414 return p.prebuilt()
1415 }
1416 return nil
1417}
1418
1419func (c *Module) Name() string {
1420 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001421 if p, ok := c.linker.(interface {
1422 Name(string) string
1423 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001424 name = p.Name(name)
1425 }
1426 return name
1427}
1428
Alex Light3d673592019-01-18 14:37:31 -08001429func (c *Module) Symlinks() []string {
1430 if p, ok := c.installer.(interface {
1431 symlinkList() []string
1432 }); ok {
1433 return p.symlinkList()
1434 }
1435 return nil
1436}
1437
Jeff Gaston294356f2017-09-27 17:05:30 -07001438// orderDeps reorders dependencies into a list such that if module A depends on B, then
1439// A will precede B in the resultant list.
1440// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001441// Note that directSharedDeps should be the analogous static library for each shared lib dep
1442func 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 -07001443 // If A depends on B, then
1444 // Every list containing A will also contain B later in the list
1445 // So, after concatenating all lists, the final instance of B will have come from the same
1446 // original list as the final instance of A
1447 // So, the final instance of B will be later in the concatenation than the final A
1448 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1449 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001450 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001451 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001452 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1453 }
1454 for _, dep := range directSharedDeps {
1455 orderedAllDeps = append(orderedAllDeps, dep)
1456 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001457 }
1458
Colin Crossb6715442017-10-24 11:13:31 -07001459 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001460
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001461 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001462 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001463 // resultant list to only what the caller has chosen to include in directStaticDeps
1464 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001465
1466 return orderedAllDeps, orderedDeclaredDeps
1467}
1468
Ivan Lozano183a3212019-10-18 14:18:45 -07001469func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001470 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001471 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001472 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1473 staticDepFiles := []android.Path{}
1474 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001475 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1476 if dep.OutputFile().Valid() {
1477 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1478 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1479 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001480 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001481 sharedDepFiles := []android.Path{}
1482 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001483 if sharedDep.HasStaticVariant() {
1484 staticAnalogue := sharedDep.GetStaticVariant()
1485 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1486 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001487 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001488 }
1489
1490 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001491 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1492 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001493
1494 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001495}
1496
Roland Levillainf89cd092019-07-29 16:22:59 +01001497func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1498 test, ok := c.linker.(testPerSrc)
1499 return ok && test.isAllTestsVariation()
1500}
1501
Chris Parsons216e10a2020-07-09 17:12:52 -04001502func (c *Module) DataPaths() []android.DataPath {
Liz Kammer1c14a212020-05-12 15:26:55 -07001503 if p, ok := c.installer.(interface {
Chris Parsons216e10a2020-07-09 17:12:52 -04001504 dataPaths() []android.DataPath
Liz Kammer1c14a212020-05-12 15:26:55 -07001505 }); ok {
1506 return p.dataPaths()
1507 }
1508 return nil
1509}
1510
Justin Yun5f7f7e82019-11-18 19:52:14 +09001511func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1512 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1513 // "current", it will append the VNDK version to the name suffix.
1514 var vndkVersion string
1515 var nameSuffix string
1516 if c.inProduct() {
1517 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1518 nameSuffix = productSuffix
1519 } else {
1520 vndkVersion = ctx.DeviceConfig().VndkVersion()
1521 nameSuffix = vendorSuffix
1522 }
1523 if vndkVersion == "current" {
1524 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1525 }
1526 if c.Properties.VndkVersion != vndkVersion {
1527 // add version suffix only if the module is using different vndk version than the
1528 // version in product or vendor partition.
1529 nameSuffix += "." + c.Properties.VndkVersion
1530 }
1531 return nameSuffix
1532}
1533
Colin Cross635c3b02016-05-18 15:37:25 -07001534func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001535 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001536 //
1537 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1538 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1539 // module and return early, as this module does not produce an output file per se.
1540 if c.IsTestPerSrcAllTestsVariation() {
1541 c.outputFile = android.OptionalPath{}
1542 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001543 }
1544
Jooyung Han38002912019-05-16 04:01:54 +09001545 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001546
Inseob Kim64c43952019-08-26 16:52:35 +09001547 c.Properties.SubName = ""
1548
1549 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1550 c.Properties.SubName += nativeBridgeSuffix
1551 }
1552
Justin Yun5f7f7e82019-11-18 19:52:14 +09001553 _, llndk := c.linker.(*llndkStubDecorator)
1554 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1555 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1556 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1557 // added for product variant only when we have vendor and product variants with core
1558 // variant. The suffix is not added for vendor-only or product-only module.
1559 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1560 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001561 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1562 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1563 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001564 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1565 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001566 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001567 c.Properties.SubName += recoverySuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001568 } else if c.IsSdkVariant() && (c.Properties.SdkAndPlatformVariantVisibleToMake || c.SplitPerApiLevel()) {
Colin Crossc511bc52020-04-07 16:50:32 +00001569 c.Properties.SubName += sdkSuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001570 if c.SplitPerApiLevel() {
1571 c.Properties.SubName += "." + c.SdkVersion()
1572 }
Inseob Kim64c43952019-08-26 16:52:35 +09001573 }
1574
Colin Crossca860ac2016-01-04 14:34:37 -08001575 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001576 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001577 moduleContextImpl: moduleContextImpl{
1578 mod: c,
1579 },
1580 }
1581 ctx.ctx = ctx
1582
Colin Crossf18e1102017-11-16 14:33:08 -08001583 deps := c.depsToPaths(ctx)
1584 if ctx.Failed() {
1585 return
1586 }
1587
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001588 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1589 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1590 }
1591
Colin Crossca860ac2016-01-04 14:34:37 -08001592 flags := Flags{
1593 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001594 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001595 }
Colin Crossca860ac2016-01-04 14:34:37 -08001596 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001597 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001598 }
1599 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001600 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001601 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001602 if c.stl != nil {
1603 flags = c.stl.flags(ctx, flags)
1604 }
Colin Cross16b23492016-01-06 14:41:07 -08001605 if c.sanitize != nil {
1606 flags = c.sanitize.flags(ctx, flags)
1607 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001608 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001609 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001610 }
Stephen Craneba090d12017-05-09 15:44:35 -07001611 if c.lto != nil {
1612 flags = c.lto.flags(ctx, flags)
1613 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001614 if c.pgo != nil {
1615 flags = c.pgo.flags(ctx, flags)
1616 }
Colin Crossca860ac2016-01-04 14:34:37 -08001617 for _, feature := range c.features {
1618 flags = feature.flags(ctx, flags)
1619 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001620 if ctx.Failed() {
1621 return
1622 }
1623
Colin Cross4af21ed2019-11-04 09:37:55 -08001624 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1625 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1626 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001627
Colin Cross4af21ed2019-11-04 09:37:55 -08001628 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001629
1630 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001631 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001632 }
1633 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001634 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001635 }
1636
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001637 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001638 // We need access to all the flags seen by a source file.
1639 if c.sabi != nil {
1640 flags = c.sabi.flags(ctx, flags)
1641 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001642
Colin Cross4af21ed2019-11-04 09:37:55 -08001643 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001644
Colin Crossca860ac2016-01-04 14:34:37 -08001645 // Optimization to reduce size of build.ninja
1646 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001647 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1648 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1649 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1650 flags.Local.CFlags = []string{"$cflags"}
1651 flags.Local.CppFlags = []string{"$cppflags"}
1652 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001653
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001654 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001655 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001656 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001657 if ctx.Failed() {
1658 return
1659 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001660 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001661 }
1662
Colin Crossca860ac2016-01-04 14:34:37 -08001663 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001664 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001665 if ctx.Failed() {
1666 return
1667 }
Colin Cross635c3b02016-05-18 15:37:25 -07001668 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001669
1670 // If a lib is directly included in any of the APEXes, unhide the stubs
1671 // variant having the latest version gets visible to make. In addition,
1672 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1673 // force anything in the make world to link against the stubs library.
1674 // (unless it is explicitly referenced via .bootstrap suffix or the
1675 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001676 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001677 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001678 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001679 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001680 c.Properties.HideFromMake = false // unhide
1681 // Note: this is still non-installable
1682 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001683
1684 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1685 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1686 if isSnapshotAware(ctx, c) {
1687 i.collectHeadersForSnapshot(ctx)
1688 }
1689 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001690 }
Colin Cross5049f022015-03-18 13:28:46 -07001691
Inseob Kim1f086e22019-05-09 13:29:15 +09001692 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001693 c.installer.install(ctx, c.outputFile.Path())
1694 if ctx.Failed() {
1695 return
Colin Crossca860ac2016-01-04 14:34:37 -08001696 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001697 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1698 // If the module has been specifically configure to not be installed then
1699 // skip the installation as otherwise it will break when running inside make
1700 // as the output path to install will not be specified. Not all uninstallable
1701 // modules can skip installation as some are needed for resolving make side
1702 // dependencies.
1703 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001704 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001705}
1706
Colin Cross0ea8ba82019-06-06 14:33:29 -07001707func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001708 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001709 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001710 }
Colin Crossca860ac2016-01-04 14:34:37 -08001711 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001712}
1713
Colin Crossca860ac2016-01-04 14:34:37 -08001714func (c *Module) begin(ctx BaseModuleContext) {
1715 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001716 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001717 }
Colin Crossca860ac2016-01-04 14:34:37 -08001718 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001719 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001720 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001721 if c.stl != nil {
1722 c.stl.begin(ctx)
1723 }
Colin Cross16b23492016-01-06 14:41:07 -08001724 if c.sanitize != nil {
1725 c.sanitize.begin(ctx)
1726 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001727 if c.coverage != nil {
1728 c.coverage.begin(ctx)
1729 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001730 if c.sabi != nil {
1731 c.sabi.begin(ctx)
1732 }
Justin Yun8effde42017-06-23 19:24:43 +09001733 if c.vndkdep != nil {
1734 c.vndkdep.begin(ctx)
1735 }
Stephen Craneba090d12017-05-09 15:44:35 -07001736 if c.lto != nil {
1737 c.lto.begin(ctx)
1738 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001739 if c.pgo != nil {
1740 c.pgo.begin(ctx)
1741 }
Colin Crossca860ac2016-01-04 14:34:37 -08001742 for _, feature := range c.features {
1743 feature.begin(ctx)
1744 }
Dan Albert92fe7402020-07-15 13:33:30 -07001745 if ctx.useSdk() && c.IsSdkVariant() {
Dan Albert1a246272020-07-06 14:49:35 -07001746 version, err := nativeApiLevelFromUser(ctx, ctx.sdkVersion())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001747 if err != nil {
1748 ctx.PropertyErrorf("sdk_version", err.Error())
Dan Albert1a246272020-07-06 14:49:35 -07001749 c.Properties.Sdk_version = nil
1750 } else {
1751 c.Properties.Sdk_version = StringPtr(version.String())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001752 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001753 }
Colin Crossca860ac2016-01-04 14:34:37 -08001754}
1755
Colin Cross37047f12016-12-13 17:06:13 -08001756func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001757 deps := Deps{}
1758
1759 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001760 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001761 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001762 // Add the PGO dependency (the clang_rt.profile runtime library), which
1763 // sometimes depends on symbols from libgcc, before libgcc gets added
1764 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001765 if c.pgo != nil {
1766 deps = c.pgo.deps(ctx, deps)
1767 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001768 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001769 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001770 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001771 if c.stl != nil {
1772 deps = c.stl.deps(ctx, deps)
1773 }
Colin Cross16b23492016-01-06 14:41:07 -08001774 if c.sanitize != nil {
1775 deps = c.sanitize.deps(ctx, deps)
1776 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001777 if c.coverage != nil {
1778 deps = c.coverage.deps(ctx, deps)
1779 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001780 if c.sabi != nil {
1781 deps = c.sabi.deps(ctx, deps)
1782 }
Justin Yun8effde42017-06-23 19:24:43 +09001783 if c.vndkdep != nil {
1784 deps = c.vndkdep.deps(ctx, deps)
1785 }
Stephen Craneba090d12017-05-09 15:44:35 -07001786 if c.lto != nil {
1787 deps = c.lto.deps(ctx, deps)
1788 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001789 for _, feature := range c.features {
1790 deps = feature.deps(ctx, deps)
1791 }
1792
Colin Crossb6715442017-10-24 11:13:31 -07001793 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1794 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1795 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1796 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1797 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1798 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001799 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001800
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001801 for _, lib := range deps.ReexportSharedLibHeaders {
1802 if !inList(lib, deps.SharedLibs) {
1803 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1804 }
1805 }
1806
1807 for _, lib := range deps.ReexportStaticLibHeaders {
1808 if !inList(lib, deps.StaticLibs) {
1809 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1810 }
1811 }
1812
Colin Cross5950f382016-12-13 12:50:57 -08001813 for _, lib := range deps.ReexportHeaderLibHeaders {
1814 if !inList(lib, deps.HeaderLibs) {
1815 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1816 }
1817 }
1818
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001819 for _, gen := range deps.ReexportGeneratedHeaders {
1820 if !inList(gen, deps.GeneratedHeaders) {
1821 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1822 }
1823 }
1824
Colin Crossc99deeb2016-04-11 15:06:20 -07001825 return deps
1826}
1827
Dan Albert7e9d2952016-08-04 13:02:36 -07001828func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001829 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001830 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001831 moduleContextImpl: moduleContextImpl{
1832 mod: c,
1833 },
1834 }
1835 ctx.ctx = ctx
1836
Colin Crossca860ac2016-01-04 14:34:37 -08001837 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001838}
1839
Jiyong Park7ed9de32018-10-15 22:25:07 +09001840// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001841func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001842 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1843 version := name[sharp+1:]
1844 libname := name[:sharp]
1845 return libname, version
1846 }
1847 return name, ""
1848}
1849
Dan Albert92fe7402020-07-15 13:33:30 -07001850func GetCrtVariations(ctx android.BottomUpMutatorContext,
1851 m LinkableInterface) []blueprint.Variation {
1852 if ctx.Os() != android.Android {
1853 return nil
1854 }
1855 if m.UseSdk() {
1856 return []blueprint.Variation{
1857 {Mutator: "sdk", Variation: "sdk"},
1858 {Mutator: "ndk_api", Variation: m.SdkVersion()},
1859 }
1860 }
1861 return []blueprint.Variation{
1862 {Mutator: "sdk", Variation: ""},
1863 }
1864}
1865
Colin Crosse7257d22020-09-24 09:56:18 -07001866func (c *Module) addSharedLibDependenciesWithVersions(ctx android.BottomUpMutatorContext,
1867 variations []blueprint.Variation, depTag libraryDependencyTag, name, version string, far bool) {
1868
1869 variations = append([]blueprint.Variation(nil), variations...)
1870
1871 if version != "" && VersionVariantAvailable(c) {
1872 // Version is explicitly specified. i.e. libFoo#30
1873 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1874 depTag.explicitlyVersioned = true
1875 }
1876 var deps []blueprint.Module
1877 if far {
1878 deps = ctx.AddFarVariationDependencies(variations, depTag, name)
1879 } else {
1880 deps = ctx.AddVariationDependencies(variations, depTag, name)
1881 }
1882
1883 // If the version is not specified, add dependency to all stubs libraries.
1884 // The stubs library will be used when the depending module is built for APEX and
1885 // the dependent module is not in the same APEX.
1886 if version == "" && VersionVariantAvailable(c) {
1887 if dep, ok := deps[0].(*Module); ok {
1888 for _, ver := range dep.AllStubsVersions() {
1889 // Note that depTag.ExplicitlyVersioned is false in this case.
1890 versionVariations := append(variations,
1891 blueprint.Variation{Mutator: "version", Variation: ver})
1892 if far {
1893 ctx.AddFarVariationDependencies(versionVariations, depTag, name)
1894 } else {
1895 ctx.AddVariationDependencies(versionVariations, depTag, name)
1896 }
1897 }
1898 }
1899 }
1900}
1901
Colin Cross1e676be2016-10-12 14:38:15 -07001902func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001903 if !c.Enabled() {
1904 return
1905 }
1906
Colin Cross37047f12016-12-13 17:06:13 -08001907 ctx := &depsContext{
1908 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001909 moduleContextImpl: moduleContextImpl{
1910 mod: c,
1911 },
1912 }
1913 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001914
Colin Crossc99deeb2016-04-11 15:06:20 -07001915 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001916
Yo Chiang219968c2020-09-22 18:45:04 +08001917 c.Properties.AndroidMkSystemSharedLibs = deps.SystemSharedLibs
1918
Dan Albert914449f2016-06-17 16:45:24 -07001919 variantNdkLibs := []string{}
1920 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001921 if ctx.Os() == android.Android {
Inseob Kimeec88e12020-01-22 11:11:29 +09001922 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001923 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001924 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001925 // 1. Name of an NDK library that refers to a prebuilt module.
1926 // For each of these, it adds the name of the prebuilt module (which will be in
1927 // prebuilts/ndk) to the list of nonvariant libs.
1928 // 2. Name of an NDK library that refers to an ndk_library module.
1929 // For each of these, it adds the name of the ndk_library module to the list of
1930 // variant libs.
1931 // 3. Anything else (so anything that isn't an NDK library).
1932 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001933 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001934 // The caller can then know to add the variantLibs dependencies differently from the
1935 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001936
Inseob Kim9516ee92019-05-09 10:56:13 +09001937 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001938 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1939
1940 rewriteVendorLibs := func(lib string) string {
1941 if isLlndkLibrary(lib, ctx.Config()) {
1942 return lib + llndkLibrarySuffix
1943 }
1944
1945 // only modules with BOARD_VNDK_VERSION uses snapshot.
1946 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1947 return lib
1948 }
1949
1950 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1951 return snapshot
1952 }
1953
1954 return lib
1955 }
1956
1957 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001958 variantLibs = []string{}
1959 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001960 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001961 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001962 name, _ := StubsLibNameAndVersion(entry)
Dan Albertde5aade2020-06-30 12:32:51 -07001963 if ctx.useSdk() && inList(name, ndkKnownLibs) {
1964 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +09001965 } else if ctx.useVndk() {
1966 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001967 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001968 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001969 if actx.OtherModuleExists(vendorPublicLib) {
1970 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1971 } else {
1972 // This can happen if vendor_public_library module is defined in a
1973 // namespace that isn't visible to the current module. In that case,
1974 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001975 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001976 }
Dan Albert914449f2016-06-17 16:45:24 -07001977 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001978 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001979 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001980 }
1981 }
Dan Albert914449f2016-06-17 16:45:24 -07001982 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001983 }
1984
Inseob Kimeec88e12020-01-22 11:11:29 +09001985 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1986 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1987 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1988 if ctx.useVndk() {
1989 for idx, lib := range deps.RuntimeLibs {
1990 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1991 }
1992 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001993 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001994
Jiyong Park7e636d02019-01-28 16:16:54 +09001995 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001996 if c.linker != nil {
1997 if library, ok := c.linker.(*libraryDecorator); ok {
1998 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001999 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09002000 }
2001 }
Colin Crossd48fe732020-09-23 20:37:24 -07002002 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
2003 if library.buildStubs() {
2004 buildStubs = true
2005 }
2006 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002007 }
2008
Inseob Kimeec88e12020-01-22 11:11:29 +09002009 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
2010 // only modules with BOARD_VNDK_VERSION uses snapshot.
2011 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
2012 return lib
2013 }
2014
2015 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
2016 return snapshot
2017 }
2018
2019 return lib
2020 }
2021
2022 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08002023 for _, lib := range deps.HeaderLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002024 depTag := libraryDependencyTag{Kind: headerLibraryDependency}
Colin Cross32ec36c2016-12-15 07:39:51 -08002025 if inList(lib, deps.ReexportHeaderLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002026 depTag.reexportFlags = true
Colin Cross32ec36c2016-12-15 07:39:51 -08002027 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002028
2029 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
2030
Jiyong Park7e636d02019-01-28 16:16:54 +09002031 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08002032 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07002033 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09002034 } else {
2035 actx.AddVariationDependencies(nil, depTag, lib)
2036 }
2037 }
2038
2039 if buildStubs {
2040 // Stubs lib does not have dependency to other static/shared libraries.
2041 // Don't proceed.
2042 return
Colin Cross32ec36c2016-12-15 07:39:51 -08002043 }
Colin Cross5950f382016-12-13 12:50:57 -08002044
Inseob Kimc0907f12019-02-08 21:00:45 +09002045 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09002046 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09002047
Jiyong Park5d1598f2019-02-25 22:14:17 +09002048 for _, lib := range deps.WholeStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002049 depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
Jiyong Park5d1598f2019-02-25 22:14:17 +09002050 if impl, ok := syspropImplLibraries[lib]; ok {
2051 lib = impl
2052 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002053
2054 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
2055
Jiyong Park5d1598f2019-02-25 22:14:17 +09002056 actx.AddVariationDependencies([]blueprint.Variation{
2057 {Mutator: "link", Variation: "static"},
2058 }, depTag, lib)
2059 }
2060
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002061 for _, lib := range deps.StaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002062 depTag := libraryDependencyTag{Kind: staticLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002063 if inList(lib, deps.ReexportStaticLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002064 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002065 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002066
2067 if impl, ok := syspropImplLibraries[lib]; ok {
2068 lib = impl
2069 }
2070
Inseob Kimeec88e12020-01-22 11:11:29 +09002071 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
2072
Dan Willemsen59339a22018-07-22 21:18:45 -07002073 actx.AddVariationDependencies([]blueprint.Variation{
2074 {Mutator: "link", Variation: "static"},
2075 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002076 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002077
Jooyung Han75568392020-03-20 04:29:24 +09002078 // staticUnwinderDep is treated as staticDep for Q apexes
2079 // so that native libraries/binaries are linked with static unwinder
2080 // because Q libc doesn't have unwinder APIs
2081 if deps.StaticUnwinderIfLegacy {
Colin Cross6e511a92020-07-27 21:26:48 -07002082 depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002083 actx.AddVariationDependencies([]blueprint.Variation{
2084 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07002085 }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002086 }
2087
Inseob Kimeec88e12020-01-22 11:11:29 +09002088 for _, lib := range deps.LateStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002089 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
Inseob Kimeec88e12020-01-22 11:11:29 +09002090 actx.AddVariationDependencies([]blueprint.Variation{
2091 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07002092 }, depTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
Inseob Kimeec88e12020-01-22 11:11:29 +09002093 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002094
Jiyong Park7ed9de32018-10-15 22:25:07 +09002095 // shared lib names without the #version suffix
2096 var sharedLibNames []string
2097
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002098 for _, lib := range deps.SharedLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002099 depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002100 if inList(lib, deps.ReexportSharedLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002101 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002102 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002103
2104 if impl, ok := syspropImplLibraries[lib]; ok {
2105 lib = impl
2106 }
2107
Jiyong Park73c54ee2019-10-22 20:31:18 +09002108 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09002109 sharedLibNames = append(sharedLibNames, name)
2110
Colin Crosse7257d22020-09-24 09:56:18 -07002111 variations := []blueprint.Variation{
2112 {Mutator: "link", Variation: "shared"},
2113 }
2114 c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, name, version, false)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002115 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002116
Jiyong Park7ed9de32018-10-15 22:25:07 +09002117 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002118 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09002119 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
2120 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
2121 // linking against both the stubs lib and the non-stubs lib at the same time.
2122 continue
2123 }
Colin Cross6e511a92020-07-27 21:26:48 -07002124 depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
Colin Crosse7257d22020-09-24 09:56:18 -07002125 variations := []blueprint.Variation{
2126 {Mutator: "link", Variation: "shared"},
2127 }
2128 c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, lib, "", false)
Jiyong Park7ed9de32018-10-15 22:25:07 +09002129 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002130
Dan Willemsen59339a22018-07-22 21:18:45 -07002131 actx.AddVariationDependencies([]blueprint.Variation{
2132 {Mutator: "link", Variation: "shared"},
Chris Parsons79d66a52020-06-05 17:26:16 -04002133 }, dataLibDepTag, deps.DataLibs...)
2134
2135 actx.AddVariationDependencies([]blueprint.Variation{
2136 {Mutator: "link", Variation: "shared"},
Dan Willemsen59339a22018-07-22 21:18:45 -07002137 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08002138
Colin Cross68861832016-07-08 10:41:41 -07002139 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002140
2141 for _, gen := range deps.GeneratedHeaders {
2142 depTag := genHeaderDepTag
2143 if inList(gen, deps.ReexportGeneratedHeaders) {
2144 depTag = genHeaderExportDepTag
2145 }
2146 actx.AddDependency(c, depTag, gen)
2147 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002148
Colin Cross42d48b72018-08-29 14:10:52 -07002149 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07002150
Inseob Kim1042d292020-06-01 23:23:05 +09002151 vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())
2152
Dan Albert92fe7402020-07-15 13:33:30 -07002153 crtVariations := GetCrtVariations(ctx, c)
Colin Crossc99deeb2016-04-11 15:06:20 -07002154 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002155 actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
2156 rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08002157 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002158 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002159 actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
2160 rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07002161 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002162 if deps.LinkerFlagsFile != "" {
2163 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
2164 }
2165 if deps.DynamicLinker != "" {
2166 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002167 }
Dan Albert914449f2016-06-17 16:45:24 -07002168
2169 version := ctx.sdkVersion()
Colin Cross6e511a92020-07-27 21:26:48 -07002170
2171 ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002172 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002173 {Mutator: "ndk_api", Variation: version},
2174 {Mutator: "link", Variation: "shared"},
2175 }, ndkStubDepTag, variantNdkLibs...)
Colin Cross6e511a92020-07-27 21:26:48 -07002176
2177 ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002178 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002179 {Mutator: "ndk_api", Variation: version},
2180 {Mutator: "link", Variation: "shared"},
2181 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002182
2183 if vndkdep := c.vndkdep; vndkdep != nil {
2184 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002185 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002186 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002187 {Mutator: "link", Variation: "shared"},
2188 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002189 }
2190 }
Colin Cross6362e272015-10-29 15:25:03 -07002191}
Colin Cross21b9a242015-03-24 14:15:58 -07002192
Colin Crosse40b4ea2018-10-02 22:25:58 -07002193func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002194 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2195 c.beginMutator(ctx)
2196 }
2197}
2198
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002199// Whether a module can link to another module, taking into
2200// account NDK linking.
Colin Cross6e511a92020-07-27 21:26:48 -07002201func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface,
2202 tag blueprint.DependencyTag) {
2203
2204 switch t := tag.(type) {
2205 case dependencyTag:
2206 if t != vndkExtDepTag {
2207 return
2208 }
2209 case libraryDependencyTag:
2210 default:
2211 return
2212 }
2213
Ivan Lozano52767be2019-10-18 14:49:46 -07002214 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002215 // Host code is not restricted
2216 return
2217 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002218
2219 // VNDK is cc.Module supported only for now.
2220 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002221 // Though vendor code is limited by the vendor mutator,
2222 // each vendor-available module needs to check
2223 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002224 if ccTo, ok := to.(*Module); ok {
2225 if ccFrom.vndkdep != nil {
2226 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2227 }
2228 } else {
2229 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002230 }
2231 return
2232 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002233 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002234 // Platform code can link to anything
2235 return
2236 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002237 if from.InRamdisk() {
2238 // Ramdisk code is not NDK
2239 return
2240 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002241 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002242 // Recovery code is not NDK
2243 return
2244 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002245 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002246 // These are always allowed
2247 return
2248 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002249 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002250 // These are allowed, but they don't set sdk_version
2251 return
2252 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002253 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002254 // These aren't real libraries, but are the stub shared libraries that are included in
2255 // the NDK.
2256 return
2257 }
Logan Chien834b9a62019-01-14 15:39:03 +08002258
Ivan Lozano52767be2019-10-18 14:49:46 -07002259 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002260 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2261 // to link to libc++ (non-NDK and without sdk_version).
2262 return
2263 }
2264
Ivan Lozano52767be2019-10-18 14:49:46 -07002265 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002266 // NDK code linking to platform code is never okay.
2267 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002268 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002269 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002270 }
2271
2272 // At this point we know we have two NDK libraries, but we need to
2273 // check that we're not linking against anything built against a higher
2274 // API level, as it is only valid to link against older or equivalent
2275 // APIs.
2276
Inseob Kim01a28722018-04-11 09:48:45 +09002277 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002278 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002279 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002280 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002281 // Current can't be linked against by anything else.
2282 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002283 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002284 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002285 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002286 if err != nil {
2287 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002288 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002289 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002290 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002291 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002292 if err != nil {
2293 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002294 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002295 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002296 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002297
Inseob Kim01a28722018-04-11 09:48:45 +09002298 if toApi > fromApi {
2299 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002300 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002301 }
2302 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002303 }
Dan Albert202fe492017-12-15 13:56:59 -08002304
2305 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002306 fromStl := from.SelectedStl()
2307 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002308 if fromStl == "" || toStl == "" {
2309 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002310 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002311 // We can be permissive with the system "STL" since it is only the C++
2312 // ABI layer, but in the future we should make sure that everyone is
2313 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002314 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002315 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002316 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2317 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002318 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002319}
2320
Jiyong Park5fb8c102018-04-09 12:03:06 +09002321// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002322// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2323// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002324// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002325func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2326 check := func(child, parent android.Module) bool {
2327 to, ok := child.(*Module)
2328 if !ok {
2329 // follow thru cc.Defaults, etc.
2330 return true
2331 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002332
Jooyung Hana70f0672019-01-18 15:20:43 +09002333 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2334 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002335 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002336
2337 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002338 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002339 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002340 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002341
Jooyung Han0302a842019-10-30 18:43:49 +09002342 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002343 return false
2344 }
2345
2346 var stringPath []string
2347 for _, m := range ctx.GetWalkPath() {
2348 stringPath = append(stringPath, m.Name())
2349 }
2350 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2351 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2352 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2353 return false
2354 }
2355 if module, ok := ctx.Module().(*Module); ok {
2356 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002357 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002358 ctx.WalkDeps(check)
2359 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002360 }
2361 }
2362}
2363
Colin Crossc99deeb2016-04-11 15:06:20 -07002364// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002365func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002366 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002367
Ivan Lozano183a3212019-10-18 14:18:45 -07002368 directStaticDeps := []LinkableInterface{}
2369 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002370
Inseob Kim69378442019-06-03 19:10:47 +09002371 reexportExporter := func(exporter exportedFlagsProducer) {
2372 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2373 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2374 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2375 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002376 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002377 }
2378
Jooyung Hande34d232020-07-23 13:04:15 +09002379 // For the dependency from platform to apex, use the latest stubs
2380 c.apexSdkVersion = android.FutureApiLevel
2381 if !c.IsForPlatform() {
Dan Albertc8060532020-07-22 22:32:17 -07002382 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion(ctx)
Jooyung Hande34d232020-07-23 13:04:15 +09002383 }
2384
2385 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2386 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2387 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2388 // (b/144430859)
2389 c.apexSdkVersion = android.FutureApiLevel
2390 }
2391
Colin Crossd11fcda2017-10-23 17:59:01 -07002392 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002393 depName := ctx.OtherModuleName(dep)
2394 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002395
Ivan Lozano52767be2019-10-18 14:49:46 -07002396 ccDep, ok := dep.(LinkableInterface)
2397 if !ok {
2398
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002399 // handling for a few module types that aren't cc Module but that are also supported
2400 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002401 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002402 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002403 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2404 genRule.GeneratedSourceFiles()...)
2405 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002406 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002407 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002408 // Support exported headers from a generated_sources dependency
2409 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002410 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002411 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09002412 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002413 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002414 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002415 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002416 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002417 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002418 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2419 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002420 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002421 // 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 +09002422 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002423
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002424 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002425 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002426 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002427 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002428 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002429 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002430 files := genRule.GeneratedSourceFiles()
2431 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002432 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002433 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002434 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 -07002435 }
2436 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002437 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002438 }
Colin Crossca860ac2016-01-04 14:34:37 -08002439 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002440 return
2441 }
2442
Colin Crossfe17f6f2019-03-28 19:30:56 -07002443 if depTag == android.ProtoPluginDepTag {
2444 return
2445 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002446 if depTag == llndkImplDep {
2447 return
2448 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002449
Colin Crossd11fcda2017-10-23 17:59:01 -07002450 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002451 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2452 return
2453 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002454 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002455 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2456 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002457 return
2458 }
2459
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002460 // re-exporting flags
2461 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002462 // reusing objects only make sense for cc.Modules.
2463 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002464 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002465 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002466 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002467 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002468 return
2469 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002470 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002471
Jiyong Parke4bb9862019-02-01 00:31:10 +09002472 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002473 // staticVariants are a cc.Module specific concept.
2474 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002475 c.staticVariant = ccDep
2476 return
2477 }
2478 }
2479
Colin Cross6e511a92020-07-27 21:26:48 -07002480 checkLinkType(ctx, c, ccDep, depTag)
2481
2482 linkFile := ccDep.OutputFile()
2483
2484 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
2485 // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
Dan Albertc8060532020-07-22 22:32:17 -07002486 if libDepTag.staticUnwinder && c.apexSdkVersion.GreaterThan(android.SdkVersion_Android10) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002487 return
2488 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002489
Colin Cross6e511a92020-07-27 21:26:48 -07002490 if ccDep.CcLibrary() && !libDepTag.static() {
Ivan Lozano52767be2019-10-18 14:49:46 -07002491 depIsStubs := ccDep.BuildStubs()
Jooyung Han624d35c2020-04-10 12:57:24 +09002492 depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
Colin Crossaede88c2020-08-11 12:17:01 -07002493 depInSameApexes := android.DirectlyInAllApexes(c.InApexes(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002494 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002495
2496 var useThisDep bool
Colin Cross6e511a92020-07-27 21:26:48 -07002497 if depIsStubs && libDepTag.explicitlyVersioned {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002498 // Always respect dependency to the versioned stubs (i.e. libX#10)
2499 useThisDep = true
2500 } else if !depHasStubs {
2501 // Use non-stub variant if that is the only choice
2502 // (i.e. depending on a lib without stubs.version property)
2503 useThisDep = true
2504 } else if c.IsForPlatform() {
2505 // If not building for APEX, use stubs only when it is from
2506 // an APEX (and not from platform)
2507 useThisDep = (depInPlatform != depIsStubs)
Jooyung Han624d35c2020-04-10 12:57:24 +09002508 if c.bootstrap() {
2509 // However, for host, ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002510 // always link to non-stub variant
2511 useThisDep = !depIsStubs
2512 }
Jiyong Park62304bb2020-04-13 16:19:48 +09002513 for _, testFor := range c.TestFor() {
2514 // Another exception: if this module is bundled with an APEX, then
2515 // it is linked with the non-stub variant of a module in the APEX
2516 // as if this is part of the APEX.
2517 if android.DirectlyInApex(testFor, depName) {
2518 useThisDep = !depIsStubs
2519 break
2520 }
2521 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002522 } else {
Colin Crossaede88c2020-08-11 12:17:01 -07002523 // If building for APEX, use stubs when the parent is in any APEX that
2524 // the child is not in.
2525 useThisDep = (depInSameApexes != depIsStubs)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002526 }
2527
Jooyung Han03b51852020-02-26 22:45:42 +09002528 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
Colin Cross6e511a92020-07-27 21:26:48 -07002529 if useThisDep && depIsStubs && !libDepTag.explicitlyVersioned {
Colin Cross7812fd32020-09-25 12:35:10 -07002530 versionToUse, err := c.ChooseSdkVersion(ctx, ccDep.StubsVersions(), c.apexSdkVersion)
Jooyung Han03b51852020-02-26 22:45:42 +09002531 if err != nil {
2532 ctx.OtherModuleErrorf(dep, err.Error())
2533 return
2534 }
2535 if versionToUse != ccDep.StubsVersion() {
2536 useThisDep = false
2537 }
2538 }
2539
Jiyong Park25fc6a92018-11-18 18:02:45 +09002540 if !useThisDep {
2541 return // stop processing this dep
2542 }
2543 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002544 if c.UseVndk() {
2545 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2546 // by default, use current version of LLNDK
2547 versionToUse := ""
Colin Crossd1f898e2020-08-18 18:35:15 -07002548 versions := m.AllStubsVersions()
Colin Crosse07f2312020-08-13 11:24:56 -07002549 if c.ApexVariationName() != "" && len(versions) > 0 {
Jooyung Han61b66e92020-03-21 14:21:46 +00002550 // if this is for use_vendor apex && dep has stubsVersions
2551 // apply the same rule of apex sdk enforcement to choose right version
2552 var err error
Colin Cross7812fd32020-09-25 12:35:10 -07002553 versionToUse, err = c.ChooseSdkVersion(ctx, versions, c.apexSdkVersion)
Jooyung Han61b66e92020-03-21 14:21:46 +00002554 if err != nil {
2555 ctx.OtherModuleErrorf(dep, err.Error())
2556 return
2557 }
2558 }
2559 if versionToUse != ccDep.StubsVersion() {
2560 return
2561 }
2562 }
2563 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002564
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002565 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2566
Ivan Lozano52767be2019-10-18 14:49:46 -07002567 // Exporting flags only makes sense for cc.Modules
2568 if _, ok := ccDep.(*Module); ok {
2569 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002570 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002571 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002572 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002573
Colin Cross6e511a92020-07-27 21:26:48 -07002574 if libDepTag.reexportFlags {
Ivan Lozano52767be2019-10-18 14:49:46 -07002575 reexportExporter(i)
2576 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2577 // Re-exported shared library headers must be included as well since they can help us with type information
2578 // about template instantiations (instantiated from their headers).
2579 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2580 // scripts.
2581 c.sabi.Properties.ReexportedIncludes = append(
2582 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2583 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002584 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002585 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002586
Colin Cross6e511a92020-07-27 21:26:48 -07002587 var ptr *android.Paths
2588 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002589
Colin Cross6e511a92020-07-27 21:26:48 -07002590 depFile := android.OptionalPath{}
Colin Cross26c34ed2016-09-30 17:10:16 -07002591
Colin Cross6e511a92020-07-27 21:26:48 -07002592 switch {
2593 case libDepTag.header():
2594 // nothing
2595 case libDepTag.shared():
2596 ptr = &depPaths.SharedLibs
2597 switch libDepTag.Order {
2598 case earlyLibraryDependency:
2599 ptr = &depPaths.EarlySharedLibs
2600 depPtr = &depPaths.EarlySharedLibsDeps
2601 case normalLibraryDependency:
2602 ptr = &depPaths.SharedLibs
2603 depPtr = &depPaths.SharedLibsDeps
2604 directSharedDeps = append(directSharedDeps, ccDep)
2605 case lateLibraryDependency:
2606 ptr = &depPaths.LateSharedLibs
2607 depPtr = &depPaths.LateSharedLibsDeps
2608 default:
2609 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Colin Crossc99deeb2016-04-11 15:06:20 -07002610 }
Colin Cross6e511a92020-07-27 21:26:48 -07002611 depFile = ccDep.Toc()
2612 case libDepTag.static():
2613 if libDepTag.wholeStatic {
2614 ptr = &depPaths.WholeStaticLibs
2615 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2616 ctx.ModuleErrorf("module %q not a static library", depName)
2617 return
Inseob Kim752edec2020-03-14 01:30:34 +09002618 }
2619
Colin Cross6e511a92020-07-27 21:26:48 -07002620 // Because the static library objects are included, this only makes sense
2621 // in the context of proper cc.Modules.
2622 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2623 staticLib := ccWholeStaticLib.linker.(libraryInterface)
Colin Crosse4f6eba2020-09-22 18:11:25 -07002624 if objs := staticLib.objs(); len(objs.objFiles) > 0 {
2625 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(objs)
Colin Cross6e511a92020-07-27 21:26:48 -07002626 } else {
Colin Crosse4f6eba2020-09-22 18:11:25 -07002627 // This case normally catches prebuilt static
2628 // libraries, but it can also occur when
2629 // AllowMissingDependencies is on and the
2630 // dependencies has no sources of its own
2631 // but has a whole_static_libs dependency
2632 // on a missing library. We want to depend
2633 // on the .a file so that there is something
2634 // in the dependency tree that contains the
2635 // error rule for the missing transitive
2636 // dependency.
2637 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
Colin Cross6e511a92020-07-27 21:26:48 -07002638 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002639 } else {
Colin Cross6e511a92020-07-27 21:26:48 -07002640 ctx.ModuleErrorf(
2641 "non-cc.Modules cannot be included as whole static libraries.", depName)
2642 return
2643 }
2644
2645 } else {
2646 switch libDepTag.Order {
2647 case earlyLibraryDependency:
2648 panic(fmt.Errorf("early static libs not suppported"))
2649 case normalLibraryDependency:
2650 // static dependencies will be handled separately so they can be ordered
2651 // using transitive dependencies.
2652 ptr = nil
2653 directStaticDeps = append(directStaticDeps, ccDep)
2654 case lateLibraryDependency:
2655 ptr = &depPaths.LateStaticLibs
2656 default:
2657 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Inseob Kimeec88e12020-01-22 11:11:29 +09002658 }
2659 }
2660 }
2661
Colin Cross6e511a92020-07-27 21:26:48 -07002662 if libDepTag.static() && !libDepTag.wholeStatic {
2663 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2664 ctx.ModuleErrorf("module %q not a static library", depName)
2665 return
2666 }
Logan Chien43d34c32017-12-20 01:17:32 +08002667
Colin Cross6e511a92020-07-27 21:26:48 -07002668 // When combining coverage files for shared libraries and executables, coverage files
2669 // in static libraries act as if they were whole static libraries. The same goes for
2670 // source based Abi dump files.
2671 if c, ok := ccDep.(*Module); ok {
2672 staticLib := c.linker.(libraryInterface)
2673 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2674 staticLib.objs().coverageFiles...)
2675 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2676 staticLib.objs().sAbiDumpFiles...)
2677 } else if c, ok := ccDep.(LinkableInterface); ok {
2678 // Handle non-CC modules here
2679 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2680 c.CoverageFiles()...)
Jiyong Parkde866cb2018-12-07 23:08:36 +09002681 }
2682 }
2683
Colin Cross6e511a92020-07-27 21:26:48 -07002684 if ptr != nil {
2685 if !linkFile.Valid() {
2686 if !ctx.Config().AllowMissingDependencies() {
2687 ctx.ModuleErrorf("module %q missing output file", depName)
2688 } else {
2689 ctx.AddMissingDependencies([]string{depName})
2690 }
2691 return
2692 }
2693 *ptr = append(*ptr, linkFile.Path())
2694 }
2695
2696 if depPtr != nil {
2697 dep := depFile
2698 if !dep.Valid() {
2699 dep = linkFile
2700 }
2701 *depPtr = append(*depPtr, dep.Path())
2702 }
2703
2704 makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix
2705 switch {
2706 case libDepTag.header():
Colin Cross370173e2020-07-29 12:48:33 -07002707 c.Properties.AndroidMkHeaderLibs = append(
2708 c.Properties.AndroidMkHeaderLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002709 case libDepTag.shared():
2710 if ccDep.CcLibrary() {
2711 if ccDep.BuildStubs() && android.InAnyApex(depName) {
2712 // Add the dependency to the APEX(es) providing the library so that
2713 // m <module> can trigger building the APEXes as well.
2714 for _, an := range android.GetApexesForModule(depName) {
2715 c.Properties.ApexesProvidingSharedLibs = append(
2716 c.Properties.ApexesProvidingSharedLibs, an)
2717 }
2718 }
2719 }
2720
2721 // Note: the order of libs in this list is not important because
2722 // they merely serve as Make dependencies and do not affect this lib itself.
Colin Cross370173e2020-07-29 12:48:33 -07002723 c.Properties.AndroidMkSharedLibs = append(
2724 c.Properties.AndroidMkSharedLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002725 // Record baseLibName for snapshots.
2726 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
2727 case libDepTag.static():
2728 if libDepTag.wholeStatic {
2729 c.Properties.AndroidMkWholeStaticLibs = append(
2730 c.Properties.AndroidMkWholeStaticLibs, makeLibName)
2731 } else {
2732 c.Properties.AndroidMkStaticLibs = append(
2733 c.Properties.AndroidMkStaticLibs, makeLibName)
2734 }
2735 }
2736 } else {
2737 switch depTag {
2738 case runtimeDepTag:
2739 c.Properties.AndroidMkRuntimeLibs = append(
2740 c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix)
2741 // Record baseLibName for snapshots.
2742 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
2743 case objDepTag:
2744 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
2745 case CrtBeginDepTag:
2746 depPaths.CrtBegin = linkFile
2747 case CrtEndDepTag:
2748 depPaths.CrtEnd = linkFile
2749 case dynamicLinkerDepTag:
2750 depPaths.DynamicLinker = linkFile
2751 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002752 }
Colin Crossca860ac2016-01-04 14:34:37 -08002753 })
2754
Jeff Gaston294356f2017-09-27 17:05:30 -07002755 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002756 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002757
Colin Crossdd84e052017-05-17 13:44:16 -07002758 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002759 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002760 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2761 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09002762 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002763 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2764 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002765 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002766 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002767 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002768
2769 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002770 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002771 }
Colin Crossdd84e052017-05-17 13:44:16 -07002772
Colin Crossca860ac2016-01-04 14:34:37 -08002773 return depPaths
2774}
2775
Colin Cross6e511a92020-07-27 21:26:48 -07002776// baseLibName trims known prefixes and suffixes
2777func baseLibName(depName string) string {
2778 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
2779 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
2780 libName = strings.TrimPrefix(libName, "prebuilt_")
2781 return libName
2782}
2783
2784func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
2785 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2786 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2787
2788 libName := baseLibName(depName)
2789 isLLndk := isLlndkLibrary(libName, ctx.Config())
2790 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
2791 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
2792
2793 if c, ok := ccDep.(*Module); ok {
2794 // Use base module name for snapshots when exporting to Makefile.
2795 if c.isSnapshotPrebuilt() {
2796 baseName := c.BaseModuleName()
2797
2798 if c.IsVndk() {
2799 return baseName + ".vendor"
2800 }
2801
2802 if vendorSuffixModules[baseName] {
2803 return baseName + ".vendor"
2804 } else {
2805 return baseName
2806 }
2807 }
2808 }
2809
2810 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
2811 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2812 // core module instead.
2813 return libName
2814 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
2815 // The vendor module in Make will have been renamed to not conflict with the core
2816 // module, so update the dependency name here accordingly.
2817 return libName + c.getNameSuffixWithVndkVersion(ctx)
2818 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
2819 return libName + vendorPublicLibrarySuffix
2820 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2821 return libName + ramdiskSuffix
2822 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
2823 return libName + recoverySuffix
2824 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
2825 return libName + nativeBridgeSuffix
2826 } else {
2827 return libName
2828 }
2829}
2830
Colin Crossca860ac2016-01-04 14:34:37 -08002831func (c *Module) InstallInData() bool {
2832 if c.installer == nil {
2833 return false
2834 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002835 return c.installer.inData()
2836}
2837
2838func (c *Module) InstallInSanitizerDir() bool {
2839 if c.installer == nil {
2840 return false
2841 }
2842 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002843 return true
2844 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002845 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002846}
2847
Yifan Hong1b3348d2020-01-21 15:53:22 -08002848func (c *Module) InstallInRamdisk() bool {
2849 return c.InRamdisk()
2850}
2851
Jiyong Parkf9332f12018-02-01 00:54:12 +09002852func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002853 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002854}
2855
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002856func (c *Module) MakeUninstallable() {
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002857 if c.installer == nil {
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002858 c.ModuleBase.MakeUninstallable()
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002859 return
2860 }
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002861 c.installer.makeUninstallable(c)
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002862}
2863
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002864func (c *Module) HostToolPath() android.OptionalPath {
2865 if c.installer == nil {
2866 return android.OptionalPath{}
2867 }
2868 return c.installer.hostToolPath()
2869}
2870
Nan Zhangd4e641b2017-07-12 12:55:28 -07002871func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2872 return c.outputFile
2873}
2874
Colin Cross41955e82019-05-29 14:40:35 -07002875func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2876 switch tag {
2877 case "":
2878 if c.outputFile.Valid() {
2879 return android.Paths{c.outputFile.Path()}, nil
2880 }
2881 return android.Paths{}, nil
2882 default:
2883 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002884 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002885}
2886
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002887func (c *Module) static() bool {
2888 if static, ok := c.linker.(interface {
2889 static() bool
2890 }); ok {
2891 return static.static()
2892 }
2893 return false
2894}
2895
Jiyong Park379de2f2018-12-19 02:47:14 +09002896func (c *Module) staticBinary() bool {
2897 if static, ok := c.linker.(interface {
2898 staticBinary() bool
2899 }); ok {
2900 return static.staticBinary()
2901 }
2902 return false
2903}
2904
Jiyong Park1d1119f2019-07-29 21:27:18 +09002905func (c *Module) header() bool {
2906 if h, ok := c.linker.(interface {
2907 header() bool
2908 }); ok {
2909 return h.header()
2910 }
2911 return false
2912}
2913
Inseob Kim7f283f42020-06-01 21:53:49 +09002914func (c *Module) binary() bool {
2915 if b, ok := c.linker.(interface {
2916 binary() bool
2917 }); ok {
2918 return b.binary()
2919 }
2920 return false
2921}
2922
Inseob Kim1042d292020-06-01 23:23:05 +09002923func (c *Module) object() bool {
2924 if o, ok := c.linker.(interface {
2925 object() bool
2926 }); ok {
2927 return o.object()
2928 }
2929 return false
2930}
2931
Jooyung Han38002912019-05-16 04:01:54 +09002932func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002933 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002934 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2935 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002936 return "native:vndk"
2937 }
Jooyung Han38002912019-05-16 04:01:54 +09002938 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002939 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002940 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002941 if Bool(c.VendorProperties.Vendor_available) {
2942 return "native:vndk"
2943 }
2944 return "native:vndk_private"
2945 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002946 if c.inProduct() {
2947 return "native:product"
2948 }
Jooyung Han38002912019-05-16 04:01:54 +09002949 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002950 } else if c.InRamdisk() {
2951 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002952 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002953 return "native:recovery"
2954 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2955 return "native:ndk:none:none"
2956 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2957 //family, link := getNdkStlFamilyAndLinkType(c)
2958 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002959 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002960 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002961 } else {
2962 return "native:platform"
2963 }
2964}
2965
Jiyong Park9d452992018-10-03 00:38:19 +09002966// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002967// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002968func (c *Module) IsInstallableToApex() bool {
2969 if shared, ok := c.linker.(interface {
2970 shared() bool
2971 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002972 // Stub libs and prebuilt libs in a versioned SDK are not
2973 // installable to APEX even though they are shared libs.
2974 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002975 } else if _, ok := c.linker.(testPerSrc); ok {
2976 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002977 }
2978 return false
2979}
2980
Jiyong Parka90ca002019-10-07 15:47:24 +09002981func (c *Module) AvailableFor(what string) bool {
2982 if linker, ok := c.linker.(interface {
2983 availableFor(string) bool
2984 }); ok {
2985 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2986 } else {
2987 return c.ApexModuleBase.AvailableFor(what)
2988 }
2989}
2990
Jiyong Park62304bb2020-04-13 16:19:48 +09002991func (c *Module) TestFor() []string {
2992 if test, ok := c.linker.(interface {
2993 testFor() []string
2994 }); ok {
2995 return test.testFor()
2996 } else {
2997 return c.ApexModuleBase.TestFor()
2998 }
2999}
3000
Colin Crossaede88c2020-08-11 12:17:01 -07003001func (c *Module) UniqueApexVariations() bool {
3002 if u, ok := c.compiler.(interface {
3003 uniqueApexVariations() bool
3004 }); ok {
3005 return u.uniqueApexVariations()
3006 } else {
3007 return false
3008 }
3009}
3010
Paul Duffin0cb37b92020-03-04 14:52:46 +00003011// Return true if the module is ever installable.
3012func (c *Module) EverInstallable() bool {
3013 return c.installer != nil &&
3014 // Check to see whether the module is actually ever installable.
3015 c.installer.everInstallable()
3016}
3017
Inseob Kim1f086e22019-05-09 13:29:15 +09003018func (c *Module) installable() bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00003019 ret := c.EverInstallable() &&
3020 // Check to see whether the module has been configured to not be installed.
3021 proptools.BoolDefault(c.Properties.Installable, true) &&
3022 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09003023
3024 // The platform variant doesn't need further condition. Apex variants however might not
3025 // be installable because it will likely to be included in the APEX and won't appear
3026 // in the system partition.
3027 if c.IsForPlatform() {
3028 return ret
3029 }
3030
3031 // Special case for modules that are configured to be installed to /data, which includes
3032 // test modules. For these modules, both APEX and non-APEX variants are considered as
3033 // installable. This is because even the APEX variants won't be included in the APEX, but
3034 // will anyway be installed to /data/*.
3035 // See b/146995717
3036 if c.InstallInData() {
3037 return ret
3038 }
3039
3040 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09003041}
3042
Logan Chien41eabe62019-04-10 13:33:58 +08003043func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
3044 if c.linker != nil {
3045 if library, ok := c.linker.(*libraryDecorator); ok {
3046 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
3047 }
3048 }
3049}
3050
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003051func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Colin Cross6e511a92020-07-27 21:26:48 -07003052 depTag := ctx.OtherModuleDependencyTag(dep)
3053 libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
3054
3055 if cc, ok := dep.(*Module); ok {
3056 if cc.HasStubsVariants() {
3057 if isLibDepTag && libDepTag.shared() {
3058 // dynamic dep to a stubs lib crosses APEX boundary
3059 return false
Jiyong Parkd7536ba2020-01-16 17:14:23 +09003060 }
Colin Cross6e511a92020-07-27 21:26:48 -07003061 if IsRuntimeDepTag(depTag) {
3062 // runtime dep to a stubs lib also crosses APEX boundary
Jiyong Parkd7536ba2020-01-16 17:14:23 +09003063 return false
3064 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003065 }
Colin Crossaac32222020-07-29 12:51:56 -07003066 if isLibDepTag && c.static() && libDepTag.shared() {
Colin Cross6e511a92020-07-27 21:26:48 -07003067 // shared_lib dependency from a static lib is considered as crossing
3068 // the APEX boundary because the dependency doesn't actually is
3069 // linked; the dependency is used only during the compilation phase.
3070 return false
3071 }
3072 }
3073 if depTag == llndkImplDep {
Jiyong Park7d95a512020-05-10 15:16:24 +09003074 // We don't track beyond LLNDK
3075 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003076 }
3077 return true
3078}
3079
Dan Albertc8060532020-07-22 22:32:17 -07003080func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
3081 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +09003082 // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
3083 if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
3084 return nil
3085 }
3086 // b/154569636: set min_sdk_version correctly for toolchain_libraries
3087 if c.ToolchainLibrary() {
3088 return nil
3089 }
3090 // We don't check for prebuilt modules
3091 if _, ok := c.linker.(prebuiltLinkerInterface); ok {
3092 return nil
3093 }
3094 minSdkVersion := c.MinSdkVersion()
3095 if minSdkVersion == "apex_inherit" {
3096 return nil
3097 }
3098 if minSdkVersion == "" {
3099 // JNI libs within APK-in-APEX fall into here
3100 // Those are okay to set sdk_version instead
3101 // We don't have to check if this is a SDK variant because
3102 // non-SDK variant resets sdk_version, which works too.
3103 minSdkVersion = c.SdkVersion()
3104 }
Dan Albertc8060532020-07-22 22:32:17 -07003105 if minSdkVersion == "" {
3106 return fmt.Errorf("neither min_sdk_version nor sdk_version specificed")
3107 }
3108 // Not using nativeApiLevelFromUser because the context here is not
3109 // necessarily a native context.
3110 ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
Jooyung Han749dc692020-04-15 11:03:39 +09003111 if err != nil {
3112 return err
3113 }
Dan Albertc8060532020-07-22 22:32:17 -07003114
3115 if ver.GreaterThan(sdkVersion) {
Jooyung Han749dc692020-04-15 11:03:39 +09003116 return fmt.Errorf("newer SDK(%v)", ver)
3117 }
3118 return nil
3119}
3120
Colin Cross2ba19d92015-05-07 15:44:20 -07003121//
Colin Crosscfad1192015-11-02 16:43:11 -08003122// Defaults
3123//
Colin Crossca860ac2016-01-04 14:34:37 -08003124type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07003125 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07003126 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09003127 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08003128}
3129
Patrice Arrudac249c712019-03-19 17:00:29 -07003130// cc_defaults provides a set of properties that can be inherited by other cc
3131// modules. A module can use the properties from a cc_defaults using
3132// `defaults: ["<:default_module_name>"]`. Properties of both modules are
3133// merged (when possible) by prepending the default module's values to the
3134// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07003135func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07003136 return DefaultsFactory()
3137}
3138
Colin Cross36242852017-06-23 15:06:31 -07003139func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08003140 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08003141
Colin Cross36242852017-06-23 15:06:31 -07003142 module.AddProperties(props...)
3143 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08003144 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07003145 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003146 &BaseCompilerProperties{},
3147 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01003148 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003149 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07003150 &StaticProperties{},
3151 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07003152 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003153 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003154 &TestProperties{},
3155 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07003156 &BenchmarkProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07003157 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003158 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08003159 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07003160 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07003161 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07003162 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08003163 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08003164 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09003165 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07003166 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07003167 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08003168 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07003169 )
Colin Crosscfad1192015-11-02 16:43:11 -08003170
Jooyung Hancc372c52019-09-25 15:18:44 +09003171 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07003172
3173 return module
Colin Crosscfad1192015-11-02 16:43:11 -08003174}
3175
Jiyong Park6a43f042017-10-12 23:05:00 +09003176func squashVendorSrcs(m *Module) {
3177 if lib, ok := m.compiler.(*libraryDecorator); ok {
3178 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3179 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
3180
3181 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3182 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003183
3184 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3185 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
Jiyong Park6a43f042017-10-12 23:05:00 +09003186 }
3187}
3188
Jiyong Parkf9332f12018-02-01 00:54:12 +09003189func squashRecoverySrcs(m *Module) {
3190 if lib, ok := m.compiler.(*libraryDecorator); ok {
3191 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3192 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
3193
3194 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3195 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003196
3197 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3198 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003199 }
3200}
3201
Jiyong Park2286afd2020-06-16 21:58:53 +09003202func (c *Module) IsSdkVariant() bool {
Dan Albert92fe7402020-07-15 13:33:30 -07003203 return c.Properties.IsSdkVariant || c.AlwaysSdk()
Jiyong Park2286afd2020-06-16 21:58:53 +09003204}
3205
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003206func kytheExtractAllFactory() android.Singleton {
3207 return &kytheExtractAllSingleton{}
3208}
3209
3210type kytheExtractAllSingleton struct {
3211}
3212
3213func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3214 var xrefTargets android.Paths
3215 ctx.VisitAllModules(func(module android.Module) {
3216 if ccModule, ok := module.(xref); ok {
3217 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3218 }
3219 })
3220 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3221 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07003222 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003223 }
3224}
3225
Colin Cross06a931b2015-10-28 17:23:31 -07003226var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003227var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003228var BoolPtr = proptools.BoolPtr
3229var String = proptools.String
3230var StringPtr = proptools.StringPtr