blob: 006a4a596011af90ece39f832acccc2db170e65e [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 {
Colin Cross1348ce32020-10-01 13:37:16 -0700700 if !c.canUseSdk() {
701 return false
702 }
Dan Albert92fe7402020-07-15 13:33:30 -0700703 if linker, ok := c.linker.(*objectLinker); ok {
704 return linker.isCrt()
705 }
706 return false
707}
708
Colin Crossc511bc52020-04-07 16:50:32 +0000709func (c *Module) AlwaysSdk() bool {
710 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
711}
712
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800713func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700714 if c.linker != nil {
715 if library, ok := c.linker.(exportedFlagsProducer); ok {
716 return library.exportedDirs()
717 }
718 }
719 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
720}
721
722func (c *Module) HasStaticVariant() bool {
723 if c.staticVariant != nil {
724 return true
725 }
726 return false
727}
728
729func (c *Module) GetStaticVariant() LinkableInterface {
730 return c.staticVariant
731}
732
733func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
734 c.depsInLinkOrder = depsInLinkOrder
735}
736
737func (c *Module) GetDepsInLinkOrder() []android.Path {
738 return c.depsInLinkOrder
739}
740
741func (c *Module) StubsVersions() []string {
742 if c.linker != nil {
743 if library, ok := c.linker.(*libraryDecorator); ok {
744 return library.Properties.Stubs.Versions
745 }
Colin Crossd48fe732020-09-23 20:37:24 -0700746 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
747 return library.Properties.Stubs.Versions
748 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700749 }
750 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
751}
752
753func (c *Module) CcLibrary() bool {
754 if c.linker != nil {
755 if _, ok := c.linker.(*libraryDecorator); ok {
756 return true
757 }
Colin Crossd48fe732020-09-23 20:37:24 -0700758 if _, ok := c.linker.(*prebuiltLibraryLinker); ok {
759 return true
760 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700761 }
762 return false
763}
764
765func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700766 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700767 return true
768 }
769 return false
770}
771
Ivan Lozano2b262972019-11-21 12:30:50 -0800772func (c *Module) NonCcVariants() bool {
773 return false
774}
775
Ivan Lozano183a3212019-10-18 14:18:45 -0700776func (c *Module) SetBuildStubs() {
777 if c.linker != nil {
778 if library, ok := c.linker.(*libraryDecorator); ok {
779 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700780 c.Properties.HideFromMake = true
781 c.sanitize = nil
782 c.stl = nil
783 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700784 return
785 }
Colin Crossd48fe732020-09-23 20:37:24 -0700786 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
787 library.MutatedProperties.BuildStubs = true
788 c.Properties.HideFromMake = true
789 c.sanitize = nil
790 c.stl = nil
791 c.Properties.PreventInstall = true
792 return
793 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000794 if _, ok := c.linker.(*llndkStubDecorator); ok {
795 c.Properties.HideFromMake = true
796 return
797 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700798 }
799 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
800}
801
Ivan Lozano52767be2019-10-18 14:49:46 -0700802func (c *Module) BuildStubs() bool {
803 if c.linker != nil {
804 if library, ok := c.linker.(*libraryDecorator); ok {
805 return library.buildStubs()
806 }
Colin Crossd48fe732020-09-23 20:37:24 -0700807 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
808 return library.buildStubs()
809 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700810 }
811 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
812}
813
Colin Crossd1f898e2020-08-18 18:35:15 -0700814func (c *Module) SetAllStubsVersions(versions []string) {
815 if library, ok := c.linker.(*libraryDecorator); ok {
816 library.MutatedProperties.AllStubsVersions = versions
817 return
818 }
Colin Crossd48fe732020-09-23 20:37:24 -0700819 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
820 library.MutatedProperties.AllStubsVersions = versions
821 return
822 }
Colin Crossd1f898e2020-08-18 18:35:15 -0700823 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
824 llndk.libraryDecorator.MutatedProperties.AllStubsVersions = versions
825 return
826 }
827}
828
829func (c *Module) AllStubsVersions() []string {
830 if library, ok := c.linker.(*libraryDecorator); ok {
831 return library.MutatedProperties.AllStubsVersions
832 }
Colin Crossd48fe732020-09-23 20:37:24 -0700833 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
834 return library.MutatedProperties.AllStubsVersions
835 }
Colin Crossd1f898e2020-08-18 18:35:15 -0700836 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
837 return llndk.libraryDecorator.MutatedProperties.AllStubsVersions
838 }
839 return nil
840}
841
842func (c *Module) SetStubsVersion(version string) {
Ivan Lozano183a3212019-10-18 14:18:45 -0700843 if c.linker != nil {
844 if library, ok := c.linker.(*libraryDecorator); ok {
845 library.MutatedProperties.StubsVersion = version
846 return
847 }
Colin Crossd48fe732020-09-23 20:37:24 -0700848 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
849 library.MutatedProperties.StubsVersion = version
850 return
851 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000852 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
853 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
854 return
855 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700856 }
Colin Crossd1f898e2020-08-18 18:35:15 -0700857 panic(fmt.Errorf("SetStubsVersion called on non-library module: %q", c.BaseModuleName()))
Ivan Lozano183a3212019-10-18 14:18:45 -0700858}
859
Jooyung Han03b51852020-02-26 22:45:42 +0900860func (c *Module) StubsVersion() string {
861 if c.linker != nil {
862 if library, ok := c.linker.(*libraryDecorator); ok {
863 return library.MutatedProperties.StubsVersion
864 }
Colin Crossd48fe732020-09-23 20:37:24 -0700865 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
866 return library.MutatedProperties.StubsVersion
867 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000868 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
869 return llndk.libraryDecorator.MutatedProperties.StubsVersion
870 }
Jooyung Han03b51852020-02-26 22:45:42 +0900871 }
872 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
873}
874
Ivan Lozano183a3212019-10-18 14:18:45 -0700875func (c *Module) SetStatic() {
876 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700877 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700878 library.setStatic()
879 return
880 }
881 }
882 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
883}
884
885func (c *Module) SetShared() {
886 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700887 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700888 library.setShared()
889 return
890 }
891 }
892 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
893}
894
895func (c *Module) BuildStaticVariant() bool {
896 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700897 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700898 return library.buildStatic()
899 }
900 }
901 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
902}
903
904func (c *Module) BuildSharedVariant() bool {
905 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700906 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700907 return library.buildShared()
908 }
909 }
910 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
911}
912
913func (c *Module) Module() android.Module {
914 return c
915}
916
Jiyong Parkc20eee32018-09-05 22:36:17 +0900917func (c *Module) OutputFile() android.OptionalPath {
918 return c.outputFile
919}
920
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400921func (c *Module) CoverageFiles() android.Paths {
922 if c.linker != nil {
923 if library, ok := c.linker.(libraryInterface); ok {
924 return library.objs().coverageFiles
925 }
926 }
927 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
928}
929
Ivan Lozano183a3212019-10-18 14:18:45 -0700930var _ LinkableInterface = (*Module)(nil)
931
Jiyong Park719b4462019-01-13 00:39:51 +0900932func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900933 if c.linker != nil {
934 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900935 }
936 return nil
937}
938
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900939func (c *Module) CoverageOutputFile() android.OptionalPath {
940 if c.linker != nil {
941 return c.linker.coverageOutputFilePath()
942 }
943 return android.OptionalPath{}
944}
945
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900946func (c *Module) RelativeInstallPath() string {
947 if c.installer != nil {
948 return c.installer.relativeInstallPath()
949 }
950 return ""
951}
952
Jooyung Han344d5432019-08-23 11:17:39 +0900953func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900954 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900955}
956
Colin Cross36242852017-06-23 15:06:31 -0700957func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700958 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800959 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700960 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800961 }
962 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700963 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800964 }
965 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700966 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800967 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700968 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700969 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700970 }
Colin Cross16b23492016-01-06 14:41:07 -0800971 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700972 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800973 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800974 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700975 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800976 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800977 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700978 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800979 }
Justin Yun8effde42017-06-23 19:24:43 +0900980 if c.vndkdep != nil {
981 c.AddProperties(c.vndkdep.props()...)
982 }
Stephen Craneba090d12017-05-09 15:44:35 -0700983 if c.lto != nil {
984 c.AddProperties(c.lto.props()...)
985 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700986 if c.pgo != nil {
987 c.AddProperties(c.pgo.props()...)
988 }
Colin Crossca860ac2016-01-04 14:34:37 -0800989 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700990 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800991 }
Colin Crossc472d572015-03-17 15:06:21 -0700992
Jiyong Park1613e552020-09-14 19:43:17 +0900993 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, os android.OsType) bool {
Elliott Hughes79ae3412020-04-17 15:49:49 -0700994 // Windows builds always prefer 32-bit
Jiyong Park1613e552020-09-14 19:43:17 +0900995 return os == android.Windows
Colin Crossa9d8bee2018-10-02 13:59:46 -0700996 })
Colin Cross36242852017-06-23 15:06:31 -0700997 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900998 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900999 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +09001000 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +09001001
Colin Cross36242852017-06-23 15:06:31 -07001002 return c
Colin Crossc472d572015-03-17 15:06:21 -07001003}
1004
Colin Crossb916a382016-07-29 17:28:03 -07001005// Returns true for dependency roots (binaries)
1006// TODO(ccross): also handle dlopenable libraries
1007func (c *Module) isDependencyRoot() bool {
1008 if root, ok := c.linker.(interface {
1009 isDependencyRoot() bool
1010 }); ok {
1011 return root.isDependencyRoot()
1012 }
1013 return false
1014}
1015
Justin Yun5f7f7e82019-11-18 19:52:14 +09001016// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
1017// "product" and "vendor" variant modules return true for this function.
1018// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
1019// "soc_specific: true" and more vendor installed modules are included here.
1020// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
1021// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -07001022func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +09001023 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001024}
1025
Colin Crossc511bc52020-04-07 16:50:32 +00001026func (c *Module) canUseSdk() bool {
1027 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery()
1028}
1029
1030func (c *Module) UseSdk() bool {
1031 if c.canUseSdk() {
Colin Cross1348ce32020-10-01 13:37:16 -07001032 return String(c.Properties.Sdk_version) != ""
Colin Crossc511bc52020-04-07 16:50:32 +00001033 }
1034 return false
1035}
1036
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001037func (c *Module) isCoverageVariant() bool {
1038 return c.coverage.Properties.IsCoverageVariant
1039}
1040
Peter Collingbournead84f972019-12-17 16:46:18 -08001041func (c *Module) IsNdk() bool {
Colin Crossf0913fb2020-07-29 12:59:39 -07001042 return inList(c.BaseModuleName(), ndkKnownLibs)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001043}
1044
Inseob Kim9516ee92019-05-09 10:56:13 +09001045func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001046 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +09001047 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001048}
1049
Inseob Kim9516ee92019-05-09 10:56:13 +09001050func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001051 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +09001052 name := c.BaseModuleName()
1053 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001054}
1055
Inseob Kim9516ee92019-05-09 10:56:13 +09001056func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001057 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +09001058 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001059}
1060
Ivan Lozano52767be2019-10-18 14:49:46 -07001061func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001062 if vndkdep := c.vndkdep; vndkdep != nil {
1063 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +09001064 }
1065 return false
1066}
1067
Yi Kong7e53c572018-02-14 18:16:12 +08001068func (c *Module) isPgoCompile() bool {
1069 if pgo := c.pgo; pgo != nil {
1070 return pgo.Properties.PgoCompile
1071 }
1072 return false
1073}
1074
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001075func (c *Module) isNDKStubLibrary() bool {
1076 if _, ok := c.compiler.(*stubDecorator); ok {
1077 return true
1078 }
1079 return false
1080}
1081
Logan Chienf3511742017-10-31 18:04:35 +08001082func (c *Module) isVndkSp() bool {
1083 if vndkdep := c.vndkdep; vndkdep != nil {
1084 return vndkdep.isVndkSp()
1085 }
1086 return false
1087}
1088
1089func (c *Module) isVndkExt() bool {
1090 if vndkdep := c.vndkdep; vndkdep != nil {
1091 return vndkdep.isVndkExt()
1092 }
1093 return false
1094}
1095
Ivan Lozano52767be2019-10-18 14:49:46 -07001096func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +09001097 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -08001098}
1099
Logan Chienf3511742017-10-31 18:04:35 +08001100func (c *Module) getVndkExtendsModuleName() string {
1101 if vndkdep := c.vndkdep; vndkdep != nil {
1102 return vndkdep.getVndkExtendsModuleName()
1103 }
1104 return ""
1105}
1106
Jiyong Park25fc6a92018-11-18 18:02:45 +09001107func (c *Module) IsStubs() bool {
1108 if library, ok := c.linker.(*libraryDecorator); ok {
1109 return library.buildStubs()
Colin Crossd48fe732020-09-23 20:37:24 -07001110 } else if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
1111 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +09001112 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
1113 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001114 }
1115 return false
1116}
1117
1118func (c *Module) HasStubsVariants() bool {
1119 if library, ok := c.linker.(*libraryDecorator); ok {
1120 return len(library.Properties.Stubs.Versions) > 0
1121 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001122 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
1123 return len(library.Properties.Stubs.Versions) > 0
1124 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001125 return false
1126}
1127
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001128func (c *Module) bootstrap() bool {
1129 return Bool(c.Properties.Bootstrap)
1130}
1131
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001132func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001133 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1134 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1135 return false
1136 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001137 return c.linker != nil && c.linker.nativeCoverage()
1138}
1139
Inseob Kim8471cda2019-11-15 09:59:12 +09001140func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kim1042d292020-06-01 23:23:05 +09001141 if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
1142 return p.isSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001143 }
1144 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001145}
1146
Jiyong Park73c54ee2019-10-22 20:31:18 +09001147func (c *Module) ExportedIncludeDirs() android.Paths {
1148 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1149 return flagsProducer.exportedDirs()
1150 }
Jiyong Park232e7852019-11-04 12:23:40 +09001151 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001152}
1153
1154func (c *Module) ExportedSystemIncludeDirs() android.Paths {
1155 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1156 return flagsProducer.exportedSystemDirs()
1157 }
Jiyong Park232e7852019-11-04 12:23:40 +09001158 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001159}
1160
1161func (c *Module) ExportedFlags() []string {
1162 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1163 return flagsProducer.exportedFlags()
1164 }
Jiyong Park232e7852019-11-04 12:23:40 +09001165 return nil
1166}
1167
1168func (c *Module) ExportedDeps() android.Paths {
1169 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1170 return flagsProducer.exportedDeps()
1171 }
1172 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001173}
1174
Inseob Kimd110f872019-12-06 13:15:38 +09001175func (c *Module) ExportedGeneratedHeaders() android.Paths {
1176 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1177 return flagsProducer.exportedGeneratedHeaders()
1178 }
1179 return nil
1180}
1181
Bill Peckham945441c2020-08-31 16:07:58 -07001182func (c *Module) ExcludeFromVendorSnapshot() bool {
1183 return Bool(c.Properties.Exclude_from_vendor_snapshot)
1184}
1185
Jiyong Parkf1194352019-02-25 11:05:47 +09001186func isBionic(name string) bool {
1187 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001188 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001189 return true
1190 }
1191 return false
1192}
1193
Martin Stjernholm279de572019-09-10 23:18:20 +01001194func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001195 if name == "libclang_rt.hwasan-aarch64-android" {
Jooyung Han8ce8db92020-05-15 19:05:05 +09001196 return true
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001197 }
1198 return isBionic(name)
1199}
1200
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001201func (c *Module) XrefCcFiles() android.Paths {
1202 return c.kytheFiles
1203}
1204
Colin Crossca860ac2016-01-04 14:34:37 -08001205type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001206 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001207 moduleContextImpl
1208}
1209
Colin Cross37047f12016-12-13 17:06:13 -08001210type depsContext struct {
1211 android.BottomUpMutatorContext
1212 moduleContextImpl
1213}
1214
Colin Crossca860ac2016-01-04 14:34:37 -08001215type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001216 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001217 moduleContextImpl
1218}
1219
1220type moduleContextImpl struct {
1221 mod *Module
1222 ctx BaseModuleContext
1223}
1224
Colin Crossb98c8b02016-07-29 13:44:28 -07001225func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001226 return ctx.mod.toolchain(ctx.ctx)
1227}
1228
1229func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001230 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001231}
1232
1233func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001234 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001235}
1236
Jiyong Park1d1119f2019-07-29 21:27:18 +09001237func (ctx *moduleContextImpl) header() bool {
1238 return ctx.mod.header()
1239}
1240
Inseob Kim7f283f42020-06-01 21:53:49 +09001241func (ctx *moduleContextImpl) binary() bool {
1242 return ctx.mod.binary()
1243}
1244
Inseob Kim1042d292020-06-01 23:23:05 +09001245func (ctx *moduleContextImpl) object() bool {
1246 return ctx.mod.object()
1247}
1248
Jooyung Hanccce2f22020-03-07 03:45:53 +09001249func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001250 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001251}
1252
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001253func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001254 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001255}
1256
1257func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001258 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001259 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001260 vndkVer := ctx.mod.VndkVersion()
Jooyung Han03302ee2020-04-08 09:22:26 +09001261 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001262 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001263 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001264 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001265 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001266 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001267 }
1268 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001269}
1270
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001271func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001272 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001273}
Justin Yun8effde42017-06-23 19:24:43 +09001274
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001275func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001276 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001277}
1278
Inseob Kim9516ee92019-05-09 10:56:13 +09001279func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1280 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001281}
1282
Inseob Kim9516ee92019-05-09 10:56:13 +09001283func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1284 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001285}
1286
Inseob Kim9516ee92019-05-09 10:56:13 +09001287func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1288 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001289}
1290
Logan Chienf3511742017-10-31 18:04:35 +08001291func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001292 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001293}
1294
Yi Kong7e53c572018-02-14 18:16:12 +08001295func (ctx *moduleContextImpl) isPgoCompile() bool {
1296 return ctx.mod.isPgoCompile()
1297}
1298
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001299func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1300 return ctx.mod.isNDKStubLibrary()
1301}
1302
Justin Yun8effde42017-06-23 19:24:43 +09001303func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001304 return ctx.mod.isVndkSp()
1305}
1306
1307func (ctx *moduleContextImpl) isVndkExt() bool {
1308 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001309}
1310
Vic Yangefd249e2018-11-12 20:19:56 -08001311func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001312 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001313}
1314
Logan Chien2f2b8902018-07-10 15:01:19 +08001315// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001316func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001317 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1318 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001319 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001320
Hsin-Yi Chenf81bb652020-04-07 21:42:19 +08001321 // Coverage builds have extra symbols.
1322 if ctx.mod.isCoverageVariant() {
1323 return false
1324 }
1325
Doug Hornc32c6b02019-01-17 14:44:05 -08001326 if ctx.ctx.Fuchsia() {
1327 return false
1328 }
1329
Logan Chien2f2b8902018-07-10 15:01:19 +08001330 if sanitize := ctx.mod.sanitize; sanitize != nil {
1331 if !sanitize.isVariantOnProductionDevice() {
1332 return false
1333 }
1334 }
1335 if !ctx.ctx.Device() {
1336 // Host modules do not need ABI dumps.
1337 return false
1338 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001339 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001340 // Stubs do not need ABI dumps.
1341 return false
1342 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001343 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001344}
1345
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001346func (ctx *moduleContextImpl) selectedStl() string {
1347 if stl := ctx.mod.stl; stl != nil {
1348 return stl.Properties.SelectedStl
1349 }
1350 return ""
1351}
1352
Ivan Lozanobd721262018-11-27 14:33:03 -08001353func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1354 return ctx.mod.linker.useClangLld(actx)
1355}
1356
Colin Crossce75d2c2016-10-06 16:12:58 -07001357func (ctx *moduleContextImpl) baseModuleName() string {
1358 return ctx.mod.ModuleBase.BaseModuleName()
1359}
1360
Logan Chienf3511742017-10-31 18:04:35 +08001361func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1362 return ctx.mod.getVndkExtendsModuleName()
1363}
1364
Logan Chiene274fc92019-12-03 11:18:32 -08001365func (ctx *moduleContextImpl) isForPlatform() bool {
1366 return ctx.mod.IsForPlatform()
1367}
1368
Colin Crosse07f2312020-08-13 11:24:56 -07001369func (ctx *moduleContextImpl) apexVariationName() string {
1370 return ctx.mod.ApexVariationName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001371}
1372
Dan Albertc8060532020-07-22 22:32:17 -07001373func (ctx *moduleContextImpl) apexSdkVersion() android.ApiLevel {
Jooyung Han75568392020-03-20 04:29:24 +09001374 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001375}
1376
Jiyong Parkb0788572018-12-20 22:10:17 +09001377func (ctx *moduleContextImpl) hasStubsVariants() bool {
1378 return ctx.mod.HasStubsVariants()
1379}
1380
1381func (ctx *moduleContextImpl) isStubs() bool {
1382 return ctx.mod.IsStubs()
1383}
1384
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001385func (ctx *moduleContextImpl) bootstrap() bool {
1386 return ctx.mod.bootstrap()
1387}
1388
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001389func (ctx *moduleContextImpl) nativeCoverage() bool {
1390 return ctx.mod.nativeCoverage()
1391}
1392
Colin Cross635c3b02016-05-18 15:37:25 -07001393func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001394 return &Module{
1395 hod: hod,
1396 multilib: multilib,
1397 }
1398}
1399
Colin Cross635c3b02016-05-18 15:37:25 -07001400func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001401 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001402 module.features = []feature{
1403 &tidyFeature{},
1404 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001405 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001406 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001407 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001408 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001409 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001410 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001411 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001412 return module
1413}
1414
Colin Crossce75d2c2016-10-06 16:12:58 -07001415func (c *Module) Prebuilt() *android.Prebuilt {
1416 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1417 return p.prebuilt()
1418 }
1419 return nil
1420}
1421
1422func (c *Module) Name() string {
1423 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001424 if p, ok := c.linker.(interface {
1425 Name(string) string
1426 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001427 name = p.Name(name)
1428 }
1429 return name
1430}
1431
Alex Light3d673592019-01-18 14:37:31 -08001432func (c *Module) Symlinks() []string {
1433 if p, ok := c.installer.(interface {
1434 symlinkList() []string
1435 }); ok {
1436 return p.symlinkList()
1437 }
1438 return nil
1439}
1440
Jeff Gaston294356f2017-09-27 17:05:30 -07001441// orderDeps reorders dependencies into a list such that if module A depends on B, then
1442// A will precede B in the resultant list.
1443// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001444// Note that directSharedDeps should be the analogous static library for each shared lib dep
1445func 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 -07001446 // If A depends on B, then
1447 // Every list containing A will also contain B later in the list
1448 // So, after concatenating all lists, the final instance of B will have come from the same
1449 // original list as the final instance of A
1450 // So, the final instance of B will be later in the concatenation than the final A
1451 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1452 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001453 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001454 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001455 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1456 }
1457 for _, dep := range directSharedDeps {
1458 orderedAllDeps = append(orderedAllDeps, dep)
1459 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001460 }
1461
Colin Crossb6715442017-10-24 11:13:31 -07001462 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001463
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001464 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001465 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001466 // resultant list to only what the caller has chosen to include in directStaticDeps
1467 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001468
1469 return orderedAllDeps, orderedDeclaredDeps
1470}
1471
Ivan Lozano183a3212019-10-18 14:18:45 -07001472func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001473 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001474 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001475 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1476 staticDepFiles := []android.Path{}
1477 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001478 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1479 if dep.OutputFile().Valid() {
1480 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1481 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1482 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001483 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001484 sharedDepFiles := []android.Path{}
1485 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001486 if sharedDep.HasStaticVariant() {
1487 staticAnalogue := sharedDep.GetStaticVariant()
1488 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1489 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001490 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001491 }
1492
1493 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001494 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1495 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001496
1497 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001498}
1499
Roland Levillainf89cd092019-07-29 16:22:59 +01001500func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1501 test, ok := c.linker.(testPerSrc)
1502 return ok && test.isAllTestsVariation()
1503}
1504
Chris Parsons216e10a2020-07-09 17:12:52 -04001505func (c *Module) DataPaths() []android.DataPath {
Liz Kammer1c14a212020-05-12 15:26:55 -07001506 if p, ok := c.installer.(interface {
Chris Parsons216e10a2020-07-09 17:12:52 -04001507 dataPaths() []android.DataPath
Liz Kammer1c14a212020-05-12 15:26:55 -07001508 }); ok {
1509 return p.dataPaths()
1510 }
1511 return nil
1512}
1513
Justin Yun5f7f7e82019-11-18 19:52:14 +09001514func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1515 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1516 // "current", it will append the VNDK version to the name suffix.
1517 var vndkVersion string
1518 var nameSuffix string
1519 if c.inProduct() {
1520 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1521 nameSuffix = productSuffix
1522 } else {
1523 vndkVersion = ctx.DeviceConfig().VndkVersion()
1524 nameSuffix = vendorSuffix
1525 }
1526 if vndkVersion == "current" {
1527 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1528 }
1529 if c.Properties.VndkVersion != vndkVersion {
1530 // add version suffix only if the module is using different vndk version than the
1531 // version in product or vendor partition.
1532 nameSuffix += "." + c.Properties.VndkVersion
1533 }
1534 return nameSuffix
1535}
1536
Colin Cross635c3b02016-05-18 15:37:25 -07001537func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001538 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001539 //
1540 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1541 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1542 // module and return early, as this module does not produce an output file per se.
1543 if c.IsTestPerSrcAllTestsVariation() {
1544 c.outputFile = android.OptionalPath{}
1545 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001546 }
1547
Jooyung Han38002912019-05-16 04:01:54 +09001548 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001549
Inseob Kim64c43952019-08-26 16:52:35 +09001550 c.Properties.SubName = ""
1551
1552 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1553 c.Properties.SubName += nativeBridgeSuffix
1554 }
1555
Justin Yun5f7f7e82019-11-18 19:52:14 +09001556 _, llndk := c.linker.(*llndkStubDecorator)
1557 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1558 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1559 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1560 // added for product variant only when we have vendor and product variants with core
1561 // variant. The suffix is not added for vendor-only or product-only module.
1562 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1563 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001564 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1565 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1566 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001567 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1568 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001569 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001570 c.Properties.SubName += recoverySuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001571 } else if c.IsSdkVariant() && (c.Properties.SdkAndPlatformVariantVisibleToMake || c.SplitPerApiLevel()) {
Colin Crossc511bc52020-04-07 16:50:32 +00001572 c.Properties.SubName += sdkSuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001573 if c.SplitPerApiLevel() {
1574 c.Properties.SubName += "." + c.SdkVersion()
1575 }
Inseob Kim64c43952019-08-26 16:52:35 +09001576 }
1577
Colin Crossca860ac2016-01-04 14:34:37 -08001578 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001579 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001580 moduleContextImpl: moduleContextImpl{
1581 mod: c,
1582 },
1583 }
1584 ctx.ctx = ctx
1585
Colin Crossf18e1102017-11-16 14:33:08 -08001586 deps := c.depsToPaths(ctx)
1587 if ctx.Failed() {
1588 return
1589 }
1590
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001591 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1592 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1593 }
1594
Colin Crossca860ac2016-01-04 14:34:37 -08001595 flags := Flags{
1596 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001597 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001598 }
Colin Crossca860ac2016-01-04 14:34:37 -08001599 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001600 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001601 }
1602 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001603 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001604 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001605 if c.stl != nil {
1606 flags = c.stl.flags(ctx, flags)
1607 }
Colin Cross16b23492016-01-06 14:41:07 -08001608 if c.sanitize != nil {
1609 flags = c.sanitize.flags(ctx, flags)
1610 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001611 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001612 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001613 }
Stephen Craneba090d12017-05-09 15:44:35 -07001614 if c.lto != nil {
1615 flags = c.lto.flags(ctx, flags)
1616 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001617 if c.pgo != nil {
1618 flags = c.pgo.flags(ctx, flags)
1619 }
Colin Crossca860ac2016-01-04 14:34:37 -08001620 for _, feature := range c.features {
1621 flags = feature.flags(ctx, flags)
1622 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001623 if ctx.Failed() {
1624 return
1625 }
1626
Colin Cross4af21ed2019-11-04 09:37:55 -08001627 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1628 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1629 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001630
Colin Cross4af21ed2019-11-04 09:37:55 -08001631 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001632
1633 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001634 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001635 }
1636 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001637 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001638 }
1639
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001640 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001641 // We need access to all the flags seen by a source file.
1642 if c.sabi != nil {
1643 flags = c.sabi.flags(ctx, flags)
1644 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001645
Colin Cross4af21ed2019-11-04 09:37:55 -08001646 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001647
Colin Crossca860ac2016-01-04 14:34:37 -08001648 // Optimization to reduce size of build.ninja
1649 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001650 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1651 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1652 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1653 flags.Local.CFlags = []string{"$cflags"}
1654 flags.Local.CppFlags = []string{"$cppflags"}
1655 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001656
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001657 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001658 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001659 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001660 if ctx.Failed() {
1661 return
1662 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001663 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001664 }
1665
Colin Crossca860ac2016-01-04 14:34:37 -08001666 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001667 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001668 if ctx.Failed() {
1669 return
1670 }
Colin Cross635c3b02016-05-18 15:37:25 -07001671 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001672
1673 // If a lib is directly included in any of the APEXes, unhide the stubs
1674 // variant having the latest version gets visible to make. In addition,
1675 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1676 // force anything in the make world to link against the stubs library.
1677 // (unless it is explicitly referenced via .bootstrap suffix or the
1678 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001679 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001680 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001681 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001682 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001683 c.Properties.HideFromMake = false // unhide
1684 // Note: this is still non-installable
1685 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001686
1687 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1688 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1689 if isSnapshotAware(ctx, c) {
1690 i.collectHeadersForSnapshot(ctx)
1691 }
1692 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001693 }
Colin Cross5049f022015-03-18 13:28:46 -07001694
Inseob Kim1f086e22019-05-09 13:29:15 +09001695 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001696 c.installer.install(ctx, c.outputFile.Path())
1697 if ctx.Failed() {
1698 return
Colin Crossca860ac2016-01-04 14:34:37 -08001699 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001700 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1701 // If the module has been specifically configure to not be installed then
1702 // skip the installation as otherwise it will break when running inside make
1703 // as the output path to install will not be specified. Not all uninstallable
1704 // modules can skip installation as some are needed for resolving make side
1705 // dependencies.
1706 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001707 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001708}
1709
Colin Cross0ea8ba82019-06-06 14:33:29 -07001710func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001711 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001712 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001713 }
Colin Crossca860ac2016-01-04 14:34:37 -08001714 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001715}
1716
Colin Crossca860ac2016-01-04 14:34:37 -08001717func (c *Module) begin(ctx BaseModuleContext) {
1718 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001719 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001720 }
Colin Crossca860ac2016-01-04 14:34:37 -08001721 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001722 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001723 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001724 if c.stl != nil {
1725 c.stl.begin(ctx)
1726 }
Colin Cross16b23492016-01-06 14:41:07 -08001727 if c.sanitize != nil {
1728 c.sanitize.begin(ctx)
1729 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001730 if c.coverage != nil {
1731 c.coverage.begin(ctx)
1732 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001733 if c.sabi != nil {
1734 c.sabi.begin(ctx)
1735 }
Justin Yun8effde42017-06-23 19:24:43 +09001736 if c.vndkdep != nil {
1737 c.vndkdep.begin(ctx)
1738 }
Stephen Craneba090d12017-05-09 15:44:35 -07001739 if c.lto != nil {
1740 c.lto.begin(ctx)
1741 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001742 if c.pgo != nil {
1743 c.pgo.begin(ctx)
1744 }
Colin Crossca860ac2016-01-04 14:34:37 -08001745 for _, feature := range c.features {
1746 feature.begin(ctx)
1747 }
Dan Albert92fe7402020-07-15 13:33:30 -07001748 if ctx.useSdk() && c.IsSdkVariant() {
Dan Albert1a246272020-07-06 14:49:35 -07001749 version, err := nativeApiLevelFromUser(ctx, ctx.sdkVersion())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001750 if err != nil {
1751 ctx.PropertyErrorf("sdk_version", err.Error())
Dan Albert1a246272020-07-06 14:49:35 -07001752 c.Properties.Sdk_version = nil
1753 } else {
1754 c.Properties.Sdk_version = StringPtr(version.String())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001755 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001756 }
Colin Crossca860ac2016-01-04 14:34:37 -08001757}
1758
Colin Cross37047f12016-12-13 17:06:13 -08001759func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001760 deps := Deps{}
1761
1762 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001763 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001764 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001765 // Add the PGO dependency (the clang_rt.profile runtime library), which
1766 // sometimes depends on symbols from libgcc, before libgcc gets added
1767 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001768 if c.pgo != nil {
1769 deps = c.pgo.deps(ctx, deps)
1770 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001771 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001772 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001773 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001774 if c.stl != nil {
1775 deps = c.stl.deps(ctx, deps)
1776 }
Colin Cross16b23492016-01-06 14:41:07 -08001777 if c.sanitize != nil {
1778 deps = c.sanitize.deps(ctx, deps)
1779 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001780 if c.coverage != nil {
1781 deps = c.coverage.deps(ctx, deps)
1782 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001783 if c.sabi != nil {
1784 deps = c.sabi.deps(ctx, deps)
1785 }
Justin Yun8effde42017-06-23 19:24:43 +09001786 if c.vndkdep != nil {
1787 deps = c.vndkdep.deps(ctx, deps)
1788 }
Stephen Craneba090d12017-05-09 15:44:35 -07001789 if c.lto != nil {
1790 deps = c.lto.deps(ctx, deps)
1791 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001792 for _, feature := range c.features {
1793 deps = feature.deps(ctx, deps)
1794 }
1795
Colin Crossb6715442017-10-24 11:13:31 -07001796 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1797 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1798 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1799 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1800 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1801 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001802 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001803
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001804 for _, lib := range deps.ReexportSharedLibHeaders {
1805 if !inList(lib, deps.SharedLibs) {
1806 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1807 }
1808 }
1809
1810 for _, lib := range deps.ReexportStaticLibHeaders {
1811 if !inList(lib, deps.StaticLibs) {
1812 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1813 }
1814 }
1815
Colin Cross5950f382016-12-13 12:50:57 -08001816 for _, lib := range deps.ReexportHeaderLibHeaders {
1817 if !inList(lib, deps.HeaderLibs) {
1818 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1819 }
1820 }
1821
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001822 for _, gen := range deps.ReexportGeneratedHeaders {
1823 if !inList(gen, deps.GeneratedHeaders) {
1824 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1825 }
1826 }
1827
Colin Crossc99deeb2016-04-11 15:06:20 -07001828 return deps
1829}
1830
Dan Albert7e9d2952016-08-04 13:02:36 -07001831func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001832 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001833 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001834 moduleContextImpl: moduleContextImpl{
1835 mod: c,
1836 },
1837 }
1838 ctx.ctx = ctx
1839
Colin Crossca860ac2016-01-04 14:34:37 -08001840 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001841}
1842
Jiyong Park7ed9de32018-10-15 22:25:07 +09001843// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001844func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001845 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1846 version := name[sharp+1:]
1847 libname := name[:sharp]
1848 return libname, version
1849 }
1850 return name, ""
1851}
1852
Dan Albert92fe7402020-07-15 13:33:30 -07001853func GetCrtVariations(ctx android.BottomUpMutatorContext,
1854 m LinkableInterface) []blueprint.Variation {
1855 if ctx.Os() != android.Android {
1856 return nil
1857 }
1858 if m.UseSdk() {
1859 return []blueprint.Variation{
1860 {Mutator: "sdk", Variation: "sdk"},
1861 {Mutator: "ndk_api", Variation: m.SdkVersion()},
1862 }
1863 }
1864 return []blueprint.Variation{
1865 {Mutator: "sdk", Variation: ""},
1866 }
1867}
1868
Colin Crosse7257d22020-09-24 09:56:18 -07001869func (c *Module) addSharedLibDependenciesWithVersions(ctx android.BottomUpMutatorContext,
1870 variations []blueprint.Variation, depTag libraryDependencyTag, name, version string, far bool) {
1871
1872 variations = append([]blueprint.Variation(nil), variations...)
1873
1874 if version != "" && VersionVariantAvailable(c) {
1875 // Version is explicitly specified. i.e. libFoo#30
1876 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1877 depTag.explicitlyVersioned = true
1878 }
1879 var deps []blueprint.Module
1880 if far {
1881 deps = ctx.AddFarVariationDependencies(variations, depTag, name)
1882 } else {
1883 deps = ctx.AddVariationDependencies(variations, depTag, name)
1884 }
1885
1886 // If the version is not specified, add dependency to all stubs libraries.
1887 // The stubs library will be used when the depending module is built for APEX and
1888 // the dependent module is not in the same APEX.
1889 if version == "" && VersionVariantAvailable(c) {
1890 if dep, ok := deps[0].(*Module); ok {
1891 for _, ver := range dep.AllStubsVersions() {
1892 // Note that depTag.ExplicitlyVersioned is false in this case.
1893 versionVariations := append(variations,
1894 blueprint.Variation{Mutator: "version", Variation: ver})
1895 if far {
1896 ctx.AddFarVariationDependencies(versionVariations, depTag, name)
1897 } else {
1898 ctx.AddVariationDependencies(versionVariations, depTag, name)
1899 }
1900 }
1901 }
1902 }
1903}
1904
Colin Cross1e676be2016-10-12 14:38:15 -07001905func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001906 if !c.Enabled() {
1907 return
1908 }
1909
Colin Cross37047f12016-12-13 17:06:13 -08001910 ctx := &depsContext{
1911 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001912 moduleContextImpl: moduleContextImpl{
1913 mod: c,
1914 },
1915 }
1916 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001917
Colin Crossc99deeb2016-04-11 15:06:20 -07001918 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001919
Yo Chiang219968c2020-09-22 18:45:04 +08001920 c.Properties.AndroidMkSystemSharedLibs = deps.SystemSharedLibs
1921
Dan Albert914449f2016-06-17 16:45:24 -07001922 variantNdkLibs := []string{}
1923 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001924 if ctx.Os() == android.Android {
Inseob Kimeec88e12020-01-22 11:11:29 +09001925 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001926 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001927 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001928 // 1. Name of an NDK library that refers to a prebuilt module.
1929 // For each of these, it adds the name of the prebuilt module (which will be in
1930 // prebuilts/ndk) to the list of nonvariant libs.
1931 // 2. Name of an NDK library that refers to an ndk_library module.
1932 // For each of these, it adds the name of the ndk_library module to the list of
1933 // variant libs.
1934 // 3. Anything else (so anything that isn't an NDK library).
1935 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001936 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001937 // The caller can then know to add the variantLibs dependencies differently from the
1938 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001939
Inseob Kim9516ee92019-05-09 10:56:13 +09001940 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001941 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1942
1943 rewriteVendorLibs := func(lib string) string {
1944 if isLlndkLibrary(lib, ctx.Config()) {
1945 return lib + llndkLibrarySuffix
1946 }
1947
1948 // only modules with BOARD_VNDK_VERSION uses snapshot.
1949 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1950 return lib
1951 }
1952
1953 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1954 return snapshot
1955 }
1956
1957 return lib
1958 }
1959
1960 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001961 variantLibs = []string{}
1962 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001963 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001964 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001965 name, _ := StubsLibNameAndVersion(entry)
Dan Albertde5aade2020-06-30 12:32:51 -07001966 if ctx.useSdk() && inList(name, ndkKnownLibs) {
1967 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +09001968 } else if ctx.useVndk() {
1969 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001970 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001971 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001972 if actx.OtherModuleExists(vendorPublicLib) {
1973 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1974 } else {
1975 // This can happen if vendor_public_library module is defined in a
1976 // namespace that isn't visible to the current module. In that case,
1977 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001978 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001979 }
Dan Albert914449f2016-06-17 16:45:24 -07001980 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001981 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001982 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001983 }
1984 }
Dan Albert914449f2016-06-17 16:45:24 -07001985 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001986 }
1987
Inseob Kimeec88e12020-01-22 11:11:29 +09001988 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1989 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1990 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1991 if ctx.useVndk() {
1992 for idx, lib := range deps.RuntimeLibs {
1993 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1994 }
1995 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001996 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001997
Jiyong Park7e636d02019-01-28 16:16:54 +09001998 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001999 if c.linker != nil {
2000 if library, ok := c.linker.(*libraryDecorator); ok {
2001 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09002002 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09002003 }
2004 }
Colin Crossd48fe732020-09-23 20:37:24 -07002005 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
2006 if library.buildStubs() {
2007 buildStubs = true
2008 }
2009 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002010 }
2011
Inseob Kimeec88e12020-01-22 11:11:29 +09002012 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
2013 // only modules with BOARD_VNDK_VERSION uses snapshot.
2014 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
2015 return lib
2016 }
2017
2018 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
2019 return snapshot
2020 }
2021
2022 return lib
2023 }
2024
2025 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08002026 for _, lib := range deps.HeaderLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002027 depTag := libraryDependencyTag{Kind: headerLibraryDependency}
Colin Cross32ec36c2016-12-15 07:39:51 -08002028 if inList(lib, deps.ReexportHeaderLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002029 depTag.reexportFlags = true
Colin Cross32ec36c2016-12-15 07:39:51 -08002030 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002031
2032 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
2033
Jiyong Park7e636d02019-01-28 16:16:54 +09002034 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08002035 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07002036 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09002037 } else {
2038 actx.AddVariationDependencies(nil, depTag, lib)
2039 }
2040 }
2041
2042 if buildStubs {
2043 // Stubs lib does not have dependency to other static/shared libraries.
2044 // Don't proceed.
2045 return
Colin Cross32ec36c2016-12-15 07:39:51 -08002046 }
Colin Cross5950f382016-12-13 12:50:57 -08002047
Inseob Kimc0907f12019-02-08 21:00:45 +09002048 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09002049 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09002050
Jiyong Park5d1598f2019-02-25 22:14:17 +09002051 for _, lib := range deps.WholeStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002052 depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
Jiyong Park5d1598f2019-02-25 22:14:17 +09002053 if impl, ok := syspropImplLibraries[lib]; ok {
2054 lib = impl
2055 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002056
2057 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
2058
Jiyong Park5d1598f2019-02-25 22:14:17 +09002059 actx.AddVariationDependencies([]blueprint.Variation{
2060 {Mutator: "link", Variation: "static"},
2061 }, depTag, lib)
2062 }
2063
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002064 for _, lib := range deps.StaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002065 depTag := libraryDependencyTag{Kind: staticLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002066 if inList(lib, deps.ReexportStaticLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002067 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002068 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002069
2070 if impl, ok := syspropImplLibraries[lib]; ok {
2071 lib = impl
2072 }
2073
Inseob Kimeec88e12020-01-22 11:11:29 +09002074 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
2075
Dan Willemsen59339a22018-07-22 21:18:45 -07002076 actx.AddVariationDependencies([]blueprint.Variation{
2077 {Mutator: "link", Variation: "static"},
2078 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002079 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002080
Jooyung Han75568392020-03-20 04:29:24 +09002081 // staticUnwinderDep is treated as staticDep for Q apexes
2082 // so that native libraries/binaries are linked with static unwinder
2083 // because Q libc doesn't have unwinder APIs
2084 if deps.StaticUnwinderIfLegacy {
Colin Cross6e511a92020-07-27 21:26:48 -07002085 depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002086 actx.AddVariationDependencies([]blueprint.Variation{
2087 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07002088 }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002089 }
2090
Inseob Kimeec88e12020-01-22 11:11:29 +09002091 for _, lib := range deps.LateStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002092 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
Inseob Kimeec88e12020-01-22 11:11:29 +09002093 actx.AddVariationDependencies([]blueprint.Variation{
2094 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07002095 }, depTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
Inseob Kimeec88e12020-01-22 11:11:29 +09002096 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002097
Jiyong Park7ed9de32018-10-15 22:25:07 +09002098 // shared lib names without the #version suffix
2099 var sharedLibNames []string
2100
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002101 for _, lib := range deps.SharedLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002102 depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002103 if inList(lib, deps.ReexportSharedLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002104 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002105 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002106
2107 if impl, ok := syspropImplLibraries[lib]; ok {
2108 lib = impl
2109 }
2110
Jiyong Park73c54ee2019-10-22 20:31:18 +09002111 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09002112 sharedLibNames = append(sharedLibNames, name)
2113
Colin Crosse7257d22020-09-24 09:56:18 -07002114 variations := []blueprint.Variation{
2115 {Mutator: "link", Variation: "shared"},
2116 }
2117 c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, name, version, false)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002118 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002119
Jiyong Park7ed9de32018-10-15 22:25:07 +09002120 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002121 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09002122 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
2123 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
2124 // linking against both the stubs lib and the non-stubs lib at the same time.
2125 continue
2126 }
Colin Cross6e511a92020-07-27 21:26:48 -07002127 depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
Colin Crosse7257d22020-09-24 09:56:18 -07002128 variations := []blueprint.Variation{
2129 {Mutator: "link", Variation: "shared"},
2130 }
2131 c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, lib, "", false)
Jiyong Park7ed9de32018-10-15 22:25:07 +09002132 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002133
Dan Willemsen59339a22018-07-22 21:18:45 -07002134 actx.AddVariationDependencies([]blueprint.Variation{
2135 {Mutator: "link", Variation: "shared"},
Chris Parsons79d66a52020-06-05 17:26:16 -04002136 }, dataLibDepTag, deps.DataLibs...)
2137
2138 actx.AddVariationDependencies([]blueprint.Variation{
2139 {Mutator: "link", Variation: "shared"},
Dan Willemsen59339a22018-07-22 21:18:45 -07002140 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08002141
Colin Cross68861832016-07-08 10:41:41 -07002142 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002143
2144 for _, gen := range deps.GeneratedHeaders {
2145 depTag := genHeaderDepTag
2146 if inList(gen, deps.ReexportGeneratedHeaders) {
2147 depTag = genHeaderExportDepTag
2148 }
2149 actx.AddDependency(c, depTag, gen)
2150 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002151
Colin Cross42d48b72018-08-29 14:10:52 -07002152 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07002153
Inseob Kim1042d292020-06-01 23:23:05 +09002154 vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())
2155
Dan Albert92fe7402020-07-15 13:33:30 -07002156 crtVariations := GetCrtVariations(ctx, c)
Colin Crossc99deeb2016-04-11 15:06:20 -07002157 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002158 actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
2159 rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08002160 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002161 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002162 actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
2163 rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07002164 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002165 if deps.LinkerFlagsFile != "" {
2166 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
2167 }
2168 if deps.DynamicLinker != "" {
2169 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002170 }
Dan Albert914449f2016-06-17 16:45:24 -07002171
2172 version := ctx.sdkVersion()
Colin Cross6e511a92020-07-27 21:26:48 -07002173
2174 ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002175 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002176 {Mutator: "ndk_api", Variation: version},
2177 {Mutator: "link", Variation: "shared"},
2178 }, ndkStubDepTag, variantNdkLibs...)
Colin Cross6e511a92020-07-27 21:26:48 -07002179
2180 ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002181 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002182 {Mutator: "ndk_api", Variation: version},
2183 {Mutator: "link", Variation: "shared"},
2184 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002185
2186 if vndkdep := c.vndkdep; vndkdep != nil {
2187 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002188 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002189 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002190 {Mutator: "link", Variation: "shared"},
2191 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002192 }
2193 }
Colin Cross6362e272015-10-29 15:25:03 -07002194}
Colin Cross21b9a242015-03-24 14:15:58 -07002195
Colin Crosse40b4ea2018-10-02 22:25:58 -07002196func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002197 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2198 c.beginMutator(ctx)
2199 }
2200}
2201
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002202// Whether a module can link to another module, taking into
2203// account NDK linking.
Colin Cross6e511a92020-07-27 21:26:48 -07002204func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface,
2205 tag blueprint.DependencyTag) {
2206
2207 switch t := tag.(type) {
2208 case dependencyTag:
2209 if t != vndkExtDepTag {
2210 return
2211 }
2212 case libraryDependencyTag:
2213 default:
2214 return
2215 }
2216
Ivan Lozano52767be2019-10-18 14:49:46 -07002217 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002218 // Host code is not restricted
2219 return
2220 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002221
2222 // VNDK is cc.Module supported only for now.
2223 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002224 // Though vendor code is limited by the vendor mutator,
2225 // each vendor-available module needs to check
2226 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002227 if ccTo, ok := to.(*Module); ok {
2228 if ccFrom.vndkdep != nil {
2229 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2230 }
2231 } else {
2232 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002233 }
2234 return
2235 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002236 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002237 // Platform code can link to anything
2238 return
2239 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002240 if from.InRamdisk() {
2241 // Ramdisk code is not NDK
2242 return
2243 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002244 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002245 // Recovery code is not NDK
2246 return
2247 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002248 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002249 // These are always allowed
2250 return
2251 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002252 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002253 // These are allowed, but they don't set sdk_version
2254 return
2255 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002256 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002257 // These aren't real libraries, but are the stub shared libraries that are included in
2258 // the NDK.
2259 return
2260 }
Logan Chien834b9a62019-01-14 15:39:03 +08002261
Ivan Lozano52767be2019-10-18 14:49:46 -07002262 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002263 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2264 // to link to libc++ (non-NDK and without sdk_version).
2265 return
2266 }
2267
Ivan Lozano52767be2019-10-18 14:49:46 -07002268 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002269 // NDK code linking to platform code is never okay.
2270 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002271 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002272 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002273 }
2274
2275 // At this point we know we have two NDK libraries, but we need to
2276 // check that we're not linking against anything built against a higher
2277 // API level, as it is only valid to link against older or equivalent
2278 // APIs.
2279
Inseob Kim01a28722018-04-11 09:48:45 +09002280 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002281 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002282 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002283 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002284 // Current can't be linked against by anything else.
2285 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002286 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002287 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002288 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002289 if err != nil {
2290 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002291 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002292 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002293 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002294 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002295 if err != nil {
2296 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002297 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002298 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002299 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002300
Inseob Kim01a28722018-04-11 09:48:45 +09002301 if toApi > fromApi {
2302 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002303 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002304 }
2305 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002306 }
Dan Albert202fe492017-12-15 13:56:59 -08002307
2308 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002309 fromStl := from.SelectedStl()
2310 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002311 if fromStl == "" || toStl == "" {
2312 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002313 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002314 // We can be permissive with the system "STL" since it is only the C++
2315 // ABI layer, but in the future we should make sure that everyone is
2316 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002317 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002318 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002319 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2320 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002321 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002322}
2323
Jiyong Park5fb8c102018-04-09 12:03:06 +09002324// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002325// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2326// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002327// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002328func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2329 check := func(child, parent android.Module) bool {
2330 to, ok := child.(*Module)
2331 if !ok {
2332 // follow thru cc.Defaults, etc.
2333 return true
2334 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002335
Jooyung Hana70f0672019-01-18 15:20:43 +09002336 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2337 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002338 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002339
2340 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002341 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002342 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002343 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002344
Jooyung Han0302a842019-10-30 18:43:49 +09002345 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002346 return false
2347 }
2348
2349 var stringPath []string
2350 for _, m := range ctx.GetWalkPath() {
2351 stringPath = append(stringPath, m.Name())
2352 }
2353 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2354 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2355 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2356 return false
2357 }
2358 if module, ok := ctx.Module().(*Module); ok {
2359 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002360 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002361 ctx.WalkDeps(check)
2362 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002363 }
2364 }
2365}
2366
Colin Crossc99deeb2016-04-11 15:06:20 -07002367// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002368func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002369 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002370
Ivan Lozano183a3212019-10-18 14:18:45 -07002371 directStaticDeps := []LinkableInterface{}
2372 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002373
Inseob Kim69378442019-06-03 19:10:47 +09002374 reexportExporter := func(exporter exportedFlagsProducer) {
2375 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2376 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2377 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2378 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002379 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002380 }
2381
Jooyung Hande34d232020-07-23 13:04:15 +09002382 // For the dependency from platform to apex, use the latest stubs
2383 c.apexSdkVersion = android.FutureApiLevel
2384 if !c.IsForPlatform() {
Dan Albertc8060532020-07-22 22:32:17 -07002385 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion(ctx)
Jooyung Hande34d232020-07-23 13:04:15 +09002386 }
2387
2388 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2389 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2390 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2391 // (b/144430859)
2392 c.apexSdkVersion = android.FutureApiLevel
2393 }
2394
Colin Crossd11fcda2017-10-23 17:59:01 -07002395 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002396 depName := ctx.OtherModuleName(dep)
2397 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002398
Ivan Lozano52767be2019-10-18 14:49:46 -07002399 ccDep, ok := dep.(LinkableInterface)
2400 if !ok {
2401
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002402 // handling for a few module types that aren't cc Module but that are also supported
2403 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002404 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002405 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002406 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2407 genRule.GeneratedSourceFiles()...)
2408 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002409 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002410 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002411 // Support exported headers from a generated_sources dependency
2412 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002413 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002414 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09002415 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002416 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002417 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002418 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002419 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002420 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002421 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2422 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002423 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002424 // 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 +09002425 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002426
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002427 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002428 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002429 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002430 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002431 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002432 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002433 files := genRule.GeneratedSourceFiles()
2434 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002435 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002436 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002437 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 -07002438 }
2439 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002440 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002441 }
Colin Crossca860ac2016-01-04 14:34:37 -08002442 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002443 return
2444 }
2445
Colin Crossfe17f6f2019-03-28 19:30:56 -07002446 if depTag == android.ProtoPluginDepTag {
2447 return
2448 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002449 if depTag == llndkImplDep {
2450 return
2451 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002452
Colin Crossd11fcda2017-10-23 17:59:01 -07002453 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002454 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2455 return
2456 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002457 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002458 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2459 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002460 return
2461 }
2462
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002463 // re-exporting flags
2464 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002465 // reusing objects only make sense for cc.Modules.
2466 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002467 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002468 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002469 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002470 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002471 return
2472 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002473 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002474
Jiyong Parke4bb9862019-02-01 00:31:10 +09002475 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002476 // staticVariants are a cc.Module specific concept.
2477 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002478 c.staticVariant = ccDep
2479 return
2480 }
2481 }
2482
Colin Cross6e511a92020-07-27 21:26:48 -07002483 checkLinkType(ctx, c, ccDep, depTag)
2484
2485 linkFile := ccDep.OutputFile()
2486
2487 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
2488 // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
Dan Albertc8060532020-07-22 22:32:17 -07002489 if libDepTag.staticUnwinder && c.apexSdkVersion.GreaterThan(android.SdkVersion_Android10) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002490 return
2491 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002492
Colin Cross6e511a92020-07-27 21:26:48 -07002493 if ccDep.CcLibrary() && !libDepTag.static() {
Ivan Lozano52767be2019-10-18 14:49:46 -07002494 depIsStubs := ccDep.BuildStubs()
Jooyung Han624d35c2020-04-10 12:57:24 +09002495 depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
Colin Crossaede88c2020-08-11 12:17:01 -07002496 depInSameApexes := android.DirectlyInAllApexes(c.InApexes(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002497 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002498
2499 var useThisDep bool
Colin Cross6e511a92020-07-27 21:26:48 -07002500 if depIsStubs && libDepTag.explicitlyVersioned {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002501 // Always respect dependency to the versioned stubs (i.e. libX#10)
2502 useThisDep = true
2503 } else if !depHasStubs {
2504 // Use non-stub variant if that is the only choice
2505 // (i.e. depending on a lib without stubs.version property)
2506 useThisDep = true
2507 } else if c.IsForPlatform() {
2508 // If not building for APEX, use stubs only when it is from
2509 // an APEX (and not from platform)
2510 useThisDep = (depInPlatform != depIsStubs)
Jooyung Han624d35c2020-04-10 12:57:24 +09002511 if c.bootstrap() {
2512 // However, for host, ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002513 // always link to non-stub variant
2514 useThisDep = !depIsStubs
2515 }
Jiyong Park62304bb2020-04-13 16:19:48 +09002516 for _, testFor := range c.TestFor() {
2517 // Another exception: if this module is bundled with an APEX, then
2518 // it is linked with the non-stub variant of a module in the APEX
2519 // as if this is part of the APEX.
2520 if android.DirectlyInApex(testFor, depName) {
2521 useThisDep = !depIsStubs
2522 break
2523 }
2524 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002525 } else {
Colin Crossaede88c2020-08-11 12:17:01 -07002526 // If building for APEX, use stubs when the parent is in any APEX that
2527 // the child is not in.
2528 useThisDep = (depInSameApexes != depIsStubs)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002529 }
2530
Jooyung Han03b51852020-02-26 22:45:42 +09002531 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
Colin Cross6e511a92020-07-27 21:26:48 -07002532 if useThisDep && depIsStubs && !libDepTag.explicitlyVersioned {
Colin Cross7812fd32020-09-25 12:35:10 -07002533 versionToUse, err := c.ChooseSdkVersion(ctx, ccDep.StubsVersions(), c.apexSdkVersion)
Jooyung Han03b51852020-02-26 22:45:42 +09002534 if err != nil {
2535 ctx.OtherModuleErrorf(dep, err.Error())
2536 return
2537 }
2538 if versionToUse != ccDep.StubsVersion() {
2539 useThisDep = false
2540 }
2541 }
2542
Jiyong Park25fc6a92018-11-18 18:02:45 +09002543 if !useThisDep {
2544 return // stop processing this dep
2545 }
2546 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002547 if c.UseVndk() {
2548 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2549 // by default, use current version of LLNDK
2550 versionToUse := ""
Colin Crossd1f898e2020-08-18 18:35:15 -07002551 versions := m.AllStubsVersions()
Colin Crosse07f2312020-08-13 11:24:56 -07002552 if c.ApexVariationName() != "" && len(versions) > 0 {
Jooyung Han61b66e92020-03-21 14:21:46 +00002553 // if this is for use_vendor apex && dep has stubsVersions
2554 // apply the same rule of apex sdk enforcement to choose right version
2555 var err error
Colin Cross7812fd32020-09-25 12:35:10 -07002556 versionToUse, err = c.ChooseSdkVersion(ctx, versions, c.apexSdkVersion)
Jooyung Han61b66e92020-03-21 14:21:46 +00002557 if err != nil {
2558 ctx.OtherModuleErrorf(dep, err.Error())
2559 return
2560 }
2561 }
2562 if versionToUse != ccDep.StubsVersion() {
2563 return
2564 }
2565 }
2566 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002567
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002568 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2569
Ivan Lozano52767be2019-10-18 14:49:46 -07002570 // Exporting flags only makes sense for cc.Modules
2571 if _, ok := ccDep.(*Module); ok {
2572 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002573 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002574 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002575 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002576
Colin Cross6e511a92020-07-27 21:26:48 -07002577 if libDepTag.reexportFlags {
Ivan Lozano52767be2019-10-18 14:49:46 -07002578 reexportExporter(i)
2579 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2580 // Re-exported shared library headers must be included as well since they can help us with type information
2581 // about template instantiations (instantiated from their headers).
2582 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2583 // scripts.
2584 c.sabi.Properties.ReexportedIncludes = append(
2585 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2586 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002587 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002588 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002589
Colin Cross6e511a92020-07-27 21:26:48 -07002590 var ptr *android.Paths
2591 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002592
Colin Cross6e511a92020-07-27 21:26:48 -07002593 depFile := android.OptionalPath{}
Colin Cross26c34ed2016-09-30 17:10:16 -07002594
Colin Cross6e511a92020-07-27 21:26:48 -07002595 switch {
2596 case libDepTag.header():
2597 // nothing
2598 case libDepTag.shared():
2599 ptr = &depPaths.SharedLibs
2600 switch libDepTag.Order {
2601 case earlyLibraryDependency:
2602 ptr = &depPaths.EarlySharedLibs
2603 depPtr = &depPaths.EarlySharedLibsDeps
2604 case normalLibraryDependency:
2605 ptr = &depPaths.SharedLibs
2606 depPtr = &depPaths.SharedLibsDeps
2607 directSharedDeps = append(directSharedDeps, ccDep)
2608 case lateLibraryDependency:
2609 ptr = &depPaths.LateSharedLibs
2610 depPtr = &depPaths.LateSharedLibsDeps
2611 default:
2612 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Colin Crossc99deeb2016-04-11 15:06:20 -07002613 }
Colin Cross6e511a92020-07-27 21:26:48 -07002614 depFile = ccDep.Toc()
2615 case libDepTag.static():
2616 if libDepTag.wholeStatic {
2617 ptr = &depPaths.WholeStaticLibs
2618 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2619 ctx.ModuleErrorf("module %q not a static library", depName)
2620 return
Inseob Kim752edec2020-03-14 01:30:34 +09002621 }
2622
Colin Cross6e511a92020-07-27 21:26:48 -07002623 // Because the static library objects are included, this only makes sense
2624 // in the context of proper cc.Modules.
2625 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2626 staticLib := ccWholeStaticLib.linker.(libraryInterface)
Colin Crosse4f6eba2020-09-22 18:11:25 -07002627 if objs := staticLib.objs(); len(objs.objFiles) > 0 {
2628 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(objs)
Colin Cross6e511a92020-07-27 21:26:48 -07002629 } else {
Colin Crosse4f6eba2020-09-22 18:11:25 -07002630 // This case normally catches prebuilt static
2631 // libraries, but it can also occur when
2632 // AllowMissingDependencies is on and the
2633 // dependencies has no sources of its own
2634 // but has a whole_static_libs dependency
2635 // on a missing library. We want to depend
2636 // on the .a file so that there is something
2637 // in the dependency tree that contains the
2638 // error rule for the missing transitive
2639 // dependency.
2640 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
Colin Cross6e511a92020-07-27 21:26:48 -07002641 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002642 } else {
Colin Cross6e511a92020-07-27 21:26:48 -07002643 ctx.ModuleErrorf(
2644 "non-cc.Modules cannot be included as whole static libraries.", depName)
2645 return
2646 }
2647
2648 } else {
2649 switch libDepTag.Order {
2650 case earlyLibraryDependency:
2651 panic(fmt.Errorf("early static libs not suppported"))
2652 case normalLibraryDependency:
2653 // static dependencies will be handled separately so they can be ordered
2654 // using transitive dependencies.
2655 ptr = nil
2656 directStaticDeps = append(directStaticDeps, ccDep)
2657 case lateLibraryDependency:
2658 ptr = &depPaths.LateStaticLibs
2659 default:
2660 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Inseob Kimeec88e12020-01-22 11:11:29 +09002661 }
2662 }
2663 }
2664
Colin Cross6e511a92020-07-27 21:26:48 -07002665 if libDepTag.static() && !libDepTag.wholeStatic {
2666 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2667 ctx.ModuleErrorf("module %q not a static library", depName)
2668 return
2669 }
Logan Chien43d34c32017-12-20 01:17:32 +08002670
Colin Cross6e511a92020-07-27 21:26:48 -07002671 // When combining coverage files for shared libraries and executables, coverage files
2672 // in static libraries act as if they were whole static libraries. The same goes for
2673 // source based Abi dump files.
2674 if c, ok := ccDep.(*Module); ok {
2675 staticLib := c.linker.(libraryInterface)
2676 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2677 staticLib.objs().coverageFiles...)
2678 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2679 staticLib.objs().sAbiDumpFiles...)
2680 } else if c, ok := ccDep.(LinkableInterface); ok {
2681 // Handle non-CC modules here
2682 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2683 c.CoverageFiles()...)
Jiyong Parkde866cb2018-12-07 23:08:36 +09002684 }
2685 }
2686
Colin Cross6e511a92020-07-27 21:26:48 -07002687 if ptr != nil {
2688 if !linkFile.Valid() {
2689 if !ctx.Config().AllowMissingDependencies() {
2690 ctx.ModuleErrorf("module %q missing output file", depName)
2691 } else {
2692 ctx.AddMissingDependencies([]string{depName})
2693 }
2694 return
2695 }
2696 *ptr = append(*ptr, linkFile.Path())
2697 }
2698
2699 if depPtr != nil {
2700 dep := depFile
2701 if !dep.Valid() {
2702 dep = linkFile
2703 }
2704 *depPtr = append(*depPtr, dep.Path())
2705 }
2706
2707 makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix
2708 switch {
2709 case libDepTag.header():
Colin Cross370173e2020-07-29 12:48:33 -07002710 c.Properties.AndroidMkHeaderLibs = append(
2711 c.Properties.AndroidMkHeaderLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002712 case libDepTag.shared():
2713 if ccDep.CcLibrary() {
2714 if ccDep.BuildStubs() && android.InAnyApex(depName) {
2715 // Add the dependency to the APEX(es) providing the library so that
2716 // m <module> can trigger building the APEXes as well.
2717 for _, an := range android.GetApexesForModule(depName) {
2718 c.Properties.ApexesProvidingSharedLibs = append(
2719 c.Properties.ApexesProvidingSharedLibs, an)
2720 }
2721 }
2722 }
2723
2724 // Note: the order of libs in this list is not important because
2725 // they merely serve as Make dependencies and do not affect this lib itself.
Colin Cross370173e2020-07-29 12:48:33 -07002726 c.Properties.AndroidMkSharedLibs = append(
2727 c.Properties.AndroidMkSharedLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002728 // Record baseLibName for snapshots.
2729 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
2730 case libDepTag.static():
2731 if libDepTag.wholeStatic {
2732 c.Properties.AndroidMkWholeStaticLibs = append(
2733 c.Properties.AndroidMkWholeStaticLibs, makeLibName)
2734 } else {
2735 c.Properties.AndroidMkStaticLibs = append(
2736 c.Properties.AndroidMkStaticLibs, makeLibName)
2737 }
2738 }
2739 } else {
2740 switch depTag {
2741 case runtimeDepTag:
2742 c.Properties.AndroidMkRuntimeLibs = append(
2743 c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix)
2744 // Record baseLibName for snapshots.
2745 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
2746 case objDepTag:
2747 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
2748 case CrtBeginDepTag:
2749 depPaths.CrtBegin = linkFile
2750 case CrtEndDepTag:
2751 depPaths.CrtEnd = linkFile
2752 case dynamicLinkerDepTag:
2753 depPaths.DynamicLinker = linkFile
2754 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002755 }
Colin Crossca860ac2016-01-04 14:34:37 -08002756 })
2757
Jeff Gaston294356f2017-09-27 17:05:30 -07002758 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002759 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002760
Colin Crossdd84e052017-05-17 13:44:16 -07002761 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002762 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002763 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2764 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09002765 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002766 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2767 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002768 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002769 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002770 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002771
2772 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002773 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002774 }
Colin Crossdd84e052017-05-17 13:44:16 -07002775
Colin Crossca860ac2016-01-04 14:34:37 -08002776 return depPaths
2777}
2778
Colin Cross6e511a92020-07-27 21:26:48 -07002779// baseLibName trims known prefixes and suffixes
2780func baseLibName(depName string) string {
2781 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
2782 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
2783 libName = strings.TrimPrefix(libName, "prebuilt_")
2784 return libName
2785}
2786
2787func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
2788 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2789 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2790
2791 libName := baseLibName(depName)
2792 isLLndk := isLlndkLibrary(libName, ctx.Config())
2793 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
2794 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
2795
2796 if c, ok := ccDep.(*Module); ok {
2797 // Use base module name for snapshots when exporting to Makefile.
2798 if c.isSnapshotPrebuilt() {
2799 baseName := c.BaseModuleName()
2800
2801 if c.IsVndk() {
2802 return baseName + ".vendor"
2803 }
2804
2805 if vendorSuffixModules[baseName] {
2806 return baseName + ".vendor"
2807 } else {
2808 return baseName
2809 }
2810 }
2811 }
2812
2813 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
2814 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2815 // core module instead.
2816 return libName
2817 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
2818 // The vendor module in Make will have been renamed to not conflict with the core
2819 // module, so update the dependency name here accordingly.
2820 return libName + c.getNameSuffixWithVndkVersion(ctx)
2821 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
2822 return libName + vendorPublicLibrarySuffix
2823 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2824 return libName + ramdiskSuffix
2825 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
2826 return libName + recoverySuffix
2827 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
2828 return libName + nativeBridgeSuffix
2829 } else {
2830 return libName
2831 }
2832}
2833
Colin Crossca860ac2016-01-04 14:34:37 -08002834func (c *Module) InstallInData() bool {
2835 if c.installer == nil {
2836 return false
2837 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002838 return c.installer.inData()
2839}
2840
2841func (c *Module) InstallInSanitizerDir() bool {
2842 if c.installer == nil {
2843 return false
2844 }
2845 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002846 return true
2847 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002848 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002849}
2850
Yifan Hong1b3348d2020-01-21 15:53:22 -08002851func (c *Module) InstallInRamdisk() bool {
2852 return c.InRamdisk()
2853}
2854
Jiyong Parkf9332f12018-02-01 00:54:12 +09002855func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002856 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002857}
2858
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002859func (c *Module) MakeUninstallable() {
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002860 if c.installer == nil {
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002861 c.ModuleBase.MakeUninstallable()
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002862 return
2863 }
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002864 c.installer.makeUninstallable(c)
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002865}
2866
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002867func (c *Module) HostToolPath() android.OptionalPath {
2868 if c.installer == nil {
2869 return android.OptionalPath{}
2870 }
2871 return c.installer.hostToolPath()
2872}
2873
Nan Zhangd4e641b2017-07-12 12:55:28 -07002874func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2875 return c.outputFile
2876}
2877
Colin Cross41955e82019-05-29 14:40:35 -07002878func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2879 switch tag {
2880 case "":
2881 if c.outputFile.Valid() {
2882 return android.Paths{c.outputFile.Path()}, nil
2883 }
2884 return android.Paths{}, nil
2885 default:
2886 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002887 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002888}
2889
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002890func (c *Module) static() bool {
2891 if static, ok := c.linker.(interface {
2892 static() bool
2893 }); ok {
2894 return static.static()
2895 }
2896 return false
2897}
2898
Jiyong Park379de2f2018-12-19 02:47:14 +09002899func (c *Module) staticBinary() bool {
2900 if static, ok := c.linker.(interface {
2901 staticBinary() bool
2902 }); ok {
2903 return static.staticBinary()
2904 }
2905 return false
2906}
2907
Jiyong Park1d1119f2019-07-29 21:27:18 +09002908func (c *Module) header() bool {
2909 if h, ok := c.linker.(interface {
2910 header() bool
2911 }); ok {
2912 return h.header()
2913 }
2914 return false
2915}
2916
Inseob Kim7f283f42020-06-01 21:53:49 +09002917func (c *Module) binary() bool {
2918 if b, ok := c.linker.(interface {
2919 binary() bool
2920 }); ok {
2921 return b.binary()
2922 }
2923 return false
2924}
2925
Inseob Kim1042d292020-06-01 23:23:05 +09002926func (c *Module) object() bool {
2927 if o, ok := c.linker.(interface {
2928 object() bool
2929 }); ok {
2930 return o.object()
2931 }
2932 return false
2933}
2934
Jooyung Han38002912019-05-16 04:01:54 +09002935func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002936 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002937 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2938 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002939 return "native:vndk"
2940 }
Jooyung Han38002912019-05-16 04:01:54 +09002941 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002942 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002943 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002944 if Bool(c.VendorProperties.Vendor_available) {
2945 return "native:vndk"
2946 }
2947 return "native:vndk_private"
2948 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002949 if c.inProduct() {
2950 return "native:product"
2951 }
Jooyung Han38002912019-05-16 04:01:54 +09002952 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002953 } else if c.InRamdisk() {
2954 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002955 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002956 return "native:recovery"
2957 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2958 return "native:ndk:none:none"
2959 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2960 //family, link := getNdkStlFamilyAndLinkType(c)
2961 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002962 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002963 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002964 } else {
2965 return "native:platform"
2966 }
2967}
2968
Jiyong Park9d452992018-10-03 00:38:19 +09002969// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002970// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002971func (c *Module) IsInstallableToApex() bool {
2972 if shared, ok := c.linker.(interface {
2973 shared() bool
2974 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002975 // Stub libs and prebuilt libs in a versioned SDK are not
2976 // installable to APEX even though they are shared libs.
2977 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002978 } else if _, ok := c.linker.(testPerSrc); ok {
2979 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002980 }
2981 return false
2982}
2983
Jiyong Parka90ca002019-10-07 15:47:24 +09002984func (c *Module) AvailableFor(what string) bool {
2985 if linker, ok := c.linker.(interface {
2986 availableFor(string) bool
2987 }); ok {
2988 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2989 } else {
2990 return c.ApexModuleBase.AvailableFor(what)
2991 }
2992}
2993
Jiyong Park62304bb2020-04-13 16:19:48 +09002994func (c *Module) TestFor() []string {
2995 if test, ok := c.linker.(interface {
2996 testFor() []string
2997 }); ok {
2998 return test.testFor()
2999 } else {
3000 return c.ApexModuleBase.TestFor()
3001 }
3002}
3003
Colin Crossaede88c2020-08-11 12:17:01 -07003004func (c *Module) UniqueApexVariations() bool {
3005 if u, ok := c.compiler.(interface {
3006 uniqueApexVariations() bool
3007 }); ok {
3008 return u.uniqueApexVariations()
3009 } else {
3010 return false
3011 }
3012}
3013
Paul Duffin0cb37b92020-03-04 14:52:46 +00003014// Return true if the module is ever installable.
3015func (c *Module) EverInstallable() bool {
3016 return c.installer != nil &&
3017 // Check to see whether the module is actually ever installable.
3018 c.installer.everInstallable()
3019}
3020
Inseob Kim1f086e22019-05-09 13:29:15 +09003021func (c *Module) installable() bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00003022 ret := c.EverInstallable() &&
3023 // Check to see whether the module has been configured to not be installed.
3024 proptools.BoolDefault(c.Properties.Installable, true) &&
3025 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09003026
3027 // The platform variant doesn't need further condition. Apex variants however might not
3028 // be installable because it will likely to be included in the APEX and won't appear
3029 // in the system partition.
3030 if c.IsForPlatform() {
3031 return ret
3032 }
3033
3034 // Special case for modules that are configured to be installed to /data, which includes
3035 // test modules. For these modules, both APEX and non-APEX variants are considered as
3036 // installable. This is because even the APEX variants won't be included in the APEX, but
3037 // will anyway be installed to /data/*.
3038 // See b/146995717
3039 if c.InstallInData() {
3040 return ret
3041 }
3042
3043 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09003044}
3045
Logan Chien41eabe62019-04-10 13:33:58 +08003046func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
3047 if c.linker != nil {
3048 if library, ok := c.linker.(*libraryDecorator); ok {
3049 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
3050 }
3051 }
3052}
3053
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003054func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Colin Cross6e511a92020-07-27 21:26:48 -07003055 depTag := ctx.OtherModuleDependencyTag(dep)
3056 libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
3057
3058 if cc, ok := dep.(*Module); ok {
3059 if cc.HasStubsVariants() {
3060 if isLibDepTag && libDepTag.shared() {
3061 // dynamic dep to a stubs lib crosses APEX boundary
3062 return false
Jiyong Parkd7536ba2020-01-16 17:14:23 +09003063 }
Colin Cross6e511a92020-07-27 21:26:48 -07003064 if IsRuntimeDepTag(depTag) {
3065 // runtime dep to a stubs lib also crosses APEX boundary
Jiyong Parkd7536ba2020-01-16 17:14:23 +09003066 return false
3067 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003068 }
Colin Crossaac32222020-07-29 12:51:56 -07003069 if isLibDepTag && c.static() && libDepTag.shared() {
Colin Cross6e511a92020-07-27 21:26:48 -07003070 // shared_lib dependency from a static lib is considered as crossing
3071 // the APEX boundary because the dependency doesn't actually is
3072 // linked; the dependency is used only during the compilation phase.
3073 return false
3074 }
3075 }
3076 if depTag == llndkImplDep {
Jiyong Park7d95a512020-05-10 15:16:24 +09003077 // We don't track beyond LLNDK
3078 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003079 }
3080 return true
3081}
3082
Dan Albertc8060532020-07-22 22:32:17 -07003083func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
3084 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +09003085 // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
3086 if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
3087 return nil
3088 }
3089 // b/154569636: set min_sdk_version correctly for toolchain_libraries
3090 if c.ToolchainLibrary() {
3091 return nil
3092 }
3093 // We don't check for prebuilt modules
3094 if _, ok := c.linker.(prebuiltLinkerInterface); ok {
3095 return nil
3096 }
3097 minSdkVersion := c.MinSdkVersion()
3098 if minSdkVersion == "apex_inherit" {
3099 return nil
3100 }
3101 if minSdkVersion == "" {
3102 // JNI libs within APK-in-APEX fall into here
3103 // Those are okay to set sdk_version instead
3104 // We don't have to check if this is a SDK variant because
3105 // non-SDK variant resets sdk_version, which works too.
3106 minSdkVersion = c.SdkVersion()
3107 }
Dan Albertc8060532020-07-22 22:32:17 -07003108 if minSdkVersion == "" {
3109 return fmt.Errorf("neither min_sdk_version nor sdk_version specificed")
3110 }
3111 // Not using nativeApiLevelFromUser because the context here is not
3112 // necessarily a native context.
3113 ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
Jooyung Han749dc692020-04-15 11:03:39 +09003114 if err != nil {
3115 return err
3116 }
Dan Albertc8060532020-07-22 22:32:17 -07003117
3118 if ver.GreaterThan(sdkVersion) {
Jooyung Han749dc692020-04-15 11:03:39 +09003119 return fmt.Errorf("newer SDK(%v)", ver)
3120 }
3121 return nil
3122}
3123
Colin Cross2ba19d92015-05-07 15:44:20 -07003124//
Colin Crosscfad1192015-11-02 16:43:11 -08003125// Defaults
3126//
Colin Crossca860ac2016-01-04 14:34:37 -08003127type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07003128 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07003129 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09003130 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08003131}
3132
Patrice Arrudac249c712019-03-19 17:00:29 -07003133// cc_defaults provides a set of properties that can be inherited by other cc
3134// modules. A module can use the properties from a cc_defaults using
3135// `defaults: ["<:default_module_name>"]`. Properties of both modules are
3136// merged (when possible) by prepending the default module's values to the
3137// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07003138func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07003139 return DefaultsFactory()
3140}
3141
Colin Cross36242852017-06-23 15:06:31 -07003142func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08003143 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08003144
Colin Cross36242852017-06-23 15:06:31 -07003145 module.AddProperties(props...)
3146 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08003147 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07003148 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003149 &BaseCompilerProperties{},
3150 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01003151 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003152 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07003153 &StaticProperties{},
3154 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07003155 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003156 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003157 &TestProperties{},
3158 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07003159 &BenchmarkProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07003160 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003161 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08003162 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07003163 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07003164 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07003165 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08003166 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08003167 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09003168 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07003169 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07003170 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08003171 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07003172 )
Colin Crosscfad1192015-11-02 16:43:11 -08003173
Jooyung Hancc372c52019-09-25 15:18:44 +09003174 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07003175
3176 return module
Colin Crosscfad1192015-11-02 16:43:11 -08003177}
3178
Jiyong Park6a43f042017-10-12 23:05:00 +09003179func squashVendorSrcs(m *Module) {
3180 if lib, ok := m.compiler.(*libraryDecorator); ok {
3181 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3182 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
3183
3184 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3185 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003186
3187 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3188 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
Jiyong Park6a43f042017-10-12 23:05:00 +09003189 }
3190}
3191
Jiyong Parkf9332f12018-02-01 00:54:12 +09003192func squashRecoverySrcs(m *Module) {
3193 if lib, ok := m.compiler.(*libraryDecorator); ok {
3194 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3195 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
3196
3197 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3198 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003199
3200 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3201 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003202 }
3203}
3204
Jiyong Park2286afd2020-06-16 21:58:53 +09003205func (c *Module) IsSdkVariant() bool {
Dan Albert92fe7402020-07-15 13:33:30 -07003206 return c.Properties.IsSdkVariant || c.AlwaysSdk()
Jiyong Park2286afd2020-06-16 21:58:53 +09003207}
3208
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003209func kytheExtractAllFactory() android.Singleton {
3210 return &kytheExtractAllSingleton{}
3211}
3212
3213type kytheExtractAllSingleton struct {
3214}
3215
3216func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3217 var xrefTargets android.Paths
3218 ctx.VisitAllModules(func(module android.Module) {
3219 if ccModule, ok := module.(xref); ok {
3220 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3221 }
3222 })
3223 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3224 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07003225 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003226 }
3227}
3228
Colin Cross06a931b2015-10-28 17:23:31 -07003229var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003230var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003231var BoolPtr = proptools.BoolPtr
3232var String = proptools.String
3233var StringPtr = proptools.StringPtr