blob: 512fe8eb4125c92ac007512bf2f0bd2fa8fb2de6 [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() {
Colin Cross798bfce2016-10-12 14:28:16 -070036 android.RegisterModuleType("cc_defaults", defaultsFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070037
Colin Cross1e676be2016-10-12 14:38:15 -070038 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Inseob Kim64c43952019-08-26 16:52:35 +090039 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070040 ctx.BottomUp("link", LinkageMutator).Parallel()
Jooyung Hanb90e4912019-12-09 18:21:48 +090041 ctx.BottomUp("ndk_api", NdkApiMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +010042 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090043 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070044 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimc0907f12019-02-08 21:00:45 +090045 ctx.BottomUp("sysprop", SyspropMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070046 })
Colin Cross16b23492016-01-06 14:41:07 -080047
Colin Cross1e676be2016-10-12 14:38:15 -070048 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
49 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
50 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080051
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070052 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
53 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
54
Mitch Phillipsbfeade62019-05-01 14:42:05 -070055 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
56 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
57
Jiyong Park1d1119f2019-07-29 21:27:18 +090058 // cfi mutator shouldn't run before sanitizers that return true for
59 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000060 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
61 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
62
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080063 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
64 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
65
Colin Cross1e676be2016-10-12 14:38:15 -070066 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
67 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080068
Colin Cross0b908332019-06-19 23:00:20 -070069 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090070 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080071
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080072 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080073 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070074
75 ctx.TopDown("lto_deps", ltoDepsMutator)
76 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090077
78 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070079 })
Colin Crossb98c8b02016-07-29 13:44:28 -070080
Sasha Smundak2a4549e2018-11-05 16:49:08 -080081 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Crossb98c8b02016-07-29 13:44:28 -070082 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070083}
84
Colin Crossca860ac2016-01-04 14:34:37 -080085type Deps struct {
86 SharedLibs, LateSharedLibs []string
87 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080088 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080089 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070090
Colin Cross5950f382016-12-13 12:50:57 -080091 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070092
Colin Cross81413472016-04-11 14:37:39 -070093 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070094
Dan Willemsenb40aab62016-04-20 14:21:14 -070095 GeneratedSources []string
96 GeneratedHeaders []string
Inseob Kimd110f872019-12-06 13:15:38 +090097 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -070098
Dan Willemsenb3454ab2016-09-28 17:34:58 -070099 ReexportGeneratedHeaders []string
100
Colin Cross97ba0732015-03-23 17:50:24 -0700101 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700102
103 // Used for host bionic
104 LinkerFlagsFile string
105 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700106}
107
Colin Crossca860ac2016-01-04 14:34:37 -0800108type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700109 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900110 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700111 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900112 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700113 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700114 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700115
Colin Cross26c34ed2016-09-30 17:10:16 -0700116 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700117 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800118 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700119 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700120
Colin Cross26c34ed2016-09-30 17:10:16 -0700121 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700122 GeneratedSources android.Paths
123 GeneratedHeaders android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900124 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700125
Inseob Kimd110f872019-12-06 13:15:38 +0900126 Flags []string
127 IncludeDirs android.Paths
128 SystemIncludeDirs android.Paths
129 ReexportedDirs android.Paths
130 ReexportedSystemDirs android.Paths
131 ReexportedFlags []string
132 ReexportedGeneratedHeaders android.Paths
133 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700134
Colin Cross26c34ed2016-09-30 17:10:16 -0700135 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700136 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700137
138 // Path to the file container flags to use with the linker
139 LinkerFlagsFile android.OptionalPath
140
141 // Path to the dynamic linker binary
142 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700143}
144
Colin Cross4af21ed2019-11-04 09:37:55 -0800145// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
146// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
147// command line so they can be overridden by the local module flags).
148type LocalOrGlobalFlags struct {
149 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700150 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800151 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700152 CFlags []string // Flags that apply to C and C++ source files
153 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
154 ConlyFlags []string // Flags that apply to C source files
155 CppFlags []string // Flags that apply to C++ source files
156 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700157 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800158}
159
160type Flags struct {
161 Local LocalOrGlobalFlags
162 Global LocalOrGlobalFlags
163
164 aidlFlags []string // Flags that apply to aidl source files
165 rsFlags []string // Flags that apply to renderscript source files
166 libFlags []string // Flags to add libraries early to the link order
167 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
168 TidyFlags []string // Flags that apply to clang-tidy
169 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700170
Colin Crossc3199482017-03-30 15:03:04 -0700171 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800172 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700173 SystemIncludeFlags []string
174
Colin Crossb98c8b02016-07-29 13:44:28 -0700175 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700176 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800177 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800178 SAbiDump bool
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800179 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800180
181 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800182 DynamicLinker string
183
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700184 CFlagsDeps android.Paths // Files depended on by compiler flags
185 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800186
Dan Willemsen98ab3112019-08-27 21:20:40 -0700187 AssemblerWithCpp bool
188 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800189
Colin Cross19878da2019-03-28 14:45:07 -0700190 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700191 protoC bool // Whether to use C instead of C++
192 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700193
194 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700195}
196
Colin Crossca860ac2016-01-04 14:34:37 -0800197// Properties used to compile all C or C++ modules
198type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700199 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800200 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700201
202 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800203 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700204
Jiyong Parkde866cb2018-12-07 23:08:36 +0900205 AndroidMkSharedLibs []string `blueprint:"mutated"`
206 AndroidMkStaticLibs []string `blueprint:"mutated"`
207 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
208 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
209 HideFromMake bool `blueprint:"mutated"`
210 PreventInstall bool `blueprint:"mutated"`
211 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700212
Inseob Kim64c43952019-08-26 16:52:35 +0900213 VndkVersion string `blueprint:"mutated"`
214 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800215
216 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
217 // file
218 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900219
220 // Make this module available when building for recovery
221 Recovery_available *bool
222
Colin Crossae6c5202019-11-20 13:35:50 -0800223 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800224 CoreVariantNeeded bool `blueprint:"mutated"`
225 RecoveryVariantNeeded bool `blueprint:"mutated"`
226 VendorVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900227
228 // Allows this module to use non-APEX version of libraries. Useful
229 // for building binaries that are started before APEXes are activated.
230 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900231
232 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
233 // see soong/cc/config/vndk.go
234 MustUseVendorVariant bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700235}
236
237type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900238 // whether this module should be allowed to be directly depended by other
239 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
240 // If set to true, two variants will be built separately, one like
241 // normal, and the other limited to the set of libraries and headers
242 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700243 //
244 // The vendor variant may be used with a different (newer) /system,
245 // so it shouldn't have any unversioned runtime dependencies, or
246 // make assumptions about the system that may not be true in the
247 // future.
248 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900249 // If set to false, this module becomes inaccessible from /vendor modules.
250 //
251 // Default value is true when vndk: {enabled: true} or vendor: true.
252 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700253 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
254 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900255
256 // whether this module is capable of being loaded with other instance
257 // (possibly an older version) of the same module in the same process.
258 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
259 // can be double loaded in a vendor process if the library is also a
260 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
261 // explicitly marked as `double_loadable: true` by the owner, or the dependency
262 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
263 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800264}
265
Colin Crossca860ac2016-01-04 14:34:37 -0800266type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800267 static() bool
268 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900269 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700270 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700271 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800272 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700273 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800274 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900275 isLlndk(config android.Config) bool
276 isLlndkPublic(config android.Config) bool
277 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900278 isVndk() bool
279 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800280 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900281 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800282 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700283 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700284 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800285 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800286 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800287 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800288 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800289 isForPlatform() bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900290 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900291 hasStubsVariants() bool
292 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900293 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800294 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700295 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800296}
297
298type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700299 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800300 ModuleContextIntf
301}
302
303type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700304 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800305 ModuleContextIntf
306}
307
Colin Cross37047f12016-12-13 17:06:13 -0800308type DepsContext interface {
309 android.BottomUpMutatorContext
310 ModuleContextIntf
311}
312
Colin Crossca860ac2016-01-04 14:34:37 -0800313type feature interface {
314 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800315 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800316 flags(ctx ModuleContext, flags Flags) Flags
317 props() []interface{}
318}
319
320type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700321 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800322 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800323 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700324 compilerProps() []interface{}
325
Colin Cross76fada02016-07-27 10:31:13 -0700326 appendCflags([]string)
327 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700328 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800329}
330
331type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700332 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800333 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700334 linkerFlags(ctx ModuleContext, flags Flags) Flags
335 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800336 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700337
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700338 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700339 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900340 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700341
342 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900343 coverageOutputFilePath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800344}
345
346type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700347 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700348 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800349 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700350 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700351 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900352 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800353}
354
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800355type xref interface {
356 XrefCcFiles() android.Paths
357}
358
Colin Crossc99deeb2016-04-11 15:06:20 -0700359var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700360 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
361 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
362 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
363 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
364 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
365 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
366 headerDepTag = DependencyTag{Name: "header", Library: true}
367 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
368 genSourceDepTag = DependencyTag{Name: "gen source"}
369 genHeaderDepTag = DependencyTag{Name: "gen header"}
370 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
371 objDepTag = DependencyTag{Name: "obj"}
372 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
373 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
374 reuseObjTag = DependencyTag{Name: "reuse objects"}
375 staticVariantTag = DependencyTag{Name: "static variant"}
376 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
377 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
378 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
379 runtimeDepTag = DependencyTag{Name: "runtime lib"}
380 coverageDepTag = DependencyTag{Name: "coverage"}
381 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700382)
383
Roland Levillainf89cd092019-07-29 16:22:59 +0100384func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700385 ccDepTag, ok := depTag.(DependencyTag)
386 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100387}
388
389func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700390 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100391 return ok && ccDepTag == runtimeDepTag
392}
393
394func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700395 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100396 return ok && ccDepTag == testPerSrcDepTag
397}
398
Colin Crossca860ac2016-01-04 14:34:37 -0800399// Module contains the properties and members used by all C/C++ module types, and implements
400// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
401// to construct the output file. Behavior can be customized with a Customizer interface
402type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700403 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700404 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900405 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900406 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700407
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700408 Properties BaseProperties
409 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700410
Colin Crossca860ac2016-01-04 14:34:37 -0800411 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700412 hod android.HostOrDeviceSupported
413 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700414
Colin Crossca860ac2016-01-04 14:34:37 -0800415 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700416 features []feature
417 compiler compiler
418 linker linker
419 installer installer
420 stl *stl
421 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800422 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800423 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900424 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700425 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700426 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800427 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800428
429 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700430
Colin Cross635c3b02016-05-18 15:37:25 -0700431 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800432
Colin Crossb98c8b02016-07-29 13:44:28 -0700433 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700434
435 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800436
437 // Flags used to compile this module
438 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700439
440 // 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 -0800441 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700442 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800443 depsInLinkOrder android.Paths
444
445 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700446 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900447
448 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800449 // Kythe (source file indexer) paths for this compilation module
450 kytheFiles android.Paths
Colin Crossc472d572015-03-17 15:06:21 -0700451}
452
Ivan Lozano52767be2019-10-18 14:49:46 -0700453func (c *Module) Toc() android.OptionalPath {
454 if c.linker != nil {
455 if library, ok := c.linker.(libraryInterface); ok {
456 return library.toc()
457 }
458 }
459 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
460}
461
462func (c *Module) ApiLevel() string {
463 if c.linker != nil {
464 if stub, ok := c.linker.(*stubDecorator); ok {
465 return stub.properties.ApiLevel
466 }
467 }
468 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
469}
470
471func (c *Module) Static() bool {
472 if c.linker != nil {
473 if library, ok := c.linker.(libraryInterface); ok {
474 return library.static()
475 }
476 }
477 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
478}
479
480func (c *Module) Shared() bool {
481 if c.linker != nil {
482 if library, ok := c.linker.(libraryInterface); ok {
483 return library.shared()
484 }
485 }
486 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
487}
488
489func (c *Module) SelectedStl() string {
490 return c.stl.Properties.SelectedStl
491}
492
493func (c *Module) ToolchainLibrary() bool {
494 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
495 return true
496 }
497 return false
498}
499
500func (c *Module) NdkPrebuiltStl() bool {
501 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
502 return true
503 }
504 return false
505}
506
507func (c *Module) StubDecorator() bool {
508 if _, ok := c.linker.(*stubDecorator); ok {
509 return true
510 }
511 return false
512}
513
514func (c *Module) SdkVersion() string {
515 return String(c.Properties.Sdk_version)
516}
517
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800518func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700519 if c.linker != nil {
520 if library, ok := c.linker.(exportedFlagsProducer); ok {
521 return library.exportedDirs()
522 }
523 }
524 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
525}
526
527func (c *Module) HasStaticVariant() bool {
528 if c.staticVariant != nil {
529 return true
530 }
531 return false
532}
533
534func (c *Module) GetStaticVariant() LinkableInterface {
535 return c.staticVariant
536}
537
538func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
539 c.depsInLinkOrder = depsInLinkOrder
540}
541
542func (c *Module) GetDepsInLinkOrder() []android.Path {
543 return c.depsInLinkOrder
544}
545
546func (c *Module) StubsVersions() []string {
547 if c.linker != nil {
548 if library, ok := c.linker.(*libraryDecorator); ok {
549 return library.Properties.Stubs.Versions
550 }
551 }
552 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
553}
554
555func (c *Module) CcLibrary() bool {
556 if c.linker != nil {
557 if _, ok := c.linker.(*libraryDecorator); ok {
558 return true
559 }
560 }
561 return false
562}
563
564func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700565 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700566 return true
567 }
568 return false
569}
570
Ivan Lozano2b262972019-11-21 12:30:50 -0800571func (c *Module) NonCcVariants() bool {
572 return false
573}
574
Ivan Lozano183a3212019-10-18 14:18:45 -0700575func (c *Module) SetBuildStubs() {
576 if c.linker != nil {
577 if library, ok := c.linker.(*libraryDecorator); ok {
578 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700579 c.Properties.HideFromMake = true
580 c.sanitize = nil
581 c.stl = nil
582 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700583 return
584 }
585 }
586 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
587}
588
Ivan Lozano52767be2019-10-18 14:49:46 -0700589func (c *Module) BuildStubs() bool {
590 if c.linker != nil {
591 if library, ok := c.linker.(*libraryDecorator); ok {
592 return library.buildStubs()
593 }
594 }
595 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
596}
597
Ivan Lozano183a3212019-10-18 14:18:45 -0700598func (c *Module) SetStubsVersions(version string) {
599 if c.linker != nil {
600 if library, ok := c.linker.(*libraryDecorator); ok {
601 library.MutatedProperties.StubsVersion = version
602 return
603 }
604 }
605 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
606}
607
608func (c *Module) SetStatic() {
609 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700610 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700611 library.setStatic()
612 return
613 }
614 }
615 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
616}
617
618func (c *Module) SetShared() {
619 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700620 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700621 library.setShared()
622 return
623 }
624 }
625 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
626}
627
628func (c *Module) BuildStaticVariant() bool {
629 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700630 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700631 return library.buildStatic()
632 }
633 }
634 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
635}
636
637func (c *Module) BuildSharedVariant() bool {
638 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700639 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700640 return library.buildShared()
641 }
642 }
643 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
644}
645
646func (c *Module) Module() android.Module {
647 return c
648}
649
Jiyong Parkc20eee32018-09-05 22:36:17 +0900650func (c *Module) OutputFile() android.OptionalPath {
651 return c.outputFile
652}
653
Ivan Lozano183a3212019-10-18 14:18:45 -0700654var _ LinkableInterface = (*Module)(nil)
655
Jiyong Park719b4462019-01-13 00:39:51 +0900656func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900657 if c.linker != nil {
658 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900659 }
660 return nil
661}
662
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900663func (c *Module) CoverageOutputFile() android.OptionalPath {
664 if c.linker != nil {
665 return c.linker.coverageOutputFilePath()
666 }
667 return android.OptionalPath{}
668}
669
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900670func (c *Module) RelativeInstallPath() string {
671 if c.installer != nil {
672 return c.installer.relativeInstallPath()
673 }
674 return ""
675}
676
Jooyung Han344d5432019-08-23 11:17:39 +0900677func (c *Module) VndkVersion() string {
678 return c.vndkVersion()
679}
680
Colin Cross36242852017-06-23 15:06:31 -0700681func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700682 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800683 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700684 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800685 }
686 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700687 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800688 }
689 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700690 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800691 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700692 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700693 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700694 }
Colin Cross16b23492016-01-06 14:41:07 -0800695 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700696 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800697 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800698 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700699 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800700 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800701 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700702 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800703 }
Justin Yun8effde42017-06-23 19:24:43 +0900704 if c.vndkdep != nil {
705 c.AddProperties(c.vndkdep.props()...)
706 }
Stephen Craneba090d12017-05-09 15:44:35 -0700707 if c.lto != nil {
708 c.AddProperties(c.lto.props()...)
709 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700710 if c.pgo != nil {
711 c.AddProperties(c.pgo.props()...)
712 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800713 if c.xom != nil {
714 c.AddProperties(c.xom.props()...)
715 }
Colin Crossca860ac2016-01-04 14:34:37 -0800716 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700717 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800718 }
Colin Crossc472d572015-03-17 15:06:21 -0700719
Colin Crossa9d8bee2018-10-02 13:59:46 -0700720 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
721 switch class {
722 case android.Device:
723 return ctx.Config().DevicePrefer32BitExecutables()
724 case android.HostCross:
725 // Windows builds always prefer 32-bit
726 return true
727 default:
728 return false
729 }
730 })
Colin Cross36242852017-06-23 15:06:31 -0700731 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900732 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900733 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900734 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900735
Colin Cross36242852017-06-23 15:06:31 -0700736 return c
Colin Crossc472d572015-03-17 15:06:21 -0700737}
738
Colin Crossb916a382016-07-29 17:28:03 -0700739// Returns true for dependency roots (binaries)
740// TODO(ccross): also handle dlopenable libraries
741func (c *Module) isDependencyRoot() bool {
742 if root, ok := c.linker.(interface {
743 isDependencyRoot() bool
744 }); ok {
745 return root.isDependencyRoot()
746 }
747 return false
748}
749
Ivan Lozano52767be2019-10-18 14:49:46 -0700750func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900751 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700752}
753
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800754func (c *Module) isCoverageVariant() bool {
755 return c.coverage.Properties.IsCoverageVariant
756}
757
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800758func (c *Module) isNdk() bool {
759 return inList(c.Name(), ndkMigratedLibs)
760}
761
Lorenzo Colitti2973c112019-12-18 00:15:07 +0000762func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800763 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900764 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800765}
766
Inseob Kim9516ee92019-05-09 10:56:13 +0900767func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800768 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900769 name := c.BaseModuleName()
770 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800771}
772
Inseob Kim9516ee92019-05-09 10:56:13 +0900773func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800774 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900775 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800776}
777
Ivan Lozano52767be2019-10-18 14:49:46 -0700778func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800779 if vndkdep := c.vndkdep; vndkdep != nil {
780 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900781 }
782 return false
783}
784
Jooyung Han76106d92019-05-20 18:49:10 +0900785func (c *Module) vndkVersion() string {
Inseob Kim64c43952019-08-26 16:52:35 +0900786 return c.Properties.VndkVersion
Jooyung Han76106d92019-05-20 18:49:10 +0900787}
788
Yi Kong7e53c572018-02-14 18:16:12 +0800789func (c *Module) isPgoCompile() bool {
790 if pgo := c.pgo; pgo != nil {
791 return pgo.Properties.PgoCompile
792 }
793 return false
794}
795
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800796func (c *Module) isNDKStubLibrary() bool {
797 if _, ok := c.compiler.(*stubDecorator); ok {
798 return true
799 }
800 return false
801}
802
Logan Chienf3511742017-10-31 18:04:35 +0800803func (c *Module) isVndkSp() bool {
804 if vndkdep := c.vndkdep; vndkdep != nil {
805 return vndkdep.isVndkSp()
806 }
807 return false
808}
809
810func (c *Module) isVndkExt() bool {
811 if vndkdep := c.vndkdep; vndkdep != nil {
812 return vndkdep.isVndkExt()
813 }
814 return false
815}
816
Ivan Lozano52767be2019-10-18 14:49:46 -0700817func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900818 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800819}
820
Logan Chienf3511742017-10-31 18:04:35 +0800821func (c *Module) getVndkExtendsModuleName() string {
822 if vndkdep := c.vndkdep; vndkdep != nil {
823 return vndkdep.getVndkExtendsModuleName()
824 }
825 return ""
826}
827
Jiyong Park82e2bf32017-08-16 14:05:54 +0900828// Returns true only when this module is configured to have core and vendor
829// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700830func (c *Module) HasVendorVariant() bool {
831 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900832}
833
Ivan Lozano52767be2019-10-18 14:49:46 -0700834func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800835 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900836}
837
Ivan Lozano52767be2019-10-18 14:49:46 -0700838func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900839 return c.ModuleBase.InstallInRecovery()
840}
841
Jiyong Park25fc6a92018-11-18 18:02:45 +0900842func (c *Module) IsStubs() bool {
843 if library, ok := c.linker.(*libraryDecorator); ok {
844 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900845 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
846 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900847 }
848 return false
849}
850
851func (c *Module) HasStubsVariants() bool {
852 if library, ok := c.linker.(*libraryDecorator); ok {
853 return len(library.Properties.Stubs.Versions) > 0
854 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700855 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
856 return len(library.Properties.Stubs.Versions) > 0
857 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900858 return false
859}
860
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900861func (c *Module) bootstrap() bool {
862 return Bool(c.Properties.Bootstrap)
863}
864
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700865func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700866 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
867 if c.Target().NativeBridge == android.NativeBridgeEnabled {
868 return false
869 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700870 return c.linker != nil && c.linker.nativeCoverage()
871}
872
Jiyong Park73c54ee2019-10-22 20:31:18 +0900873func (c *Module) ExportedIncludeDirs() android.Paths {
874 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
875 return flagsProducer.exportedDirs()
876 }
Jiyong Park232e7852019-11-04 12:23:40 +0900877 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900878}
879
880func (c *Module) ExportedSystemIncludeDirs() android.Paths {
881 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
882 return flagsProducer.exportedSystemDirs()
883 }
Jiyong Park232e7852019-11-04 12:23:40 +0900884 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900885}
886
887func (c *Module) ExportedFlags() []string {
888 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
889 return flagsProducer.exportedFlags()
890 }
Jiyong Park232e7852019-11-04 12:23:40 +0900891 return nil
892}
893
894func (c *Module) ExportedDeps() android.Paths {
895 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
896 return flagsProducer.exportedDeps()
897 }
898 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900899}
900
Inseob Kimd110f872019-12-06 13:15:38 +0900901func (c *Module) ExportedGeneratedHeaders() android.Paths {
902 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
903 return flagsProducer.exportedGeneratedHeaders()
904 }
905 return nil
906}
907
Jiyong Parkf1194352019-02-25 11:05:47 +0900908func isBionic(name string) bool {
909 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +0000910 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +0900911 return true
912 }
913 return false
914}
915
Martin Stjernholm279de572019-09-10 23:18:20 +0100916func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700917 if name == "libclang_rt.hwasan-aarch64-android" {
918 return inList("hwaddress", config.SanitizeDevice())
919 }
920 return isBionic(name)
921}
922
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800923func (c *Module) XrefCcFiles() android.Paths {
924 return c.kytheFiles
925}
926
Colin Crossca860ac2016-01-04 14:34:37 -0800927type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700928 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800929 moduleContextImpl
930}
931
Colin Cross37047f12016-12-13 17:06:13 -0800932type depsContext struct {
933 android.BottomUpMutatorContext
934 moduleContextImpl
935}
936
Colin Crossca860ac2016-01-04 14:34:37 -0800937type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700938 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800939 moduleContextImpl
940}
941
Jiyong Park2db76922017-11-08 16:03:48 +0900942func (ctx *moduleContext) SocSpecific() bool {
943 return ctx.ModuleContext.SocSpecific() ||
Ivan Lozano52767be2019-10-18 14:49:46 -0700944 (ctx.mod.HasVendorVariant() && ctx.mod.UseVndk() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700945}
946
Colin Crossca860ac2016-01-04 14:34:37 -0800947type moduleContextImpl struct {
948 mod *Module
949 ctx BaseModuleContext
950}
951
Colin Crossb98c8b02016-07-29 13:44:28 -0700952func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800953 return ctx.mod.toolchain(ctx.ctx)
954}
955
956func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000957 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800958}
959
960func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900961 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800962}
963
Jiyong Park1d1119f2019-07-29 21:27:18 +0900964func (ctx *moduleContextImpl) header() bool {
965 return ctx.mod.header()
966}
967
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700968func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800969 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800970 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700971 }
972 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800973}
974
975func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700976 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700977 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900978 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700979 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900980 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
981 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
982 return "current"
983 }
984 return platform_vndk_ver
985 }
986 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800987 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900988 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700989 }
990 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800991}
992
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700993func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700994 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700995}
Justin Yun8effde42017-06-23 19:24:43 +0900996
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800997func (ctx *moduleContextImpl) isNdk() bool {
998 return ctx.mod.isNdk()
999}
1000
Inseob Kim9516ee92019-05-09 10:56:13 +09001001func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
Lorenzo Colitti2973c112019-12-18 00:15:07 +00001002 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001003}
1004
Inseob Kim9516ee92019-05-09 10:56:13 +09001005func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1006 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001007}
1008
Inseob Kim9516ee92019-05-09 10:56:13 +09001009func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1010 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001011}
1012
Logan Chienf3511742017-10-31 18:04:35 +08001013func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001014 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001015}
1016
Yi Kong7e53c572018-02-14 18:16:12 +08001017func (ctx *moduleContextImpl) isPgoCompile() bool {
1018 return ctx.mod.isPgoCompile()
1019}
1020
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001021func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1022 return ctx.mod.isNDKStubLibrary()
1023}
1024
Justin Yun8effde42017-06-23 19:24:43 +09001025func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001026 return ctx.mod.isVndkSp()
1027}
1028
1029func (ctx *moduleContextImpl) isVndkExt() bool {
1030 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001031}
1032
Vic Yangefd249e2018-11-12 20:19:56 -08001033func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001034 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001035}
1036
Jiyong Parkf9332f12018-02-01 00:54:12 +09001037func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001038 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001039}
1040
Logan Chien2f2b8902018-07-10 15:01:19 +08001041// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001042func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001043 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1044 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001045 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001046
1047 if ctx.ctx.Fuchsia() {
1048 return false
1049 }
1050
Logan Chien2f2b8902018-07-10 15:01:19 +08001051 if sanitize := ctx.mod.sanitize; sanitize != nil {
1052 if !sanitize.isVariantOnProductionDevice() {
1053 return false
1054 }
1055 }
1056 if !ctx.ctx.Device() {
1057 // Host modules do not need ABI dumps.
1058 return false
1059 }
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001060 if ctx.isStubs() {
1061 // Stubs do not need ABI dumps.
1062 return false
1063 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001064 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001065}
1066
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001067func (ctx *moduleContextImpl) selectedStl() string {
1068 if stl := ctx.mod.stl; stl != nil {
1069 return stl.Properties.SelectedStl
1070 }
1071 return ""
1072}
1073
Ivan Lozanobd721262018-11-27 14:33:03 -08001074func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1075 return ctx.mod.linker.useClangLld(actx)
1076}
1077
Colin Crossce75d2c2016-10-06 16:12:58 -07001078func (ctx *moduleContextImpl) baseModuleName() string {
1079 return ctx.mod.ModuleBase.BaseModuleName()
1080}
1081
Logan Chienf3511742017-10-31 18:04:35 +08001082func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1083 return ctx.mod.getVndkExtendsModuleName()
1084}
1085
Logan Chiene274fc92019-12-03 11:18:32 -08001086func (ctx *moduleContextImpl) isForPlatform() bool {
1087 return ctx.mod.IsForPlatform()
1088}
1089
Jiyong Park58e364a2019-01-19 19:24:06 +09001090func (ctx *moduleContextImpl) apexName() string {
1091 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001092}
1093
Jiyong Parkb0788572018-12-20 22:10:17 +09001094func (ctx *moduleContextImpl) hasStubsVariants() bool {
1095 return ctx.mod.HasStubsVariants()
1096}
1097
1098func (ctx *moduleContextImpl) isStubs() bool {
1099 return ctx.mod.IsStubs()
1100}
1101
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001102func (ctx *moduleContextImpl) bootstrap() bool {
1103 return ctx.mod.bootstrap()
1104}
1105
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001106func (ctx *moduleContextImpl) nativeCoverage() bool {
1107 return ctx.mod.nativeCoverage()
1108}
1109
Colin Cross635c3b02016-05-18 15:37:25 -07001110func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001111 return &Module{
1112 hod: hod,
1113 multilib: multilib,
1114 }
1115}
1116
Colin Cross635c3b02016-05-18 15:37:25 -07001117func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001118 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001119 module.features = []feature{
1120 &tidyFeature{},
1121 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001122 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001123 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001124 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001125 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001126 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001127 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001128 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -08001129 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -08001130 return module
1131}
1132
Colin Crossce75d2c2016-10-06 16:12:58 -07001133func (c *Module) Prebuilt() *android.Prebuilt {
1134 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1135 return p.prebuilt()
1136 }
1137 return nil
1138}
1139
1140func (c *Module) Name() string {
1141 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001142 if p, ok := c.linker.(interface {
1143 Name(string) string
1144 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001145 name = p.Name(name)
1146 }
1147 return name
1148}
1149
Alex Light3d673592019-01-18 14:37:31 -08001150func (c *Module) Symlinks() []string {
1151 if p, ok := c.installer.(interface {
1152 symlinkList() []string
1153 }); ok {
1154 return p.symlinkList()
1155 }
1156 return nil
1157}
1158
Jeff Gaston294356f2017-09-27 17:05:30 -07001159// orderDeps reorders dependencies into a list such that if module A depends on B, then
1160// A will precede B in the resultant list.
1161// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001162// Note that directSharedDeps should be the analogous static library for each shared lib dep
1163func 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 -07001164 // If A depends on B, then
1165 // Every list containing A will also contain B later in the list
1166 // So, after concatenating all lists, the final instance of B will have come from the same
1167 // original list as the final instance of A
1168 // So, the final instance of B will be later in the concatenation than the final A
1169 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1170 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001171 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001172 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001173 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1174 }
1175 for _, dep := range directSharedDeps {
1176 orderedAllDeps = append(orderedAllDeps, dep)
1177 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001178 }
1179
Colin Crossb6715442017-10-24 11:13:31 -07001180 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001181
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001182 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001183 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001184 // resultant list to only what the caller has chosen to include in directStaticDeps
1185 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001186
1187 return orderedAllDeps, orderedDeclaredDeps
1188}
1189
Ivan Lozano183a3212019-10-18 14:18:45 -07001190func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001191 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001192 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001193 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1194 staticDepFiles := []android.Path{}
1195 for _, dep := range staticDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001196 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1197 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
Jeff Gaston294356f2017-09-27 17:05:30 -07001198 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001199 sharedDepFiles := []android.Path{}
1200 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001201 if sharedDep.HasStaticVariant() {
1202 staticAnalogue := sharedDep.GetStaticVariant()
1203 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1204 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001205 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001206 }
1207
1208 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001209 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1210 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001211
1212 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001213}
1214
Roland Levillainf89cd092019-07-29 16:22:59 +01001215func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1216 test, ok := c.linker.(testPerSrc)
1217 return ok && test.isAllTestsVariation()
1218}
1219
Colin Cross635c3b02016-05-18 15:37:25 -07001220func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001221 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001222 //
1223 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1224 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1225 // module and return early, as this module does not produce an output file per se.
1226 if c.IsTestPerSrcAllTestsVariation() {
1227 c.outputFile = android.OptionalPath{}
1228 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001229 }
1230
Jooyung Han38002912019-05-16 04:01:54 +09001231 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001232
Inseob Kim64c43952019-08-26 16:52:35 +09001233 c.Properties.SubName = ""
1234
1235 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1236 c.Properties.SubName += nativeBridgeSuffix
1237 }
1238
1239 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
1240 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1241 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1242 c.Properties.SubName += vendorSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001243 } else if _, ok := c.linker.(*llndkStubDecorator); ok || (c.UseVndk() && c.HasVendorVariant()) {
Inseob Kim64c43952019-08-26 16:52:35 +09001244 // .vendor.{version} suffix is added only when we will have two variants: core and vendor.
1245 // The suffix is not added for vendor-only module.
1246 c.Properties.SubName += vendorSuffix
1247 vendorVersion := actx.DeviceConfig().VndkVersion()
1248 if vendorVersion == "current" {
1249 vendorVersion = actx.DeviceConfig().PlatformVndkVersion()
1250 }
1251 if c.Properties.VndkVersion != vendorVersion {
1252 c.Properties.SubName += "." + c.Properties.VndkVersion
1253 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001254 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001255 c.Properties.SubName += recoverySuffix
1256 }
1257
Colin Crossca860ac2016-01-04 14:34:37 -08001258 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001259 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001260 moduleContextImpl: moduleContextImpl{
1261 mod: c,
1262 },
1263 }
1264 ctx.ctx = ctx
1265
Colin Crossf18e1102017-11-16 14:33:08 -08001266 deps := c.depsToPaths(ctx)
1267 if ctx.Failed() {
1268 return
1269 }
1270
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001271 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1272 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1273 }
1274
Colin Crossca860ac2016-01-04 14:34:37 -08001275 flags := Flags{
1276 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001277 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001278 }
Colin Crossca860ac2016-01-04 14:34:37 -08001279 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001280 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001281 }
1282 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001283 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001284 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001285 if c.stl != nil {
1286 flags = c.stl.flags(ctx, flags)
1287 }
Colin Cross16b23492016-01-06 14:41:07 -08001288 if c.sanitize != nil {
1289 flags = c.sanitize.flags(ctx, flags)
1290 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001291 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001292 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001293 }
Stephen Craneba090d12017-05-09 15:44:35 -07001294 if c.lto != nil {
1295 flags = c.lto.flags(ctx, flags)
1296 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001297 if c.pgo != nil {
1298 flags = c.pgo.flags(ctx, flags)
1299 }
Ivan Lozano074ec482018-11-21 08:59:37 -08001300 if c.xom != nil {
1301 flags = c.xom.flags(ctx, flags)
1302 }
Colin Crossca860ac2016-01-04 14:34:37 -08001303 for _, feature := range c.features {
1304 flags = feature.flags(ctx, flags)
1305 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001306 if ctx.Failed() {
1307 return
1308 }
1309
Colin Cross4af21ed2019-11-04 09:37:55 -08001310 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1311 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1312 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001313
Colin Cross4af21ed2019-11-04 09:37:55 -08001314 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001315
1316 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001317 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001318 }
1319 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001320 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001321 }
1322
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001323 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001324 // We need access to all the flags seen by a source file.
1325 if c.sabi != nil {
1326 flags = c.sabi.flags(ctx, flags)
1327 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001328
Colin Cross4af21ed2019-11-04 09:37:55 -08001329 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001330
Colin Crossca860ac2016-01-04 14:34:37 -08001331 // Optimization to reduce size of build.ninja
1332 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001333 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1334 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1335 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1336 flags.Local.CFlags = []string{"$cflags"}
1337 flags.Local.CppFlags = []string{"$cppflags"}
1338 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001339
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001340 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001341 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001342 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001343 if ctx.Failed() {
1344 return
1345 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001346 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001347 }
1348
Colin Crossca860ac2016-01-04 14:34:37 -08001349 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001350 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001351 if ctx.Failed() {
1352 return
1353 }
Colin Cross635c3b02016-05-18 15:37:25 -07001354 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001355
1356 // If a lib is directly included in any of the APEXes, unhide the stubs
1357 // variant having the latest version gets visible to make. In addition,
1358 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1359 // force anything in the make world to link against the stubs library.
1360 // (unless it is explicitly referenced via .bootstrap suffix or the
1361 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001362 if c.HasStubsVariants() &&
1363 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001364 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001365 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001366 c.Properties.HideFromMake = false // unhide
1367 // Note: this is still non-installable
1368 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001369 }
Colin Cross5049f022015-03-18 13:28:46 -07001370
Inseob Kim1f086e22019-05-09 13:29:15 +09001371 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001372 c.installer.install(ctx, c.outputFile.Path())
1373 if ctx.Failed() {
1374 return
Colin Crossca860ac2016-01-04 14:34:37 -08001375 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001376 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001377}
1378
Colin Cross0ea8ba82019-06-06 14:33:29 -07001379func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001380 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001381 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001382 }
Colin Crossca860ac2016-01-04 14:34:37 -08001383 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001384}
1385
Colin Crossca860ac2016-01-04 14:34:37 -08001386func (c *Module) begin(ctx BaseModuleContext) {
1387 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001388 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001389 }
Colin Crossca860ac2016-01-04 14:34:37 -08001390 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001391 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001392 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001393 if c.stl != nil {
1394 c.stl.begin(ctx)
1395 }
Colin Cross16b23492016-01-06 14:41:07 -08001396 if c.sanitize != nil {
1397 c.sanitize.begin(ctx)
1398 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001399 if c.coverage != nil {
1400 c.coverage.begin(ctx)
1401 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001402 if c.sabi != nil {
1403 c.sabi.begin(ctx)
1404 }
Justin Yun8effde42017-06-23 19:24:43 +09001405 if c.vndkdep != nil {
1406 c.vndkdep.begin(ctx)
1407 }
Stephen Craneba090d12017-05-09 15:44:35 -07001408 if c.lto != nil {
1409 c.lto.begin(ctx)
1410 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001411 if c.pgo != nil {
1412 c.pgo.begin(ctx)
1413 }
Colin Crossca860ac2016-01-04 14:34:37 -08001414 for _, feature := range c.features {
1415 feature.begin(ctx)
1416 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001417 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001418 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001419 if err != nil {
1420 ctx.PropertyErrorf("sdk_version", err.Error())
1421 }
Nan Zhang0007d812017-11-07 10:57:05 -08001422 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001423 }
Colin Crossca860ac2016-01-04 14:34:37 -08001424}
1425
Colin Cross37047f12016-12-13 17:06:13 -08001426func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001427 deps := Deps{}
1428
1429 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001430 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001431 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001432 // Add the PGO dependency (the clang_rt.profile runtime library), which
1433 // sometimes depends on symbols from libgcc, before libgcc gets added
1434 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001435 if c.pgo != nil {
1436 deps = c.pgo.deps(ctx, deps)
1437 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001438 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001439 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001440 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001441 if c.stl != nil {
1442 deps = c.stl.deps(ctx, deps)
1443 }
Colin Cross16b23492016-01-06 14:41:07 -08001444 if c.sanitize != nil {
1445 deps = c.sanitize.deps(ctx, deps)
1446 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001447 if c.coverage != nil {
1448 deps = c.coverage.deps(ctx, deps)
1449 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001450 if c.sabi != nil {
1451 deps = c.sabi.deps(ctx, deps)
1452 }
Justin Yun8effde42017-06-23 19:24:43 +09001453 if c.vndkdep != nil {
1454 deps = c.vndkdep.deps(ctx, deps)
1455 }
Stephen Craneba090d12017-05-09 15:44:35 -07001456 if c.lto != nil {
1457 deps = c.lto.deps(ctx, deps)
1458 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001459 for _, feature := range c.features {
1460 deps = feature.deps(ctx, deps)
1461 }
1462
Colin Crossb6715442017-10-24 11:13:31 -07001463 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1464 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1465 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1466 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1467 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1468 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001469 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001470
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001471 for _, lib := range deps.ReexportSharedLibHeaders {
1472 if !inList(lib, deps.SharedLibs) {
1473 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1474 }
1475 }
1476
1477 for _, lib := range deps.ReexportStaticLibHeaders {
1478 if !inList(lib, deps.StaticLibs) {
1479 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1480 }
1481 }
1482
Colin Cross5950f382016-12-13 12:50:57 -08001483 for _, lib := range deps.ReexportHeaderLibHeaders {
1484 if !inList(lib, deps.HeaderLibs) {
1485 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1486 }
1487 }
1488
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001489 for _, gen := range deps.ReexportGeneratedHeaders {
1490 if !inList(gen, deps.GeneratedHeaders) {
1491 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1492 }
1493 }
1494
Colin Crossc99deeb2016-04-11 15:06:20 -07001495 return deps
1496}
1497
Dan Albert7e9d2952016-08-04 13:02:36 -07001498func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001499 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001500 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001501 moduleContextImpl: moduleContextImpl{
1502 mod: c,
1503 },
1504 }
1505 ctx.ctx = ctx
1506
Colin Crossca860ac2016-01-04 14:34:37 -08001507 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001508}
1509
Jiyong Park7ed9de32018-10-15 22:25:07 +09001510// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001511func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001512 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1513 version := name[sharp+1:]
1514 libname := name[:sharp]
1515 return libname, version
1516 }
1517 return name, ""
1518}
1519
Colin Cross1e676be2016-10-12 14:38:15 -07001520func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001521 ctx := &depsContext{
1522 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001523 moduleContextImpl: moduleContextImpl{
1524 mod: c,
1525 },
1526 }
1527 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001528
Colin Crossc99deeb2016-04-11 15:06:20 -07001529 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001530
Dan Albert914449f2016-06-17 16:45:24 -07001531 variantNdkLibs := []string{}
1532 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001533 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001534 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001535
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001536 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1537 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001538 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001539 // 1. Name of an NDK library that refers to a prebuilt module.
1540 // For each of these, it adds the name of the prebuilt module (which will be in
1541 // prebuilts/ndk) to the list of nonvariant libs.
1542 // 2. Name of an NDK library that refers to an ndk_library module.
1543 // For each of these, it adds the name of the ndk_library module to the list of
1544 // variant libs.
1545 // 3. Anything else (so anything that isn't an NDK library).
1546 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001547 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001548 // The caller can then know to add the variantLibs dependencies differently from the
1549 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001550
Inseob Kim9516ee92019-05-09 10:56:13 +09001551 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001552 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1553 variantLibs = []string{}
1554 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001555 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001556 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001557 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001558 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1559 if !inList(name, ndkMigratedLibs) {
1560 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001561 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001562 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001563 }
Jooyung Han0302a842019-10-30 18:43:49 +09001564 } else if ctx.useVndk() && isLlndkLibrary(name, ctx.Config()) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001565 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001566 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001567 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001568 if actx.OtherModuleExists(vendorPublicLib) {
1569 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1570 } else {
1571 // This can happen if vendor_public_library module is defined in a
1572 // namespace that isn't visible to the current module. In that case,
1573 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001574 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001575 }
Dan Albert914449f2016-06-17 16:45:24 -07001576 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001577 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001578 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001579 }
1580 }
Dan Albert914449f2016-06-17 16:45:24 -07001581 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001582 }
1583
Dan Albert914449f2016-06-17 16:45:24 -07001584 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1585 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001586 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001587 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001588
Jiyong Park7e636d02019-01-28 16:16:54 +09001589 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001590 if c.linker != nil {
1591 if library, ok := c.linker.(*libraryDecorator); ok {
1592 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001593 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001594 }
1595 }
1596 }
1597
Colin Cross32ec36c2016-12-15 07:39:51 -08001598 for _, lib := range deps.HeaderLibs {
1599 depTag := headerDepTag
1600 if inList(lib, deps.ReexportHeaderLibHeaders) {
1601 depTag = headerExportDepTag
1602 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001603 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001604 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001605 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001606 } else {
1607 actx.AddVariationDependencies(nil, depTag, lib)
1608 }
1609 }
1610
1611 if buildStubs {
1612 // Stubs lib does not have dependency to other static/shared libraries.
1613 // Don't proceed.
1614 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001615 }
Colin Cross5950f382016-12-13 12:50:57 -08001616
Inseob Kimc0907f12019-02-08 21:00:45 +09001617 syspropImplLibraries := syspropImplLibraries(actx.Config())
1618
Jiyong Park5d1598f2019-02-25 22:14:17 +09001619 for _, lib := range deps.WholeStaticLibs {
1620 depTag := wholeStaticDepTag
1621 if impl, ok := syspropImplLibraries[lib]; ok {
1622 lib = impl
1623 }
1624 actx.AddVariationDependencies([]blueprint.Variation{
1625 {Mutator: "link", Variation: "static"},
1626 }, depTag, lib)
1627 }
1628
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001629 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001630 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001631 if inList(lib, deps.ReexportStaticLibHeaders) {
1632 depTag = staticExportDepTag
1633 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001634
1635 if impl, ok := syspropImplLibraries[lib]; ok {
1636 lib = impl
1637 }
1638
Dan Willemsen59339a22018-07-22 21:18:45 -07001639 actx.AddVariationDependencies([]blueprint.Variation{
1640 {Mutator: "link", Variation: "static"},
1641 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001642 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001643
Dan Willemsen59339a22018-07-22 21:18:45 -07001644 actx.AddVariationDependencies([]blueprint.Variation{
1645 {Mutator: "link", Variation: "static"},
1646 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001647
Ivan Lozano183a3212019-10-18 14:18:45 -07001648 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001649 var variations []blueprint.Variation
1650 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Ivan Lozano52767be2019-10-18 14:49:46 -07001651 versionVariantAvail := !ctx.useVndk() && !c.InRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001652 if version != "" && versionVariantAvail {
1653 // Version is explicitly specified. i.e. libFoo#30
1654 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001655 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001656 }
1657 actx.AddVariationDependencies(variations, depTag, name)
1658
1659 // If the version is not specified, add dependency to the latest stubs library.
1660 // The stubs library will be used when the depending module is built for APEX and
1661 // the dependent module is not in the same APEX.
Jiyong Park73c54ee2019-10-22 20:31:18 +09001662 latestVersion := LatestStubsVersionFor(actx.Config(), name)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001663 if version == "" && latestVersion != "" && versionVariantAvail {
1664 actx.AddVariationDependencies([]blueprint.Variation{
1665 {Mutator: "link", Variation: "shared"},
1666 {Mutator: "version", Variation: latestVersion},
1667 }, depTag, name)
Ivan Lozano183a3212019-10-18 14:18:45 -07001668 // Note that depTag.ExplicitlyVersioned is false in this case.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001669 }
1670 }
1671
Jiyong Park7ed9de32018-10-15 22:25:07 +09001672 // shared lib names without the #version suffix
1673 var sharedLibNames []string
1674
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001675 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001676 depTag := SharedDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001677 if inList(lib, deps.ReexportSharedLibHeaders) {
1678 depTag = sharedExportDepTag
1679 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001680
1681 if impl, ok := syspropImplLibraries[lib]; ok {
1682 lib = impl
1683 }
1684
Jiyong Park73c54ee2019-10-22 20:31:18 +09001685 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001686 sharedLibNames = append(sharedLibNames, name)
1687
Jiyong Park25fc6a92018-11-18 18:02:45 +09001688 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001689 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001690
Jiyong Park7ed9de32018-10-15 22:25:07 +09001691 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001692 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001693 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1694 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1695 // linking against both the stubs lib and the non-stubs lib at the same time.
1696 continue
1697 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001698 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001699 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001700
Dan Willemsen59339a22018-07-22 21:18:45 -07001701 actx.AddVariationDependencies([]blueprint.Variation{
1702 {Mutator: "link", Variation: "shared"},
1703 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001704
Colin Cross68861832016-07-08 10:41:41 -07001705 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001706
1707 for _, gen := range deps.GeneratedHeaders {
1708 depTag := genHeaderDepTag
1709 if inList(gen, deps.ReexportGeneratedHeaders) {
1710 depTag = genHeaderExportDepTag
1711 }
1712 actx.AddDependency(c, depTag, gen)
1713 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001714
Colin Cross42d48b72018-08-29 14:10:52 -07001715 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001716
1717 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001718 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001719 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001720 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001721 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001722 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001723 if deps.LinkerFlagsFile != "" {
1724 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1725 }
1726 if deps.DynamicLinker != "" {
1727 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001728 }
Dan Albert914449f2016-06-17 16:45:24 -07001729
1730 version := ctx.sdkVersion()
1731 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001732 {Mutator: "ndk_api", Variation: version},
1733 {Mutator: "link", Variation: "shared"},
1734 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001735 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001736 {Mutator: "ndk_api", Variation: version},
1737 {Mutator: "link", Variation: "shared"},
1738 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001739
1740 if vndkdep := c.vndkdep; vndkdep != nil {
1741 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08001742 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08001743 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07001744 {Mutator: "link", Variation: "shared"},
1745 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001746 }
1747 }
Colin Cross6362e272015-10-29 15:25:03 -07001748}
Colin Cross21b9a242015-03-24 14:15:58 -07001749
Colin Crosse40b4ea2018-10-02 22:25:58 -07001750func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001751 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1752 c.beginMutator(ctx)
1753 }
1754}
1755
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001756// Whether a module can link to another module, taking into
1757// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07001758func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
1759 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001760 // Host code is not restricted
1761 return
1762 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001763
1764 // VNDK is cc.Module supported only for now.
1765 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001766 // Though vendor code is limited by the vendor mutator,
1767 // each vendor-available module needs to check
1768 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07001769 if ccTo, ok := to.(*Module); ok {
1770 if ccFrom.vndkdep != nil {
1771 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
1772 }
1773 } else {
1774 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001775 }
1776 return
1777 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001778 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001779 // Platform code can link to anything
1780 return
1781 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001782 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09001783 // Recovery code is not NDK
1784 return
1785 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001786 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001787 // These are always allowed
1788 return
1789 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001790 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001791 // These are allowed, but they don't set sdk_version
1792 return
1793 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001794 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001795 // These aren't real libraries, but are the stub shared libraries that are included in
1796 // the NDK.
1797 return
1798 }
Logan Chien834b9a62019-01-14 15:39:03 +08001799
Ivan Lozano52767be2019-10-18 14:49:46 -07001800 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08001801 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1802 // to link to libc++ (non-NDK and without sdk_version).
1803 return
1804 }
1805
Ivan Lozano52767be2019-10-18 14:49:46 -07001806 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001807 // NDK code linking to platform code is never okay.
1808 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001809 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001810 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001811 }
1812
1813 // At this point we know we have two NDK libraries, but we need to
1814 // check that we're not linking against anything built against a higher
1815 // API level, as it is only valid to link against older or equivalent
1816 // APIs.
1817
Inseob Kim01a28722018-04-11 09:48:45 +09001818 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07001819 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001820 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07001821 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001822 // Current can't be linked against by anything else.
1823 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001824 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09001825 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07001826 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001827 if err != nil {
1828 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001829 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001830 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001831 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001832 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001833 if err != nil {
1834 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001835 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001836 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001837 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001838
Inseob Kim01a28722018-04-11 09:48:45 +09001839 if toApi > fromApi {
1840 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001841 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001842 }
1843 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001844 }
Dan Albert202fe492017-12-15 13:56:59 -08001845
1846 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07001847 fromStl := from.SelectedStl()
1848 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08001849 if fromStl == "" || toStl == "" {
1850 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001851 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001852 // We can be permissive with the system "STL" since it is only the C++
1853 // ABI layer, but in the future we should make sure that everyone is
1854 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001855 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001856 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001857 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
1858 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08001859 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001860}
1861
Jiyong Park5fb8c102018-04-09 12:03:06 +09001862// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001863// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1864// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001865// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001866func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
1867 check := func(child, parent android.Module) bool {
1868 to, ok := child.(*Module)
1869 if !ok {
1870 // follow thru cc.Defaults, etc.
1871 return true
1872 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001873
Jooyung Hana70f0672019-01-18 15:20:43 +09001874 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1875 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001876 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001877
1878 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07001879 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09001880 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001881 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001882
Lorenzo Colitti2973c112019-12-18 00:15:07 +00001883 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001884 return false
1885 }
1886
1887 var stringPath []string
1888 for _, m := range ctx.GetWalkPath() {
1889 stringPath = append(stringPath, m.Name())
1890 }
1891 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1892 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1893 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1894 return false
1895 }
1896 if module, ok := ctx.Module().(*Module); ok {
1897 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Lorenzo Colitti2973c112019-12-18 00:15:07 +00001898 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001899 ctx.WalkDeps(check)
1900 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001901 }
1902 }
1903}
1904
Colin Crossc99deeb2016-04-11 15:06:20 -07001905// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001906func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001907 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001908
Ivan Lozano183a3212019-10-18 14:18:45 -07001909 directStaticDeps := []LinkableInterface{}
1910 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001911
Inseob Kim9516ee92019-05-09 10:56:13 +09001912 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
1913
Inseob Kim69378442019-06-03 19:10:47 +09001914 reexportExporter := func(exporter exportedFlagsProducer) {
1915 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
1916 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
1917 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
1918 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09001919 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09001920 }
1921
Colin Crossd11fcda2017-10-23 17:59:01 -07001922 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001923 depName := ctx.OtherModuleName(dep)
1924 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001925
Ivan Lozano52767be2019-10-18 14:49:46 -07001926 ccDep, ok := dep.(LinkableInterface)
1927 if !ok {
1928
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001929 // handling for a few module types that aren't cc Module but that are also supported
1930 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001931 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001932 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001933 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1934 genRule.GeneratedSourceFiles()...)
1935 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001936 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001937 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001938 // Support exported headers from a generated_sources dependency
1939 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001940 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001941 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001942 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Inseob Kimd110f872019-12-06 13:15:38 +09001943 genRule.GeneratedSourceFiles()...)
1944 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001945 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09001946 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09001947 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001948 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09001949 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09001950 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
1951 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09001952 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001953 // 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 +09001954 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001955
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001956 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001957 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001958 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001959 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001960 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001961 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001962 files := genRule.GeneratedSourceFiles()
1963 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001964 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001965 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001966 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 -07001967 }
1968 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001969 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001970 }
Colin Crossca860ac2016-01-04 14:34:37 -08001971 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001972 return
1973 }
1974
Colin Crossfe17f6f2019-03-28 19:30:56 -07001975 if depTag == android.ProtoPluginDepTag {
1976 return
1977 }
1978
Colin Crossd11fcda2017-10-23 17:59:01 -07001979 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001980 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1981 return
1982 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001983 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001984 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001985 return
1986 }
1987
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001988 // re-exporting flags
1989 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07001990 // reusing objects only make sense for cc.Modules.
1991 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001992 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07001993 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001994 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09001995 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08001996 return
1997 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001998 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001999
Jiyong Parke4bb9862019-02-01 00:31:10 +09002000 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002001 // staticVariants are a cc.Module specific concept.
2002 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002003 c.staticVariant = ccDep
2004 return
2005 }
2006 }
2007
Ivan Lozano183a3212019-10-18 14:18:45 -07002008 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
2009 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
2010 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002011 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07002012 if t, ok := depTag.(DependencyTag); ok {
2013 explicitlyVersioned = t.ExplicitlyVersioned
2014 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002015 depTag = t
2016 }
2017
Ivan Lozano183a3212019-10-18 14:18:45 -07002018 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002019 depIsStatic := false
2020 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002021 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002022 depIsStatic = true
2023 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002024 if ccDep.CcLibrary() && !depIsStatic {
2025 depIsStubs := ccDep.BuildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09002026 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002027 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002028 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002029
2030 var useThisDep bool
2031 if depIsStubs && explicitlyVersioned {
2032 // Always respect dependency to the versioned stubs (i.e. libX#10)
2033 useThisDep = true
2034 } else if !depHasStubs {
2035 // Use non-stub variant if that is the only choice
2036 // (i.e. depending on a lib without stubs.version property)
2037 useThisDep = true
2038 } else if c.IsForPlatform() {
2039 // If not building for APEX, use stubs only when it is from
2040 // an APEX (and not from platform)
2041 useThisDep = (depInPlatform != depIsStubs)
Ivan Lozano52767be2019-10-18 14:49:46 -07002042 if c.InRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09002043 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002044 // always link to non-stub variant
2045 useThisDep = !depIsStubs
2046 }
2047 } else {
2048 // If building for APEX, use stubs only when it is not from
2049 // the same APEX
2050 useThisDep = (depInSameApex != depIsStubs)
2051 }
2052
2053 if !useThisDep {
2054 return // stop processing this dep
2055 }
2056 }
2057
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002058 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2059
Ivan Lozano52767be2019-10-18 14:49:46 -07002060 // Exporting flags only makes sense for cc.Modules
2061 if _, ok := ccDep.(*Module); ok {
2062 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002063 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002064 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedGeneratedHeaders()...)
2065 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002066 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002067
Ivan Lozano52767be2019-10-18 14:49:46 -07002068 if t.ReexportFlags {
2069 reexportExporter(i)
2070 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2071 // Re-exported shared library headers must be included as well since they can help us with type information
2072 // about template instantiations (instantiated from their headers).
2073 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2074 // scripts.
2075 c.sabi.Properties.ReexportedIncludes = append(
2076 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2077 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002078 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002079 }
Logan Chienf3511742017-10-31 18:04:35 +08002080 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002081 }
2082
Colin Cross26c34ed2016-09-30 17:10:16 -07002083 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002084 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002085
Ivan Lozano52767be2019-10-18 14:49:46 -07002086 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002087 depFile := android.OptionalPath{}
2088
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002089 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002090 case ndkStubDepTag, SharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002091 ptr = &depPaths.SharedLibs
2092 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002093 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002094 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002095
Jiyong Park64a44f22019-01-18 14:37:08 +09002096 case earlySharedDepTag:
2097 ptr = &depPaths.EarlySharedLibs
2098 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002099 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002100 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002101 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002102 ptr = &depPaths.LateSharedLibs
2103 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002104 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002105 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002106 ptr = nil
2107 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002108 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002109 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002110 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002111 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002112 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002113 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002114 return
2115 }
2116
Ivan Lozano52767be2019-10-18 14:49:46 -07002117 // Because the static library objects are included, this only makes sense
2118 // in the context of proper cc.Modules.
2119 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2120 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2121 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2122 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2123 for i := range missingDeps {
2124 missingDeps[i] += postfix
2125 }
2126 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002127 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002128 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2129 } else {
2130 ctx.ModuleErrorf(
2131 "non-cc.Modules cannot be included as whole static libraries.", depName)
2132 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002133 }
Colin Cross5950f382016-12-13 12:50:57 -08002134 case headerDepTag:
2135 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002136 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002137 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002138 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002139 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002140 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002141 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002142 case dynamicLinkerDepTag:
2143 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002144 }
2145
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002146 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002147 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002148 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002149 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002150 return
2151 }
2152
2153 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002154 // in static libraries act as if they were whole static libraries. The same goes for
2155 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002156 // This should only be done for cc.Modules
2157 if c, ok := ccDep.(*Module); ok {
2158 staticLib := c.linker.(libraryInterface)
2159 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2160 staticLib.objs().coverageFiles...)
2161 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2162 staticLib.objs().sAbiDumpFiles...)
2163 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002164 }
2165
Colin Cross26c34ed2016-09-30 17:10:16 -07002166 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002167 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002168 if !ctx.Config().AllowMissingDependencies() {
2169 ctx.ModuleErrorf("module %q missing output file", depName)
2170 } else {
2171 ctx.AddMissingDependencies([]string{depName})
2172 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002173 return
2174 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002175 *ptr = append(*ptr, linkFile.Path())
2176 }
2177
Colin Crossc99deeb2016-04-11 15:06:20 -07002178 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002179 dep := depFile
2180 if !dep.Valid() {
2181 dep = linkFile
2182 }
2183 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002184 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002185
Logan Chien43d34c32017-12-20 01:17:32 +08002186 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002187 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002188 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002189 libName = strings.TrimPrefix(libName, "prebuilt_")
Jooyung Han0302a842019-10-30 18:43:49 +09002190 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002191 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002192 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002193
Ivan Lozano52767be2019-10-18 14:49:46 -07002194 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002195 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2196 // core module instead.
2197 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002198 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002199 // The vendor module in Make will have been renamed to not conflict with the core
2200 // module, so update the dependency name here accordingly.
Inseob Kim64c43952019-08-26 16:52:35 +09002201 ret := libName + vendorSuffix
2202 vendorVersion := ctx.DeviceConfig().VndkVersion()
2203 if vendorVersion == "current" {
2204 vendorVersion = ctx.DeviceConfig().PlatformVndkVersion()
2205 }
2206 if c.Properties.VndkVersion != vendorVersion {
2207 ret += "." + c.Properties.VndkVersion
2208 }
2209 return ret
Jiyong Park374510b2018-03-19 18:23:01 +09002210 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002211 return libName + vendorPublicLibrarySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002212 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002213 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002214 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002215 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002216 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002217 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002218 }
Logan Chien43d34c32017-12-20 01:17:32 +08002219 }
2220
2221 // Export the shared libs to Make.
2222 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002223 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002224 if ccDep.CcLibrary() {
2225 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002226 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002227 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002228 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002229 c.Properties.ApexesProvidingSharedLibs = append(
2230 c.Properties.ApexesProvidingSharedLibs, an)
2231 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002232 }
2233 }
2234
Jiyong Park27b188b2017-07-18 13:23:39 +09002235 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002236 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002237 c.Properties.AndroidMkSharedLibs = append(
2238 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002239 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002240 c.Properties.AndroidMkSharedLibs = append(
2241 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002242 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002243 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002244 c.Properties.AndroidMkStaticLibs = append(
2245 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002246 case runtimeDepTag:
2247 c.Properties.AndroidMkRuntimeLibs = append(
2248 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002249 case wholeStaticDepTag:
2250 c.Properties.AndroidMkWholeStaticLibs = append(
2251 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002252 }
Colin Crossca860ac2016-01-04 14:34:37 -08002253 })
2254
Jeff Gaston294356f2017-09-27 17:05:30 -07002255 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002256 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002257
Colin Crossdd84e052017-05-17 13:44:16 -07002258 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002259 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002260 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2261 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002262 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kimd110f872019-12-06 13:15:38 +09002263 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002264 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2265 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002266 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002267 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002268 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002269
2270 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002271 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002272 }
Colin Crossdd84e052017-05-17 13:44:16 -07002273
Colin Crossca860ac2016-01-04 14:34:37 -08002274 return depPaths
2275}
2276
2277func (c *Module) InstallInData() bool {
2278 if c.installer == nil {
2279 return false
2280 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002281 return c.installer.inData()
2282}
2283
2284func (c *Module) InstallInSanitizerDir() bool {
2285 if c.installer == nil {
2286 return false
2287 }
2288 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002289 return true
2290 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002291 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002292}
2293
Jiyong Parkf9332f12018-02-01 00:54:12 +09002294func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002295 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002296}
2297
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002298func (c *Module) HostToolPath() android.OptionalPath {
2299 if c.installer == nil {
2300 return android.OptionalPath{}
2301 }
2302 return c.installer.hostToolPath()
2303}
2304
Nan Zhangd4e641b2017-07-12 12:55:28 -07002305func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2306 return c.outputFile
2307}
2308
Colin Cross41955e82019-05-29 14:40:35 -07002309func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2310 switch tag {
2311 case "":
2312 if c.outputFile.Valid() {
2313 return android.Paths{c.outputFile.Path()}, nil
2314 }
2315 return android.Paths{}, nil
2316 default:
2317 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002318 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002319}
2320
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002321func (c *Module) static() bool {
2322 if static, ok := c.linker.(interface {
2323 static() bool
2324 }); ok {
2325 return static.static()
2326 }
2327 return false
2328}
2329
Jiyong Park379de2f2018-12-19 02:47:14 +09002330func (c *Module) staticBinary() bool {
2331 if static, ok := c.linker.(interface {
2332 staticBinary() bool
2333 }); ok {
2334 return static.staticBinary()
2335 }
2336 return false
2337}
2338
Jiyong Park1d1119f2019-07-29 21:27:18 +09002339func (c *Module) header() bool {
2340 if h, ok := c.linker.(interface {
2341 header() bool
2342 }); ok {
2343 return h.header()
2344 }
2345 return false
2346}
2347
Jooyung Han38002912019-05-16 04:01:54 +09002348func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002349 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002350 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2351 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002352 return "native:vndk"
2353 }
Jooyung Han38002912019-05-16 04:01:54 +09002354 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002355 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002356 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002357 if Bool(c.VendorProperties.Vendor_available) {
2358 return "native:vndk"
2359 }
2360 return "native:vndk_private"
2361 }
2362 return "native:vendor"
Ivan Lozano52767be2019-10-18 14:49:46 -07002363 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002364 return "native:recovery"
2365 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2366 return "native:ndk:none:none"
2367 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2368 //family, link := getNdkStlFamilyAndLinkType(c)
2369 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002370 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002371 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002372 } else {
2373 return "native:platform"
2374 }
2375}
2376
Jiyong Park9d452992018-10-03 00:38:19 +09002377// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002378// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002379func (c *Module) IsInstallableToApex() bool {
2380 if shared, ok := c.linker.(interface {
2381 shared() bool
2382 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002383 // Stub libs and prebuilt libs in a versioned SDK are not
2384 // installable to APEX even though they are shared libs.
2385 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002386 } else if _, ok := c.linker.(testPerSrc); ok {
2387 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002388 }
2389 return false
2390}
2391
Jiyong Parka90ca002019-10-07 15:47:24 +09002392func (c *Module) AvailableFor(what string) bool {
2393 if linker, ok := c.linker.(interface {
2394 availableFor(string) bool
2395 }); ok {
2396 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2397 } else {
2398 return c.ApexModuleBase.AvailableFor(what)
2399 }
2400}
2401
Inseob Kim1f086e22019-05-09 13:29:15 +09002402func (c *Module) installable() bool {
2403 return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
2404}
2405
bralee3f49f4d2019-03-04 06:58:15 +08002406func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
Colin Cross41955e82019-05-29 14:40:35 -07002407 outputFiles, err := c.OutputFiles("")
2408 if err != nil {
2409 panic(err)
2410 }
2411 dpInfo.Srcs = append(dpInfo.Srcs, outputFiles.Strings()...)
bralee3f49f4d2019-03-04 06:58:15 +08002412}
2413
Logan Chien41eabe62019-04-10 13:33:58 +08002414func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2415 if c.linker != nil {
2416 if library, ok := c.linker.(*libraryDecorator); ok {
2417 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2418 }
2419 }
2420}
2421
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002422func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002423 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
2424 if cc, ok := dep.(*Module); ok && cc.IsStubs() && depTag.Shared {
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002425 // dynamic dep to a stubs lib crosses APEX boundary
2426 return false
2427 }
2428 }
2429 return true
2430}
2431
Colin Cross2ba19d92015-05-07 15:44:20 -07002432//
Colin Crosscfad1192015-11-02 16:43:11 -08002433// Defaults
2434//
Colin Crossca860ac2016-01-04 14:34:37 -08002435type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002436 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002437 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002438 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002439}
2440
Patrice Arrudac249c712019-03-19 17:00:29 -07002441// cc_defaults provides a set of properties that can be inherited by other cc
2442// modules. A module can use the properties from a cc_defaults using
2443// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2444// merged (when possible) by prepending the default module's values to the
2445// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002446func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002447 return DefaultsFactory()
2448}
2449
Colin Cross36242852017-06-23 15:06:31 -07002450func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002451 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002452
Colin Cross36242852017-06-23 15:06:31 -07002453 module.AddProperties(props...)
2454 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002455 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002456 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002457 &BaseCompilerProperties{},
2458 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002459 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002460 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002461 &StaticProperties{},
2462 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002463 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002464 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002465 &TestProperties{},
2466 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002467 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002468 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002469 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002470 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002471 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002472 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002473 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002474 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002475 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002476 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002477 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002478 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002479 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002480 )
Colin Crosscfad1192015-11-02 16:43:11 -08002481
Jooyung Hancc372c52019-09-25 15:18:44 +09002482 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002483
2484 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002485}
2486
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002487const (
Colin Cross7228ecd2019-11-18 16:00:16 -08002488 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002489 // against the VNDK.
Colin Cross7228ecd2019-11-18 16:00:16 -08002490 VendorVariationPrefix = "vendor."
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002491)
2492
Jiyong Park6a43f042017-10-12 23:05:00 +09002493func squashVendorSrcs(m *Module) {
2494 if lib, ok := m.compiler.(*libraryDecorator); ok {
2495 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2496 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2497
2498 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2499 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2500 }
2501}
2502
Jiyong Parkf9332f12018-02-01 00:54:12 +09002503func squashRecoverySrcs(m *Module) {
2504 if lib, ok := m.compiler.(*libraryDecorator); ok {
2505 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2506 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2507
2508 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2509 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2510 }
2511}
2512
Colin Cross7228ecd2019-11-18 16:00:16 -08002513var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002514
Colin Cross7228ecd2019-11-18 16:00:16 -08002515func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002516 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002517 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002518 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002519
2520 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002521 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002522 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002523 }
Logan Chienf3511742017-10-31 18:04:35 +08002524
2525 if vndkdep := m.vndkdep; vndkdep != nil {
2526 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002527 if productSpecific {
2528 mctx.PropertyErrorf("product_specific",
2529 "product_specific must not be true when `vndk: {enabled: true}`")
Justin Yun9357f4a2018-11-28 15:14:47 +09002530 }
Logan Chienf3511742017-10-31 18:04:35 +08002531 if vendorSpecific {
2532 if !vndkdep.isVndkExt() {
2533 mctx.PropertyErrorf("vndk",
2534 "must set `extends: \"...\"` to vndk extension")
Logan Chienf3511742017-10-31 18:04:35 +08002535 }
2536 } else {
2537 if vndkdep.isVndkExt() {
2538 mctx.PropertyErrorf("vndk",
2539 "must set `vendor: true` to set `extends: %q`",
2540 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002541 }
2542 if m.VendorProperties.Vendor_available == nil {
2543 mctx.PropertyErrorf("vndk",
2544 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08002545 }
2546 }
2547 } else {
2548 if vndkdep.isVndkSp() {
2549 mctx.PropertyErrorf("vndk",
2550 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08002551 }
2552 if vndkdep.isVndkExt() {
2553 mctx.PropertyErrorf("vndk",
2554 "must set `enabled: true` to set `extends: %q`",
2555 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002556 }
Justin Yun8effde42017-06-23 19:24:43 +09002557 }
2558 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002559
Jiyong Parkf9332f12018-02-01 00:54:12 +09002560 var coreVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002561 var recoveryVariantNeeded bool = false
2562
Inseob Kim64c43952019-08-26 16:52:35 +09002563 var vendorVariants []string
2564
2565 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
2566 deviceVndkVersion := mctx.DeviceConfig().VndkVersion()
2567 if deviceVndkVersion == "current" {
2568 deviceVndkVersion = platformVndkVersion
2569 }
2570
Justin Yun71549282017-11-17 12:10:28 +09002571 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002572 // If the device isn't compiling against the VNDK, we always
2573 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002574 coreVariantNeeded = true
Justin Yun1282f422019-09-09 14:42:44 +09002575 } else if m.Target().NativeBridge == android.NativeBridgeEnabled {
2576 // Skip creating vendor variants for natvie bridge modules
2577 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002578 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2579 // LL-NDK stubs only exist in the vendor variant, since the
2580 // real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002581 vendorVariants = append(vendorVariants,
2582 platformVndkVersion,
2583 deviceVndkVersion,
2584 )
Jiyong Park2a454122017-10-19 15:59:33 +09002585 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2586 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002587 vendorVariants = append(vendorVariants,
2588 platformVndkVersion,
2589 deviceVndkVersion,
2590 )
2591 } else if lib, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002592 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2593 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kim64c43952019-08-26 16:52:35 +09002594 vendorVariants = append(vendorVariants, lib.version())
Ivan Lozano52767be2019-10-18 14:49:46 -07002595 } else if m.HasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002596 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002597 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002598 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002599 vendorVariants = append(vendorVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09002600 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
2601 // code is PLATFORM_VNDK_VERSION.
2602 // On the other hand, vendor_available modules which are not VNDK should
2603 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
2604 if !m.IsVndk() {
Inseob Kim64c43952019-08-26 16:52:35 +09002605 vendorVariants = append(vendorVariants, deviceVndkVersion)
2606 }
Logan Chienf3511742017-10-31 18:04:35 +08002607 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002608 // This will be available in /vendor (or /odm) only
Inseob Kim64c43952019-08-26 16:52:35 +09002609 vendorVariants = append(vendorVariants, deviceVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002610 } else {
2611 // This is either in /system (or similar: /data), or is a
2612 // modules built with the NDK. Modules built with the NDK
2613 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002614 coreVariantNeeded = true
2615 }
2616
2617 if Bool(m.Properties.Recovery_available) {
2618 recoveryVariantNeeded = true
2619 }
2620
2621 if m.ModuleBase.InstallInRecovery() {
2622 recoveryVariantNeeded = true
2623 coreVariantNeeded = false
2624 }
2625
Jiyong Park413cc742018-06-19 01:46:06 +09002626 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002627 primaryArch := mctx.Config().DevicePrimaryArchType()
2628 moduleArch := m.Target().Arch.ArchType
2629 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002630 recoveryVariantNeeded = false
2631 }
2632 }
2633
Inseob Kim64c43952019-08-26 16:52:35 +09002634 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Colin Cross7228ecd2019-11-18 16:00:16 -08002635 m.Properties.VendorVariants = append(m.Properties.VendorVariants, VendorVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09002636 }
Colin Cross7228ecd2019-11-18 16:00:16 -08002637
2638 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
2639 m.Properties.CoreVariantNeeded = coreVariantNeeded
2640}
2641
2642func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
2643 return c.Properties.CoreVariantNeeded
2644}
2645
2646func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
2647 return c.Properties.RecoveryVariantNeeded
2648}
2649
2650func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
2651 return c.Properties.VendorVariants
2652}
2653
2654func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
2655 m := module.(*Module)
2656 if variant == android.RecoveryVariation {
2657 m.MakeAsPlatform()
2658 squashRecoverySrcs(m)
2659 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
2660 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
2661 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002662 }
2663}
2664
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002665func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002666 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002667 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2668 }
Colin Cross6510f912017-11-29 00:27:14 -08002669 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002670}
2671
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002672func kytheExtractAllFactory() android.Singleton {
2673 return &kytheExtractAllSingleton{}
2674}
2675
2676type kytheExtractAllSingleton struct {
2677}
2678
2679func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2680 var xrefTargets android.Paths
2681 ctx.VisitAllModules(func(module android.Module) {
2682 if ccModule, ok := module.(xref); ok {
2683 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
2684 }
2685 })
2686 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
2687 if len(xrefTargets) > 0 {
2688 ctx.Build(pctx, android.BuildParams{
2689 Rule: blueprint.Phony,
2690 Output: android.PathForPhony(ctx, "xref_cxx"),
2691 Inputs: xrefTargets,
2692 //Default: true,
2693 })
2694 }
2695}
2696
Colin Cross06a931b2015-10-28 17:23:31 -07002697var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002698var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002699var BoolPtr = proptools.BoolPtr
2700var String = proptools.String
2701var StringPtr = proptools.StringPtr