blob: 0718ee6e3be002b2dc70740982da59b8241df3b3 [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -07001// Copyright 2015 Google Inc. All rights reserved.
Colin Cross3f40fa42015-01-30 17:27:36 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17// This file contains the module types for compiling C/C++ for Android, and converts the properties
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
Colin Cross41955e82019-05-29 14:40:35 -070022 "fmt"
Logan Chien41eabe62019-04-10 13:33:58 +080023 "io"
Dan Albert9e10cd42016-08-03 14:12:14 -070024 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080025 "strings"
26
Colin Cross97ba0732015-03-23 17:50:24 -070027 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070028 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070029
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070031 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070032 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080033)
34
Colin Cross463a90e2015-06-17 14:20:06 -070035func init() {
Paul Duffin036e7002019-12-19 19:16:28 +000036 RegisterCCBuildComponents(android.InitRegistrationContext)
Colin Cross463a90e2015-06-17 14:20:06 -070037
Paul Duffin036e7002019-12-19 19:16:28 +000038 pctx.Import("android/soong/cc/config")
39}
40
41func RegisterCCBuildComponents(ctx android.RegistrationContext) {
42 ctx.RegisterModuleType("cc_defaults", defaultsFactory)
43
44 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Crossc511bc52020-04-07 16:50:32 +000045 ctx.BottomUp("sdk", sdkMutator).Parallel()
Inseob Kim64c43952019-08-26 16:52:35 +090046 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070047 ctx.BottomUp("link", LinkageMutator).Parallel()
Jooyung Hanb90e4912019-12-09 18:21:48 +090048 ctx.BottomUp("ndk_api", NdkApiMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +010049 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Colin Crossd1f898e2020-08-18 18:35:15 -070050 ctx.BottomUp("version_selector", versionSelectorMutator).Parallel()
51 ctx.BottomUp("version", versionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070052 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimac1e9862019-12-09 18:15:47 +090053 ctx.BottomUp("sysprop_cc", SyspropMutator).Parallel()
Inseob Kimeec88e12020-01-22 11:11:29 +090054 ctx.BottomUp("vendor_snapshot", VendorSnapshotMutator).Parallel()
55 ctx.BottomUp("vendor_snapshot_source", VendorSnapshotSourceMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070056 })
Colin Cross16b23492016-01-06 14:41:07 -080057
Paul Duffin036e7002019-12-19 19:16:28 +000058 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Cross1e676be2016-10-12 14:38:15 -070059 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
60 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080061
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070062 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
63 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
64
Mitch Phillipsbfeade62019-05-01 14:42:05 -070065 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
66 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
67
Jiyong Park1d1119f2019-07-29 21:27:18 +090068 // cfi mutator shouldn't run before sanitizers that return true for
69 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000070 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
71 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
72
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080073 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
74 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
75
Colin Cross1e676be2016-10-12 14:38:15 -070076 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
77 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080078
Colin Cross0b908332019-06-19 23:00:20 -070079 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090080 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080081
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080082 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080083 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070084
85 ctx.TopDown("lto_deps", ltoDepsMutator)
86 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090087
88 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070089 })
Colin Crossb98c8b02016-07-29 13:44:28 -070090
Sasha Smundak2a4549e2018-11-05 16:49:08 -080091 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070092}
93
Colin Crossca860ac2016-01-04 14:34:37 -080094type Deps struct {
95 SharedLibs, LateSharedLibs []string
96 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080097 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080098 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070099
Chris Parsons79d66a52020-06-05 17:26:16 -0400100 // Used for data dependencies adjacent to tests
101 DataLibs []string
102
Yo Chiang219968c2020-09-22 18:45:04 +0800103 // Used by DepsMutator to pass system_shared_libs information to check_elf_file.py.
104 SystemSharedLibs []string
105
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800106 StaticUnwinderIfLegacy bool
107
Colin Cross5950f382016-12-13 12:50:57 -0800108 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700109
Colin Cross81413472016-04-11 14:37:39 -0700110 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700111
Dan Willemsenb40aab62016-04-20 14:21:14 -0700112 GeneratedSources []string
113 GeneratedHeaders []string
Inseob Kimd110f872019-12-06 13:15:38 +0900114 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700115
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700116 ReexportGeneratedHeaders []string
117
Colin Cross97ba0732015-03-23 17:50:24 -0700118 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700119
120 // Used for host bionic
121 LinkerFlagsFile string
122 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700123}
124
Colin Crossca860ac2016-01-04 14:34:37 -0800125type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700126 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900127 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700128 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900129 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700130 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700131 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700132
Colin Cross26c34ed2016-09-30 17:10:16 -0700133 // Paths to .o files
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100134 Objs Objects
135 // Paths to .o files in dependencies that provide them. Note that these lists
136 // aren't complete since prebuilt modules don't provide the .o files.
Dan Willemsen581341d2017-02-09 16:16:31 -0800137 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700138 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700139
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100140 // Paths to .a files in prebuilts. Complements WholeStaticLibObjs to contain
141 // the libs from all whole_static_lib dependencies.
142 WholeStaticLibsFromPrebuilts android.Paths
143
Colin Cross26c34ed2016-09-30 17:10:16 -0700144 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700145 GeneratedSources android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900146 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700147
Inseob Kimd110f872019-12-06 13:15:38 +0900148 Flags []string
149 IncludeDirs android.Paths
150 SystemIncludeDirs android.Paths
151 ReexportedDirs android.Paths
152 ReexportedSystemDirs android.Paths
153 ReexportedFlags []string
154 ReexportedGeneratedHeaders android.Paths
155 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700156
Colin Cross26c34ed2016-09-30 17:10:16 -0700157 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700158 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700159
160 // Path to the file container flags to use with the linker
161 LinkerFlagsFile android.OptionalPath
162
163 // Path to the dynamic linker binary
164 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700165}
166
Colin Cross4af21ed2019-11-04 09:37:55 -0800167// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
168// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
169// command line so they can be overridden by the local module flags).
170type LocalOrGlobalFlags struct {
171 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700172 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800173 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700174 CFlags []string // Flags that apply to C and C++ source files
175 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
176 ConlyFlags []string // Flags that apply to C source files
177 CppFlags []string // Flags that apply to C++ source files
178 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700179 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800180}
181
182type Flags struct {
183 Local LocalOrGlobalFlags
184 Global LocalOrGlobalFlags
185
186 aidlFlags []string // Flags that apply to aidl source files
187 rsFlags []string // Flags that apply to renderscript source files
188 libFlags []string // Flags to add libraries early to the link order
189 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
190 TidyFlags []string // Flags that apply to clang-tidy
191 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700192
Colin Crossc3199482017-03-30 15:03:04 -0700193 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800194 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700195 SystemIncludeFlags []string
196
Oliver Nguyen04526782020-04-21 12:40:27 -0700197 Toolchain config.Toolchain
198 Tidy bool
199 GcovCoverage bool
200 SAbiDump bool
201 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800202
203 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800204 DynamicLinker string
205
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700206 CFlagsDeps android.Paths // Files depended on by compiler flags
207 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800208
Dan Willemsen98ab3112019-08-27 21:20:40 -0700209 AssemblerWithCpp bool
210 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800211
Colin Cross19878da2019-03-28 14:45:07 -0700212 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700213 protoC bool // Whether to use C instead of C++
214 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700215
216 Yacc *YaccProperties
Matthias Maennich22fd4d12020-07-15 10:58:56 +0200217 Lex *LexProperties
Colin Crossc472d572015-03-17 15:06:21 -0700218}
219
Colin Crossca860ac2016-01-04 14:34:37 -0800220// Properties used to compile all C or C++ modules
221type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700222 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800223 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700224
Colin Crossc511bc52020-04-07 16:50:32 +0000225 // Minimum sdk version supported when compiling against the ndk. Setting this property causes
226 // two variants to be built, one for the platform and one for apps.
Nan Zhang0007d812017-11-07 10:57:05 -0800227 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700228
Jooyung Han379660c2020-04-21 15:24:00 +0900229 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
230 Min_sdk_version *string
231
Colin Crossc511bc52020-04-07 16:50:32 +0000232 // If true, always create an sdk variant and don't create a platform variant.
233 Sdk_variant_only *bool
234
Jiyong Parkde866cb2018-12-07 23:08:36 +0900235 AndroidMkSharedLibs []string `blueprint:"mutated"`
236 AndroidMkStaticLibs []string `blueprint:"mutated"`
237 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
238 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
Bill Peckhama46de702020-04-21 17:23:37 -0700239 AndroidMkHeaderLibs []string `blueprint:"mutated"`
Jiyong Parkde866cb2018-12-07 23:08:36 +0900240 HideFromMake bool `blueprint:"mutated"`
241 PreventInstall bool `blueprint:"mutated"`
242 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700243
Yo Chiang219968c2020-09-22 18:45:04 +0800244 // Set by DepsMutator.
245 AndroidMkSystemSharedLibs []string `blueprint:"mutated"`
246
Justin Yun5f7f7e82019-11-18 19:52:14 +0900247 ImageVariationPrefix string `blueprint:"mutated"`
248 VndkVersion string `blueprint:"mutated"`
249 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800250
251 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
252 // file
253 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900254
Yifan Hong1b3348d2020-01-21 15:53:22 -0800255 // Make this module available when building for ramdisk
256 Ramdisk_available *bool
257
Jiyong Parkf9332f12018-02-01 00:54:12 +0900258 // Make this module available when building for recovery
259 Recovery_available *bool
260
Colin Crossae6c5202019-11-20 13:35:50 -0800261 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800262 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800263 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800264 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900265 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900266
267 // Allows this module to use non-APEX version of libraries. Useful
268 // for building binaries that are started before APEXes are activated.
269 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900270
271 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
272 // see soong/cc/config/vndk.go
273 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900274
275 // Used by vendor snapshot to record dependencies from snapshot modules.
276 SnapshotSharedLibs []string `blueprint:"mutated"`
277 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Paul Duffin0cb37b92020-03-04 14:52:46 +0000278
279 Installable *bool
Colin Crossc511bc52020-04-07 16:50:32 +0000280
281 // Set by factories of module types that can only be referenced from variants compiled against
282 // the SDK.
283 AlwaysSdk bool `blueprint:"mutated"`
284
285 // Variant is an SDK variant created by sdkMutator
286 IsSdkVariant bool `blueprint:"mutated"`
287 // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK
288 // variant to have a ".sdk" suffix.
289 SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"`
Bill Peckham945441c2020-08-31 16:07:58 -0700290
291 // Normally Soong uses the directory structure to decide which modules
292 // should be included (framework) or excluded (non-framework) from the
293 // vendor snapshot, but this property allows a partner to exclude a
294 // module normally thought of as a framework module from the vendor
295 // snapshot.
296 Exclude_from_vendor_snapshot *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700297}
298
299type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900300 // whether this module should be allowed to be directly depended by other
301 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900302 // In addition, this module should be allowed to be directly depended by
303 // product modules with `product_specific: true`.
304 // If set to true, three variants will be built separately, one like
305 // normal, another limited to the set of libraries and headers
306 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700307 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900308 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700309 // so it shouldn't have any unversioned runtime dependencies, or
310 // make assumptions about the system that may not be true in the
311 // future.
312 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900313 // If set to false, this module becomes inaccessible from /vendor or /product
314 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900315 //
316 // Default value is true when vndk: {enabled: true} or vendor: true.
317 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700318 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900319 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700320 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900321
322 // whether this module is capable of being loaded with other instance
323 // (possibly an older version) of the same module in the same process.
324 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
325 // can be double loaded in a vendor process if the library is also a
326 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
327 // explicitly marked as `double_loadable: true` by the owner, or the dependency
328 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
329 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800330}
331
Colin Crossca860ac2016-01-04 14:34:37 -0800332type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800333 static() bool
334 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900335 header() bool
Inseob Kim7f283f42020-06-01 21:53:49 +0900336 binary() bool
Inseob Kim1042d292020-06-01 23:23:05 +0900337 object() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700338 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900339 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700340 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800341 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700342 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800343 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900344 isLlndk(config android.Config) bool
345 isLlndkPublic(config android.Config) bool
346 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900347 isVndk() bool
348 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800349 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900350 inProduct() bool
351 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800352 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900353 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800354 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700355 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700356 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800357 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800358 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800359 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800360 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800361 isForPlatform() bool
Colin Crosse07f2312020-08-13 11:24:56 -0700362 apexVariationName() string
Dan Albertc8060532020-07-22 22:32:17 -0700363 apexSdkVersion() android.ApiLevel
Jiyong Parkb0788572018-12-20 22:10:17 +0900364 hasStubsVariants() bool
365 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900366 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800367 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700368 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800369}
370
371type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700372 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800373 ModuleContextIntf
374}
375
376type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700377 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800378 ModuleContextIntf
379}
380
Colin Cross37047f12016-12-13 17:06:13 -0800381type DepsContext interface {
382 android.BottomUpMutatorContext
383 ModuleContextIntf
384}
385
Colin Crossca860ac2016-01-04 14:34:37 -0800386type feature interface {
387 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800388 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800389 flags(ctx ModuleContext, flags Flags) Flags
390 props() []interface{}
391}
392
393type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700394 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800395 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800396 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700397 compilerProps() []interface{}
398
Colin Cross76fada02016-07-27 10:31:13 -0700399 appendCflags([]string)
400 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700401 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800402}
403
404type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700405 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800406 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700407 linkerFlags(ctx ModuleContext, flags Flags) Flags
408 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800409 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700410
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700411 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700412 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900413 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700414
415 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900416 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000417
418 // Get the deps that have been explicitly specified in the properties.
419 // Only updates the
420 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
421}
422
423type specifiedDeps struct {
424 sharedLibs []string
Martin Stjernholm10566a02020-03-24 01:19:52 +0000425 systemSharedLibs []string // Note nil and [] are semantically distinct.
Colin Crossca860ac2016-01-04 14:34:37 -0800426}
427
428type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700429 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700430 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000431 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800432 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700433 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700434 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900435 relativeInstallPath() string
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +0100436 makeUninstallable(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800437}
438
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800439type xref interface {
440 XrefCcFiles() android.Paths
441}
442
Colin Cross6e511a92020-07-27 21:26:48 -0700443type libraryDependencyKind int
444
445const (
446 headerLibraryDependency = iota
447 sharedLibraryDependency
448 staticLibraryDependency
449)
450
451func (k libraryDependencyKind) String() string {
452 switch k {
453 case headerLibraryDependency:
454 return "headerLibraryDependency"
455 case sharedLibraryDependency:
456 return "sharedLibraryDependency"
457 case staticLibraryDependency:
458 return "staticLibraryDependency"
459 default:
460 panic(fmt.Errorf("unknown libraryDependencyKind %d", k))
461 }
462}
463
464type libraryDependencyOrder int
465
466const (
467 earlyLibraryDependency = -1
468 normalLibraryDependency = 0
469 lateLibraryDependency = 1
470)
471
472func (o libraryDependencyOrder) String() string {
473 switch o {
474 case earlyLibraryDependency:
475 return "earlyLibraryDependency"
476 case normalLibraryDependency:
477 return "normalLibraryDependency"
478 case lateLibraryDependency:
479 return "lateLibraryDependency"
480 default:
481 panic(fmt.Errorf("unknown libraryDependencyOrder %d", o))
482 }
483}
484
485// libraryDependencyTag is used to tag dependencies on libraries. Unlike many dependency
486// tags that have a set of predefined tag objects that are reused for each dependency, a
487// libraryDependencyTag is designed to contain extra metadata and is constructed as needed.
488// That means that comparing a libraryDependencyTag for equality will only be equal if all
489// of the metadata is equal. Most usages will want to type assert to libraryDependencyTag and
490// then check individual metadata fields instead.
491type libraryDependencyTag struct {
492 blueprint.BaseDependencyTag
493
494 // These are exported so that fmt.Printf("%#v") can call their String methods.
495 Kind libraryDependencyKind
496 Order libraryDependencyOrder
497
498 wholeStatic bool
499
500 reexportFlags bool
501 explicitlyVersioned bool
502 dataLib bool
503 ndk bool
504
505 staticUnwinder bool
506
507 makeSuffix string
508}
509
510// header returns true if the libraryDependencyTag is tagging a header lib dependency.
511func (d libraryDependencyTag) header() bool {
512 return d.Kind == headerLibraryDependency
513}
514
515// shared returns true if the libraryDependencyTag is tagging a shared lib dependency.
516func (d libraryDependencyTag) shared() bool {
517 return d.Kind == sharedLibraryDependency
518}
519
520// shared returns true if the libraryDependencyTag is tagging a static lib dependency.
521func (d libraryDependencyTag) static() bool {
522 return d.Kind == staticLibraryDependency
523}
524
525// dependencyTag is used for tagging miscellanous dependency types that don't fit into
526// libraryDependencyTag. Each tag object is created globally and reused for multiple
527// dependencies (although since the object contains no references, assigning a tag to a
528// variable and modifying it will not modify the original). Users can compare the tag
529// returned by ctx.OtherModuleDependencyTag against the global original
530type dependencyTag struct {
531 blueprint.BaseDependencyTag
532 name string
533}
534
Colin Crossc99deeb2016-04-11 15:06:20 -0700535var (
Colin Cross6e511a92020-07-27 21:26:48 -0700536 genSourceDepTag = dependencyTag{name: "gen source"}
537 genHeaderDepTag = dependencyTag{name: "gen header"}
538 genHeaderExportDepTag = dependencyTag{name: "gen header export"}
539 objDepTag = dependencyTag{name: "obj"}
540 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
541 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
542 reuseObjTag = dependencyTag{name: "reuse objects"}
543 staticVariantTag = dependencyTag{name: "static variant"}
544 vndkExtDepTag = dependencyTag{name: "vndk extends"}
545 dataLibDepTag = dependencyTag{name: "data lib"}
546 runtimeDepTag = dependencyTag{name: "runtime lib"}
547 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700548)
549
Roland Levillainf89cd092019-07-29 16:22:59 +0100550func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700551 ccLibDepTag, ok := depTag.(libraryDependencyTag)
552 return ok && ccLibDepTag.shared()
553}
554
555func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
556 ccLibDepTag, ok := depTag.(libraryDependencyTag)
557 return ok && ccLibDepTag.static()
Roland Levillainf89cd092019-07-29 16:22:59 +0100558}
559
560func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700561 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100562 return ok && ccDepTag == runtimeDepTag
563}
564
565func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700566 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100567 return ok && ccDepTag == testPerSrcDepTag
568}
569
Colin Crossca860ac2016-01-04 14:34:37 -0800570// Module contains the properties and members used by all C/C++ module types, and implements
571// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
572// to construct the output file. Behavior can be customized with a Customizer interface
573type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700574 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700575 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900576 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900577 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700578
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700579 Properties BaseProperties
580 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700581
Colin Crossca860ac2016-01-04 14:34:37 -0800582 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700583 hod android.HostOrDeviceSupported
584 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700585
Paul Duffina0843f62019-12-13 19:50:38 +0000586 // Allowable SdkMemberTypes of this module type.
587 sdkMemberTypes []android.SdkMemberType
588
Colin Crossca860ac2016-01-04 14:34:37 -0800589 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700590 features []feature
591 compiler compiler
592 linker linker
593 installer installer
594 stl *stl
595 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800596 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800597 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900598 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700599 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700600 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800601
Colin Cross635c3b02016-05-18 15:37:25 -0700602 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800603
Colin Crossb98c8b02016-07-29 13:44:28 -0700604 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700605
606 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800607
608 // Flags used to compile this module
609 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700610
611 // When calling a linker, if module A depends on module B, then A must precede B in its command
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800612 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700613 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800614 depsInLinkOrder android.Paths
615
616 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700617 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900618
619 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800620 // Kythe (source file indexer) paths for this compilation module
621 kytheFiles android.Paths
Jooyung Han75568392020-03-20 04:29:24 +0900622
623 // For apex variants, this is set as apex.min_sdk_version
Dan Albertc8060532020-07-22 22:32:17 -0700624 apexSdkVersion android.ApiLevel
Colin Crossc472d572015-03-17 15:06:21 -0700625}
626
Ivan Lozano52767be2019-10-18 14:49:46 -0700627func (c *Module) Toc() android.OptionalPath {
628 if c.linker != nil {
629 if library, ok := c.linker.(libraryInterface); ok {
630 return library.toc()
631 }
632 }
633 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
634}
635
636func (c *Module) ApiLevel() string {
637 if c.linker != nil {
638 if stub, ok := c.linker.(*stubDecorator); ok {
Dan Albert1a246272020-07-06 14:49:35 -0700639 return stub.apiLevel.String()
Ivan Lozano52767be2019-10-18 14:49:46 -0700640 }
641 }
642 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
643}
644
645func (c *Module) Static() bool {
646 if c.linker != nil {
647 if library, ok := c.linker.(libraryInterface); ok {
648 return library.static()
649 }
650 }
651 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
652}
653
654func (c *Module) Shared() bool {
655 if c.linker != nil {
656 if library, ok := c.linker.(libraryInterface); ok {
657 return library.shared()
658 }
659 }
660 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
661}
662
663func (c *Module) SelectedStl() string {
Colin Crossc511bc52020-04-07 16:50:32 +0000664 if c.stl != nil {
665 return c.stl.Properties.SelectedStl
666 }
667 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700668}
669
670func (c *Module) ToolchainLibrary() bool {
671 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
672 return true
673 }
674 return false
675}
676
677func (c *Module) NdkPrebuiltStl() bool {
678 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
679 return true
680 }
681 return false
682}
683
684func (c *Module) StubDecorator() bool {
685 if _, ok := c.linker.(*stubDecorator); ok {
686 return true
687 }
688 return false
689}
690
691func (c *Module) SdkVersion() string {
692 return String(c.Properties.Sdk_version)
693}
694
Artur Satayev480e25b2020-04-27 18:53:18 +0100695func (c *Module) MinSdkVersion() string {
696 return String(c.Properties.Min_sdk_version)
697}
698
Dan Albert92fe7402020-07-15 13:33:30 -0700699func (c *Module) SplitPerApiLevel() bool {
700 if linker, ok := c.linker.(*objectLinker); ok {
701 return linker.isCrt()
702 }
703 return false
704}
705
Colin Crossc511bc52020-04-07 16:50:32 +0000706func (c *Module) AlwaysSdk() bool {
707 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
708}
709
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800710func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700711 if c.linker != nil {
712 if library, ok := c.linker.(exportedFlagsProducer); ok {
713 return library.exportedDirs()
714 }
715 }
716 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
717}
718
719func (c *Module) HasStaticVariant() bool {
720 if c.staticVariant != nil {
721 return true
722 }
723 return false
724}
725
726func (c *Module) GetStaticVariant() LinkableInterface {
727 return c.staticVariant
728}
729
730func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
731 c.depsInLinkOrder = depsInLinkOrder
732}
733
734func (c *Module) GetDepsInLinkOrder() []android.Path {
735 return c.depsInLinkOrder
736}
737
738func (c *Module) StubsVersions() []string {
739 if c.linker != nil {
740 if library, ok := c.linker.(*libraryDecorator); ok {
741 return library.Properties.Stubs.Versions
742 }
Colin Crossd48fe732020-09-23 20:37:24 -0700743 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
744 return library.Properties.Stubs.Versions
745 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700746 }
747 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
748}
749
750func (c *Module) CcLibrary() bool {
751 if c.linker != nil {
752 if _, ok := c.linker.(*libraryDecorator); ok {
753 return true
754 }
Colin Crossd48fe732020-09-23 20:37:24 -0700755 if _, ok := c.linker.(*prebuiltLibraryLinker); ok {
756 return true
757 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700758 }
759 return false
760}
761
762func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700763 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700764 return true
765 }
766 return false
767}
768
Ivan Lozano2b262972019-11-21 12:30:50 -0800769func (c *Module) NonCcVariants() bool {
770 return false
771}
772
Ivan Lozano183a3212019-10-18 14:18:45 -0700773func (c *Module) SetBuildStubs() {
774 if c.linker != nil {
775 if library, ok := c.linker.(*libraryDecorator); ok {
776 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700777 c.Properties.HideFromMake = true
778 c.sanitize = nil
779 c.stl = nil
780 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700781 return
782 }
Colin Crossd48fe732020-09-23 20:37:24 -0700783 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
784 library.MutatedProperties.BuildStubs = true
785 c.Properties.HideFromMake = true
786 c.sanitize = nil
787 c.stl = nil
788 c.Properties.PreventInstall = true
789 return
790 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000791 if _, ok := c.linker.(*llndkStubDecorator); ok {
792 c.Properties.HideFromMake = true
793 return
794 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700795 }
796 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
797}
798
Ivan Lozano52767be2019-10-18 14:49:46 -0700799func (c *Module) BuildStubs() bool {
800 if c.linker != nil {
801 if library, ok := c.linker.(*libraryDecorator); ok {
802 return library.buildStubs()
803 }
Colin Crossd48fe732020-09-23 20:37:24 -0700804 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
805 return library.buildStubs()
806 }
Ivan Lozano52767be2019-10-18 14:49:46 -0700807 }
808 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
809}
810
Colin Crossd1f898e2020-08-18 18:35:15 -0700811func (c *Module) SetAllStubsVersions(versions []string) {
812 if library, ok := c.linker.(*libraryDecorator); ok {
813 library.MutatedProperties.AllStubsVersions = versions
814 return
815 }
Colin Crossd48fe732020-09-23 20:37:24 -0700816 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
817 library.MutatedProperties.AllStubsVersions = versions
818 return
819 }
Colin Crossd1f898e2020-08-18 18:35:15 -0700820 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
821 llndk.libraryDecorator.MutatedProperties.AllStubsVersions = versions
822 return
823 }
824}
825
826func (c *Module) AllStubsVersions() []string {
827 if library, ok := c.linker.(*libraryDecorator); ok {
828 return library.MutatedProperties.AllStubsVersions
829 }
Colin Crossd48fe732020-09-23 20:37:24 -0700830 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
831 return library.MutatedProperties.AllStubsVersions
832 }
Colin Crossd1f898e2020-08-18 18:35:15 -0700833 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
834 return llndk.libraryDecorator.MutatedProperties.AllStubsVersions
835 }
836 return nil
837}
838
839func (c *Module) SetStubsVersion(version string) {
Ivan Lozano183a3212019-10-18 14:18:45 -0700840 if c.linker != nil {
841 if library, ok := c.linker.(*libraryDecorator); ok {
842 library.MutatedProperties.StubsVersion = version
843 return
844 }
Colin Crossd48fe732020-09-23 20:37:24 -0700845 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
846 library.MutatedProperties.StubsVersion = version
847 return
848 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000849 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
850 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
851 return
852 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700853 }
Colin Crossd1f898e2020-08-18 18:35:15 -0700854 panic(fmt.Errorf("SetStubsVersion called on non-library module: %q", c.BaseModuleName()))
Ivan Lozano183a3212019-10-18 14:18:45 -0700855}
856
Jooyung Han03b51852020-02-26 22:45:42 +0900857func (c *Module) StubsVersion() string {
858 if c.linker != nil {
859 if library, ok := c.linker.(*libraryDecorator); ok {
860 return library.MutatedProperties.StubsVersion
861 }
Colin Crossd48fe732020-09-23 20:37:24 -0700862 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
863 return library.MutatedProperties.StubsVersion
864 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000865 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
866 return llndk.libraryDecorator.MutatedProperties.StubsVersion
867 }
Jooyung Han03b51852020-02-26 22:45:42 +0900868 }
869 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
870}
871
Ivan Lozano183a3212019-10-18 14:18:45 -0700872func (c *Module) SetStatic() {
873 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700874 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700875 library.setStatic()
876 return
877 }
878 }
879 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
880}
881
882func (c *Module) SetShared() {
883 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700884 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700885 library.setShared()
886 return
887 }
888 }
889 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
890}
891
892func (c *Module) BuildStaticVariant() bool {
893 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700894 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700895 return library.buildStatic()
896 }
897 }
898 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
899}
900
901func (c *Module) BuildSharedVariant() bool {
902 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700903 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700904 return library.buildShared()
905 }
906 }
907 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
908}
909
910func (c *Module) Module() android.Module {
911 return c
912}
913
Jiyong Parkc20eee32018-09-05 22:36:17 +0900914func (c *Module) OutputFile() android.OptionalPath {
915 return c.outputFile
916}
917
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400918func (c *Module) CoverageFiles() android.Paths {
919 if c.linker != nil {
920 if library, ok := c.linker.(libraryInterface); ok {
921 return library.objs().coverageFiles
922 }
923 }
924 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
925}
926
Ivan Lozano183a3212019-10-18 14:18:45 -0700927var _ LinkableInterface = (*Module)(nil)
928
Jiyong Park719b4462019-01-13 00:39:51 +0900929func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900930 if c.linker != nil {
931 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900932 }
933 return nil
934}
935
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900936func (c *Module) CoverageOutputFile() android.OptionalPath {
937 if c.linker != nil {
938 return c.linker.coverageOutputFilePath()
939 }
940 return android.OptionalPath{}
941}
942
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900943func (c *Module) RelativeInstallPath() string {
944 if c.installer != nil {
945 return c.installer.relativeInstallPath()
946 }
947 return ""
948}
949
Jooyung Han344d5432019-08-23 11:17:39 +0900950func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900951 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900952}
953
Colin Cross36242852017-06-23 15:06:31 -0700954func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700955 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800956 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700957 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800958 }
959 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700960 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800961 }
962 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700963 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800964 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700965 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700966 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700967 }
Colin Cross16b23492016-01-06 14:41:07 -0800968 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700969 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800970 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800971 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700972 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800973 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800974 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700975 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800976 }
Justin Yun8effde42017-06-23 19:24:43 +0900977 if c.vndkdep != nil {
978 c.AddProperties(c.vndkdep.props()...)
979 }
Stephen Craneba090d12017-05-09 15:44:35 -0700980 if c.lto != nil {
981 c.AddProperties(c.lto.props()...)
982 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700983 if c.pgo != nil {
984 c.AddProperties(c.pgo.props()...)
985 }
Colin Crossca860ac2016-01-04 14:34:37 -0800986 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700987 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800988 }
Colin Crossc472d572015-03-17 15:06:21 -0700989
Jiyong Park1613e552020-09-14 19:43:17 +0900990 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, os android.OsType) bool {
Elliott Hughes79ae3412020-04-17 15:49:49 -0700991 // Windows builds always prefer 32-bit
Jiyong Park1613e552020-09-14 19:43:17 +0900992 return os == android.Windows
Colin Crossa9d8bee2018-10-02 13:59:46 -0700993 })
Colin Cross36242852017-06-23 15:06:31 -0700994 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900995 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900996 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900997 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900998
Colin Cross36242852017-06-23 15:06:31 -0700999 return c
Colin Crossc472d572015-03-17 15:06:21 -07001000}
1001
Colin Crossb916a382016-07-29 17:28:03 -07001002// Returns true for dependency roots (binaries)
1003// TODO(ccross): also handle dlopenable libraries
1004func (c *Module) isDependencyRoot() bool {
1005 if root, ok := c.linker.(interface {
1006 isDependencyRoot() bool
1007 }); ok {
1008 return root.isDependencyRoot()
1009 }
1010 return false
1011}
1012
Justin Yun5f7f7e82019-11-18 19:52:14 +09001013// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
1014// "product" and "vendor" variant modules return true for this function.
1015// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
1016// "soc_specific: true" and more vendor installed modules are included here.
1017// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
1018// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -07001019func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +09001020 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001021}
1022
Colin Crossc511bc52020-04-07 16:50:32 +00001023func (c *Module) canUseSdk() bool {
1024 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery()
1025}
1026
1027func (c *Module) UseSdk() bool {
1028 if c.canUseSdk() {
Dan Albert92fe7402020-07-15 13:33:30 -07001029 return String(c.Properties.Sdk_version) != "" || c.SplitPerApiLevel()
Colin Crossc511bc52020-04-07 16:50:32 +00001030 }
1031 return false
1032}
1033
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001034func (c *Module) isCoverageVariant() bool {
1035 return c.coverage.Properties.IsCoverageVariant
1036}
1037
Peter Collingbournead84f972019-12-17 16:46:18 -08001038func (c *Module) IsNdk() bool {
Colin Crossf0913fb2020-07-29 12:59:39 -07001039 return inList(c.BaseModuleName(), ndkKnownLibs)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001040}
1041
Inseob Kim9516ee92019-05-09 10:56:13 +09001042func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001043 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +09001044 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001045}
1046
Inseob Kim9516ee92019-05-09 10:56:13 +09001047func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001048 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +09001049 name := c.BaseModuleName()
1050 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001051}
1052
Inseob Kim9516ee92019-05-09 10:56:13 +09001053func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001054 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +09001055 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001056}
1057
Ivan Lozano52767be2019-10-18 14:49:46 -07001058func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001059 if vndkdep := c.vndkdep; vndkdep != nil {
1060 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +09001061 }
1062 return false
1063}
1064
Yi Kong7e53c572018-02-14 18:16:12 +08001065func (c *Module) isPgoCompile() bool {
1066 if pgo := c.pgo; pgo != nil {
1067 return pgo.Properties.PgoCompile
1068 }
1069 return false
1070}
1071
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001072func (c *Module) isNDKStubLibrary() bool {
1073 if _, ok := c.compiler.(*stubDecorator); ok {
1074 return true
1075 }
1076 return false
1077}
1078
Logan Chienf3511742017-10-31 18:04:35 +08001079func (c *Module) isVndkSp() bool {
1080 if vndkdep := c.vndkdep; vndkdep != nil {
1081 return vndkdep.isVndkSp()
1082 }
1083 return false
1084}
1085
1086func (c *Module) isVndkExt() bool {
1087 if vndkdep := c.vndkdep; vndkdep != nil {
1088 return vndkdep.isVndkExt()
1089 }
1090 return false
1091}
1092
Ivan Lozano52767be2019-10-18 14:49:46 -07001093func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +09001094 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -08001095}
1096
Logan Chienf3511742017-10-31 18:04:35 +08001097func (c *Module) getVndkExtendsModuleName() string {
1098 if vndkdep := c.vndkdep; vndkdep != nil {
1099 return vndkdep.getVndkExtendsModuleName()
1100 }
1101 return ""
1102}
1103
Jiyong Park25fc6a92018-11-18 18:02:45 +09001104func (c *Module) IsStubs() bool {
1105 if library, ok := c.linker.(*libraryDecorator); ok {
1106 return library.buildStubs()
Colin Crossd48fe732020-09-23 20:37:24 -07001107 } else if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
1108 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +09001109 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
1110 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001111 }
1112 return false
1113}
1114
1115func (c *Module) HasStubsVariants() bool {
1116 if library, ok := c.linker.(*libraryDecorator); ok {
1117 return len(library.Properties.Stubs.Versions) > 0
1118 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001119 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
1120 return len(library.Properties.Stubs.Versions) > 0
1121 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001122 return false
1123}
1124
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001125func (c *Module) bootstrap() bool {
1126 return Bool(c.Properties.Bootstrap)
1127}
1128
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001129func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001130 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1131 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1132 return false
1133 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001134 return c.linker != nil && c.linker.nativeCoverage()
1135}
1136
Inseob Kim8471cda2019-11-15 09:59:12 +09001137func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kim1042d292020-06-01 23:23:05 +09001138 if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
1139 return p.isSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001140 }
1141 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001142}
1143
Jiyong Park73c54ee2019-10-22 20:31:18 +09001144func (c *Module) ExportedIncludeDirs() android.Paths {
1145 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1146 return flagsProducer.exportedDirs()
1147 }
Jiyong Park232e7852019-11-04 12:23:40 +09001148 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001149}
1150
1151func (c *Module) ExportedSystemIncludeDirs() android.Paths {
1152 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1153 return flagsProducer.exportedSystemDirs()
1154 }
Jiyong Park232e7852019-11-04 12:23:40 +09001155 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001156}
1157
1158func (c *Module) ExportedFlags() []string {
1159 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1160 return flagsProducer.exportedFlags()
1161 }
Jiyong Park232e7852019-11-04 12:23:40 +09001162 return nil
1163}
1164
1165func (c *Module) ExportedDeps() android.Paths {
1166 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1167 return flagsProducer.exportedDeps()
1168 }
1169 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001170}
1171
Inseob Kimd110f872019-12-06 13:15:38 +09001172func (c *Module) ExportedGeneratedHeaders() android.Paths {
1173 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1174 return flagsProducer.exportedGeneratedHeaders()
1175 }
1176 return nil
1177}
1178
Bill Peckham945441c2020-08-31 16:07:58 -07001179func (c *Module) ExcludeFromVendorSnapshot() bool {
1180 return Bool(c.Properties.Exclude_from_vendor_snapshot)
1181}
1182
Jiyong Parkf1194352019-02-25 11:05:47 +09001183func isBionic(name string) bool {
1184 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001185 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001186 return true
1187 }
1188 return false
1189}
1190
Martin Stjernholm279de572019-09-10 23:18:20 +01001191func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001192 if name == "libclang_rt.hwasan-aarch64-android" {
Jooyung Han8ce8db92020-05-15 19:05:05 +09001193 return true
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001194 }
1195 return isBionic(name)
1196}
1197
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001198func (c *Module) XrefCcFiles() android.Paths {
1199 return c.kytheFiles
1200}
1201
Colin Crossca860ac2016-01-04 14:34:37 -08001202type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001203 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001204 moduleContextImpl
1205}
1206
Colin Cross37047f12016-12-13 17:06:13 -08001207type depsContext struct {
1208 android.BottomUpMutatorContext
1209 moduleContextImpl
1210}
1211
Colin Crossca860ac2016-01-04 14:34:37 -08001212type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001213 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001214 moduleContextImpl
1215}
1216
1217type moduleContextImpl struct {
1218 mod *Module
1219 ctx BaseModuleContext
1220}
1221
Colin Crossb98c8b02016-07-29 13:44:28 -07001222func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001223 return ctx.mod.toolchain(ctx.ctx)
1224}
1225
1226func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001227 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001228}
1229
1230func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001231 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001232}
1233
Jiyong Park1d1119f2019-07-29 21:27:18 +09001234func (ctx *moduleContextImpl) header() bool {
1235 return ctx.mod.header()
1236}
1237
Inseob Kim7f283f42020-06-01 21:53:49 +09001238func (ctx *moduleContextImpl) binary() bool {
1239 return ctx.mod.binary()
1240}
1241
Inseob Kim1042d292020-06-01 23:23:05 +09001242func (ctx *moduleContextImpl) object() bool {
1243 return ctx.mod.object()
1244}
1245
Jooyung Hanccce2f22020-03-07 03:45:53 +09001246func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001247 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001248}
1249
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001250func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001251 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001252}
1253
1254func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001255 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001256 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001257 vndkVer := ctx.mod.VndkVersion()
Jooyung Han03302ee2020-04-08 09:22:26 +09001258 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001259 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001260 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001261 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001262 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001263 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001264 }
1265 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001266}
1267
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001268func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001269 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001270}
Justin Yun8effde42017-06-23 19:24:43 +09001271
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001272func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001273 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001274}
1275
Inseob Kim9516ee92019-05-09 10:56:13 +09001276func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1277 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001278}
1279
Inseob Kim9516ee92019-05-09 10:56:13 +09001280func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1281 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001282}
1283
Inseob Kim9516ee92019-05-09 10:56:13 +09001284func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1285 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001286}
1287
Logan Chienf3511742017-10-31 18:04:35 +08001288func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001289 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001290}
1291
Yi Kong7e53c572018-02-14 18:16:12 +08001292func (ctx *moduleContextImpl) isPgoCompile() bool {
1293 return ctx.mod.isPgoCompile()
1294}
1295
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001296func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1297 return ctx.mod.isNDKStubLibrary()
1298}
1299
Justin Yun8effde42017-06-23 19:24:43 +09001300func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001301 return ctx.mod.isVndkSp()
1302}
1303
1304func (ctx *moduleContextImpl) isVndkExt() bool {
1305 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001306}
1307
Vic Yangefd249e2018-11-12 20:19:56 -08001308func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001309 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001310}
1311
Logan Chien2f2b8902018-07-10 15:01:19 +08001312// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001313func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001314 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1315 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001316 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001317
Hsin-Yi Chenf81bb652020-04-07 21:42:19 +08001318 // Coverage builds have extra symbols.
1319 if ctx.mod.isCoverageVariant() {
1320 return false
1321 }
1322
Doug Hornc32c6b02019-01-17 14:44:05 -08001323 if ctx.ctx.Fuchsia() {
1324 return false
1325 }
1326
Logan Chien2f2b8902018-07-10 15:01:19 +08001327 if sanitize := ctx.mod.sanitize; sanitize != nil {
1328 if !sanitize.isVariantOnProductionDevice() {
1329 return false
1330 }
1331 }
1332 if !ctx.ctx.Device() {
1333 // Host modules do not need ABI dumps.
1334 return false
1335 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001336 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001337 // Stubs do not need ABI dumps.
1338 return false
1339 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001340 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001341}
1342
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001343func (ctx *moduleContextImpl) selectedStl() string {
1344 if stl := ctx.mod.stl; stl != nil {
1345 return stl.Properties.SelectedStl
1346 }
1347 return ""
1348}
1349
Ivan Lozanobd721262018-11-27 14:33:03 -08001350func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1351 return ctx.mod.linker.useClangLld(actx)
1352}
1353
Colin Crossce75d2c2016-10-06 16:12:58 -07001354func (ctx *moduleContextImpl) baseModuleName() string {
1355 return ctx.mod.ModuleBase.BaseModuleName()
1356}
1357
Logan Chienf3511742017-10-31 18:04:35 +08001358func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1359 return ctx.mod.getVndkExtendsModuleName()
1360}
1361
Logan Chiene274fc92019-12-03 11:18:32 -08001362func (ctx *moduleContextImpl) isForPlatform() bool {
1363 return ctx.mod.IsForPlatform()
1364}
1365
Colin Crosse07f2312020-08-13 11:24:56 -07001366func (ctx *moduleContextImpl) apexVariationName() string {
1367 return ctx.mod.ApexVariationName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001368}
1369
Dan Albertc8060532020-07-22 22:32:17 -07001370func (ctx *moduleContextImpl) apexSdkVersion() android.ApiLevel {
Jooyung Han75568392020-03-20 04:29:24 +09001371 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001372}
1373
Jiyong Parkb0788572018-12-20 22:10:17 +09001374func (ctx *moduleContextImpl) hasStubsVariants() bool {
1375 return ctx.mod.HasStubsVariants()
1376}
1377
1378func (ctx *moduleContextImpl) isStubs() bool {
1379 return ctx.mod.IsStubs()
1380}
1381
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001382func (ctx *moduleContextImpl) bootstrap() bool {
1383 return ctx.mod.bootstrap()
1384}
1385
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001386func (ctx *moduleContextImpl) nativeCoverage() bool {
1387 return ctx.mod.nativeCoverage()
1388}
1389
Colin Cross635c3b02016-05-18 15:37:25 -07001390func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001391 return &Module{
1392 hod: hod,
1393 multilib: multilib,
1394 }
1395}
1396
Colin Cross635c3b02016-05-18 15:37:25 -07001397func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001398 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001399 module.features = []feature{
1400 &tidyFeature{},
1401 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001402 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001403 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001404 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001405 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001406 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001407 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001408 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001409 return module
1410}
1411
Colin Crossce75d2c2016-10-06 16:12:58 -07001412func (c *Module) Prebuilt() *android.Prebuilt {
1413 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1414 return p.prebuilt()
1415 }
1416 return nil
1417}
1418
1419func (c *Module) Name() string {
1420 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001421 if p, ok := c.linker.(interface {
1422 Name(string) string
1423 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001424 name = p.Name(name)
1425 }
1426 return name
1427}
1428
Alex Light3d673592019-01-18 14:37:31 -08001429func (c *Module) Symlinks() []string {
1430 if p, ok := c.installer.(interface {
1431 symlinkList() []string
1432 }); ok {
1433 return p.symlinkList()
1434 }
1435 return nil
1436}
1437
Jeff Gaston294356f2017-09-27 17:05:30 -07001438// orderDeps reorders dependencies into a list such that if module A depends on B, then
1439// A will precede B in the resultant list.
1440// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001441// Note that directSharedDeps should be the analogous static library for each shared lib dep
1442func orderDeps(directStaticDeps []android.Path, directSharedDeps []android.Path, allTransitiveDeps map[android.Path][]android.Path) (orderedAllDeps []android.Path, orderedDeclaredDeps []android.Path) {
Jeff Gaston294356f2017-09-27 17:05:30 -07001443 // If A depends on B, then
1444 // Every list containing A will also contain B later in the list
1445 // So, after concatenating all lists, the final instance of B will have come from the same
1446 // original list as the final instance of A
1447 // So, the final instance of B will be later in the concatenation than the final A
1448 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1449 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001450 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001451 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001452 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1453 }
1454 for _, dep := range directSharedDeps {
1455 orderedAllDeps = append(orderedAllDeps, dep)
1456 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001457 }
1458
Colin Crossb6715442017-10-24 11:13:31 -07001459 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001460
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001461 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001462 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001463 // resultant list to only what the caller has chosen to include in directStaticDeps
1464 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001465
1466 return orderedAllDeps, orderedDeclaredDeps
1467}
1468
Ivan Lozano183a3212019-10-18 14:18:45 -07001469func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001470 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001471 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001472 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1473 staticDepFiles := []android.Path{}
1474 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001475 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1476 if dep.OutputFile().Valid() {
1477 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1478 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1479 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001480 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001481 sharedDepFiles := []android.Path{}
1482 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001483 if sharedDep.HasStaticVariant() {
1484 staticAnalogue := sharedDep.GetStaticVariant()
1485 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1486 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001487 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001488 }
1489
1490 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001491 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1492 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001493
1494 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001495}
1496
Roland Levillainf89cd092019-07-29 16:22:59 +01001497func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1498 test, ok := c.linker.(testPerSrc)
1499 return ok && test.isAllTestsVariation()
1500}
1501
Chris Parsons216e10a2020-07-09 17:12:52 -04001502func (c *Module) DataPaths() []android.DataPath {
Liz Kammer1c14a212020-05-12 15:26:55 -07001503 if p, ok := c.installer.(interface {
Chris Parsons216e10a2020-07-09 17:12:52 -04001504 dataPaths() []android.DataPath
Liz Kammer1c14a212020-05-12 15:26:55 -07001505 }); ok {
1506 return p.dataPaths()
1507 }
1508 return nil
1509}
1510
Justin Yun5f7f7e82019-11-18 19:52:14 +09001511func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1512 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1513 // "current", it will append the VNDK version to the name suffix.
1514 var vndkVersion string
1515 var nameSuffix string
1516 if c.inProduct() {
1517 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1518 nameSuffix = productSuffix
1519 } else {
1520 vndkVersion = ctx.DeviceConfig().VndkVersion()
1521 nameSuffix = vendorSuffix
1522 }
1523 if vndkVersion == "current" {
1524 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1525 }
1526 if c.Properties.VndkVersion != vndkVersion {
1527 // add version suffix only if the module is using different vndk version than the
1528 // version in product or vendor partition.
1529 nameSuffix += "." + c.Properties.VndkVersion
1530 }
1531 return nameSuffix
1532}
1533
Colin Cross635c3b02016-05-18 15:37:25 -07001534func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001535 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001536 //
1537 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1538 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1539 // module and return early, as this module does not produce an output file per se.
1540 if c.IsTestPerSrcAllTestsVariation() {
1541 c.outputFile = android.OptionalPath{}
1542 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001543 }
1544
Jooyung Han38002912019-05-16 04:01:54 +09001545 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001546
Inseob Kim64c43952019-08-26 16:52:35 +09001547 c.Properties.SubName = ""
1548
1549 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1550 c.Properties.SubName += nativeBridgeSuffix
1551 }
1552
Justin Yun5f7f7e82019-11-18 19:52:14 +09001553 _, llndk := c.linker.(*llndkStubDecorator)
1554 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1555 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1556 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1557 // added for product variant only when we have vendor and product variants with core
1558 // variant. The suffix is not added for vendor-only or product-only module.
1559 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1560 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001561 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1562 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1563 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001564 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1565 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001566 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001567 c.Properties.SubName += recoverySuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001568 } else if c.IsSdkVariant() && (c.Properties.SdkAndPlatformVariantVisibleToMake || c.SplitPerApiLevel()) {
Colin Crossc511bc52020-04-07 16:50:32 +00001569 c.Properties.SubName += sdkSuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001570 if c.SplitPerApiLevel() {
1571 c.Properties.SubName += "." + c.SdkVersion()
1572 }
Inseob Kim64c43952019-08-26 16:52:35 +09001573 }
1574
Colin Crossca860ac2016-01-04 14:34:37 -08001575 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001576 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001577 moduleContextImpl: moduleContextImpl{
1578 mod: c,
1579 },
1580 }
1581 ctx.ctx = ctx
1582
Colin Crossf18e1102017-11-16 14:33:08 -08001583 deps := c.depsToPaths(ctx)
1584 if ctx.Failed() {
1585 return
1586 }
1587
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001588 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1589 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1590 }
1591
Colin Crossca860ac2016-01-04 14:34:37 -08001592 flags := Flags{
1593 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001594 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001595 }
Colin Crossca860ac2016-01-04 14:34:37 -08001596 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001597 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001598 }
1599 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001600 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001601 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001602 if c.stl != nil {
1603 flags = c.stl.flags(ctx, flags)
1604 }
Colin Cross16b23492016-01-06 14:41:07 -08001605 if c.sanitize != nil {
1606 flags = c.sanitize.flags(ctx, flags)
1607 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001608 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001609 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001610 }
Stephen Craneba090d12017-05-09 15:44:35 -07001611 if c.lto != nil {
1612 flags = c.lto.flags(ctx, flags)
1613 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001614 if c.pgo != nil {
1615 flags = c.pgo.flags(ctx, flags)
1616 }
Colin Crossca860ac2016-01-04 14:34:37 -08001617 for _, feature := range c.features {
1618 flags = feature.flags(ctx, flags)
1619 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001620 if ctx.Failed() {
1621 return
1622 }
1623
Colin Cross4af21ed2019-11-04 09:37:55 -08001624 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1625 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1626 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001627
Colin Cross4af21ed2019-11-04 09:37:55 -08001628 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001629
1630 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001631 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001632 }
1633 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001634 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001635 }
1636
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001637 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001638 // We need access to all the flags seen by a source file.
1639 if c.sabi != nil {
1640 flags = c.sabi.flags(ctx, flags)
1641 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001642
Colin Cross4af21ed2019-11-04 09:37:55 -08001643 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001644
Colin Crossca860ac2016-01-04 14:34:37 -08001645 // Optimization to reduce size of build.ninja
1646 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001647 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1648 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1649 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1650 flags.Local.CFlags = []string{"$cflags"}
1651 flags.Local.CppFlags = []string{"$cppflags"}
1652 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001653
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001654 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001655 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001656 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001657 if ctx.Failed() {
1658 return
1659 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001660 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001661 }
1662
Colin Crossca860ac2016-01-04 14:34:37 -08001663 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001664 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001665 if ctx.Failed() {
1666 return
1667 }
Colin Cross635c3b02016-05-18 15:37:25 -07001668 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001669
1670 // If a lib is directly included in any of the APEXes, unhide the stubs
1671 // variant having the latest version gets visible to make. In addition,
1672 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1673 // force anything in the make world to link against the stubs library.
1674 // (unless it is explicitly referenced via .bootstrap suffix or the
1675 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001676 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001677 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001678 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001679 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001680 c.Properties.HideFromMake = false // unhide
1681 // Note: this is still non-installable
1682 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001683
1684 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1685 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1686 if isSnapshotAware(ctx, c) {
1687 i.collectHeadersForSnapshot(ctx)
1688 }
1689 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001690 }
Colin Cross5049f022015-03-18 13:28:46 -07001691
Inseob Kim1f086e22019-05-09 13:29:15 +09001692 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001693 c.installer.install(ctx, c.outputFile.Path())
1694 if ctx.Failed() {
1695 return
Colin Crossca860ac2016-01-04 14:34:37 -08001696 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001697 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1698 // If the module has been specifically configure to not be installed then
1699 // skip the installation as otherwise it will break when running inside make
1700 // as the output path to install will not be specified. Not all uninstallable
1701 // modules can skip installation as some are needed for resolving make side
1702 // dependencies.
1703 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001704 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001705}
1706
Colin Cross0ea8ba82019-06-06 14:33:29 -07001707func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001708 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001709 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001710 }
Colin Crossca860ac2016-01-04 14:34:37 -08001711 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001712}
1713
Colin Crossca860ac2016-01-04 14:34:37 -08001714func (c *Module) begin(ctx BaseModuleContext) {
1715 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001716 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001717 }
Colin Crossca860ac2016-01-04 14:34:37 -08001718 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001719 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001720 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001721 if c.stl != nil {
1722 c.stl.begin(ctx)
1723 }
Colin Cross16b23492016-01-06 14:41:07 -08001724 if c.sanitize != nil {
1725 c.sanitize.begin(ctx)
1726 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001727 if c.coverage != nil {
1728 c.coverage.begin(ctx)
1729 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001730 if c.sabi != nil {
1731 c.sabi.begin(ctx)
1732 }
Justin Yun8effde42017-06-23 19:24:43 +09001733 if c.vndkdep != nil {
1734 c.vndkdep.begin(ctx)
1735 }
Stephen Craneba090d12017-05-09 15:44:35 -07001736 if c.lto != nil {
1737 c.lto.begin(ctx)
1738 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001739 if c.pgo != nil {
1740 c.pgo.begin(ctx)
1741 }
Colin Crossca860ac2016-01-04 14:34:37 -08001742 for _, feature := range c.features {
1743 feature.begin(ctx)
1744 }
Dan Albert92fe7402020-07-15 13:33:30 -07001745 if ctx.useSdk() && c.IsSdkVariant() {
Dan Albert1a246272020-07-06 14:49:35 -07001746 version, err := nativeApiLevelFromUser(ctx, ctx.sdkVersion())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001747 if err != nil {
1748 ctx.PropertyErrorf("sdk_version", err.Error())
Dan Albert1a246272020-07-06 14:49:35 -07001749 c.Properties.Sdk_version = nil
1750 } else {
1751 c.Properties.Sdk_version = StringPtr(version.String())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001752 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001753 }
Colin Crossca860ac2016-01-04 14:34:37 -08001754}
1755
Colin Cross37047f12016-12-13 17:06:13 -08001756func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001757 deps := Deps{}
1758
1759 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001760 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001761 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001762 // Add the PGO dependency (the clang_rt.profile runtime library), which
1763 // sometimes depends on symbols from libgcc, before libgcc gets added
1764 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001765 if c.pgo != nil {
1766 deps = c.pgo.deps(ctx, deps)
1767 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001768 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001769 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001770 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001771 if c.stl != nil {
1772 deps = c.stl.deps(ctx, deps)
1773 }
Colin Cross16b23492016-01-06 14:41:07 -08001774 if c.sanitize != nil {
1775 deps = c.sanitize.deps(ctx, deps)
1776 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001777 if c.coverage != nil {
1778 deps = c.coverage.deps(ctx, deps)
1779 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001780 if c.sabi != nil {
1781 deps = c.sabi.deps(ctx, deps)
1782 }
Justin Yun8effde42017-06-23 19:24:43 +09001783 if c.vndkdep != nil {
1784 deps = c.vndkdep.deps(ctx, deps)
1785 }
Stephen Craneba090d12017-05-09 15:44:35 -07001786 if c.lto != nil {
1787 deps = c.lto.deps(ctx, deps)
1788 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001789 for _, feature := range c.features {
1790 deps = feature.deps(ctx, deps)
1791 }
1792
Colin Crossb6715442017-10-24 11:13:31 -07001793 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1794 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1795 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1796 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1797 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1798 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001799 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001800
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001801 for _, lib := range deps.ReexportSharedLibHeaders {
1802 if !inList(lib, deps.SharedLibs) {
1803 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1804 }
1805 }
1806
1807 for _, lib := range deps.ReexportStaticLibHeaders {
1808 if !inList(lib, deps.StaticLibs) {
1809 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1810 }
1811 }
1812
Colin Cross5950f382016-12-13 12:50:57 -08001813 for _, lib := range deps.ReexportHeaderLibHeaders {
1814 if !inList(lib, deps.HeaderLibs) {
1815 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1816 }
1817 }
1818
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001819 for _, gen := range deps.ReexportGeneratedHeaders {
1820 if !inList(gen, deps.GeneratedHeaders) {
1821 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1822 }
1823 }
1824
Colin Crossc99deeb2016-04-11 15:06:20 -07001825 return deps
1826}
1827
Dan Albert7e9d2952016-08-04 13:02:36 -07001828func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001829 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001830 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001831 moduleContextImpl: moduleContextImpl{
1832 mod: c,
1833 },
1834 }
1835 ctx.ctx = ctx
1836
Colin Crossca860ac2016-01-04 14:34:37 -08001837 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001838}
1839
Jiyong Park7ed9de32018-10-15 22:25:07 +09001840// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001841func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001842 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1843 version := name[sharp+1:]
1844 libname := name[:sharp]
1845 return libname, version
1846 }
1847 return name, ""
1848}
1849
Dan Albert92fe7402020-07-15 13:33:30 -07001850func GetCrtVariations(ctx android.BottomUpMutatorContext,
1851 m LinkableInterface) []blueprint.Variation {
1852 if ctx.Os() != android.Android {
1853 return nil
1854 }
1855 if m.UseSdk() {
1856 return []blueprint.Variation{
1857 {Mutator: "sdk", Variation: "sdk"},
1858 {Mutator: "ndk_api", Variation: m.SdkVersion()},
1859 }
1860 }
1861 return []blueprint.Variation{
1862 {Mutator: "sdk", Variation: ""},
1863 }
1864}
1865
Colin Cross1e676be2016-10-12 14:38:15 -07001866func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001867 if !c.Enabled() {
1868 return
1869 }
1870
Colin Cross37047f12016-12-13 17:06:13 -08001871 ctx := &depsContext{
1872 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001873 moduleContextImpl: moduleContextImpl{
1874 mod: c,
1875 },
1876 }
1877 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001878
Colin Crossc99deeb2016-04-11 15:06:20 -07001879 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001880
Yo Chiang219968c2020-09-22 18:45:04 +08001881 c.Properties.AndroidMkSystemSharedLibs = deps.SystemSharedLibs
1882
Dan Albert914449f2016-06-17 16:45:24 -07001883 variantNdkLibs := []string{}
1884 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001885 if ctx.Os() == android.Android {
Inseob Kimeec88e12020-01-22 11:11:29 +09001886 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001887 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001888 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001889 // 1. Name of an NDK library that refers to a prebuilt module.
1890 // For each of these, it adds the name of the prebuilt module (which will be in
1891 // prebuilts/ndk) to the list of nonvariant libs.
1892 // 2. Name of an NDK library that refers to an ndk_library module.
1893 // For each of these, it adds the name of the ndk_library module to the list of
1894 // variant libs.
1895 // 3. Anything else (so anything that isn't an NDK library).
1896 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001897 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001898 // The caller can then know to add the variantLibs dependencies differently from the
1899 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001900
Inseob Kim9516ee92019-05-09 10:56:13 +09001901 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001902 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1903
1904 rewriteVendorLibs := func(lib string) string {
1905 if isLlndkLibrary(lib, ctx.Config()) {
1906 return lib + llndkLibrarySuffix
1907 }
1908
1909 // only modules with BOARD_VNDK_VERSION uses snapshot.
1910 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1911 return lib
1912 }
1913
1914 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1915 return snapshot
1916 }
1917
1918 return lib
1919 }
1920
1921 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001922 variantLibs = []string{}
1923 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001924 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001925 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001926 name, _ := StubsLibNameAndVersion(entry)
Dan Albertde5aade2020-06-30 12:32:51 -07001927 if ctx.useSdk() && inList(name, ndkKnownLibs) {
1928 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +09001929 } else if ctx.useVndk() {
1930 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001931 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001932 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001933 if actx.OtherModuleExists(vendorPublicLib) {
1934 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1935 } else {
1936 // This can happen if vendor_public_library module is defined in a
1937 // namespace that isn't visible to the current module. In that case,
1938 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001939 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001940 }
Dan Albert914449f2016-06-17 16:45:24 -07001941 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001942 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001943 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001944 }
1945 }
Dan Albert914449f2016-06-17 16:45:24 -07001946 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001947 }
1948
Inseob Kimeec88e12020-01-22 11:11:29 +09001949 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1950 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1951 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1952 if ctx.useVndk() {
1953 for idx, lib := range deps.RuntimeLibs {
1954 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1955 }
1956 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001957 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001958
Jiyong Park7e636d02019-01-28 16:16:54 +09001959 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001960 if c.linker != nil {
1961 if library, ok := c.linker.(*libraryDecorator); ok {
1962 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001963 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001964 }
1965 }
Colin Crossd48fe732020-09-23 20:37:24 -07001966 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
1967 if library.buildStubs() {
1968 buildStubs = true
1969 }
1970 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001971 }
1972
Inseob Kimeec88e12020-01-22 11:11:29 +09001973 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1974 // only modules with BOARD_VNDK_VERSION uses snapshot.
1975 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1976 return lib
1977 }
1978
1979 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1980 return snapshot
1981 }
1982
1983 return lib
1984 }
1985
1986 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001987 for _, lib := range deps.HeaderLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001988 depTag := libraryDependencyTag{Kind: headerLibraryDependency}
Colin Cross32ec36c2016-12-15 07:39:51 -08001989 if inList(lib, deps.ReexportHeaderLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001990 depTag.reexportFlags = true
Colin Cross32ec36c2016-12-15 07:39:51 -08001991 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001992
1993 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1994
Jiyong Park7e636d02019-01-28 16:16:54 +09001995 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001996 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001997 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001998 } else {
1999 actx.AddVariationDependencies(nil, depTag, lib)
2000 }
2001 }
2002
2003 if buildStubs {
2004 // Stubs lib does not have dependency to other static/shared libraries.
2005 // Don't proceed.
2006 return
Colin Cross32ec36c2016-12-15 07:39:51 -08002007 }
Colin Cross5950f382016-12-13 12:50:57 -08002008
Inseob Kimc0907f12019-02-08 21:00:45 +09002009 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09002010 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09002011
Jiyong Park5d1598f2019-02-25 22:14:17 +09002012 for _, lib := range deps.WholeStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002013 depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
Jiyong Park5d1598f2019-02-25 22:14:17 +09002014 if impl, ok := syspropImplLibraries[lib]; ok {
2015 lib = impl
2016 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002017
2018 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
2019
Jiyong Park5d1598f2019-02-25 22:14:17 +09002020 actx.AddVariationDependencies([]blueprint.Variation{
2021 {Mutator: "link", Variation: "static"},
2022 }, depTag, lib)
2023 }
2024
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002025 for _, lib := range deps.StaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002026 depTag := libraryDependencyTag{Kind: staticLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002027 if inList(lib, deps.ReexportStaticLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002028 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002029 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002030
2031 if impl, ok := syspropImplLibraries[lib]; ok {
2032 lib = impl
2033 }
2034
Inseob Kimeec88e12020-01-22 11:11:29 +09002035 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
2036
Dan Willemsen59339a22018-07-22 21:18:45 -07002037 actx.AddVariationDependencies([]blueprint.Variation{
2038 {Mutator: "link", Variation: "static"},
2039 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002040 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002041
Jooyung Han75568392020-03-20 04:29:24 +09002042 // staticUnwinderDep is treated as staticDep for Q apexes
2043 // so that native libraries/binaries are linked with static unwinder
2044 // because Q libc doesn't have unwinder APIs
2045 if deps.StaticUnwinderIfLegacy {
Colin Cross6e511a92020-07-27 21:26:48 -07002046 depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002047 actx.AddVariationDependencies([]blueprint.Variation{
2048 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07002049 }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002050 }
2051
Inseob Kimeec88e12020-01-22 11:11:29 +09002052 for _, lib := range deps.LateStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002053 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
Inseob Kimeec88e12020-01-22 11:11:29 +09002054 actx.AddVariationDependencies([]blueprint.Variation{
2055 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07002056 }, depTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
Inseob Kimeec88e12020-01-22 11:11:29 +09002057 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002058
Colin Cross6e511a92020-07-27 21:26:48 -07002059 addSharedLibDependencies := func(depTag libraryDependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002060 var variations []blueprint.Variation
2061 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han624d35c2020-04-10 12:57:24 +09002062 if version != "" && VersionVariantAvailable(c) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002063 // Version is explicitly specified. i.e. libFoo#30
2064 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Colin Cross6e511a92020-07-27 21:26:48 -07002065 depTag.explicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09002066 }
Colin Crossd1f898e2020-08-18 18:35:15 -07002067 deps := actx.AddVariationDependencies(variations, depTag, name)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002068
Jooyung Han03b51852020-02-26 22:45:42 +09002069 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002070 // The stubs library will be used when the depending module is built for APEX and
2071 // the dependent module is not in the same APEX.
Jooyung Han624d35c2020-04-10 12:57:24 +09002072 if version == "" && VersionVariantAvailable(c) {
Colin Crossd1f898e2020-08-18 18:35:15 -07002073 if dep, ok := deps[0].(*Module); ok {
2074 for _, ver := range dep.AllStubsVersions() {
2075 // Note that depTag.ExplicitlyVersioned is false in this case.
2076 ctx.AddVariationDependencies([]blueprint.Variation{
2077 {Mutator: "link", Variation: "shared"},
2078 {Mutator: "version", Variation: ver},
2079 }, depTag, name)
2080 }
Jooyung Han03b51852020-02-26 22:45:42 +09002081 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002082 }
2083 }
2084
Jiyong Park7ed9de32018-10-15 22:25:07 +09002085 // shared lib names without the #version suffix
2086 var sharedLibNames []string
2087
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002088 for _, lib := range deps.SharedLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002089 depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002090 if inList(lib, deps.ReexportSharedLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002091 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002092 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002093
2094 if impl, ok := syspropImplLibraries[lib]; ok {
2095 lib = impl
2096 }
2097
Jiyong Park73c54ee2019-10-22 20:31:18 +09002098 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09002099 sharedLibNames = append(sharedLibNames, name)
2100
Jiyong Park25fc6a92018-11-18 18:02:45 +09002101 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002102 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002103
Jiyong Park7ed9de32018-10-15 22:25:07 +09002104 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002105 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09002106 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
2107 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
2108 // linking against both the stubs lib and the non-stubs lib at the same time.
2109 continue
2110 }
Colin Cross6e511a92020-07-27 21:26:48 -07002111 depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
2112 addSharedLibDependencies(depTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09002113 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002114
Dan Willemsen59339a22018-07-22 21:18:45 -07002115 actx.AddVariationDependencies([]blueprint.Variation{
2116 {Mutator: "link", Variation: "shared"},
Chris Parsons79d66a52020-06-05 17:26:16 -04002117 }, dataLibDepTag, deps.DataLibs...)
2118
2119 actx.AddVariationDependencies([]blueprint.Variation{
2120 {Mutator: "link", Variation: "shared"},
Dan Willemsen59339a22018-07-22 21:18:45 -07002121 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08002122
Colin Cross68861832016-07-08 10:41:41 -07002123 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002124
2125 for _, gen := range deps.GeneratedHeaders {
2126 depTag := genHeaderDepTag
2127 if inList(gen, deps.ReexportGeneratedHeaders) {
2128 depTag = genHeaderExportDepTag
2129 }
2130 actx.AddDependency(c, depTag, gen)
2131 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002132
Colin Cross42d48b72018-08-29 14:10:52 -07002133 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07002134
Inseob Kim1042d292020-06-01 23:23:05 +09002135 vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())
2136
Dan Albert92fe7402020-07-15 13:33:30 -07002137 crtVariations := GetCrtVariations(ctx, c)
Colin Crossc99deeb2016-04-11 15:06:20 -07002138 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002139 actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
2140 rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08002141 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002142 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002143 actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
2144 rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07002145 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002146 if deps.LinkerFlagsFile != "" {
2147 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
2148 }
2149 if deps.DynamicLinker != "" {
2150 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002151 }
Dan Albert914449f2016-06-17 16:45:24 -07002152
2153 version := ctx.sdkVersion()
Colin Cross6e511a92020-07-27 21:26:48 -07002154
2155 ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002156 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002157 {Mutator: "ndk_api", Variation: version},
2158 {Mutator: "link", Variation: "shared"},
2159 }, ndkStubDepTag, variantNdkLibs...)
Colin Cross6e511a92020-07-27 21:26:48 -07002160
2161 ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002162 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002163 {Mutator: "ndk_api", Variation: version},
2164 {Mutator: "link", Variation: "shared"},
2165 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002166
2167 if vndkdep := c.vndkdep; vndkdep != nil {
2168 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002169 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002170 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002171 {Mutator: "link", Variation: "shared"},
2172 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002173 }
2174 }
Colin Cross6362e272015-10-29 15:25:03 -07002175}
Colin Cross21b9a242015-03-24 14:15:58 -07002176
Colin Crosse40b4ea2018-10-02 22:25:58 -07002177func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002178 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2179 c.beginMutator(ctx)
2180 }
2181}
2182
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002183// Whether a module can link to another module, taking into
2184// account NDK linking.
Colin Cross6e511a92020-07-27 21:26:48 -07002185func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface,
2186 tag blueprint.DependencyTag) {
2187
2188 switch t := tag.(type) {
2189 case dependencyTag:
2190 if t != vndkExtDepTag {
2191 return
2192 }
2193 case libraryDependencyTag:
2194 default:
2195 return
2196 }
2197
Ivan Lozano52767be2019-10-18 14:49:46 -07002198 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002199 // Host code is not restricted
2200 return
2201 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002202
2203 // VNDK is cc.Module supported only for now.
2204 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002205 // Though vendor code is limited by the vendor mutator,
2206 // each vendor-available module needs to check
2207 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002208 if ccTo, ok := to.(*Module); ok {
2209 if ccFrom.vndkdep != nil {
2210 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2211 }
2212 } else {
2213 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002214 }
2215 return
2216 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002217 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002218 // Platform code can link to anything
2219 return
2220 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002221 if from.InRamdisk() {
2222 // Ramdisk code is not NDK
2223 return
2224 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002225 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002226 // Recovery code is not NDK
2227 return
2228 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002229 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002230 // These are always allowed
2231 return
2232 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002233 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002234 // These are allowed, but they don't set sdk_version
2235 return
2236 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002237 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002238 // These aren't real libraries, but are the stub shared libraries that are included in
2239 // the NDK.
2240 return
2241 }
Logan Chien834b9a62019-01-14 15:39:03 +08002242
Ivan Lozano52767be2019-10-18 14:49:46 -07002243 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002244 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2245 // to link to libc++ (non-NDK and without sdk_version).
2246 return
2247 }
2248
Ivan Lozano52767be2019-10-18 14:49:46 -07002249 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002250 // NDK code linking to platform code is never okay.
2251 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002252 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002253 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002254 }
2255
2256 // At this point we know we have two NDK libraries, but we need to
2257 // check that we're not linking against anything built against a higher
2258 // API level, as it is only valid to link against older or equivalent
2259 // APIs.
2260
Inseob Kim01a28722018-04-11 09:48:45 +09002261 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002262 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002263 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002264 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002265 // Current can't be linked against by anything else.
2266 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002267 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002268 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002269 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002270 if err != nil {
2271 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002272 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002273 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002274 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002275 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002276 if err != nil {
2277 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002278 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002279 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002280 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002281
Inseob Kim01a28722018-04-11 09:48:45 +09002282 if toApi > fromApi {
2283 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002284 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002285 }
2286 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002287 }
Dan Albert202fe492017-12-15 13:56:59 -08002288
2289 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002290 fromStl := from.SelectedStl()
2291 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002292 if fromStl == "" || toStl == "" {
2293 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002294 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002295 // We can be permissive with the system "STL" since it is only the C++
2296 // ABI layer, but in the future we should make sure that everyone is
2297 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002298 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002299 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002300 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2301 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002302 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002303}
2304
Jiyong Park5fb8c102018-04-09 12:03:06 +09002305// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002306// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2307// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002308// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002309func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2310 check := func(child, parent android.Module) bool {
2311 to, ok := child.(*Module)
2312 if !ok {
2313 // follow thru cc.Defaults, etc.
2314 return true
2315 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002316
Jooyung Hana70f0672019-01-18 15:20:43 +09002317 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2318 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002319 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002320
2321 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002322 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002323 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002324 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002325
Jooyung Han0302a842019-10-30 18:43:49 +09002326 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002327 return false
2328 }
2329
2330 var stringPath []string
2331 for _, m := range ctx.GetWalkPath() {
2332 stringPath = append(stringPath, m.Name())
2333 }
2334 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2335 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2336 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2337 return false
2338 }
2339 if module, ok := ctx.Module().(*Module); ok {
2340 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002341 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002342 ctx.WalkDeps(check)
2343 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002344 }
2345 }
2346}
2347
Colin Crossc99deeb2016-04-11 15:06:20 -07002348// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002349func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002350 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002351
Ivan Lozano183a3212019-10-18 14:18:45 -07002352 directStaticDeps := []LinkableInterface{}
2353 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002354
Inseob Kim69378442019-06-03 19:10:47 +09002355 reexportExporter := func(exporter exportedFlagsProducer) {
2356 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2357 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2358 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2359 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002360 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002361 }
2362
Jooyung Hande34d232020-07-23 13:04:15 +09002363 // For the dependency from platform to apex, use the latest stubs
2364 c.apexSdkVersion = android.FutureApiLevel
2365 if !c.IsForPlatform() {
Dan Albertc8060532020-07-22 22:32:17 -07002366 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion(ctx)
Jooyung Hande34d232020-07-23 13:04:15 +09002367 }
2368
2369 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2370 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2371 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2372 // (b/144430859)
2373 c.apexSdkVersion = android.FutureApiLevel
2374 }
2375
Colin Crossd11fcda2017-10-23 17:59:01 -07002376 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002377 depName := ctx.OtherModuleName(dep)
2378 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002379
Ivan Lozano52767be2019-10-18 14:49:46 -07002380 ccDep, ok := dep.(LinkableInterface)
2381 if !ok {
2382
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002383 // handling for a few module types that aren't cc Module but that are also supported
2384 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002385 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002386 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002387 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2388 genRule.GeneratedSourceFiles()...)
2389 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002390 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002391 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002392 // Support exported headers from a generated_sources dependency
2393 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002394 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002395 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09002396 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002397 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002398 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002399 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002400 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002401 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002402 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2403 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002404 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002405 // 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 +09002406 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002407
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002408 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002409 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002410 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002411 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002412 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002413 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002414 files := genRule.GeneratedSourceFiles()
2415 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002416 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002417 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002418 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 -07002419 }
2420 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002421 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002422 }
Colin Crossca860ac2016-01-04 14:34:37 -08002423 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002424 return
2425 }
2426
Colin Crossfe17f6f2019-03-28 19:30:56 -07002427 if depTag == android.ProtoPluginDepTag {
2428 return
2429 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002430 if depTag == llndkImplDep {
2431 return
2432 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002433
Colin Crossd11fcda2017-10-23 17:59:01 -07002434 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002435 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2436 return
2437 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002438 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002439 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2440 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002441 return
2442 }
2443
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002444 // re-exporting flags
2445 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002446 // reusing objects only make sense for cc.Modules.
2447 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002448 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002449 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002450 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002451 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002452 return
2453 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002454 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002455
Jiyong Parke4bb9862019-02-01 00:31:10 +09002456 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002457 // staticVariants are a cc.Module specific concept.
2458 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002459 c.staticVariant = ccDep
2460 return
2461 }
2462 }
2463
Colin Cross6e511a92020-07-27 21:26:48 -07002464 checkLinkType(ctx, c, ccDep, depTag)
2465
2466 linkFile := ccDep.OutputFile()
2467
2468 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
2469 // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
Dan Albertc8060532020-07-22 22:32:17 -07002470 if libDepTag.staticUnwinder && c.apexSdkVersion.GreaterThan(android.SdkVersion_Android10) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002471 return
2472 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002473
Colin Cross6e511a92020-07-27 21:26:48 -07002474 if ccDep.CcLibrary() && !libDepTag.static() {
Ivan Lozano52767be2019-10-18 14:49:46 -07002475 depIsStubs := ccDep.BuildStubs()
Jooyung Han624d35c2020-04-10 12:57:24 +09002476 depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
Colin Crossaede88c2020-08-11 12:17:01 -07002477 depInSameApexes := android.DirectlyInAllApexes(c.InApexes(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002478 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002479
2480 var useThisDep bool
Colin Cross6e511a92020-07-27 21:26:48 -07002481 if depIsStubs && libDepTag.explicitlyVersioned {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002482 // Always respect dependency to the versioned stubs (i.e. libX#10)
2483 useThisDep = true
2484 } else if !depHasStubs {
2485 // Use non-stub variant if that is the only choice
2486 // (i.e. depending on a lib without stubs.version property)
2487 useThisDep = true
2488 } else if c.IsForPlatform() {
2489 // If not building for APEX, use stubs only when it is from
2490 // an APEX (and not from platform)
2491 useThisDep = (depInPlatform != depIsStubs)
Jooyung Han624d35c2020-04-10 12:57:24 +09002492 if c.bootstrap() {
2493 // However, for host, ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002494 // always link to non-stub variant
2495 useThisDep = !depIsStubs
2496 }
Jiyong Park62304bb2020-04-13 16:19:48 +09002497 for _, testFor := range c.TestFor() {
2498 // Another exception: if this module is bundled with an APEX, then
2499 // it is linked with the non-stub variant of a module in the APEX
2500 // as if this is part of the APEX.
2501 if android.DirectlyInApex(testFor, depName) {
2502 useThisDep = !depIsStubs
2503 break
2504 }
2505 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002506 } else {
Colin Crossaede88c2020-08-11 12:17:01 -07002507 // If building for APEX, use stubs when the parent is in any APEX that
2508 // the child is not in.
2509 useThisDep = (depInSameApexes != depIsStubs)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002510 }
2511
Jooyung Han03b51852020-02-26 22:45:42 +09002512 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
Colin Cross6e511a92020-07-27 21:26:48 -07002513 if useThisDep && depIsStubs && !libDepTag.explicitlyVersioned {
Colin Cross7812fd32020-09-25 12:35:10 -07002514 versionToUse, err := c.ChooseSdkVersion(ctx, ccDep.StubsVersions(), c.apexSdkVersion)
Jooyung Han03b51852020-02-26 22:45:42 +09002515 if err != nil {
2516 ctx.OtherModuleErrorf(dep, err.Error())
2517 return
2518 }
2519 if versionToUse != ccDep.StubsVersion() {
2520 useThisDep = false
2521 }
2522 }
2523
Jiyong Park25fc6a92018-11-18 18:02:45 +09002524 if !useThisDep {
2525 return // stop processing this dep
2526 }
2527 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002528 if c.UseVndk() {
2529 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2530 // by default, use current version of LLNDK
2531 versionToUse := ""
Colin Crossd1f898e2020-08-18 18:35:15 -07002532 versions := m.AllStubsVersions()
Colin Crosse07f2312020-08-13 11:24:56 -07002533 if c.ApexVariationName() != "" && len(versions) > 0 {
Jooyung Han61b66e92020-03-21 14:21:46 +00002534 // if this is for use_vendor apex && dep has stubsVersions
2535 // apply the same rule of apex sdk enforcement to choose right version
2536 var err error
Colin Cross7812fd32020-09-25 12:35:10 -07002537 versionToUse, err = c.ChooseSdkVersion(ctx, versions, c.apexSdkVersion)
Jooyung Han61b66e92020-03-21 14:21:46 +00002538 if err != nil {
2539 ctx.OtherModuleErrorf(dep, err.Error())
2540 return
2541 }
2542 }
2543 if versionToUse != ccDep.StubsVersion() {
2544 return
2545 }
2546 }
2547 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002548
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002549 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2550
Ivan Lozano52767be2019-10-18 14:49:46 -07002551 // Exporting flags only makes sense for cc.Modules
2552 if _, ok := ccDep.(*Module); ok {
2553 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002554 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002555 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002556 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002557
Colin Cross6e511a92020-07-27 21:26:48 -07002558 if libDepTag.reexportFlags {
Ivan Lozano52767be2019-10-18 14:49:46 -07002559 reexportExporter(i)
2560 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2561 // Re-exported shared library headers must be included as well since they can help us with type information
2562 // about template instantiations (instantiated from their headers).
2563 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2564 // scripts.
2565 c.sabi.Properties.ReexportedIncludes = append(
2566 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2567 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002568 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002569 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002570
Colin Cross6e511a92020-07-27 21:26:48 -07002571 var ptr *android.Paths
2572 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002573
Colin Cross6e511a92020-07-27 21:26:48 -07002574 depFile := android.OptionalPath{}
Colin Cross26c34ed2016-09-30 17:10:16 -07002575
Colin Cross6e511a92020-07-27 21:26:48 -07002576 switch {
2577 case libDepTag.header():
2578 // nothing
2579 case libDepTag.shared():
2580 ptr = &depPaths.SharedLibs
2581 switch libDepTag.Order {
2582 case earlyLibraryDependency:
2583 ptr = &depPaths.EarlySharedLibs
2584 depPtr = &depPaths.EarlySharedLibsDeps
2585 case normalLibraryDependency:
2586 ptr = &depPaths.SharedLibs
2587 depPtr = &depPaths.SharedLibsDeps
2588 directSharedDeps = append(directSharedDeps, ccDep)
2589 case lateLibraryDependency:
2590 ptr = &depPaths.LateSharedLibs
2591 depPtr = &depPaths.LateSharedLibsDeps
2592 default:
2593 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Colin Crossc99deeb2016-04-11 15:06:20 -07002594 }
Colin Cross6e511a92020-07-27 21:26:48 -07002595 depFile = ccDep.Toc()
2596 case libDepTag.static():
2597 if libDepTag.wholeStatic {
2598 ptr = &depPaths.WholeStaticLibs
2599 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2600 ctx.ModuleErrorf("module %q not a static library", depName)
2601 return
Inseob Kim752edec2020-03-14 01:30:34 +09002602 }
2603
Colin Cross6e511a92020-07-27 21:26:48 -07002604 // Because the static library objects are included, this only makes sense
2605 // in the context of proper cc.Modules.
2606 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2607 staticLib := ccWholeStaticLib.linker.(libraryInterface)
Colin Crosse4f6eba2020-09-22 18:11:25 -07002608 if objs := staticLib.objs(); len(objs.objFiles) > 0 {
2609 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(objs)
Colin Cross6e511a92020-07-27 21:26:48 -07002610 } else {
Colin Crosse4f6eba2020-09-22 18:11:25 -07002611 // This case normally catches prebuilt static
2612 // libraries, but it can also occur when
2613 // AllowMissingDependencies is on and the
2614 // dependencies has no sources of its own
2615 // but has a whole_static_libs dependency
2616 // on a missing library. We want to depend
2617 // on the .a file so that there is something
2618 // in the dependency tree that contains the
2619 // error rule for the missing transitive
2620 // dependency.
2621 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
Colin Cross6e511a92020-07-27 21:26:48 -07002622 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002623 } else {
Colin Cross6e511a92020-07-27 21:26:48 -07002624 ctx.ModuleErrorf(
2625 "non-cc.Modules cannot be included as whole static libraries.", depName)
2626 return
2627 }
2628
2629 } else {
2630 switch libDepTag.Order {
2631 case earlyLibraryDependency:
2632 panic(fmt.Errorf("early static libs not suppported"))
2633 case normalLibraryDependency:
2634 // static dependencies will be handled separately so they can be ordered
2635 // using transitive dependencies.
2636 ptr = nil
2637 directStaticDeps = append(directStaticDeps, ccDep)
2638 case lateLibraryDependency:
2639 ptr = &depPaths.LateStaticLibs
2640 default:
2641 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Inseob Kimeec88e12020-01-22 11:11:29 +09002642 }
2643 }
2644 }
2645
Colin Cross6e511a92020-07-27 21:26:48 -07002646 if libDepTag.static() && !libDepTag.wholeStatic {
2647 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2648 ctx.ModuleErrorf("module %q not a static library", depName)
2649 return
2650 }
Logan Chien43d34c32017-12-20 01:17:32 +08002651
Colin Cross6e511a92020-07-27 21:26:48 -07002652 // When combining coverage files for shared libraries and executables, coverage files
2653 // in static libraries act as if they were whole static libraries. The same goes for
2654 // source based Abi dump files.
2655 if c, ok := ccDep.(*Module); ok {
2656 staticLib := c.linker.(libraryInterface)
2657 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2658 staticLib.objs().coverageFiles...)
2659 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2660 staticLib.objs().sAbiDumpFiles...)
2661 } else if c, ok := ccDep.(LinkableInterface); ok {
2662 // Handle non-CC modules here
2663 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2664 c.CoverageFiles()...)
Jiyong Parkde866cb2018-12-07 23:08:36 +09002665 }
2666 }
2667
Colin Cross6e511a92020-07-27 21:26:48 -07002668 if ptr != nil {
2669 if !linkFile.Valid() {
2670 if !ctx.Config().AllowMissingDependencies() {
2671 ctx.ModuleErrorf("module %q missing output file", depName)
2672 } else {
2673 ctx.AddMissingDependencies([]string{depName})
2674 }
2675 return
2676 }
2677 *ptr = append(*ptr, linkFile.Path())
2678 }
2679
2680 if depPtr != nil {
2681 dep := depFile
2682 if !dep.Valid() {
2683 dep = linkFile
2684 }
2685 *depPtr = append(*depPtr, dep.Path())
2686 }
2687
2688 makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix
2689 switch {
2690 case libDepTag.header():
Colin Cross370173e2020-07-29 12:48:33 -07002691 c.Properties.AndroidMkHeaderLibs = append(
2692 c.Properties.AndroidMkHeaderLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002693 case libDepTag.shared():
2694 if ccDep.CcLibrary() {
2695 if ccDep.BuildStubs() && android.InAnyApex(depName) {
2696 // Add the dependency to the APEX(es) providing the library so that
2697 // m <module> can trigger building the APEXes as well.
2698 for _, an := range android.GetApexesForModule(depName) {
2699 c.Properties.ApexesProvidingSharedLibs = append(
2700 c.Properties.ApexesProvidingSharedLibs, an)
2701 }
2702 }
2703 }
2704
2705 // Note: the order of libs in this list is not important because
2706 // they merely serve as Make dependencies and do not affect this lib itself.
Colin Cross370173e2020-07-29 12:48:33 -07002707 c.Properties.AndroidMkSharedLibs = append(
2708 c.Properties.AndroidMkSharedLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002709 // Record baseLibName for snapshots.
2710 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
2711 case libDepTag.static():
2712 if libDepTag.wholeStatic {
2713 c.Properties.AndroidMkWholeStaticLibs = append(
2714 c.Properties.AndroidMkWholeStaticLibs, makeLibName)
2715 } else {
2716 c.Properties.AndroidMkStaticLibs = append(
2717 c.Properties.AndroidMkStaticLibs, makeLibName)
2718 }
2719 }
2720 } else {
2721 switch depTag {
2722 case runtimeDepTag:
2723 c.Properties.AndroidMkRuntimeLibs = append(
2724 c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix)
2725 // Record baseLibName for snapshots.
2726 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
2727 case objDepTag:
2728 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
2729 case CrtBeginDepTag:
2730 depPaths.CrtBegin = linkFile
2731 case CrtEndDepTag:
2732 depPaths.CrtEnd = linkFile
2733 case dynamicLinkerDepTag:
2734 depPaths.DynamicLinker = linkFile
2735 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002736 }
Colin Crossca860ac2016-01-04 14:34:37 -08002737 })
2738
Jeff Gaston294356f2017-09-27 17:05:30 -07002739 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002740 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002741
Colin Crossdd84e052017-05-17 13:44:16 -07002742 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002743 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002744 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2745 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09002746 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002747 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2748 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002749 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002750 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002751 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002752
2753 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002754 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002755 }
Colin Crossdd84e052017-05-17 13:44:16 -07002756
Colin Crossca860ac2016-01-04 14:34:37 -08002757 return depPaths
2758}
2759
Colin Cross6e511a92020-07-27 21:26:48 -07002760// baseLibName trims known prefixes and suffixes
2761func baseLibName(depName string) string {
2762 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
2763 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
2764 libName = strings.TrimPrefix(libName, "prebuilt_")
2765 return libName
2766}
2767
2768func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
2769 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2770 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2771
2772 libName := baseLibName(depName)
2773 isLLndk := isLlndkLibrary(libName, ctx.Config())
2774 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
2775 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
2776
2777 if c, ok := ccDep.(*Module); ok {
2778 // Use base module name for snapshots when exporting to Makefile.
2779 if c.isSnapshotPrebuilt() {
2780 baseName := c.BaseModuleName()
2781
2782 if c.IsVndk() {
2783 return baseName + ".vendor"
2784 }
2785
2786 if vendorSuffixModules[baseName] {
2787 return baseName + ".vendor"
2788 } else {
2789 return baseName
2790 }
2791 }
2792 }
2793
2794 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
2795 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2796 // core module instead.
2797 return libName
2798 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
2799 // The vendor module in Make will have been renamed to not conflict with the core
2800 // module, so update the dependency name here accordingly.
2801 return libName + c.getNameSuffixWithVndkVersion(ctx)
2802 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
2803 return libName + vendorPublicLibrarySuffix
2804 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2805 return libName + ramdiskSuffix
2806 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
2807 return libName + recoverySuffix
2808 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
2809 return libName + nativeBridgeSuffix
2810 } else {
2811 return libName
2812 }
2813}
2814
Colin Crossca860ac2016-01-04 14:34:37 -08002815func (c *Module) InstallInData() bool {
2816 if c.installer == nil {
2817 return false
2818 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002819 return c.installer.inData()
2820}
2821
2822func (c *Module) InstallInSanitizerDir() bool {
2823 if c.installer == nil {
2824 return false
2825 }
2826 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002827 return true
2828 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002829 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002830}
2831
Yifan Hong1b3348d2020-01-21 15:53:22 -08002832func (c *Module) InstallInRamdisk() bool {
2833 return c.InRamdisk()
2834}
2835
Jiyong Parkf9332f12018-02-01 00:54:12 +09002836func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002837 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002838}
2839
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002840func (c *Module) MakeUninstallable() {
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002841 if c.installer == nil {
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002842 c.ModuleBase.MakeUninstallable()
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002843 return
2844 }
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002845 c.installer.makeUninstallable(c)
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002846}
2847
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002848func (c *Module) HostToolPath() android.OptionalPath {
2849 if c.installer == nil {
2850 return android.OptionalPath{}
2851 }
2852 return c.installer.hostToolPath()
2853}
2854
Nan Zhangd4e641b2017-07-12 12:55:28 -07002855func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2856 return c.outputFile
2857}
2858
Colin Cross41955e82019-05-29 14:40:35 -07002859func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2860 switch tag {
2861 case "":
2862 if c.outputFile.Valid() {
2863 return android.Paths{c.outputFile.Path()}, nil
2864 }
2865 return android.Paths{}, nil
2866 default:
2867 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002868 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002869}
2870
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002871func (c *Module) static() bool {
2872 if static, ok := c.linker.(interface {
2873 static() bool
2874 }); ok {
2875 return static.static()
2876 }
2877 return false
2878}
2879
Jiyong Park379de2f2018-12-19 02:47:14 +09002880func (c *Module) staticBinary() bool {
2881 if static, ok := c.linker.(interface {
2882 staticBinary() bool
2883 }); ok {
2884 return static.staticBinary()
2885 }
2886 return false
2887}
2888
Jiyong Park1d1119f2019-07-29 21:27:18 +09002889func (c *Module) header() bool {
2890 if h, ok := c.linker.(interface {
2891 header() bool
2892 }); ok {
2893 return h.header()
2894 }
2895 return false
2896}
2897
Inseob Kim7f283f42020-06-01 21:53:49 +09002898func (c *Module) binary() bool {
2899 if b, ok := c.linker.(interface {
2900 binary() bool
2901 }); ok {
2902 return b.binary()
2903 }
2904 return false
2905}
2906
Inseob Kim1042d292020-06-01 23:23:05 +09002907func (c *Module) object() bool {
2908 if o, ok := c.linker.(interface {
2909 object() bool
2910 }); ok {
2911 return o.object()
2912 }
2913 return false
2914}
2915
Jooyung Han38002912019-05-16 04:01:54 +09002916func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002917 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002918 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2919 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002920 return "native:vndk"
2921 }
Jooyung Han38002912019-05-16 04:01:54 +09002922 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002923 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002924 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002925 if Bool(c.VendorProperties.Vendor_available) {
2926 return "native:vndk"
2927 }
2928 return "native:vndk_private"
2929 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002930 if c.inProduct() {
2931 return "native:product"
2932 }
Jooyung Han38002912019-05-16 04:01:54 +09002933 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002934 } else if c.InRamdisk() {
2935 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002936 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002937 return "native:recovery"
2938 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2939 return "native:ndk:none:none"
2940 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2941 //family, link := getNdkStlFamilyAndLinkType(c)
2942 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002943 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002944 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002945 } else {
2946 return "native:platform"
2947 }
2948}
2949
Jiyong Park9d452992018-10-03 00:38:19 +09002950// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002951// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002952func (c *Module) IsInstallableToApex() bool {
2953 if shared, ok := c.linker.(interface {
2954 shared() bool
2955 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002956 // Stub libs and prebuilt libs in a versioned SDK are not
2957 // installable to APEX even though they are shared libs.
2958 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002959 } else if _, ok := c.linker.(testPerSrc); ok {
2960 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002961 }
2962 return false
2963}
2964
Jiyong Parka90ca002019-10-07 15:47:24 +09002965func (c *Module) AvailableFor(what string) bool {
2966 if linker, ok := c.linker.(interface {
2967 availableFor(string) bool
2968 }); ok {
2969 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2970 } else {
2971 return c.ApexModuleBase.AvailableFor(what)
2972 }
2973}
2974
Jiyong Park62304bb2020-04-13 16:19:48 +09002975func (c *Module) TestFor() []string {
2976 if test, ok := c.linker.(interface {
2977 testFor() []string
2978 }); ok {
2979 return test.testFor()
2980 } else {
2981 return c.ApexModuleBase.TestFor()
2982 }
2983}
2984
Colin Crossaede88c2020-08-11 12:17:01 -07002985func (c *Module) UniqueApexVariations() bool {
2986 if u, ok := c.compiler.(interface {
2987 uniqueApexVariations() bool
2988 }); ok {
2989 return u.uniqueApexVariations()
2990 } else {
2991 return false
2992 }
2993}
2994
Paul Duffin0cb37b92020-03-04 14:52:46 +00002995// Return true if the module is ever installable.
2996func (c *Module) EverInstallable() bool {
2997 return c.installer != nil &&
2998 // Check to see whether the module is actually ever installable.
2999 c.installer.everInstallable()
3000}
3001
Inseob Kim1f086e22019-05-09 13:29:15 +09003002func (c *Module) installable() bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00003003 ret := c.EverInstallable() &&
3004 // Check to see whether the module has been configured to not be installed.
3005 proptools.BoolDefault(c.Properties.Installable, true) &&
3006 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09003007
3008 // The platform variant doesn't need further condition. Apex variants however might not
3009 // be installable because it will likely to be included in the APEX and won't appear
3010 // in the system partition.
3011 if c.IsForPlatform() {
3012 return ret
3013 }
3014
3015 // Special case for modules that are configured to be installed to /data, which includes
3016 // test modules. For these modules, both APEX and non-APEX variants are considered as
3017 // installable. This is because even the APEX variants won't be included in the APEX, but
3018 // will anyway be installed to /data/*.
3019 // See b/146995717
3020 if c.InstallInData() {
3021 return ret
3022 }
3023
3024 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09003025}
3026
Logan Chien41eabe62019-04-10 13:33:58 +08003027func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
3028 if c.linker != nil {
3029 if library, ok := c.linker.(*libraryDecorator); ok {
3030 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
3031 }
3032 }
3033}
3034
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003035func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Colin Cross6e511a92020-07-27 21:26:48 -07003036 depTag := ctx.OtherModuleDependencyTag(dep)
3037 libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
3038
3039 if cc, ok := dep.(*Module); ok {
3040 if cc.HasStubsVariants() {
3041 if isLibDepTag && libDepTag.shared() {
3042 // dynamic dep to a stubs lib crosses APEX boundary
3043 return false
Jiyong Parkd7536ba2020-01-16 17:14:23 +09003044 }
Colin Cross6e511a92020-07-27 21:26:48 -07003045 if IsRuntimeDepTag(depTag) {
3046 // runtime dep to a stubs lib also crosses APEX boundary
Jiyong Parkd7536ba2020-01-16 17:14:23 +09003047 return false
3048 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003049 }
Colin Crossaac32222020-07-29 12:51:56 -07003050 if isLibDepTag && c.static() && libDepTag.shared() {
Colin Cross6e511a92020-07-27 21:26:48 -07003051 // shared_lib dependency from a static lib is considered as crossing
3052 // the APEX boundary because the dependency doesn't actually is
3053 // linked; the dependency is used only during the compilation phase.
3054 return false
3055 }
3056 }
3057 if depTag == llndkImplDep {
Jiyong Park7d95a512020-05-10 15:16:24 +09003058 // We don't track beyond LLNDK
3059 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003060 }
3061 return true
3062}
3063
Dan Albertc8060532020-07-22 22:32:17 -07003064func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
3065 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +09003066 // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
3067 if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
3068 return nil
3069 }
3070 // b/154569636: set min_sdk_version correctly for toolchain_libraries
3071 if c.ToolchainLibrary() {
3072 return nil
3073 }
3074 // We don't check for prebuilt modules
3075 if _, ok := c.linker.(prebuiltLinkerInterface); ok {
3076 return nil
3077 }
3078 minSdkVersion := c.MinSdkVersion()
3079 if minSdkVersion == "apex_inherit" {
3080 return nil
3081 }
3082 if minSdkVersion == "" {
3083 // JNI libs within APK-in-APEX fall into here
3084 // Those are okay to set sdk_version instead
3085 // We don't have to check if this is a SDK variant because
3086 // non-SDK variant resets sdk_version, which works too.
3087 minSdkVersion = c.SdkVersion()
3088 }
Dan Albertc8060532020-07-22 22:32:17 -07003089 if minSdkVersion == "" {
3090 return fmt.Errorf("neither min_sdk_version nor sdk_version specificed")
3091 }
3092 // Not using nativeApiLevelFromUser because the context here is not
3093 // necessarily a native context.
3094 ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
Jooyung Han749dc692020-04-15 11:03:39 +09003095 if err != nil {
3096 return err
3097 }
Dan Albertc8060532020-07-22 22:32:17 -07003098
3099 if ver.GreaterThan(sdkVersion) {
Jooyung Han749dc692020-04-15 11:03:39 +09003100 return fmt.Errorf("newer SDK(%v)", ver)
3101 }
3102 return nil
3103}
3104
Colin Cross2ba19d92015-05-07 15:44:20 -07003105//
Colin Crosscfad1192015-11-02 16:43:11 -08003106// Defaults
3107//
Colin Crossca860ac2016-01-04 14:34:37 -08003108type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07003109 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07003110 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09003111 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08003112}
3113
Patrice Arrudac249c712019-03-19 17:00:29 -07003114// cc_defaults provides a set of properties that can be inherited by other cc
3115// modules. A module can use the properties from a cc_defaults using
3116// `defaults: ["<:default_module_name>"]`. Properties of both modules are
3117// merged (when possible) by prepending the default module's values to the
3118// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07003119func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07003120 return DefaultsFactory()
3121}
3122
Colin Cross36242852017-06-23 15:06:31 -07003123func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08003124 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08003125
Colin Cross36242852017-06-23 15:06:31 -07003126 module.AddProperties(props...)
3127 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08003128 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07003129 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003130 &BaseCompilerProperties{},
3131 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01003132 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003133 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07003134 &StaticProperties{},
3135 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07003136 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003137 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003138 &TestProperties{},
3139 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07003140 &BenchmarkProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07003141 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003142 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08003143 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07003144 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07003145 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07003146 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08003147 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08003148 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09003149 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07003150 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07003151 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08003152 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07003153 )
Colin Crosscfad1192015-11-02 16:43:11 -08003154
Jooyung Hancc372c52019-09-25 15:18:44 +09003155 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07003156
3157 return module
Colin Crosscfad1192015-11-02 16:43:11 -08003158}
3159
Jiyong Park6a43f042017-10-12 23:05:00 +09003160func squashVendorSrcs(m *Module) {
3161 if lib, ok := m.compiler.(*libraryDecorator); ok {
3162 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3163 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
3164
3165 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3166 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003167
3168 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3169 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
Jiyong Park6a43f042017-10-12 23:05:00 +09003170 }
3171}
3172
Jiyong Parkf9332f12018-02-01 00:54:12 +09003173func squashRecoverySrcs(m *Module) {
3174 if lib, ok := m.compiler.(*libraryDecorator); ok {
3175 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3176 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
3177
3178 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3179 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003180
3181 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3182 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003183 }
3184}
3185
Jiyong Park2286afd2020-06-16 21:58:53 +09003186func (c *Module) IsSdkVariant() bool {
Dan Albert92fe7402020-07-15 13:33:30 -07003187 return c.Properties.IsSdkVariant || c.AlwaysSdk()
Jiyong Park2286afd2020-06-16 21:58:53 +09003188}
3189
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003190func kytheExtractAllFactory() android.Singleton {
3191 return &kytheExtractAllSingleton{}
3192}
3193
3194type kytheExtractAllSingleton struct {
3195}
3196
3197func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3198 var xrefTargets android.Paths
3199 ctx.VisitAllModules(func(module android.Module) {
3200 if ccModule, ok := module.(xref); ok {
3201 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3202 }
3203 })
3204 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3205 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07003206 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003207 }
3208}
3209
Colin Cross06a931b2015-10-28 17:23:31 -07003210var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003211var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003212var BoolPtr = proptools.BoolPtr
3213var String = proptools.String
3214var StringPtr = proptools.StringPtr