blob: a813428f525f58725553a20d3222302e93973407 [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 }
743 }
744 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
745}
746
747func (c *Module) CcLibrary() bool {
748 if c.linker != nil {
749 if _, ok := c.linker.(*libraryDecorator); ok {
750 return true
751 }
752 }
753 return false
754}
755
756func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700757 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700758 return true
759 }
760 return false
761}
762
Ivan Lozano2b262972019-11-21 12:30:50 -0800763func (c *Module) NonCcVariants() bool {
764 return false
765}
766
Ivan Lozano183a3212019-10-18 14:18:45 -0700767func (c *Module) SetBuildStubs() {
768 if c.linker != nil {
769 if library, ok := c.linker.(*libraryDecorator); ok {
770 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700771 c.Properties.HideFromMake = true
772 c.sanitize = nil
773 c.stl = nil
774 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700775 return
776 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000777 if _, ok := c.linker.(*llndkStubDecorator); ok {
778 c.Properties.HideFromMake = true
779 return
780 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700781 }
782 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
783}
784
Ivan Lozano52767be2019-10-18 14:49:46 -0700785func (c *Module) BuildStubs() bool {
786 if c.linker != nil {
787 if library, ok := c.linker.(*libraryDecorator); ok {
788 return library.buildStubs()
789 }
790 }
791 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
792}
793
Colin Crossd1f898e2020-08-18 18:35:15 -0700794func (c *Module) SetAllStubsVersions(versions []string) {
795 if library, ok := c.linker.(*libraryDecorator); ok {
796 library.MutatedProperties.AllStubsVersions = versions
797 return
798 }
799 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
800 llndk.libraryDecorator.MutatedProperties.AllStubsVersions = versions
801 return
802 }
803}
804
805func (c *Module) AllStubsVersions() []string {
806 if library, ok := c.linker.(*libraryDecorator); ok {
807 return library.MutatedProperties.AllStubsVersions
808 }
809 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
810 return llndk.libraryDecorator.MutatedProperties.AllStubsVersions
811 }
812 return nil
813}
814
815func (c *Module) SetStubsVersion(version string) {
Ivan Lozano183a3212019-10-18 14:18:45 -0700816 if c.linker != nil {
817 if library, ok := c.linker.(*libraryDecorator); ok {
818 library.MutatedProperties.StubsVersion = version
819 return
820 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000821 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
822 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
823 return
824 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700825 }
Colin Crossd1f898e2020-08-18 18:35:15 -0700826 panic(fmt.Errorf("SetStubsVersion called on non-library module: %q", c.BaseModuleName()))
Ivan Lozano183a3212019-10-18 14:18:45 -0700827}
828
Jooyung Han03b51852020-02-26 22:45:42 +0900829func (c *Module) StubsVersion() string {
830 if c.linker != nil {
831 if library, ok := c.linker.(*libraryDecorator); ok {
832 return library.MutatedProperties.StubsVersion
833 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000834 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
835 return llndk.libraryDecorator.MutatedProperties.StubsVersion
836 }
Jooyung Han03b51852020-02-26 22:45:42 +0900837 }
838 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
839}
840
Ivan Lozano183a3212019-10-18 14:18:45 -0700841func (c *Module) SetStatic() {
842 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700843 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700844 library.setStatic()
845 return
846 }
847 }
848 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
849}
850
851func (c *Module) SetShared() {
852 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700853 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700854 library.setShared()
855 return
856 }
857 }
858 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
859}
860
861func (c *Module) BuildStaticVariant() bool {
862 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700863 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700864 return library.buildStatic()
865 }
866 }
867 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
868}
869
870func (c *Module) BuildSharedVariant() bool {
871 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700872 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700873 return library.buildShared()
874 }
875 }
876 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
877}
878
879func (c *Module) Module() android.Module {
880 return c
881}
882
Jiyong Parkc20eee32018-09-05 22:36:17 +0900883func (c *Module) OutputFile() android.OptionalPath {
884 return c.outputFile
885}
886
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400887func (c *Module) CoverageFiles() android.Paths {
888 if c.linker != nil {
889 if library, ok := c.linker.(libraryInterface); ok {
890 return library.objs().coverageFiles
891 }
892 }
893 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
894}
895
Ivan Lozano183a3212019-10-18 14:18:45 -0700896var _ LinkableInterface = (*Module)(nil)
897
Jiyong Park719b4462019-01-13 00:39:51 +0900898func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900899 if c.linker != nil {
900 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900901 }
902 return nil
903}
904
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900905func (c *Module) CoverageOutputFile() android.OptionalPath {
906 if c.linker != nil {
907 return c.linker.coverageOutputFilePath()
908 }
909 return android.OptionalPath{}
910}
911
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900912func (c *Module) RelativeInstallPath() string {
913 if c.installer != nil {
914 return c.installer.relativeInstallPath()
915 }
916 return ""
917}
918
Jooyung Han344d5432019-08-23 11:17:39 +0900919func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900920 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900921}
922
Colin Cross36242852017-06-23 15:06:31 -0700923func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700924 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800925 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700926 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800927 }
928 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700929 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800930 }
931 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700932 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800933 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700934 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700935 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700936 }
Colin Cross16b23492016-01-06 14:41:07 -0800937 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700938 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800939 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800940 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700941 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800942 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800943 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700944 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800945 }
Justin Yun8effde42017-06-23 19:24:43 +0900946 if c.vndkdep != nil {
947 c.AddProperties(c.vndkdep.props()...)
948 }
Stephen Craneba090d12017-05-09 15:44:35 -0700949 if c.lto != nil {
950 c.AddProperties(c.lto.props()...)
951 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700952 if c.pgo != nil {
953 c.AddProperties(c.pgo.props()...)
954 }
Colin Crossca860ac2016-01-04 14:34:37 -0800955 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700956 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800957 }
Colin Crossc472d572015-03-17 15:06:21 -0700958
Jiyong Park1613e552020-09-14 19:43:17 +0900959 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, os android.OsType) bool {
Elliott Hughes79ae3412020-04-17 15:49:49 -0700960 // Windows builds always prefer 32-bit
Jiyong Park1613e552020-09-14 19:43:17 +0900961 return os == android.Windows
Colin Crossa9d8bee2018-10-02 13:59:46 -0700962 })
Colin Cross36242852017-06-23 15:06:31 -0700963 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900964 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900965 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900966 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900967
Colin Cross36242852017-06-23 15:06:31 -0700968 return c
Colin Crossc472d572015-03-17 15:06:21 -0700969}
970
Colin Crossb916a382016-07-29 17:28:03 -0700971// Returns true for dependency roots (binaries)
972// TODO(ccross): also handle dlopenable libraries
973func (c *Module) isDependencyRoot() bool {
974 if root, ok := c.linker.(interface {
975 isDependencyRoot() bool
976 }); ok {
977 return root.isDependencyRoot()
978 }
979 return false
980}
981
Justin Yun5f7f7e82019-11-18 19:52:14 +0900982// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
983// "product" and "vendor" variant modules return true for this function.
984// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
985// "soc_specific: true" and more vendor installed modules are included here.
986// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
987// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700988func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900989 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700990}
991
Colin Crossc511bc52020-04-07 16:50:32 +0000992func (c *Module) canUseSdk() bool {
993 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery()
994}
995
996func (c *Module) UseSdk() bool {
997 if c.canUseSdk() {
Dan Albert92fe7402020-07-15 13:33:30 -0700998 return String(c.Properties.Sdk_version) != "" || c.SplitPerApiLevel()
Colin Crossc511bc52020-04-07 16:50:32 +0000999 }
1000 return false
1001}
1002
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001003func (c *Module) isCoverageVariant() bool {
1004 return c.coverage.Properties.IsCoverageVariant
1005}
1006
Peter Collingbournead84f972019-12-17 16:46:18 -08001007func (c *Module) IsNdk() bool {
Colin Crossf0913fb2020-07-29 12:59:39 -07001008 return inList(c.BaseModuleName(), ndkKnownLibs)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001009}
1010
Inseob Kim9516ee92019-05-09 10:56:13 +09001011func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001012 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +09001013 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001014}
1015
Inseob Kim9516ee92019-05-09 10:56:13 +09001016func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001017 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +09001018 name := c.BaseModuleName()
1019 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001020}
1021
Inseob Kim9516ee92019-05-09 10:56:13 +09001022func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001023 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +09001024 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001025}
1026
Ivan Lozano52767be2019-10-18 14:49:46 -07001027func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001028 if vndkdep := c.vndkdep; vndkdep != nil {
1029 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +09001030 }
1031 return false
1032}
1033
Yi Kong7e53c572018-02-14 18:16:12 +08001034func (c *Module) isPgoCompile() bool {
1035 if pgo := c.pgo; pgo != nil {
1036 return pgo.Properties.PgoCompile
1037 }
1038 return false
1039}
1040
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001041func (c *Module) isNDKStubLibrary() bool {
1042 if _, ok := c.compiler.(*stubDecorator); ok {
1043 return true
1044 }
1045 return false
1046}
1047
Logan Chienf3511742017-10-31 18:04:35 +08001048func (c *Module) isVndkSp() bool {
1049 if vndkdep := c.vndkdep; vndkdep != nil {
1050 return vndkdep.isVndkSp()
1051 }
1052 return false
1053}
1054
1055func (c *Module) isVndkExt() bool {
1056 if vndkdep := c.vndkdep; vndkdep != nil {
1057 return vndkdep.isVndkExt()
1058 }
1059 return false
1060}
1061
Ivan Lozano52767be2019-10-18 14:49:46 -07001062func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +09001063 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -08001064}
1065
Logan Chienf3511742017-10-31 18:04:35 +08001066func (c *Module) getVndkExtendsModuleName() string {
1067 if vndkdep := c.vndkdep; vndkdep != nil {
1068 return vndkdep.getVndkExtendsModuleName()
1069 }
1070 return ""
1071}
1072
Jiyong Park25fc6a92018-11-18 18:02:45 +09001073func (c *Module) IsStubs() bool {
1074 if library, ok := c.linker.(*libraryDecorator); ok {
1075 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +09001076 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
1077 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001078 }
1079 return false
1080}
1081
1082func (c *Module) HasStubsVariants() bool {
1083 if library, ok := c.linker.(*libraryDecorator); ok {
1084 return len(library.Properties.Stubs.Versions) > 0
1085 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001086 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
1087 return len(library.Properties.Stubs.Versions) > 0
1088 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001089 return false
1090}
1091
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001092func (c *Module) bootstrap() bool {
1093 return Bool(c.Properties.Bootstrap)
1094}
1095
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001096func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001097 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1098 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1099 return false
1100 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001101 return c.linker != nil && c.linker.nativeCoverage()
1102}
1103
Inseob Kim8471cda2019-11-15 09:59:12 +09001104func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kim1042d292020-06-01 23:23:05 +09001105 if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
1106 return p.isSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001107 }
1108 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001109}
1110
Jiyong Park73c54ee2019-10-22 20:31:18 +09001111func (c *Module) ExportedIncludeDirs() android.Paths {
1112 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1113 return flagsProducer.exportedDirs()
1114 }
Jiyong Park232e7852019-11-04 12:23:40 +09001115 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001116}
1117
1118func (c *Module) ExportedSystemIncludeDirs() android.Paths {
1119 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1120 return flagsProducer.exportedSystemDirs()
1121 }
Jiyong Park232e7852019-11-04 12:23:40 +09001122 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001123}
1124
1125func (c *Module) ExportedFlags() []string {
1126 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1127 return flagsProducer.exportedFlags()
1128 }
Jiyong Park232e7852019-11-04 12:23:40 +09001129 return nil
1130}
1131
1132func (c *Module) ExportedDeps() android.Paths {
1133 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1134 return flagsProducer.exportedDeps()
1135 }
1136 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001137}
1138
Inseob Kimd110f872019-12-06 13:15:38 +09001139func (c *Module) ExportedGeneratedHeaders() android.Paths {
1140 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1141 return flagsProducer.exportedGeneratedHeaders()
1142 }
1143 return nil
1144}
1145
Bill Peckham945441c2020-08-31 16:07:58 -07001146func (c *Module) ExcludeFromVendorSnapshot() bool {
1147 return Bool(c.Properties.Exclude_from_vendor_snapshot)
1148}
1149
Jiyong Parkf1194352019-02-25 11:05:47 +09001150func isBionic(name string) bool {
1151 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001152 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001153 return true
1154 }
1155 return false
1156}
1157
Martin Stjernholm279de572019-09-10 23:18:20 +01001158func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001159 if name == "libclang_rt.hwasan-aarch64-android" {
Jooyung Han8ce8db92020-05-15 19:05:05 +09001160 return true
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001161 }
1162 return isBionic(name)
1163}
1164
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001165func (c *Module) XrefCcFiles() android.Paths {
1166 return c.kytheFiles
1167}
1168
Colin Crossca860ac2016-01-04 14:34:37 -08001169type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001170 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001171 moduleContextImpl
1172}
1173
Colin Cross37047f12016-12-13 17:06:13 -08001174type depsContext struct {
1175 android.BottomUpMutatorContext
1176 moduleContextImpl
1177}
1178
Colin Crossca860ac2016-01-04 14:34:37 -08001179type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001180 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001181 moduleContextImpl
1182}
1183
1184type moduleContextImpl struct {
1185 mod *Module
1186 ctx BaseModuleContext
1187}
1188
Colin Crossb98c8b02016-07-29 13:44:28 -07001189func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001190 return ctx.mod.toolchain(ctx.ctx)
1191}
1192
1193func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001194 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001195}
1196
1197func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001198 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001199}
1200
Jiyong Park1d1119f2019-07-29 21:27:18 +09001201func (ctx *moduleContextImpl) header() bool {
1202 return ctx.mod.header()
1203}
1204
Inseob Kim7f283f42020-06-01 21:53:49 +09001205func (ctx *moduleContextImpl) binary() bool {
1206 return ctx.mod.binary()
1207}
1208
Inseob Kim1042d292020-06-01 23:23:05 +09001209func (ctx *moduleContextImpl) object() bool {
1210 return ctx.mod.object()
1211}
1212
Jooyung Hanccce2f22020-03-07 03:45:53 +09001213func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001214 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001215}
1216
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001217func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001218 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001219}
1220
1221func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001222 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001223 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001224 vndkVer := ctx.mod.VndkVersion()
Jooyung Han03302ee2020-04-08 09:22:26 +09001225 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001226 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001227 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001228 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001229 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001230 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001231 }
1232 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001233}
1234
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001235func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001236 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001237}
Justin Yun8effde42017-06-23 19:24:43 +09001238
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001239func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001240 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001241}
1242
Inseob Kim9516ee92019-05-09 10:56:13 +09001243func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1244 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001245}
1246
Inseob Kim9516ee92019-05-09 10:56:13 +09001247func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1248 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001249}
1250
Inseob Kim9516ee92019-05-09 10:56:13 +09001251func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1252 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001253}
1254
Logan Chienf3511742017-10-31 18:04:35 +08001255func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001256 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001257}
1258
Yi Kong7e53c572018-02-14 18:16:12 +08001259func (ctx *moduleContextImpl) isPgoCompile() bool {
1260 return ctx.mod.isPgoCompile()
1261}
1262
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001263func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1264 return ctx.mod.isNDKStubLibrary()
1265}
1266
Justin Yun8effde42017-06-23 19:24:43 +09001267func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001268 return ctx.mod.isVndkSp()
1269}
1270
1271func (ctx *moduleContextImpl) isVndkExt() bool {
1272 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001273}
1274
Vic Yangefd249e2018-11-12 20:19:56 -08001275func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001276 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001277}
1278
Logan Chien2f2b8902018-07-10 15:01:19 +08001279// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001280func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001281 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1282 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001283 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001284
Hsin-Yi Chenf81bb652020-04-07 21:42:19 +08001285 // Coverage builds have extra symbols.
1286 if ctx.mod.isCoverageVariant() {
1287 return false
1288 }
1289
Doug Hornc32c6b02019-01-17 14:44:05 -08001290 if ctx.ctx.Fuchsia() {
1291 return false
1292 }
1293
Logan Chien2f2b8902018-07-10 15:01:19 +08001294 if sanitize := ctx.mod.sanitize; sanitize != nil {
1295 if !sanitize.isVariantOnProductionDevice() {
1296 return false
1297 }
1298 }
1299 if !ctx.ctx.Device() {
1300 // Host modules do not need ABI dumps.
1301 return false
1302 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001303 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001304 // Stubs do not need ABI dumps.
1305 return false
1306 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001307 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001308}
1309
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001310func (ctx *moduleContextImpl) selectedStl() string {
1311 if stl := ctx.mod.stl; stl != nil {
1312 return stl.Properties.SelectedStl
1313 }
1314 return ""
1315}
1316
Ivan Lozanobd721262018-11-27 14:33:03 -08001317func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1318 return ctx.mod.linker.useClangLld(actx)
1319}
1320
Colin Crossce75d2c2016-10-06 16:12:58 -07001321func (ctx *moduleContextImpl) baseModuleName() string {
1322 return ctx.mod.ModuleBase.BaseModuleName()
1323}
1324
Logan Chienf3511742017-10-31 18:04:35 +08001325func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1326 return ctx.mod.getVndkExtendsModuleName()
1327}
1328
Logan Chiene274fc92019-12-03 11:18:32 -08001329func (ctx *moduleContextImpl) isForPlatform() bool {
1330 return ctx.mod.IsForPlatform()
1331}
1332
Colin Crosse07f2312020-08-13 11:24:56 -07001333func (ctx *moduleContextImpl) apexVariationName() string {
1334 return ctx.mod.ApexVariationName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001335}
1336
Dan Albertc8060532020-07-22 22:32:17 -07001337func (ctx *moduleContextImpl) apexSdkVersion() android.ApiLevel {
Jooyung Han75568392020-03-20 04:29:24 +09001338 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001339}
1340
Jiyong Parkb0788572018-12-20 22:10:17 +09001341func (ctx *moduleContextImpl) hasStubsVariants() bool {
1342 return ctx.mod.HasStubsVariants()
1343}
1344
1345func (ctx *moduleContextImpl) isStubs() bool {
1346 return ctx.mod.IsStubs()
1347}
1348
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001349func (ctx *moduleContextImpl) bootstrap() bool {
1350 return ctx.mod.bootstrap()
1351}
1352
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001353func (ctx *moduleContextImpl) nativeCoverage() bool {
1354 return ctx.mod.nativeCoverage()
1355}
1356
Colin Cross635c3b02016-05-18 15:37:25 -07001357func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001358 return &Module{
1359 hod: hod,
1360 multilib: multilib,
1361 }
1362}
1363
Colin Cross635c3b02016-05-18 15:37:25 -07001364func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001365 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001366 module.features = []feature{
1367 &tidyFeature{},
1368 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001369 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001370 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001371 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001372 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001373 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001374 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001375 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001376 return module
1377}
1378
Colin Crossce75d2c2016-10-06 16:12:58 -07001379func (c *Module) Prebuilt() *android.Prebuilt {
1380 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1381 return p.prebuilt()
1382 }
1383 return nil
1384}
1385
1386func (c *Module) Name() string {
1387 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001388 if p, ok := c.linker.(interface {
1389 Name(string) string
1390 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001391 name = p.Name(name)
1392 }
1393 return name
1394}
1395
Alex Light3d673592019-01-18 14:37:31 -08001396func (c *Module) Symlinks() []string {
1397 if p, ok := c.installer.(interface {
1398 symlinkList() []string
1399 }); ok {
1400 return p.symlinkList()
1401 }
1402 return nil
1403}
1404
Jeff Gaston294356f2017-09-27 17:05:30 -07001405// orderDeps reorders dependencies into a list such that if module A depends on B, then
1406// A will precede B in the resultant list.
1407// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001408// Note that directSharedDeps should be the analogous static library for each shared lib dep
1409func 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 -07001410 // If A depends on B, then
1411 // Every list containing A will also contain B later in the list
1412 // So, after concatenating all lists, the final instance of B will have come from the same
1413 // original list as the final instance of A
1414 // So, the final instance of B will be later in the concatenation than the final A
1415 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1416 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001417 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001418 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001419 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1420 }
1421 for _, dep := range directSharedDeps {
1422 orderedAllDeps = append(orderedAllDeps, dep)
1423 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001424 }
1425
Colin Crossb6715442017-10-24 11:13:31 -07001426 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001427
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001428 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001429 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001430 // resultant list to only what the caller has chosen to include in directStaticDeps
1431 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001432
1433 return orderedAllDeps, orderedDeclaredDeps
1434}
1435
Ivan Lozano183a3212019-10-18 14:18:45 -07001436func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001437 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001438 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001439 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1440 staticDepFiles := []android.Path{}
1441 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001442 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1443 if dep.OutputFile().Valid() {
1444 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1445 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1446 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001447 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001448 sharedDepFiles := []android.Path{}
1449 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001450 if sharedDep.HasStaticVariant() {
1451 staticAnalogue := sharedDep.GetStaticVariant()
1452 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1453 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001454 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001455 }
1456
1457 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001458 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1459 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001460
1461 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001462}
1463
Roland Levillainf89cd092019-07-29 16:22:59 +01001464func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1465 test, ok := c.linker.(testPerSrc)
1466 return ok && test.isAllTestsVariation()
1467}
1468
Chris Parsons216e10a2020-07-09 17:12:52 -04001469func (c *Module) DataPaths() []android.DataPath {
Liz Kammer1c14a212020-05-12 15:26:55 -07001470 if p, ok := c.installer.(interface {
Chris Parsons216e10a2020-07-09 17:12:52 -04001471 dataPaths() []android.DataPath
Liz Kammer1c14a212020-05-12 15:26:55 -07001472 }); ok {
1473 return p.dataPaths()
1474 }
1475 return nil
1476}
1477
Justin Yun5f7f7e82019-11-18 19:52:14 +09001478func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1479 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1480 // "current", it will append the VNDK version to the name suffix.
1481 var vndkVersion string
1482 var nameSuffix string
1483 if c.inProduct() {
1484 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1485 nameSuffix = productSuffix
1486 } else {
1487 vndkVersion = ctx.DeviceConfig().VndkVersion()
1488 nameSuffix = vendorSuffix
1489 }
1490 if vndkVersion == "current" {
1491 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1492 }
1493 if c.Properties.VndkVersion != vndkVersion {
1494 // add version suffix only if the module is using different vndk version than the
1495 // version in product or vendor partition.
1496 nameSuffix += "." + c.Properties.VndkVersion
1497 }
1498 return nameSuffix
1499}
1500
Colin Cross635c3b02016-05-18 15:37:25 -07001501func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001502 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001503 //
1504 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1505 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1506 // module and return early, as this module does not produce an output file per se.
1507 if c.IsTestPerSrcAllTestsVariation() {
1508 c.outputFile = android.OptionalPath{}
1509 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001510 }
1511
Jooyung Han38002912019-05-16 04:01:54 +09001512 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001513
Inseob Kim64c43952019-08-26 16:52:35 +09001514 c.Properties.SubName = ""
1515
1516 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1517 c.Properties.SubName += nativeBridgeSuffix
1518 }
1519
Justin Yun5f7f7e82019-11-18 19:52:14 +09001520 _, llndk := c.linker.(*llndkStubDecorator)
1521 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1522 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1523 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1524 // added for product variant only when we have vendor and product variants with core
1525 // variant. The suffix is not added for vendor-only or product-only module.
1526 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1527 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001528 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1529 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1530 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001531 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1532 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001533 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001534 c.Properties.SubName += recoverySuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001535 } else if c.IsSdkVariant() && (c.Properties.SdkAndPlatformVariantVisibleToMake || c.SplitPerApiLevel()) {
Colin Crossc511bc52020-04-07 16:50:32 +00001536 c.Properties.SubName += sdkSuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001537 if c.SplitPerApiLevel() {
1538 c.Properties.SubName += "." + c.SdkVersion()
1539 }
Inseob Kim64c43952019-08-26 16:52:35 +09001540 }
1541
Colin Crossca860ac2016-01-04 14:34:37 -08001542 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001543 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001544 moduleContextImpl: moduleContextImpl{
1545 mod: c,
1546 },
1547 }
1548 ctx.ctx = ctx
1549
Colin Crossf18e1102017-11-16 14:33:08 -08001550 deps := c.depsToPaths(ctx)
1551 if ctx.Failed() {
1552 return
1553 }
1554
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001555 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1556 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1557 }
1558
Colin Crossca860ac2016-01-04 14:34:37 -08001559 flags := Flags{
1560 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001561 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001562 }
Colin Crossca860ac2016-01-04 14:34:37 -08001563 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001564 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001565 }
1566 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001567 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001568 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001569 if c.stl != nil {
1570 flags = c.stl.flags(ctx, flags)
1571 }
Colin Cross16b23492016-01-06 14:41:07 -08001572 if c.sanitize != nil {
1573 flags = c.sanitize.flags(ctx, flags)
1574 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001575 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001576 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001577 }
Stephen Craneba090d12017-05-09 15:44:35 -07001578 if c.lto != nil {
1579 flags = c.lto.flags(ctx, flags)
1580 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001581 if c.pgo != nil {
1582 flags = c.pgo.flags(ctx, flags)
1583 }
Colin Crossca860ac2016-01-04 14:34:37 -08001584 for _, feature := range c.features {
1585 flags = feature.flags(ctx, flags)
1586 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001587 if ctx.Failed() {
1588 return
1589 }
1590
Colin Cross4af21ed2019-11-04 09:37:55 -08001591 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1592 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1593 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001594
Colin Cross4af21ed2019-11-04 09:37:55 -08001595 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001596
1597 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001598 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001599 }
1600 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001601 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001602 }
1603
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001604 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001605 // We need access to all the flags seen by a source file.
1606 if c.sabi != nil {
1607 flags = c.sabi.flags(ctx, flags)
1608 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001609
Colin Cross4af21ed2019-11-04 09:37:55 -08001610 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001611
Colin Crossca860ac2016-01-04 14:34:37 -08001612 // Optimization to reduce size of build.ninja
1613 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001614 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1615 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1616 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1617 flags.Local.CFlags = []string{"$cflags"}
1618 flags.Local.CppFlags = []string{"$cppflags"}
1619 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001620
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001621 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001622 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001623 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001624 if ctx.Failed() {
1625 return
1626 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001627 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001628 }
1629
Colin Crossca860ac2016-01-04 14:34:37 -08001630 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001631 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001632 if ctx.Failed() {
1633 return
1634 }
Colin Cross635c3b02016-05-18 15:37:25 -07001635 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001636
1637 // If a lib is directly included in any of the APEXes, unhide the stubs
1638 // variant having the latest version gets visible to make. In addition,
1639 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1640 // force anything in the make world to link against the stubs library.
1641 // (unless it is explicitly referenced via .bootstrap suffix or the
1642 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001643 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001644 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001645 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001646 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001647 c.Properties.HideFromMake = false // unhide
1648 // Note: this is still non-installable
1649 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001650
1651 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1652 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1653 if isSnapshotAware(ctx, c) {
1654 i.collectHeadersForSnapshot(ctx)
1655 }
1656 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001657 }
Colin Cross5049f022015-03-18 13:28:46 -07001658
Inseob Kim1f086e22019-05-09 13:29:15 +09001659 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001660 c.installer.install(ctx, c.outputFile.Path())
1661 if ctx.Failed() {
1662 return
Colin Crossca860ac2016-01-04 14:34:37 -08001663 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001664 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1665 // If the module has been specifically configure to not be installed then
1666 // skip the installation as otherwise it will break when running inside make
1667 // as the output path to install will not be specified. Not all uninstallable
1668 // modules can skip installation as some are needed for resolving make side
1669 // dependencies.
1670 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001671 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001672}
1673
Colin Cross0ea8ba82019-06-06 14:33:29 -07001674func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001675 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001676 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001677 }
Colin Crossca860ac2016-01-04 14:34:37 -08001678 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001679}
1680
Colin Crossca860ac2016-01-04 14:34:37 -08001681func (c *Module) begin(ctx BaseModuleContext) {
1682 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001683 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001684 }
Colin Crossca860ac2016-01-04 14:34:37 -08001685 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001686 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001687 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001688 if c.stl != nil {
1689 c.stl.begin(ctx)
1690 }
Colin Cross16b23492016-01-06 14:41:07 -08001691 if c.sanitize != nil {
1692 c.sanitize.begin(ctx)
1693 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001694 if c.coverage != nil {
1695 c.coverage.begin(ctx)
1696 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001697 if c.sabi != nil {
1698 c.sabi.begin(ctx)
1699 }
Justin Yun8effde42017-06-23 19:24:43 +09001700 if c.vndkdep != nil {
1701 c.vndkdep.begin(ctx)
1702 }
Stephen Craneba090d12017-05-09 15:44:35 -07001703 if c.lto != nil {
1704 c.lto.begin(ctx)
1705 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001706 if c.pgo != nil {
1707 c.pgo.begin(ctx)
1708 }
Colin Crossca860ac2016-01-04 14:34:37 -08001709 for _, feature := range c.features {
1710 feature.begin(ctx)
1711 }
Dan Albert92fe7402020-07-15 13:33:30 -07001712 if ctx.useSdk() && c.IsSdkVariant() {
Dan Albert1a246272020-07-06 14:49:35 -07001713 version, err := nativeApiLevelFromUser(ctx, ctx.sdkVersion())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001714 if err != nil {
1715 ctx.PropertyErrorf("sdk_version", err.Error())
Dan Albert1a246272020-07-06 14:49:35 -07001716 c.Properties.Sdk_version = nil
1717 } else {
1718 c.Properties.Sdk_version = StringPtr(version.String())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001719 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001720 }
Colin Crossca860ac2016-01-04 14:34:37 -08001721}
1722
Colin Cross37047f12016-12-13 17:06:13 -08001723func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001724 deps := Deps{}
1725
1726 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001727 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001728 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001729 // Add the PGO dependency (the clang_rt.profile runtime library), which
1730 // sometimes depends on symbols from libgcc, before libgcc gets added
1731 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001732 if c.pgo != nil {
1733 deps = c.pgo.deps(ctx, deps)
1734 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001735 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001736 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001737 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001738 if c.stl != nil {
1739 deps = c.stl.deps(ctx, deps)
1740 }
Colin Cross16b23492016-01-06 14:41:07 -08001741 if c.sanitize != nil {
1742 deps = c.sanitize.deps(ctx, deps)
1743 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001744 if c.coverage != nil {
1745 deps = c.coverage.deps(ctx, deps)
1746 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001747 if c.sabi != nil {
1748 deps = c.sabi.deps(ctx, deps)
1749 }
Justin Yun8effde42017-06-23 19:24:43 +09001750 if c.vndkdep != nil {
1751 deps = c.vndkdep.deps(ctx, deps)
1752 }
Stephen Craneba090d12017-05-09 15:44:35 -07001753 if c.lto != nil {
1754 deps = c.lto.deps(ctx, deps)
1755 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001756 for _, feature := range c.features {
1757 deps = feature.deps(ctx, deps)
1758 }
1759
Colin Crossb6715442017-10-24 11:13:31 -07001760 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1761 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1762 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1763 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1764 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1765 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001766 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001767
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001768 for _, lib := range deps.ReexportSharedLibHeaders {
1769 if !inList(lib, deps.SharedLibs) {
1770 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1771 }
1772 }
1773
1774 for _, lib := range deps.ReexportStaticLibHeaders {
1775 if !inList(lib, deps.StaticLibs) {
1776 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1777 }
1778 }
1779
Colin Cross5950f382016-12-13 12:50:57 -08001780 for _, lib := range deps.ReexportHeaderLibHeaders {
1781 if !inList(lib, deps.HeaderLibs) {
1782 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1783 }
1784 }
1785
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001786 for _, gen := range deps.ReexportGeneratedHeaders {
1787 if !inList(gen, deps.GeneratedHeaders) {
1788 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1789 }
1790 }
1791
Colin Crossc99deeb2016-04-11 15:06:20 -07001792 return deps
1793}
1794
Dan Albert7e9d2952016-08-04 13:02:36 -07001795func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001796 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001797 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001798 moduleContextImpl: moduleContextImpl{
1799 mod: c,
1800 },
1801 }
1802 ctx.ctx = ctx
1803
Colin Crossca860ac2016-01-04 14:34:37 -08001804 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001805}
1806
Jiyong Park7ed9de32018-10-15 22:25:07 +09001807// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001808func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001809 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1810 version := name[sharp+1:]
1811 libname := name[:sharp]
1812 return libname, version
1813 }
1814 return name, ""
1815}
1816
Dan Albert92fe7402020-07-15 13:33:30 -07001817func GetCrtVariations(ctx android.BottomUpMutatorContext,
1818 m LinkableInterface) []blueprint.Variation {
1819 if ctx.Os() != android.Android {
1820 return nil
1821 }
1822 if m.UseSdk() {
1823 return []blueprint.Variation{
1824 {Mutator: "sdk", Variation: "sdk"},
1825 {Mutator: "ndk_api", Variation: m.SdkVersion()},
1826 }
1827 }
1828 return []blueprint.Variation{
1829 {Mutator: "sdk", Variation: ""},
1830 }
1831}
1832
Colin Cross1e676be2016-10-12 14:38:15 -07001833func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001834 if !c.Enabled() {
1835 return
1836 }
1837
Colin Cross37047f12016-12-13 17:06:13 -08001838 ctx := &depsContext{
1839 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001840 moduleContextImpl: moduleContextImpl{
1841 mod: c,
1842 },
1843 }
1844 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001845
Colin Crossc99deeb2016-04-11 15:06:20 -07001846 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001847
Yo Chiang219968c2020-09-22 18:45:04 +08001848 c.Properties.AndroidMkSystemSharedLibs = deps.SystemSharedLibs
1849
Dan Albert914449f2016-06-17 16:45:24 -07001850 variantNdkLibs := []string{}
1851 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001852 if ctx.Os() == android.Android {
Inseob Kimeec88e12020-01-22 11:11:29 +09001853 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001854 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001855 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001856 // 1. Name of an NDK library that refers to a prebuilt module.
1857 // For each of these, it adds the name of the prebuilt module (which will be in
1858 // prebuilts/ndk) to the list of nonvariant libs.
1859 // 2. Name of an NDK library that refers to an ndk_library module.
1860 // For each of these, it adds the name of the ndk_library module to the list of
1861 // variant libs.
1862 // 3. Anything else (so anything that isn't an NDK library).
1863 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001864 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001865 // The caller can then know to add the variantLibs dependencies differently from the
1866 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001867
Inseob Kim9516ee92019-05-09 10:56:13 +09001868 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001869 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1870
1871 rewriteVendorLibs := func(lib string) string {
1872 if isLlndkLibrary(lib, ctx.Config()) {
1873 return lib + llndkLibrarySuffix
1874 }
1875
1876 // only modules with BOARD_VNDK_VERSION uses snapshot.
1877 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1878 return lib
1879 }
1880
1881 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1882 return snapshot
1883 }
1884
1885 return lib
1886 }
1887
1888 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001889 variantLibs = []string{}
1890 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001891 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001892 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001893 name, _ := StubsLibNameAndVersion(entry)
Dan Albertde5aade2020-06-30 12:32:51 -07001894 if ctx.useSdk() && inList(name, ndkKnownLibs) {
1895 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +09001896 } else if ctx.useVndk() {
1897 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001898 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001899 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001900 if actx.OtherModuleExists(vendorPublicLib) {
1901 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1902 } else {
1903 // This can happen if vendor_public_library module is defined in a
1904 // namespace that isn't visible to the current module. In that case,
1905 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001906 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001907 }
Dan Albert914449f2016-06-17 16:45:24 -07001908 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001909 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001910 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001911 }
1912 }
Dan Albert914449f2016-06-17 16:45:24 -07001913 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001914 }
1915
Inseob Kimeec88e12020-01-22 11:11:29 +09001916 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1917 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1918 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1919 if ctx.useVndk() {
1920 for idx, lib := range deps.RuntimeLibs {
1921 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1922 }
1923 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001924 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001925
Jiyong Park7e636d02019-01-28 16:16:54 +09001926 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001927 if c.linker != nil {
1928 if library, ok := c.linker.(*libraryDecorator); ok {
1929 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001930 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001931 }
1932 }
1933 }
1934
Inseob Kimeec88e12020-01-22 11:11:29 +09001935 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1936 // only modules with BOARD_VNDK_VERSION uses snapshot.
1937 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1938 return lib
1939 }
1940
1941 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1942 return snapshot
1943 }
1944
1945 return lib
1946 }
1947
1948 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001949 for _, lib := range deps.HeaderLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001950 depTag := libraryDependencyTag{Kind: headerLibraryDependency}
Colin Cross32ec36c2016-12-15 07:39:51 -08001951 if inList(lib, deps.ReexportHeaderLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001952 depTag.reexportFlags = true
Colin Cross32ec36c2016-12-15 07:39:51 -08001953 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001954
1955 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1956
Jiyong Park7e636d02019-01-28 16:16:54 +09001957 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001958 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001959 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001960 } else {
1961 actx.AddVariationDependencies(nil, depTag, lib)
1962 }
1963 }
1964
1965 if buildStubs {
1966 // Stubs lib does not have dependency to other static/shared libraries.
1967 // Don't proceed.
1968 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001969 }
Colin Cross5950f382016-12-13 12:50:57 -08001970
Inseob Kimc0907f12019-02-08 21:00:45 +09001971 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001972 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001973
Jiyong Park5d1598f2019-02-25 22:14:17 +09001974 for _, lib := range deps.WholeStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001975 depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
Jiyong Park5d1598f2019-02-25 22:14:17 +09001976 if impl, ok := syspropImplLibraries[lib]; ok {
1977 lib = impl
1978 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001979
1980 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1981
Jiyong Park5d1598f2019-02-25 22:14:17 +09001982 actx.AddVariationDependencies([]blueprint.Variation{
1983 {Mutator: "link", Variation: "static"},
1984 }, depTag, lib)
1985 }
1986
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001987 for _, lib := range deps.StaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001988 depTag := libraryDependencyTag{Kind: staticLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001989 if inList(lib, deps.ReexportStaticLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001990 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001991 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001992
1993 if impl, ok := syspropImplLibraries[lib]; ok {
1994 lib = impl
1995 }
1996
Inseob Kimeec88e12020-01-22 11:11:29 +09001997 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1998
Dan Willemsen59339a22018-07-22 21:18:45 -07001999 actx.AddVariationDependencies([]blueprint.Variation{
2000 {Mutator: "link", Variation: "static"},
2001 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002002 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002003
Jooyung Han75568392020-03-20 04:29:24 +09002004 // staticUnwinderDep is treated as staticDep for Q apexes
2005 // so that native libraries/binaries are linked with static unwinder
2006 // because Q libc doesn't have unwinder APIs
2007 if deps.StaticUnwinderIfLegacy {
Colin Cross6e511a92020-07-27 21:26:48 -07002008 depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002009 actx.AddVariationDependencies([]blueprint.Variation{
2010 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07002011 }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002012 }
2013
Inseob Kimeec88e12020-01-22 11:11:29 +09002014 for _, lib := range deps.LateStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002015 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
Inseob Kimeec88e12020-01-22 11:11:29 +09002016 actx.AddVariationDependencies([]blueprint.Variation{
2017 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07002018 }, depTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
Inseob Kimeec88e12020-01-22 11:11:29 +09002019 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002020
Colin Cross6e511a92020-07-27 21:26:48 -07002021 addSharedLibDependencies := func(depTag libraryDependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002022 var variations []blueprint.Variation
2023 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han624d35c2020-04-10 12:57:24 +09002024 if version != "" && VersionVariantAvailable(c) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002025 // Version is explicitly specified. i.e. libFoo#30
2026 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Colin Cross6e511a92020-07-27 21:26:48 -07002027 depTag.explicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09002028 }
Colin Crossd1f898e2020-08-18 18:35:15 -07002029 deps := actx.AddVariationDependencies(variations, depTag, name)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002030
Jooyung Han03b51852020-02-26 22:45:42 +09002031 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002032 // The stubs library will be used when the depending module is built for APEX and
2033 // the dependent module is not in the same APEX.
Jooyung Han624d35c2020-04-10 12:57:24 +09002034 if version == "" && VersionVariantAvailable(c) {
Colin Crossd1f898e2020-08-18 18:35:15 -07002035 if dep, ok := deps[0].(*Module); ok {
2036 for _, ver := range dep.AllStubsVersions() {
2037 // Note that depTag.ExplicitlyVersioned is false in this case.
2038 ctx.AddVariationDependencies([]blueprint.Variation{
2039 {Mutator: "link", Variation: "shared"},
2040 {Mutator: "version", Variation: ver},
2041 }, depTag, name)
2042 }
Jooyung Han03b51852020-02-26 22:45:42 +09002043 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002044 }
2045 }
2046
Jiyong Park7ed9de32018-10-15 22:25:07 +09002047 // shared lib names without the #version suffix
2048 var sharedLibNames []string
2049
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002050 for _, lib := range deps.SharedLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002051 depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002052 if inList(lib, deps.ReexportSharedLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002053 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002054 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002055
2056 if impl, ok := syspropImplLibraries[lib]; ok {
2057 lib = impl
2058 }
2059
Jiyong Park73c54ee2019-10-22 20:31:18 +09002060 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09002061 sharedLibNames = append(sharedLibNames, name)
2062
Jiyong Park25fc6a92018-11-18 18:02:45 +09002063 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002064 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002065
Jiyong Park7ed9de32018-10-15 22:25:07 +09002066 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002067 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09002068 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
2069 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
2070 // linking against both the stubs lib and the non-stubs lib at the same time.
2071 continue
2072 }
Colin Cross6e511a92020-07-27 21:26:48 -07002073 depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
2074 addSharedLibDependencies(depTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09002075 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002076
Dan Willemsen59339a22018-07-22 21:18:45 -07002077 actx.AddVariationDependencies([]blueprint.Variation{
2078 {Mutator: "link", Variation: "shared"},
Chris Parsons79d66a52020-06-05 17:26:16 -04002079 }, dataLibDepTag, deps.DataLibs...)
2080
2081 actx.AddVariationDependencies([]blueprint.Variation{
2082 {Mutator: "link", Variation: "shared"},
Dan Willemsen59339a22018-07-22 21:18:45 -07002083 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08002084
Colin Cross68861832016-07-08 10:41:41 -07002085 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002086
2087 for _, gen := range deps.GeneratedHeaders {
2088 depTag := genHeaderDepTag
2089 if inList(gen, deps.ReexportGeneratedHeaders) {
2090 depTag = genHeaderExportDepTag
2091 }
2092 actx.AddDependency(c, depTag, gen)
2093 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002094
Colin Cross42d48b72018-08-29 14:10:52 -07002095 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07002096
Inseob Kim1042d292020-06-01 23:23:05 +09002097 vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())
2098
Dan Albert92fe7402020-07-15 13:33:30 -07002099 crtVariations := GetCrtVariations(ctx, c)
Colin Crossc99deeb2016-04-11 15:06:20 -07002100 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002101 actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
2102 rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08002103 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002104 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002105 actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
2106 rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07002107 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002108 if deps.LinkerFlagsFile != "" {
2109 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
2110 }
2111 if deps.DynamicLinker != "" {
2112 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002113 }
Dan Albert914449f2016-06-17 16:45:24 -07002114
2115 version := ctx.sdkVersion()
Colin Cross6e511a92020-07-27 21:26:48 -07002116
2117 ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002118 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002119 {Mutator: "ndk_api", Variation: version},
2120 {Mutator: "link", Variation: "shared"},
2121 }, ndkStubDepTag, variantNdkLibs...)
Colin Cross6e511a92020-07-27 21:26:48 -07002122
2123 ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002124 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002125 {Mutator: "ndk_api", Variation: version},
2126 {Mutator: "link", Variation: "shared"},
2127 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002128
2129 if vndkdep := c.vndkdep; vndkdep != nil {
2130 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002131 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002132 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002133 {Mutator: "link", Variation: "shared"},
2134 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002135 }
2136 }
Colin Cross6362e272015-10-29 15:25:03 -07002137}
Colin Cross21b9a242015-03-24 14:15:58 -07002138
Colin Crosse40b4ea2018-10-02 22:25:58 -07002139func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002140 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2141 c.beginMutator(ctx)
2142 }
2143}
2144
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002145// Whether a module can link to another module, taking into
2146// account NDK linking.
Colin Cross6e511a92020-07-27 21:26:48 -07002147func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface,
2148 tag blueprint.DependencyTag) {
2149
2150 switch t := tag.(type) {
2151 case dependencyTag:
2152 if t != vndkExtDepTag {
2153 return
2154 }
2155 case libraryDependencyTag:
2156 default:
2157 return
2158 }
2159
Ivan Lozano52767be2019-10-18 14:49:46 -07002160 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002161 // Host code is not restricted
2162 return
2163 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002164
2165 // VNDK is cc.Module supported only for now.
2166 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002167 // Though vendor code is limited by the vendor mutator,
2168 // each vendor-available module needs to check
2169 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002170 if ccTo, ok := to.(*Module); ok {
2171 if ccFrom.vndkdep != nil {
2172 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2173 }
2174 } else {
2175 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002176 }
2177 return
2178 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002179 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002180 // Platform code can link to anything
2181 return
2182 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002183 if from.InRamdisk() {
2184 // Ramdisk code is not NDK
2185 return
2186 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002187 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002188 // Recovery code is not NDK
2189 return
2190 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002191 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002192 // These are always allowed
2193 return
2194 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002195 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002196 // These are allowed, but they don't set sdk_version
2197 return
2198 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002199 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002200 // These aren't real libraries, but are the stub shared libraries that are included in
2201 // the NDK.
2202 return
2203 }
Logan Chien834b9a62019-01-14 15:39:03 +08002204
Ivan Lozano52767be2019-10-18 14:49:46 -07002205 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002206 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2207 // to link to libc++ (non-NDK and without sdk_version).
2208 return
2209 }
2210
Ivan Lozano52767be2019-10-18 14:49:46 -07002211 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002212 // NDK code linking to platform code is never okay.
2213 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002214 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002215 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002216 }
2217
2218 // At this point we know we have two NDK libraries, but we need to
2219 // check that we're not linking against anything built against a higher
2220 // API level, as it is only valid to link against older or equivalent
2221 // APIs.
2222
Inseob Kim01a28722018-04-11 09:48:45 +09002223 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002224 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002225 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002226 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002227 // Current can't be linked against by anything else.
2228 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002229 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002230 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002231 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002232 if err != nil {
2233 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002234 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002235 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002236 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002237 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002238 if err != nil {
2239 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002240 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002241 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002242 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002243
Inseob Kim01a28722018-04-11 09:48:45 +09002244 if toApi > fromApi {
2245 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002246 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002247 }
2248 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002249 }
Dan Albert202fe492017-12-15 13:56:59 -08002250
2251 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002252 fromStl := from.SelectedStl()
2253 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002254 if fromStl == "" || toStl == "" {
2255 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002256 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002257 // We can be permissive with the system "STL" since it is only the C++
2258 // ABI layer, but in the future we should make sure that everyone is
2259 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002260 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002261 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002262 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2263 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002264 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002265}
2266
Jiyong Park5fb8c102018-04-09 12:03:06 +09002267// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002268// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2269// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002270// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002271func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2272 check := func(child, parent android.Module) bool {
2273 to, ok := child.(*Module)
2274 if !ok {
2275 // follow thru cc.Defaults, etc.
2276 return true
2277 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002278
Jooyung Hana70f0672019-01-18 15:20:43 +09002279 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2280 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002281 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002282
2283 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002284 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002285 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002286 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002287
Jooyung Han0302a842019-10-30 18:43:49 +09002288 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002289 return false
2290 }
2291
2292 var stringPath []string
2293 for _, m := range ctx.GetWalkPath() {
2294 stringPath = append(stringPath, m.Name())
2295 }
2296 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2297 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2298 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2299 return false
2300 }
2301 if module, ok := ctx.Module().(*Module); ok {
2302 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002303 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002304 ctx.WalkDeps(check)
2305 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002306 }
2307 }
2308}
2309
Colin Crossc99deeb2016-04-11 15:06:20 -07002310// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002311func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002312 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002313
Ivan Lozano183a3212019-10-18 14:18:45 -07002314 directStaticDeps := []LinkableInterface{}
2315 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002316
Inseob Kim69378442019-06-03 19:10:47 +09002317 reexportExporter := func(exporter exportedFlagsProducer) {
2318 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2319 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2320 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2321 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002322 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002323 }
2324
Jooyung Hande34d232020-07-23 13:04:15 +09002325 // For the dependency from platform to apex, use the latest stubs
2326 c.apexSdkVersion = android.FutureApiLevel
2327 if !c.IsForPlatform() {
Dan Albertc8060532020-07-22 22:32:17 -07002328 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion(ctx)
Jooyung Hande34d232020-07-23 13:04:15 +09002329 }
2330
2331 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2332 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2333 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2334 // (b/144430859)
2335 c.apexSdkVersion = android.FutureApiLevel
2336 }
2337
Colin Crossd11fcda2017-10-23 17:59:01 -07002338 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002339 depName := ctx.OtherModuleName(dep)
2340 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002341
Ivan Lozano52767be2019-10-18 14:49:46 -07002342 ccDep, ok := dep.(LinkableInterface)
2343 if !ok {
2344
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002345 // handling for a few module types that aren't cc Module but that are also supported
2346 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002347 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002348 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002349 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2350 genRule.GeneratedSourceFiles()...)
2351 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002352 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002353 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002354 // Support exported headers from a generated_sources dependency
2355 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002356 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002357 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09002358 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002359 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002360 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002361 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002362 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002363 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002364 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2365 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002366 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002367 // 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 +09002368 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002369
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002370 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002371 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002372 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002373 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002374 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002375 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002376 files := genRule.GeneratedSourceFiles()
2377 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002378 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002379 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002380 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 -07002381 }
2382 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002383 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002384 }
Colin Crossca860ac2016-01-04 14:34:37 -08002385 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002386 return
2387 }
2388
Colin Crossfe17f6f2019-03-28 19:30:56 -07002389 if depTag == android.ProtoPluginDepTag {
2390 return
2391 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002392 if depTag == llndkImplDep {
2393 return
2394 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002395
Colin Crossd11fcda2017-10-23 17:59:01 -07002396 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002397 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2398 return
2399 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002400 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002401 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2402 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002403 return
2404 }
2405
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002406 // re-exporting flags
2407 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002408 // reusing objects only make sense for cc.Modules.
2409 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002410 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002411 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002412 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002413 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002414 return
2415 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002416 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002417
Jiyong Parke4bb9862019-02-01 00:31:10 +09002418 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002419 // staticVariants are a cc.Module specific concept.
2420 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002421 c.staticVariant = ccDep
2422 return
2423 }
2424 }
2425
Colin Cross6e511a92020-07-27 21:26:48 -07002426 checkLinkType(ctx, c, ccDep, depTag)
2427
2428 linkFile := ccDep.OutputFile()
2429
2430 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
2431 // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
Dan Albertc8060532020-07-22 22:32:17 -07002432 if libDepTag.staticUnwinder && c.apexSdkVersion.GreaterThan(android.SdkVersion_Android10) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002433 return
2434 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002435
Colin Cross6e511a92020-07-27 21:26:48 -07002436 if ccDep.CcLibrary() && !libDepTag.static() {
Ivan Lozano52767be2019-10-18 14:49:46 -07002437 depIsStubs := ccDep.BuildStubs()
Jooyung Han624d35c2020-04-10 12:57:24 +09002438 depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
Colin Crossaede88c2020-08-11 12:17:01 -07002439 depInSameApexes := android.DirectlyInAllApexes(c.InApexes(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002440 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002441
2442 var useThisDep bool
Colin Cross6e511a92020-07-27 21:26:48 -07002443 if depIsStubs && libDepTag.explicitlyVersioned {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002444 // Always respect dependency to the versioned stubs (i.e. libX#10)
2445 useThisDep = true
2446 } else if !depHasStubs {
2447 // Use non-stub variant if that is the only choice
2448 // (i.e. depending on a lib without stubs.version property)
2449 useThisDep = true
2450 } else if c.IsForPlatform() {
2451 // If not building for APEX, use stubs only when it is from
2452 // an APEX (and not from platform)
2453 useThisDep = (depInPlatform != depIsStubs)
Jooyung Han624d35c2020-04-10 12:57:24 +09002454 if c.bootstrap() {
2455 // However, for host, ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002456 // always link to non-stub variant
2457 useThisDep = !depIsStubs
2458 }
Jiyong Park62304bb2020-04-13 16:19:48 +09002459 for _, testFor := range c.TestFor() {
2460 // Another exception: if this module is bundled with an APEX, then
2461 // it is linked with the non-stub variant of a module in the APEX
2462 // as if this is part of the APEX.
2463 if android.DirectlyInApex(testFor, depName) {
2464 useThisDep = !depIsStubs
2465 break
2466 }
2467 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002468 } else {
Colin Crossaede88c2020-08-11 12:17:01 -07002469 // If building for APEX, use stubs when the parent is in any APEX that
2470 // the child is not in.
2471 useThisDep = (depInSameApexes != depIsStubs)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002472 }
2473
Jooyung Han03b51852020-02-26 22:45:42 +09002474 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
Colin Cross6e511a92020-07-27 21:26:48 -07002475 if useThisDep && depIsStubs && !libDepTag.explicitlyVersioned {
Colin Cross7812fd32020-09-25 12:35:10 -07002476 versionToUse, err := c.ChooseSdkVersion(ctx, ccDep.StubsVersions(), c.apexSdkVersion)
Jooyung Han03b51852020-02-26 22:45:42 +09002477 if err != nil {
2478 ctx.OtherModuleErrorf(dep, err.Error())
2479 return
2480 }
2481 if versionToUse != ccDep.StubsVersion() {
2482 useThisDep = false
2483 }
2484 }
2485
Jiyong Park25fc6a92018-11-18 18:02:45 +09002486 if !useThisDep {
2487 return // stop processing this dep
2488 }
2489 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002490 if c.UseVndk() {
2491 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2492 // by default, use current version of LLNDK
2493 versionToUse := ""
Colin Crossd1f898e2020-08-18 18:35:15 -07002494 versions := m.AllStubsVersions()
Colin Crosse07f2312020-08-13 11:24:56 -07002495 if c.ApexVariationName() != "" && len(versions) > 0 {
Jooyung Han61b66e92020-03-21 14:21:46 +00002496 // if this is for use_vendor apex && dep has stubsVersions
2497 // apply the same rule of apex sdk enforcement to choose right version
2498 var err error
Colin Cross7812fd32020-09-25 12:35:10 -07002499 versionToUse, err = c.ChooseSdkVersion(ctx, versions, c.apexSdkVersion)
Jooyung Han61b66e92020-03-21 14:21:46 +00002500 if err != nil {
2501 ctx.OtherModuleErrorf(dep, err.Error())
2502 return
2503 }
2504 }
2505 if versionToUse != ccDep.StubsVersion() {
2506 return
2507 }
2508 }
2509 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002510
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002511 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2512
Ivan Lozano52767be2019-10-18 14:49:46 -07002513 // Exporting flags only makes sense for cc.Modules
2514 if _, ok := ccDep.(*Module); ok {
2515 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002516 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002517 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002518 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002519
Colin Cross6e511a92020-07-27 21:26:48 -07002520 if libDepTag.reexportFlags {
Ivan Lozano52767be2019-10-18 14:49:46 -07002521 reexportExporter(i)
2522 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2523 // Re-exported shared library headers must be included as well since they can help us with type information
2524 // about template instantiations (instantiated from their headers).
2525 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2526 // scripts.
2527 c.sabi.Properties.ReexportedIncludes = append(
2528 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2529 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002530 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002531 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002532
Colin Cross6e511a92020-07-27 21:26:48 -07002533 var ptr *android.Paths
2534 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002535
Colin Cross6e511a92020-07-27 21:26:48 -07002536 depFile := android.OptionalPath{}
Colin Cross26c34ed2016-09-30 17:10:16 -07002537
Colin Cross6e511a92020-07-27 21:26:48 -07002538 switch {
2539 case libDepTag.header():
2540 // nothing
2541 case libDepTag.shared():
2542 ptr = &depPaths.SharedLibs
2543 switch libDepTag.Order {
2544 case earlyLibraryDependency:
2545 ptr = &depPaths.EarlySharedLibs
2546 depPtr = &depPaths.EarlySharedLibsDeps
2547 case normalLibraryDependency:
2548 ptr = &depPaths.SharedLibs
2549 depPtr = &depPaths.SharedLibsDeps
2550 directSharedDeps = append(directSharedDeps, ccDep)
2551 case lateLibraryDependency:
2552 ptr = &depPaths.LateSharedLibs
2553 depPtr = &depPaths.LateSharedLibsDeps
2554 default:
2555 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Colin Crossc99deeb2016-04-11 15:06:20 -07002556 }
Colin Cross6e511a92020-07-27 21:26:48 -07002557 depFile = ccDep.Toc()
2558 case libDepTag.static():
2559 if libDepTag.wholeStatic {
2560 ptr = &depPaths.WholeStaticLibs
2561 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2562 ctx.ModuleErrorf("module %q not a static library", depName)
2563 return
Inseob Kim752edec2020-03-14 01:30:34 +09002564 }
2565
Colin Cross6e511a92020-07-27 21:26:48 -07002566 // Because the static library objects are included, this only makes sense
2567 // in the context of proper cc.Modules.
2568 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2569 staticLib := ccWholeStaticLib.linker.(libraryInterface)
Colin Crosse4f6eba2020-09-22 18:11:25 -07002570 if objs := staticLib.objs(); len(objs.objFiles) > 0 {
2571 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(objs)
Colin Cross6e511a92020-07-27 21:26:48 -07002572 } else {
Colin Crosse4f6eba2020-09-22 18:11:25 -07002573 // This case normally catches prebuilt static
2574 // libraries, but it can also occur when
2575 // AllowMissingDependencies is on and the
2576 // dependencies has no sources of its own
2577 // but has a whole_static_libs dependency
2578 // on a missing library. We want to depend
2579 // on the .a file so that there is something
2580 // in the dependency tree that contains the
2581 // error rule for the missing transitive
2582 // dependency.
2583 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
Colin Cross6e511a92020-07-27 21:26:48 -07002584 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002585 } else {
Colin Cross6e511a92020-07-27 21:26:48 -07002586 ctx.ModuleErrorf(
2587 "non-cc.Modules cannot be included as whole static libraries.", depName)
2588 return
2589 }
2590
2591 } else {
2592 switch libDepTag.Order {
2593 case earlyLibraryDependency:
2594 panic(fmt.Errorf("early static libs not suppported"))
2595 case normalLibraryDependency:
2596 // static dependencies will be handled separately so they can be ordered
2597 // using transitive dependencies.
2598 ptr = nil
2599 directStaticDeps = append(directStaticDeps, ccDep)
2600 case lateLibraryDependency:
2601 ptr = &depPaths.LateStaticLibs
2602 default:
2603 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Inseob Kimeec88e12020-01-22 11:11:29 +09002604 }
2605 }
2606 }
2607
Colin Cross6e511a92020-07-27 21:26:48 -07002608 if libDepTag.static() && !libDepTag.wholeStatic {
2609 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2610 ctx.ModuleErrorf("module %q not a static library", depName)
2611 return
2612 }
Logan Chien43d34c32017-12-20 01:17:32 +08002613
Colin Cross6e511a92020-07-27 21:26:48 -07002614 // When combining coverage files for shared libraries and executables, coverage files
2615 // in static libraries act as if they were whole static libraries. The same goes for
2616 // source based Abi dump files.
2617 if c, ok := ccDep.(*Module); ok {
2618 staticLib := c.linker.(libraryInterface)
2619 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2620 staticLib.objs().coverageFiles...)
2621 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2622 staticLib.objs().sAbiDumpFiles...)
2623 } else if c, ok := ccDep.(LinkableInterface); ok {
2624 // Handle non-CC modules here
2625 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2626 c.CoverageFiles()...)
Jiyong Parkde866cb2018-12-07 23:08:36 +09002627 }
2628 }
2629
Colin Cross6e511a92020-07-27 21:26:48 -07002630 if ptr != nil {
2631 if !linkFile.Valid() {
2632 if !ctx.Config().AllowMissingDependencies() {
2633 ctx.ModuleErrorf("module %q missing output file", depName)
2634 } else {
2635 ctx.AddMissingDependencies([]string{depName})
2636 }
2637 return
2638 }
2639 *ptr = append(*ptr, linkFile.Path())
2640 }
2641
2642 if depPtr != nil {
2643 dep := depFile
2644 if !dep.Valid() {
2645 dep = linkFile
2646 }
2647 *depPtr = append(*depPtr, dep.Path())
2648 }
2649
2650 makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix
2651 switch {
2652 case libDepTag.header():
Colin Cross370173e2020-07-29 12:48:33 -07002653 c.Properties.AndroidMkHeaderLibs = append(
2654 c.Properties.AndroidMkHeaderLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002655 case libDepTag.shared():
2656 if ccDep.CcLibrary() {
2657 if ccDep.BuildStubs() && android.InAnyApex(depName) {
2658 // Add the dependency to the APEX(es) providing the library so that
2659 // m <module> can trigger building the APEXes as well.
2660 for _, an := range android.GetApexesForModule(depName) {
2661 c.Properties.ApexesProvidingSharedLibs = append(
2662 c.Properties.ApexesProvidingSharedLibs, an)
2663 }
2664 }
2665 }
2666
2667 // Note: the order of libs in this list is not important because
2668 // they merely serve as Make dependencies and do not affect this lib itself.
Colin Cross370173e2020-07-29 12:48:33 -07002669 c.Properties.AndroidMkSharedLibs = append(
2670 c.Properties.AndroidMkSharedLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002671 // Record baseLibName for snapshots.
2672 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
2673 case libDepTag.static():
2674 if libDepTag.wholeStatic {
2675 c.Properties.AndroidMkWholeStaticLibs = append(
2676 c.Properties.AndroidMkWholeStaticLibs, makeLibName)
2677 } else {
2678 c.Properties.AndroidMkStaticLibs = append(
2679 c.Properties.AndroidMkStaticLibs, makeLibName)
2680 }
2681 }
2682 } else {
2683 switch depTag {
2684 case runtimeDepTag:
2685 c.Properties.AndroidMkRuntimeLibs = append(
2686 c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix)
2687 // Record baseLibName for snapshots.
2688 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
2689 case objDepTag:
2690 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
2691 case CrtBeginDepTag:
2692 depPaths.CrtBegin = linkFile
2693 case CrtEndDepTag:
2694 depPaths.CrtEnd = linkFile
2695 case dynamicLinkerDepTag:
2696 depPaths.DynamicLinker = linkFile
2697 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002698 }
Colin Crossca860ac2016-01-04 14:34:37 -08002699 })
2700
Jeff Gaston294356f2017-09-27 17:05:30 -07002701 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002702 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002703
Colin Crossdd84e052017-05-17 13:44:16 -07002704 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002705 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002706 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2707 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09002708 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002709 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2710 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002711 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002712 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002713 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002714
2715 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002716 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002717 }
Colin Crossdd84e052017-05-17 13:44:16 -07002718
Colin Crossca860ac2016-01-04 14:34:37 -08002719 return depPaths
2720}
2721
Colin Cross6e511a92020-07-27 21:26:48 -07002722// baseLibName trims known prefixes and suffixes
2723func baseLibName(depName string) string {
2724 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
2725 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
2726 libName = strings.TrimPrefix(libName, "prebuilt_")
2727 return libName
2728}
2729
2730func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
2731 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2732 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2733
2734 libName := baseLibName(depName)
2735 isLLndk := isLlndkLibrary(libName, ctx.Config())
2736 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
2737 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
2738
2739 if c, ok := ccDep.(*Module); ok {
2740 // Use base module name for snapshots when exporting to Makefile.
2741 if c.isSnapshotPrebuilt() {
2742 baseName := c.BaseModuleName()
2743
2744 if c.IsVndk() {
2745 return baseName + ".vendor"
2746 }
2747
2748 if vendorSuffixModules[baseName] {
2749 return baseName + ".vendor"
2750 } else {
2751 return baseName
2752 }
2753 }
2754 }
2755
2756 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
2757 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2758 // core module instead.
2759 return libName
2760 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
2761 // The vendor module in Make will have been renamed to not conflict with the core
2762 // module, so update the dependency name here accordingly.
2763 return libName + c.getNameSuffixWithVndkVersion(ctx)
2764 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
2765 return libName + vendorPublicLibrarySuffix
2766 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2767 return libName + ramdiskSuffix
2768 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
2769 return libName + recoverySuffix
2770 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
2771 return libName + nativeBridgeSuffix
2772 } else {
2773 return libName
2774 }
2775}
2776
Colin Crossca860ac2016-01-04 14:34:37 -08002777func (c *Module) InstallInData() bool {
2778 if c.installer == nil {
2779 return false
2780 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002781 return c.installer.inData()
2782}
2783
2784func (c *Module) InstallInSanitizerDir() bool {
2785 if c.installer == nil {
2786 return false
2787 }
2788 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002789 return true
2790 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002791 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002792}
2793
Yifan Hong1b3348d2020-01-21 15:53:22 -08002794func (c *Module) InstallInRamdisk() bool {
2795 return c.InRamdisk()
2796}
2797
Jiyong Parkf9332f12018-02-01 00:54:12 +09002798func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002799 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002800}
2801
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002802func (c *Module) MakeUninstallable() {
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002803 if c.installer == nil {
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002804 c.ModuleBase.MakeUninstallable()
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002805 return
2806 }
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002807 c.installer.makeUninstallable(c)
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002808}
2809
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002810func (c *Module) HostToolPath() android.OptionalPath {
2811 if c.installer == nil {
2812 return android.OptionalPath{}
2813 }
2814 return c.installer.hostToolPath()
2815}
2816
Nan Zhangd4e641b2017-07-12 12:55:28 -07002817func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2818 return c.outputFile
2819}
2820
Colin Cross41955e82019-05-29 14:40:35 -07002821func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2822 switch tag {
2823 case "":
2824 if c.outputFile.Valid() {
2825 return android.Paths{c.outputFile.Path()}, nil
2826 }
2827 return android.Paths{}, nil
2828 default:
2829 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002830 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002831}
2832
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002833func (c *Module) static() bool {
2834 if static, ok := c.linker.(interface {
2835 static() bool
2836 }); ok {
2837 return static.static()
2838 }
2839 return false
2840}
2841
Jiyong Park379de2f2018-12-19 02:47:14 +09002842func (c *Module) staticBinary() bool {
2843 if static, ok := c.linker.(interface {
2844 staticBinary() bool
2845 }); ok {
2846 return static.staticBinary()
2847 }
2848 return false
2849}
2850
Jiyong Park1d1119f2019-07-29 21:27:18 +09002851func (c *Module) header() bool {
2852 if h, ok := c.linker.(interface {
2853 header() bool
2854 }); ok {
2855 return h.header()
2856 }
2857 return false
2858}
2859
Inseob Kim7f283f42020-06-01 21:53:49 +09002860func (c *Module) binary() bool {
2861 if b, ok := c.linker.(interface {
2862 binary() bool
2863 }); ok {
2864 return b.binary()
2865 }
2866 return false
2867}
2868
Inseob Kim1042d292020-06-01 23:23:05 +09002869func (c *Module) object() bool {
2870 if o, ok := c.linker.(interface {
2871 object() bool
2872 }); ok {
2873 return o.object()
2874 }
2875 return false
2876}
2877
Jooyung Han38002912019-05-16 04:01:54 +09002878func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002879 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002880 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2881 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002882 return "native:vndk"
2883 }
Jooyung Han38002912019-05-16 04:01:54 +09002884 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002885 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002886 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002887 if Bool(c.VendorProperties.Vendor_available) {
2888 return "native:vndk"
2889 }
2890 return "native:vndk_private"
2891 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002892 if c.inProduct() {
2893 return "native:product"
2894 }
Jooyung Han38002912019-05-16 04:01:54 +09002895 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002896 } else if c.InRamdisk() {
2897 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002898 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002899 return "native:recovery"
2900 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2901 return "native:ndk:none:none"
2902 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2903 //family, link := getNdkStlFamilyAndLinkType(c)
2904 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002905 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002906 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002907 } else {
2908 return "native:platform"
2909 }
2910}
2911
Jiyong Park9d452992018-10-03 00:38:19 +09002912// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002913// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002914func (c *Module) IsInstallableToApex() bool {
2915 if shared, ok := c.linker.(interface {
2916 shared() bool
2917 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002918 // Stub libs and prebuilt libs in a versioned SDK are not
2919 // installable to APEX even though they are shared libs.
2920 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002921 } else if _, ok := c.linker.(testPerSrc); ok {
2922 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002923 }
2924 return false
2925}
2926
Jiyong Parka90ca002019-10-07 15:47:24 +09002927func (c *Module) AvailableFor(what string) bool {
2928 if linker, ok := c.linker.(interface {
2929 availableFor(string) bool
2930 }); ok {
2931 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2932 } else {
2933 return c.ApexModuleBase.AvailableFor(what)
2934 }
2935}
2936
Jiyong Park62304bb2020-04-13 16:19:48 +09002937func (c *Module) TestFor() []string {
2938 if test, ok := c.linker.(interface {
2939 testFor() []string
2940 }); ok {
2941 return test.testFor()
2942 } else {
2943 return c.ApexModuleBase.TestFor()
2944 }
2945}
2946
Colin Crossaede88c2020-08-11 12:17:01 -07002947func (c *Module) UniqueApexVariations() bool {
2948 if u, ok := c.compiler.(interface {
2949 uniqueApexVariations() bool
2950 }); ok {
2951 return u.uniqueApexVariations()
2952 } else {
2953 return false
2954 }
2955}
2956
Paul Duffin0cb37b92020-03-04 14:52:46 +00002957// Return true if the module is ever installable.
2958func (c *Module) EverInstallable() bool {
2959 return c.installer != nil &&
2960 // Check to see whether the module is actually ever installable.
2961 c.installer.everInstallable()
2962}
2963
Inseob Kim1f086e22019-05-09 13:29:15 +09002964func (c *Module) installable() bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00002965 ret := c.EverInstallable() &&
2966 // Check to see whether the module has been configured to not be installed.
2967 proptools.BoolDefault(c.Properties.Installable, true) &&
2968 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002969
2970 // The platform variant doesn't need further condition. Apex variants however might not
2971 // be installable because it will likely to be included in the APEX and won't appear
2972 // in the system partition.
2973 if c.IsForPlatform() {
2974 return ret
2975 }
2976
2977 // Special case for modules that are configured to be installed to /data, which includes
2978 // test modules. For these modules, both APEX and non-APEX variants are considered as
2979 // installable. This is because even the APEX variants won't be included in the APEX, but
2980 // will anyway be installed to /data/*.
2981 // See b/146995717
2982 if c.InstallInData() {
2983 return ret
2984 }
2985
2986 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002987}
2988
Logan Chien41eabe62019-04-10 13:33:58 +08002989func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2990 if c.linker != nil {
2991 if library, ok := c.linker.(*libraryDecorator); ok {
2992 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2993 }
2994 }
2995}
2996
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002997func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Colin Cross6e511a92020-07-27 21:26:48 -07002998 depTag := ctx.OtherModuleDependencyTag(dep)
2999 libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
3000
3001 if cc, ok := dep.(*Module); ok {
3002 if cc.HasStubsVariants() {
3003 if isLibDepTag && libDepTag.shared() {
3004 // dynamic dep to a stubs lib crosses APEX boundary
3005 return false
Jiyong Parkd7536ba2020-01-16 17:14:23 +09003006 }
Colin Cross6e511a92020-07-27 21:26:48 -07003007 if IsRuntimeDepTag(depTag) {
3008 // runtime dep to a stubs lib also crosses APEX boundary
Jiyong Parkd7536ba2020-01-16 17:14:23 +09003009 return false
3010 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003011 }
Colin Crossaac32222020-07-29 12:51:56 -07003012 if isLibDepTag && c.static() && libDepTag.shared() {
Colin Cross6e511a92020-07-27 21:26:48 -07003013 // shared_lib dependency from a static lib is considered as crossing
3014 // the APEX boundary because the dependency doesn't actually is
3015 // linked; the dependency is used only during the compilation phase.
3016 return false
3017 }
3018 }
3019 if depTag == llndkImplDep {
Jiyong Park7d95a512020-05-10 15:16:24 +09003020 // We don't track beyond LLNDK
3021 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003022 }
3023 return true
3024}
3025
Dan Albertc8060532020-07-22 22:32:17 -07003026func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
3027 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +09003028 // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
3029 if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
3030 return nil
3031 }
3032 // b/154569636: set min_sdk_version correctly for toolchain_libraries
3033 if c.ToolchainLibrary() {
3034 return nil
3035 }
3036 // We don't check for prebuilt modules
3037 if _, ok := c.linker.(prebuiltLinkerInterface); ok {
3038 return nil
3039 }
3040 minSdkVersion := c.MinSdkVersion()
3041 if minSdkVersion == "apex_inherit" {
3042 return nil
3043 }
3044 if minSdkVersion == "" {
3045 // JNI libs within APK-in-APEX fall into here
3046 // Those are okay to set sdk_version instead
3047 // We don't have to check if this is a SDK variant because
3048 // non-SDK variant resets sdk_version, which works too.
3049 minSdkVersion = c.SdkVersion()
3050 }
Dan Albertc8060532020-07-22 22:32:17 -07003051 if minSdkVersion == "" {
3052 return fmt.Errorf("neither min_sdk_version nor sdk_version specificed")
3053 }
3054 // Not using nativeApiLevelFromUser because the context here is not
3055 // necessarily a native context.
3056 ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
Jooyung Han749dc692020-04-15 11:03:39 +09003057 if err != nil {
3058 return err
3059 }
Dan Albertc8060532020-07-22 22:32:17 -07003060
3061 if ver.GreaterThan(sdkVersion) {
Jooyung Han749dc692020-04-15 11:03:39 +09003062 return fmt.Errorf("newer SDK(%v)", ver)
3063 }
3064 return nil
3065}
3066
Colin Cross2ba19d92015-05-07 15:44:20 -07003067//
Colin Crosscfad1192015-11-02 16:43:11 -08003068// Defaults
3069//
Colin Crossca860ac2016-01-04 14:34:37 -08003070type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07003071 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07003072 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09003073 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08003074}
3075
Patrice Arrudac249c712019-03-19 17:00:29 -07003076// cc_defaults provides a set of properties that can be inherited by other cc
3077// modules. A module can use the properties from a cc_defaults using
3078// `defaults: ["<:default_module_name>"]`. Properties of both modules are
3079// merged (when possible) by prepending the default module's values to the
3080// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07003081func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07003082 return DefaultsFactory()
3083}
3084
Colin Cross36242852017-06-23 15:06:31 -07003085func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08003086 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08003087
Colin Cross36242852017-06-23 15:06:31 -07003088 module.AddProperties(props...)
3089 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08003090 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07003091 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003092 &BaseCompilerProperties{},
3093 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01003094 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003095 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07003096 &StaticProperties{},
3097 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07003098 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003099 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003100 &TestProperties{},
3101 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07003102 &BenchmarkProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07003103 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003104 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08003105 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07003106 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07003107 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07003108 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08003109 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08003110 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09003111 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07003112 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07003113 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08003114 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07003115 )
Colin Crosscfad1192015-11-02 16:43:11 -08003116
Jooyung Hancc372c52019-09-25 15:18:44 +09003117 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07003118
3119 return module
Colin Crosscfad1192015-11-02 16:43:11 -08003120}
3121
Jiyong Park6a43f042017-10-12 23:05:00 +09003122func squashVendorSrcs(m *Module) {
3123 if lib, ok := m.compiler.(*libraryDecorator); ok {
3124 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3125 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
3126
3127 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3128 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003129
3130 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3131 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
Jiyong Park6a43f042017-10-12 23:05:00 +09003132 }
3133}
3134
Jiyong Parkf9332f12018-02-01 00:54:12 +09003135func squashRecoverySrcs(m *Module) {
3136 if lib, ok := m.compiler.(*libraryDecorator); ok {
3137 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3138 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
3139
3140 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3141 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003142
3143 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3144 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003145 }
3146}
3147
Jiyong Park2286afd2020-06-16 21:58:53 +09003148func (c *Module) IsSdkVariant() bool {
Dan Albert92fe7402020-07-15 13:33:30 -07003149 return c.Properties.IsSdkVariant || c.AlwaysSdk()
Jiyong Park2286afd2020-06-16 21:58:53 +09003150}
3151
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003152func kytheExtractAllFactory() android.Singleton {
3153 return &kytheExtractAllSingleton{}
3154}
3155
3156type kytheExtractAllSingleton struct {
3157}
3158
3159func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3160 var xrefTargets android.Paths
3161 ctx.VisitAllModules(func(module android.Module) {
3162 if ccModule, ok := module.(xref); ok {
3163 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3164 }
3165 })
3166 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3167 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07003168 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003169 }
3170}
3171
Colin Cross06a931b2015-10-28 17:23:31 -07003172var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003173var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003174var BoolPtr = proptools.BoolPtr
3175var String = proptools.String
3176var StringPtr = proptools.StringPtr