blob: 5dfc56386dc37ad830c411427018a39934c19cc7 [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()
Jiyong Parkda6eb592018-12-19 17:12:36 +090040 ctx.BottomUp("image", ImageMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070041 ctx.BottomUp("link", LinkageMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070042 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +010043 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090044 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070045 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimc0907f12019-02-08 21:00:45 +090046 ctx.BottomUp("sysprop", SyspropMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070047 })
Colin Cross16b23492016-01-06 14:41:07 -080048
Colin Cross1e676be2016-10-12 14:38:15 -070049 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
50 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
51 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080052
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070053 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
54 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
55
Mitch Phillipsbfeade62019-05-01 14:42:05 -070056 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
57 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
58
Jiyong Park1d1119f2019-07-29 21:27:18 +090059 // cfi mutator shouldn't run before sanitizers that return true for
60 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000061 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
62 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
63
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080064 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
65 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
66
Colin Cross1e676be2016-10-12 14:38:15 -070067 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
68 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080069
Colin Cross0b908332019-06-19 23:00:20 -070070 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090071 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080072
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080073 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080074 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070075
76 ctx.TopDown("lto_deps", ltoDepsMutator)
77 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090078
79 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070080 })
Colin Crossb98c8b02016-07-29 13:44:28 -070081
Sasha Smundak2a4549e2018-11-05 16:49:08 -080082 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Crossb98c8b02016-07-29 13:44:28 -070083 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070084}
85
Colin Crossca860ac2016-01-04 14:34:37 -080086type Deps struct {
87 SharedLibs, LateSharedLibs []string
88 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080089 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080090 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070091
Colin Cross5950f382016-12-13 12:50:57 -080092 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070093
Colin Cross81413472016-04-11 14:37:39 -070094 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070095
Dan Willemsenb40aab62016-04-20 14:21:14 -070096 GeneratedSources []string
97 GeneratedHeaders []string
98
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
Dan Willemsenb40aab62016-04-20 14:21:14 -0700124
Inseob Kim69378442019-06-03 19:10:47 +0900125 Flags []string
Jiyong Park74955042019-10-22 20:19:51 +0900126 IncludeDirs android.Paths
127 SystemIncludeDirs android.Paths
128 ReexportedDirs android.Paths
129 ReexportedSystemDirs android.Paths
Inseob Kim69378442019-06-03 19:10:47 +0900130 ReexportedFlags []string
131 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700132
Colin Cross26c34ed2016-09-30 17:10:16 -0700133 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700134 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700135
136 // Path to the file container flags to use with the linker
137 LinkerFlagsFile android.OptionalPath
138
139 // Path to the dynamic linker binary
140 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700141}
142
Colin Crossca860ac2016-01-04 14:34:37 -0800143type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700144 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
145 ArFlags []string // Flags that apply to ar
146 AsFlags []string // Flags that apply to assembly source files
147 CFlags []string // Flags that apply to C and C++ source files
148 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
149 ConlyFlags []string // Flags that apply to C source files
150 CppFlags []string // Flags that apply to C++ source files
151 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700152 aidlFlags []string // Flags that apply to aidl source files
153 rsFlags []string // Flags that apply to renderscript source files
154 LdFlags []string // Flags that apply to linker command lines
155 libFlags []string // Flags to add libraries early to the link order
Pete Bentley99f2fc22019-08-02 14:02:20 +0100156 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700157 TidyFlags []string // Flags that apply to clang-tidy
158 SAbiFlags []string // Flags that apply to header-abi-dumper
159 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700160
Colin Crossc3199482017-03-30 15:03:04 -0700161 // Global include flags that apply to C, C++, and assembly source files
162 // These must be after any module include flags, which will be in GlobalFlags.
163 SystemIncludeFlags []string
164
Colin Crossb98c8b02016-07-29 13:44:28 -0700165 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700166 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800167 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800168 SAbiDump bool
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800169 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800170
171 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800172 DynamicLinker string
173
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700174 CFlagsDeps android.Paths // Files depended on by compiler flags
175 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800176
Dan Willemsen98ab3112019-08-27 21:20:40 -0700177 AssemblerWithCpp bool
178 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800179
Colin Cross19878da2019-03-28 14:45:07 -0700180 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700181 protoC bool // Whether to use C instead of C++
182 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700183
184 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700185}
186
Colin Crossca860ac2016-01-04 14:34:37 -0800187// Properties used to compile all C or C++ modules
188type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700189 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800190 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700191
192 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800193 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700194
Jiyong Parkde866cb2018-12-07 23:08:36 +0900195 AndroidMkSharedLibs []string `blueprint:"mutated"`
196 AndroidMkStaticLibs []string `blueprint:"mutated"`
197 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
198 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
199 HideFromMake bool `blueprint:"mutated"`
200 PreventInstall bool `blueprint:"mutated"`
201 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700202
Inseob Kim64c43952019-08-26 16:52:35 +0900203 VndkVersion string `blueprint:"mutated"`
204 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800205
206 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
207 // file
208 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900209
210 // Make this module available when building for recovery
211 Recovery_available *bool
212
213 InRecovery bool `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900214
215 // Allows this module to use non-APEX version of libraries. Useful
216 // for building binaries that are started before APEXes are activated.
217 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900218
219 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
220 // see soong/cc/config/vndk.go
221 MustUseVendorVariant bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700222}
223
224type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900225 // whether this module should be allowed to be directly depended by other
226 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
227 // If set to true, two variants will be built separately, one like
228 // normal, and the other limited to the set of libraries and headers
229 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700230 //
231 // The vendor variant may be used with a different (newer) /system,
232 // so it shouldn't have any unversioned runtime dependencies, or
233 // make assumptions about the system that may not be true in the
234 // future.
235 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900236 // If set to false, this module becomes inaccessible from /vendor modules.
237 //
238 // Default value is true when vndk: {enabled: true} or vendor: true.
239 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700240 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
241 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900242
243 // whether this module is capable of being loaded with other instance
244 // (possibly an older version) of the same module in the same process.
245 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
246 // can be double loaded in a vendor process if the library is also a
247 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
248 // explicitly marked as `double_loadable: true` by the owner, or the dependency
249 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
250 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800251}
252
Colin Crossca860ac2016-01-04 14:34:37 -0800253type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800254 static() bool
255 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900256 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700257 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700258 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800259 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700260 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800261 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900262 isLlndk(config android.Config) bool
263 isLlndkPublic(config android.Config) bool
264 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900265 isVndk() bool
266 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800267 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900268 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800269 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700270 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700271 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800272 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800273 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800274 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800275 useClangLld(actx ModuleContext) bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900276 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900277 hasStubsVariants() bool
278 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900279 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800280 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700281 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800282}
283
284type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700285 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800286 ModuleContextIntf
287}
288
289type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700290 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800291 ModuleContextIntf
292}
293
Colin Cross37047f12016-12-13 17:06:13 -0800294type DepsContext interface {
295 android.BottomUpMutatorContext
296 ModuleContextIntf
297}
298
Colin Crossca860ac2016-01-04 14:34:37 -0800299type feature interface {
300 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800301 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800302 flags(ctx ModuleContext, flags Flags) Flags
303 props() []interface{}
304}
305
306type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700307 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800308 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800309 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700310 compilerProps() []interface{}
311
Colin Cross76fada02016-07-27 10:31:13 -0700312 appendCflags([]string)
313 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700314 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800315}
316
317type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700318 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800319 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700320 linkerFlags(ctx ModuleContext, flags Flags) Flags
321 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800322 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700323
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700324 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700325 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900326 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700327
328 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900329 coverageOutputFilePath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800330}
331
332type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700333 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700334 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800335 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700336 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700337 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900338 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800339}
340
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800341type xref interface {
342 XrefCcFiles() android.Paths
343}
344
Colin Crossc99deeb2016-04-11 15:06:20 -0700345var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700346 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
347 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
348 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
349 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
350 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
351 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
352 headerDepTag = DependencyTag{Name: "header", Library: true}
353 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
354 genSourceDepTag = DependencyTag{Name: "gen source"}
355 genHeaderDepTag = DependencyTag{Name: "gen header"}
356 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
357 objDepTag = DependencyTag{Name: "obj"}
358 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
359 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
360 reuseObjTag = DependencyTag{Name: "reuse objects"}
361 staticVariantTag = DependencyTag{Name: "static variant"}
362 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
363 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
364 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
365 runtimeDepTag = DependencyTag{Name: "runtime lib"}
366 coverageDepTag = DependencyTag{Name: "coverage"}
367 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700368)
369
Roland Levillainf89cd092019-07-29 16:22:59 +0100370func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700371 ccDepTag, ok := depTag.(DependencyTag)
372 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100373}
374
375func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700376 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100377 return ok && ccDepTag == runtimeDepTag
378}
379
380func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700381 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100382 return ok && ccDepTag == testPerSrcDepTag
383}
384
Colin Crossca860ac2016-01-04 14:34:37 -0800385// Module contains the properties and members used by all C/C++ module types, and implements
386// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
387// to construct the output file. Behavior can be customized with a Customizer interface
388type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700389 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700390 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900391 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900392 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700393
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700394 Properties BaseProperties
395 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700396
Colin Crossca860ac2016-01-04 14:34:37 -0800397 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700398 hod android.HostOrDeviceSupported
399 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700400
Colin Crossca860ac2016-01-04 14:34:37 -0800401 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700402 features []feature
403 compiler compiler
404 linker linker
405 installer installer
406 stl *stl
407 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800408 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800409 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900410 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700411 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700412 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800413 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800414
415 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700416
Colin Cross635c3b02016-05-18 15:37:25 -0700417 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800418
Colin Crossb98c8b02016-07-29 13:44:28 -0700419 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700420
421 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800422
423 // Flags used to compile this module
424 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700425
426 // 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 -0800427 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700428 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800429 depsInLinkOrder android.Paths
430
431 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700432 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900433
434 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800435 // Kythe (source file indexer) paths for this compilation module
436 kytheFiles android.Paths
Colin Crossc472d572015-03-17 15:06:21 -0700437}
438
Ivan Lozano52767be2019-10-18 14:49:46 -0700439func (c *Module) Toc() android.OptionalPath {
440 if c.linker != nil {
441 if library, ok := c.linker.(libraryInterface); ok {
442 return library.toc()
443 }
444 }
445 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
446}
447
448func (c *Module) ApiLevel() string {
449 if c.linker != nil {
450 if stub, ok := c.linker.(*stubDecorator); ok {
451 return stub.properties.ApiLevel
452 }
453 }
454 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
455}
456
457func (c *Module) Static() bool {
458 if c.linker != nil {
459 if library, ok := c.linker.(libraryInterface); ok {
460 return library.static()
461 }
462 }
463 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
464}
465
466func (c *Module) Shared() bool {
467 if c.linker != nil {
468 if library, ok := c.linker.(libraryInterface); ok {
469 return library.shared()
470 }
471 }
472 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
473}
474
475func (c *Module) SelectedStl() string {
476 return c.stl.Properties.SelectedStl
477}
478
479func (c *Module) ToolchainLibrary() bool {
480 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
481 return true
482 }
483 return false
484}
485
486func (c *Module) NdkPrebuiltStl() bool {
487 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
488 return true
489 }
490 return false
491}
492
493func (c *Module) StubDecorator() bool {
494 if _, ok := c.linker.(*stubDecorator); ok {
495 return true
496 }
497 return false
498}
499
500func (c *Module) SdkVersion() string {
501 return String(c.Properties.Sdk_version)
502}
503
504func (c *Module) IncludeDirs(ctx android.BaseModuleContext) android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700505 if c.linker != nil {
506 if library, ok := c.linker.(exportedFlagsProducer); ok {
507 return library.exportedDirs()
508 }
509 }
510 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
511}
512
513func (c *Module) HasStaticVariant() bool {
514 if c.staticVariant != nil {
515 return true
516 }
517 return false
518}
519
520func (c *Module) GetStaticVariant() LinkableInterface {
521 return c.staticVariant
522}
523
524func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
525 c.depsInLinkOrder = depsInLinkOrder
526}
527
528func (c *Module) GetDepsInLinkOrder() []android.Path {
529 return c.depsInLinkOrder
530}
531
532func (c *Module) StubsVersions() []string {
533 if c.linker != nil {
534 if library, ok := c.linker.(*libraryDecorator); ok {
535 return library.Properties.Stubs.Versions
536 }
537 }
538 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
539}
540
541func (c *Module) CcLibrary() bool {
542 if c.linker != nil {
543 if _, ok := c.linker.(*libraryDecorator); ok {
544 return true
545 }
546 }
547 return false
548}
549
550func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700551 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700552 return true
553 }
554 return false
555}
556
557func (c *Module) SetBuildStubs() {
558 if c.linker != nil {
559 if library, ok := c.linker.(*libraryDecorator); ok {
560 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700561 c.Properties.HideFromMake = true
562 c.sanitize = nil
563 c.stl = nil
564 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700565 return
566 }
567 }
568 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
569}
570
Ivan Lozano52767be2019-10-18 14:49:46 -0700571func (c *Module) BuildStubs() bool {
572 if c.linker != nil {
573 if library, ok := c.linker.(*libraryDecorator); ok {
574 return library.buildStubs()
575 }
576 }
577 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
578}
579
Ivan Lozano183a3212019-10-18 14:18:45 -0700580func (c *Module) SetStubsVersions(version string) {
581 if c.linker != nil {
582 if library, ok := c.linker.(*libraryDecorator); ok {
583 library.MutatedProperties.StubsVersion = version
584 return
585 }
586 }
587 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
588}
589
590func (c *Module) SetStatic() {
591 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700592 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700593 library.setStatic()
594 return
595 }
596 }
597 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
598}
599
600func (c *Module) SetShared() {
601 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700602 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700603 library.setShared()
604 return
605 }
606 }
607 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
608}
609
610func (c *Module) BuildStaticVariant() bool {
611 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700612 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700613 return library.buildStatic()
614 }
615 }
616 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
617}
618
619func (c *Module) BuildSharedVariant() bool {
620 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700621 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700622 return library.buildShared()
623 }
624 }
625 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
626}
627
628func (c *Module) Module() android.Module {
629 return c
630}
631
Jiyong Parkc20eee32018-09-05 22:36:17 +0900632func (c *Module) OutputFile() android.OptionalPath {
633 return c.outputFile
634}
635
Ivan Lozano183a3212019-10-18 14:18:45 -0700636var _ LinkableInterface = (*Module)(nil)
637
Jiyong Park719b4462019-01-13 00:39:51 +0900638func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900639 if c.linker != nil {
640 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900641 }
642 return nil
643}
644
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900645func (c *Module) CoverageOutputFile() android.OptionalPath {
646 if c.linker != nil {
647 return c.linker.coverageOutputFilePath()
648 }
649 return android.OptionalPath{}
650}
651
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900652func (c *Module) RelativeInstallPath() string {
653 if c.installer != nil {
654 return c.installer.relativeInstallPath()
655 }
656 return ""
657}
658
Jooyung Han344d5432019-08-23 11:17:39 +0900659func (c *Module) VndkVersion() string {
660 return c.vndkVersion()
661}
662
Colin Cross36242852017-06-23 15:06:31 -0700663func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700664 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800665 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700666 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800667 }
668 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700669 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800670 }
671 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700672 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800673 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700674 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700675 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700676 }
Colin Cross16b23492016-01-06 14:41:07 -0800677 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700678 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800679 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800680 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700681 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800682 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800683 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700684 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800685 }
Justin Yun8effde42017-06-23 19:24:43 +0900686 if c.vndkdep != nil {
687 c.AddProperties(c.vndkdep.props()...)
688 }
Stephen Craneba090d12017-05-09 15:44:35 -0700689 if c.lto != nil {
690 c.AddProperties(c.lto.props()...)
691 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700692 if c.pgo != nil {
693 c.AddProperties(c.pgo.props()...)
694 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800695 if c.xom != nil {
696 c.AddProperties(c.xom.props()...)
697 }
Colin Crossca860ac2016-01-04 14:34:37 -0800698 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700699 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800700 }
Colin Crossc472d572015-03-17 15:06:21 -0700701
Colin Crossa9d8bee2018-10-02 13:59:46 -0700702 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
703 switch class {
704 case android.Device:
705 return ctx.Config().DevicePrefer32BitExecutables()
706 case android.HostCross:
707 // Windows builds always prefer 32-bit
708 return true
709 default:
710 return false
711 }
712 })
Colin Cross36242852017-06-23 15:06:31 -0700713 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900714
Jooyung Hancc372c52019-09-25 15:18:44 +0900715 android.InitDefaultableModule(c)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900716
717 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900718 android.InitSdkAwareModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900719
Colin Cross36242852017-06-23 15:06:31 -0700720 return c
Colin Crossc472d572015-03-17 15:06:21 -0700721}
722
Colin Crossb916a382016-07-29 17:28:03 -0700723// Returns true for dependency roots (binaries)
724// TODO(ccross): also handle dlopenable libraries
725func (c *Module) isDependencyRoot() bool {
726 if root, ok := c.linker.(interface {
727 isDependencyRoot() bool
728 }); ok {
729 return root.isDependencyRoot()
730 }
731 return false
732}
733
Ivan Lozano52767be2019-10-18 14:49:46 -0700734func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900735 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700736}
737
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800738func (c *Module) isCoverageVariant() bool {
739 return c.coverage.Properties.IsCoverageVariant
740}
741
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800742func (c *Module) isNdk() bool {
743 return inList(c.Name(), ndkMigratedLibs)
744}
745
Inseob Kim9516ee92019-05-09 10:56:13 +0900746func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800747 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900748 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800749}
750
Inseob Kim9516ee92019-05-09 10:56:13 +0900751func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800752 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900753 name := c.BaseModuleName()
754 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800755}
756
Inseob Kim9516ee92019-05-09 10:56:13 +0900757func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800758 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900759 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800760}
761
Ivan Lozano52767be2019-10-18 14:49:46 -0700762func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800763 if vndkdep := c.vndkdep; vndkdep != nil {
764 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900765 }
766 return false
767}
768
Jooyung Han76106d92019-05-20 18:49:10 +0900769func (c *Module) vndkVersion() string {
Inseob Kim64c43952019-08-26 16:52:35 +0900770 return c.Properties.VndkVersion
Jooyung Han76106d92019-05-20 18:49:10 +0900771}
772
Yi Kong7e53c572018-02-14 18:16:12 +0800773func (c *Module) isPgoCompile() bool {
774 if pgo := c.pgo; pgo != nil {
775 return pgo.Properties.PgoCompile
776 }
777 return false
778}
779
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800780func (c *Module) isNDKStubLibrary() bool {
781 if _, ok := c.compiler.(*stubDecorator); ok {
782 return true
783 }
784 return false
785}
786
Logan Chienf3511742017-10-31 18:04:35 +0800787func (c *Module) isVndkSp() bool {
788 if vndkdep := c.vndkdep; vndkdep != nil {
789 return vndkdep.isVndkSp()
790 }
791 return false
792}
793
794func (c *Module) isVndkExt() bool {
795 if vndkdep := c.vndkdep; vndkdep != nil {
796 return vndkdep.isVndkExt()
797 }
798 return false
799}
800
Ivan Lozano52767be2019-10-18 14:49:46 -0700801func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900802 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800803}
804
Logan Chienf3511742017-10-31 18:04:35 +0800805func (c *Module) getVndkExtendsModuleName() string {
806 if vndkdep := c.vndkdep; vndkdep != nil {
807 return vndkdep.getVndkExtendsModuleName()
808 }
809 return ""
810}
811
Jiyong Park82e2bf32017-08-16 14:05:54 +0900812// Returns true only when this module is configured to have core and vendor
813// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700814func (c *Module) HasVendorVariant() bool {
815 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900816}
817
Ivan Lozano52767be2019-10-18 14:49:46 -0700818func (c *Module) InRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900819 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
820}
821
Ivan Lozano52767be2019-10-18 14:49:46 -0700822func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900823 return c.ModuleBase.InstallInRecovery()
824}
825
Jiyong Park25fc6a92018-11-18 18:02:45 +0900826func (c *Module) IsStubs() bool {
827 if library, ok := c.linker.(*libraryDecorator); ok {
828 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900829 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
830 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900831 }
832 return false
833}
834
835func (c *Module) HasStubsVariants() bool {
836 if library, ok := c.linker.(*libraryDecorator); ok {
837 return len(library.Properties.Stubs.Versions) > 0
838 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700839 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
840 return len(library.Properties.Stubs.Versions) > 0
841 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900842 return false
843}
844
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900845func (c *Module) bootstrap() bool {
846 return Bool(c.Properties.Bootstrap)
847}
848
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700849func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700850 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
851 if c.Target().NativeBridge == android.NativeBridgeEnabled {
852 return false
853 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700854 return c.linker != nil && c.linker.nativeCoverage()
855}
856
Jiyong Park73c54ee2019-10-22 20:31:18 +0900857func (c *Module) ExportedIncludeDirs() android.Paths {
858 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
859 return flagsProducer.exportedDirs()
860 }
861 return []android.Path{}
862}
863
864func (c *Module) ExportedSystemIncludeDirs() android.Paths {
865 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
866 return flagsProducer.exportedSystemDirs()
867 }
868 return []android.Path{}
869}
870
871func (c *Module) ExportedFlags() []string {
872 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
873 return flagsProducer.exportedFlags()
874 }
875 return []string{}
876}
877
Jiyong Parkf1194352019-02-25 11:05:47 +0900878func isBionic(name string) bool {
879 switch name {
880 case "libc", "libm", "libdl", "linker":
881 return true
882 }
883 return false
884}
885
Martin Stjernholm279de572019-09-10 23:18:20 +0100886func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700887 if name == "libclang_rt.hwasan-aarch64-android" {
888 return inList("hwaddress", config.SanitizeDevice())
889 }
890 return isBionic(name)
891}
892
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800893func (c *Module) XrefCcFiles() android.Paths {
894 return c.kytheFiles
895}
896
Colin Crossca860ac2016-01-04 14:34:37 -0800897type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700898 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800899 moduleContextImpl
900}
901
Colin Cross37047f12016-12-13 17:06:13 -0800902type depsContext struct {
903 android.BottomUpMutatorContext
904 moduleContextImpl
905}
906
Colin Crossca860ac2016-01-04 14:34:37 -0800907type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700908 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800909 moduleContextImpl
910}
911
Jiyong Park2db76922017-11-08 16:03:48 +0900912func (ctx *moduleContext) SocSpecific() bool {
913 return ctx.ModuleContext.SocSpecific() ||
Ivan Lozano52767be2019-10-18 14:49:46 -0700914 (ctx.mod.HasVendorVariant() && ctx.mod.UseVndk() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700915}
916
Colin Crossca860ac2016-01-04 14:34:37 -0800917type moduleContextImpl struct {
918 mod *Module
919 ctx BaseModuleContext
920}
921
Colin Crossb98c8b02016-07-29 13:44:28 -0700922func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800923 return ctx.mod.toolchain(ctx.ctx)
924}
925
926func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000927 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800928}
929
930func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900931 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800932}
933
Jiyong Park1d1119f2019-07-29 21:27:18 +0900934func (ctx *moduleContextImpl) header() bool {
935 return ctx.mod.header()
936}
937
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700938func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800939 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800940 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700941 }
942 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800943}
944
945func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700946 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700947 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900948 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700949 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900950 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
951 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
952 return "current"
953 }
954 return platform_vndk_ver
955 }
956 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800957 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900958 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700959 }
960 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800961}
962
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700963func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700964 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700965}
Justin Yun8effde42017-06-23 19:24:43 +0900966
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800967func (ctx *moduleContextImpl) isNdk() bool {
968 return ctx.mod.isNdk()
969}
970
Inseob Kim9516ee92019-05-09 10:56:13 +0900971func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
972 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800973}
974
Inseob Kim9516ee92019-05-09 10:56:13 +0900975func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
976 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800977}
978
Inseob Kim9516ee92019-05-09 10:56:13 +0900979func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
980 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800981}
982
Logan Chienf3511742017-10-31 18:04:35 +0800983func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700984 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +0800985}
986
Yi Kong7e53c572018-02-14 18:16:12 +0800987func (ctx *moduleContextImpl) isPgoCompile() bool {
988 return ctx.mod.isPgoCompile()
989}
990
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800991func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
992 return ctx.mod.isNDKStubLibrary()
993}
994
Justin Yun8effde42017-06-23 19:24:43 +0900995func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800996 return ctx.mod.isVndkSp()
997}
998
999func (ctx *moduleContextImpl) isVndkExt() bool {
1000 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001001}
1002
Vic Yangefd249e2018-11-12 20:19:56 -08001003func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001004 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001005}
1006
Jiyong Parkf9332f12018-02-01 00:54:12 +09001007func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001008 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001009}
1010
Logan Chien2f2b8902018-07-10 15:01:19 +08001011// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001012func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001013 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1014 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001015 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001016
1017 if ctx.ctx.Fuchsia() {
1018 return false
1019 }
1020
Logan Chien2f2b8902018-07-10 15:01:19 +08001021 if sanitize := ctx.mod.sanitize; sanitize != nil {
1022 if !sanitize.isVariantOnProductionDevice() {
1023 return false
1024 }
1025 }
1026 if !ctx.ctx.Device() {
1027 // Host modules do not need ABI dumps.
1028 return false
1029 }
Logan Chienfa478c02018-12-28 16:25:39 +08001030 if !ctx.mod.IsForPlatform() {
1031 // APEX variants do not need ABI dumps.
1032 return false
1033 }
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001034 if ctx.isStubs() {
1035 // Stubs do not need ABI dumps.
1036 return false
1037 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001038 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001039}
1040
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001041func (ctx *moduleContextImpl) selectedStl() string {
1042 if stl := ctx.mod.stl; stl != nil {
1043 return stl.Properties.SelectedStl
1044 }
1045 return ""
1046}
1047
Ivan Lozanobd721262018-11-27 14:33:03 -08001048func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1049 return ctx.mod.linker.useClangLld(actx)
1050}
1051
Colin Crossce75d2c2016-10-06 16:12:58 -07001052func (ctx *moduleContextImpl) baseModuleName() string {
1053 return ctx.mod.ModuleBase.BaseModuleName()
1054}
1055
Logan Chienf3511742017-10-31 18:04:35 +08001056func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1057 return ctx.mod.getVndkExtendsModuleName()
1058}
1059
Jiyong Park58e364a2019-01-19 19:24:06 +09001060func (ctx *moduleContextImpl) apexName() string {
1061 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001062}
1063
Jiyong Parkb0788572018-12-20 22:10:17 +09001064func (ctx *moduleContextImpl) hasStubsVariants() bool {
1065 return ctx.mod.HasStubsVariants()
1066}
1067
1068func (ctx *moduleContextImpl) isStubs() bool {
1069 return ctx.mod.IsStubs()
1070}
1071
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001072func (ctx *moduleContextImpl) bootstrap() bool {
1073 return ctx.mod.bootstrap()
1074}
1075
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001076func (ctx *moduleContextImpl) nativeCoverage() bool {
1077 return ctx.mod.nativeCoverage()
1078}
1079
Colin Cross635c3b02016-05-18 15:37:25 -07001080func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001081 return &Module{
1082 hod: hod,
1083 multilib: multilib,
1084 }
1085}
1086
Colin Cross635c3b02016-05-18 15:37:25 -07001087func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001088 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001089 module.features = []feature{
1090 &tidyFeature{},
1091 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001092 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001093 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001094 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001095 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001096 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001097 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001098 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -08001099 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -08001100 return module
1101}
1102
Colin Crossce75d2c2016-10-06 16:12:58 -07001103func (c *Module) Prebuilt() *android.Prebuilt {
1104 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1105 return p.prebuilt()
1106 }
1107 return nil
1108}
1109
1110func (c *Module) Name() string {
1111 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001112 if p, ok := c.linker.(interface {
1113 Name(string) string
1114 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001115 name = p.Name(name)
1116 }
1117 return name
1118}
1119
Alex Light3d673592019-01-18 14:37:31 -08001120func (c *Module) Symlinks() []string {
1121 if p, ok := c.installer.(interface {
1122 symlinkList() []string
1123 }); ok {
1124 return p.symlinkList()
1125 }
1126 return nil
1127}
1128
Jeff Gaston294356f2017-09-27 17:05:30 -07001129// orderDeps reorders dependencies into a list such that if module A depends on B, then
1130// A will precede B in the resultant list.
1131// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001132// Note that directSharedDeps should be the analogous static library for each shared lib dep
1133func 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 -07001134 // If A depends on B, then
1135 // Every list containing A will also contain B later in the list
1136 // So, after concatenating all lists, the final instance of B will have come from the same
1137 // original list as the final instance of A
1138 // So, the final instance of B will be later in the concatenation than the final A
1139 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1140 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001141 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001142 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001143 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1144 }
1145 for _, dep := range directSharedDeps {
1146 orderedAllDeps = append(orderedAllDeps, dep)
1147 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001148 }
1149
Colin Crossb6715442017-10-24 11:13:31 -07001150 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001151
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001152 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001153 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001154 // resultant list to only what the caller has chosen to include in directStaticDeps
1155 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001156
1157 return orderedAllDeps, orderedDeclaredDeps
1158}
1159
Ivan Lozano183a3212019-10-18 14:18:45 -07001160func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001161 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001162 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001163 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1164 staticDepFiles := []android.Path{}
1165 for _, dep := range staticDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001166 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1167 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
Jeff Gaston294356f2017-09-27 17:05:30 -07001168 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001169 sharedDepFiles := []android.Path{}
1170 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001171 if sharedDep.HasStaticVariant() {
1172 staticAnalogue := sharedDep.GetStaticVariant()
1173 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1174 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001175 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001176 }
1177
1178 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001179 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1180 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001181
1182 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001183}
1184
Roland Levillainf89cd092019-07-29 16:22:59 +01001185func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1186 test, ok := c.linker.(testPerSrc)
1187 return ok && test.isAllTestsVariation()
1188}
1189
Colin Cross635c3b02016-05-18 15:37:25 -07001190func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001191 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001192 //
1193 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1194 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1195 // module and return early, as this module does not produce an output file per se.
1196 if c.IsTestPerSrcAllTestsVariation() {
1197 c.outputFile = android.OptionalPath{}
1198 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001199 }
1200
Jooyung Han38002912019-05-16 04:01:54 +09001201 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001202
Inseob Kim64c43952019-08-26 16:52:35 +09001203 c.Properties.SubName = ""
1204
1205 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1206 c.Properties.SubName += nativeBridgeSuffix
1207 }
1208
1209 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
1210 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1211 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1212 c.Properties.SubName += vendorSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001213 } else if _, ok := c.linker.(*llndkStubDecorator); ok || (c.UseVndk() && c.HasVendorVariant()) {
Inseob Kim64c43952019-08-26 16:52:35 +09001214 // .vendor.{version} suffix is added only when we will have two variants: core and vendor.
1215 // The suffix is not added for vendor-only module.
1216 c.Properties.SubName += vendorSuffix
1217 vendorVersion := actx.DeviceConfig().VndkVersion()
1218 if vendorVersion == "current" {
1219 vendorVersion = actx.DeviceConfig().PlatformVndkVersion()
1220 }
1221 if c.Properties.VndkVersion != vendorVersion {
1222 c.Properties.SubName += "." + c.Properties.VndkVersion
1223 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001224 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001225 c.Properties.SubName += recoverySuffix
1226 }
1227
Colin Crossca860ac2016-01-04 14:34:37 -08001228 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001229 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001230 moduleContextImpl: moduleContextImpl{
1231 mod: c,
1232 },
1233 }
1234 ctx.ctx = ctx
1235
Colin Crossf18e1102017-11-16 14:33:08 -08001236 deps := c.depsToPaths(ctx)
1237 if ctx.Failed() {
1238 return
1239 }
1240
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001241 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1242 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1243 }
1244
Colin Crossca860ac2016-01-04 14:34:37 -08001245 flags := Flags{
1246 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001247 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001248 }
Colin Crossca860ac2016-01-04 14:34:37 -08001249 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001250 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001251 }
1252 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001253 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001254 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001255 if c.stl != nil {
1256 flags = c.stl.flags(ctx, flags)
1257 }
Colin Cross16b23492016-01-06 14:41:07 -08001258 if c.sanitize != nil {
1259 flags = c.sanitize.flags(ctx, flags)
1260 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001261 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001262 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001263 }
Stephen Craneba090d12017-05-09 15:44:35 -07001264 if c.lto != nil {
1265 flags = c.lto.flags(ctx, flags)
1266 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001267 if c.pgo != nil {
1268 flags = c.pgo.flags(ctx, flags)
1269 }
Ivan Lozano074ec482018-11-21 08:59:37 -08001270 if c.xom != nil {
1271 flags = c.xom.flags(ctx, flags)
1272 }
Colin Crossca860ac2016-01-04 14:34:37 -08001273 for _, feature := range c.features {
1274 flags = feature.flags(ctx, flags)
1275 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001276 if ctx.Failed() {
1277 return
1278 }
1279
Colin Crossb98c8b02016-07-29 13:44:28 -07001280 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
1281 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
1282 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001283
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001284 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001285
1286 for _, dir := range deps.IncludeDirs {
Jiyong Park74955042019-10-22 20:19:51 +09001287 flags.GlobalFlags = append(flags.GlobalFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001288 }
1289 for _, dir := range deps.SystemIncludeDirs {
Jiyong Park74955042019-10-22 20:19:51 +09001290 flags.GlobalFlags = append(flags.GlobalFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001291 }
1292
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001293 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001294 // We need access to all the flags seen by a source file.
1295 if c.sabi != nil {
1296 flags = c.sabi.flags(ctx, flags)
1297 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001298
1299 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.AsFlags)
1300
Colin Crossca860ac2016-01-04 14:34:37 -08001301 // Optimization to reduce size of build.ninja
1302 // Replace the long list of flags for each file with a module-local variable
1303 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
1304 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
1305 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
1306 flags.CFlags = []string{"$cflags"}
1307 flags.CppFlags = []string{"$cppflags"}
1308 flags.AsFlags = []string{"$asflags"}
1309
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001310 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001311 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001312 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001313 if ctx.Failed() {
1314 return
1315 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001316 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001317 }
1318
Colin Crossca860ac2016-01-04 14:34:37 -08001319 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001320 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001321 if ctx.Failed() {
1322 return
1323 }
Colin Cross635c3b02016-05-18 15:37:25 -07001324 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001325
1326 // If a lib is directly included in any of the APEXes, unhide the stubs
1327 // variant having the latest version gets visible to make. In addition,
1328 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1329 // force anything in the make world to link against the stubs library.
1330 // (unless it is explicitly referenced via .bootstrap suffix or the
1331 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001332 if c.HasStubsVariants() &&
1333 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001334 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001335 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001336 c.Properties.HideFromMake = false // unhide
1337 // Note: this is still non-installable
1338 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001339 }
Colin Cross5049f022015-03-18 13:28:46 -07001340
Inseob Kim1f086e22019-05-09 13:29:15 +09001341 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001342 c.installer.install(ctx, c.outputFile.Path())
1343 if ctx.Failed() {
1344 return
Colin Crossca860ac2016-01-04 14:34:37 -08001345 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001346 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001347}
1348
Colin Cross0ea8ba82019-06-06 14:33:29 -07001349func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001350 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001351 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001352 }
Colin Crossca860ac2016-01-04 14:34:37 -08001353 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001354}
1355
Colin Crossca860ac2016-01-04 14:34:37 -08001356func (c *Module) begin(ctx BaseModuleContext) {
1357 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001358 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001359 }
Colin Crossca860ac2016-01-04 14:34:37 -08001360 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001361 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001362 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001363 if c.stl != nil {
1364 c.stl.begin(ctx)
1365 }
Colin Cross16b23492016-01-06 14:41:07 -08001366 if c.sanitize != nil {
1367 c.sanitize.begin(ctx)
1368 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001369 if c.coverage != nil {
1370 c.coverage.begin(ctx)
1371 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001372 if c.sabi != nil {
1373 c.sabi.begin(ctx)
1374 }
Justin Yun8effde42017-06-23 19:24:43 +09001375 if c.vndkdep != nil {
1376 c.vndkdep.begin(ctx)
1377 }
Stephen Craneba090d12017-05-09 15:44:35 -07001378 if c.lto != nil {
1379 c.lto.begin(ctx)
1380 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001381 if c.pgo != nil {
1382 c.pgo.begin(ctx)
1383 }
Colin Crossca860ac2016-01-04 14:34:37 -08001384 for _, feature := range c.features {
1385 feature.begin(ctx)
1386 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001387 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001388 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001389 if err != nil {
1390 ctx.PropertyErrorf("sdk_version", err.Error())
1391 }
Nan Zhang0007d812017-11-07 10:57:05 -08001392 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001393 }
Colin Crossca860ac2016-01-04 14:34:37 -08001394}
1395
Colin Cross37047f12016-12-13 17:06:13 -08001396func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001397 deps := Deps{}
1398
1399 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001400 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001401 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001402 // Add the PGO dependency (the clang_rt.profile runtime library), which
1403 // sometimes depends on symbols from libgcc, before libgcc gets added
1404 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001405 if c.pgo != nil {
1406 deps = c.pgo.deps(ctx, deps)
1407 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001408 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001409 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001410 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001411 if c.stl != nil {
1412 deps = c.stl.deps(ctx, deps)
1413 }
Colin Cross16b23492016-01-06 14:41:07 -08001414 if c.sanitize != nil {
1415 deps = c.sanitize.deps(ctx, deps)
1416 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001417 if c.coverage != nil {
1418 deps = c.coverage.deps(ctx, deps)
1419 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001420 if c.sabi != nil {
1421 deps = c.sabi.deps(ctx, deps)
1422 }
Justin Yun8effde42017-06-23 19:24:43 +09001423 if c.vndkdep != nil {
1424 deps = c.vndkdep.deps(ctx, deps)
1425 }
Stephen Craneba090d12017-05-09 15:44:35 -07001426 if c.lto != nil {
1427 deps = c.lto.deps(ctx, deps)
1428 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001429 for _, feature := range c.features {
1430 deps = feature.deps(ctx, deps)
1431 }
1432
Colin Crossb6715442017-10-24 11:13:31 -07001433 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1434 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1435 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1436 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1437 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1438 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001439 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001440
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001441 for _, lib := range deps.ReexportSharedLibHeaders {
1442 if !inList(lib, deps.SharedLibs) {
1443 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1444 }
1445 }
1446
1447 for _, lib := range deps.ReexportStaticLibHeaders {
1448 if !inList(lib, deps.StaticLibs) {
1449 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1450 }
1451 }
1452
Colin Cross5950f382016-12-13 12:50:57 -08001453 for _, lib := range deps.ReexportHeaderLibHeaders {
1454 if !inList(lib, deps.HeaderLibs) {
1455 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1456 }
1457 }
1458
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001459 for _, gen := range deps.ReexportGeneratedHeaders {
1460 if !inList(gen, deps.GeneratedHeaders) {
1461 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1462 }
1463 }
1464
Colin Crossc99deeb2016-04-11 15:06:20 -07001465 return deps
1466}
1467
Dan Albert7e9d2952016-08-04 13:02:36 -07001468func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001469 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001470 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001471 moduleContextImpl: moduleContextImpl{
1472 mod: c,
1473 },
1474 }
1475 ctx.ctx = ctx
1476
Colin Crossca860ac2016-01-04 14:34:37 -08001477 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001478}
1479
Jiyong Park7ed9de32018-10-15 22:25:07 +09001480// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001481func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001482 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1483 version := name[sharp+1:]
1484 libname := name[:sharp]
1485 return libname, version
1486 }
1487 return name, ""
1488}
1489
Colin Cross1e676be2016-10-12 14:38:15 -07001490func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001491 ctx := &depsContext{
1492 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001493 moduleContextImpl: moduleContextImpl{
1494 mod: c,
1495 },
1496 }
1497 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001498
Colin Crossc99deeb2016-04-11 15:06:20 -07001499 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001500
Dan Albert914449f2016-06-17 16:45:24 -07001501 variantNdkLibs := []string{}
1502 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001503 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001504 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001505
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001506 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1507 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001508 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001509 // 1. Name of an NDK library that refers to a prebuilt module.
1510 // For each of these, it adds the name of the prebuilt module (which will be in
1511 // prebuilts/ndk) to the list of nonvariant libs.
1512 // 2. Name of an NDK library that refers to an ndk_library module.
1513 // For each of these, it adds the name of the ndk_library module to the list of
1514 // variant libs.
1515 // 3. Anything else (so anything that isn't an NDK library).
1516 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001517 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001518 // The caller can then know to add the variantLibs dependencies differently from the
1519 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001520
Inseob Kim9516ee92019-05-09 10:56:13 +09001521 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001522 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1523 variantLibs = []string{}
1524 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001525 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001526 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001527 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001528 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1529 if !inList(name, ndkMigratedLibs) {
1530 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001531 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001532 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001533 }
Jooyung Han0302a842019-10-30 18:43:49 +09001534 } else if ctx.useVndk() && isLlndkLibrary(name, ctx.Config()) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001535 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001536 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001537 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001538 if actx.OtherModuleExists(vendorPublicLib) {
1539 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1540 } else {
1541 // This can happen if vendor_public_library module is defined in a
1542 // namespace that isn't visible to the current module. In that case,
1543 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001544 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001545 }
Dan Albert914449f2016-06-17 16:45:24 -07001546 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001547 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001548 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001549 }
1550 }
Dan Albert914449f2016-06-17 16:45:24 -07001551 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001552 }
1553
Dan Albert914449f2016-06-17 16:45:24 -07001554 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1555 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001556 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001557 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001558
Jiyong Park7e636d02019-01-28 16:16:54 +09001559 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001560 if c.linker != nil {
1561 if library, ok := c.linker.(*libraryDecorator); ok {
1562 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001563 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001564 }
1565 }
1566 }
1567
Colin Cross32ec36c2016-12-15 07:39:51 -08001568 for _, lib := range deps.HeaderLibs {
1569 depTag := headerDepTag
1570 if inList(lib, deps.ReexportHeaderLibHeaders) {
1571 depTag = headerExportDepTag
1572 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001573 if buildStubs {
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001574 actx.AddFarVariationDependencies(append(ctx.Target().Variations(),
1575 blueprint.Variation{Mutator: "image", Variation: c.imageVariation()}),
1576 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001577 } else {
1578 actx.AddVariationDependencies(nil, depTag, lib)
1579 }
1580 }
1581
1582 if buildStubs {
1583 // Stubs lib does not have dependency to other static/shared libraries.
1584 // Don't proceed.
1585 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001586 }
Colin Cross5950f382016-12-13 12:50:57 -08001587
Inseob Kimc0907f12019-02-08 21:00:45 +09001588 syspropImplLibraries := syspropImplLibraries(actx.Config())
1589
Jiyong Park5d1598f2019-02-25 22:14:17 +09001590 for _, lib := range deps.WholeStaticLibs {
1591 depTag := wholeStaticDepTag
1592 if impl, ok := syspropImplLibraries[lib]; ok {
1593 lib = impl
1594 }
1595 actx.AddVariationDependencies([]blueprint.Variation{
1596 {Mutator: "link", Variation: "static"},
1597 }, depTag, lib)
1598 }
1599
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001600 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001601 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001602 if inList(lib, deps.ReexportStaticLibHeaders) {
1603 depTag = staticExportDepTag
1604 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001605
1606 if impl, ok := syspropImplLibraries[lib]; ok {
1607 lib = impl
1608 }
1609
Dan Willemsen59339a22018-07-22 21:18:45 -07001610 actx.AddVariationDependencies([]blueprint.Variation{
1611 {Mutator: "link", Variation: "static"},
1612 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001613 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001614
Dan Willemsen59339a22018-07-22 21:18:45 -07001615 actx.AddVariationDependencies([]blueprint.Variation{
1616 {Mutator: "link", Variation: "static"},
1617 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001618
Ivan Lozano183a3212019-10-18 14:18:45 -07001619 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001620 var variations []blueprint.Variation
1621 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Ivan Lozano52767be2019-10-18 14:49:46 -07001622 versionVariantAvail := !ctx.useVndk() && !c.InRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001623 if version != "" && versionVariantAvail {
1624 // Version is explicitly specified. i.e. libFoo#30
1625 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001626 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001627 }
1628 actx.AddVariationDependencies(variations, depTag, name)
1629
1630 // If the version is not specified, add dependency to the latest stubs library.
1631 // The stubs library will be used when the depending module is built for APEX and
1632 // the dependent module is not in the same APEX.
Jiyong Park73c54ee2019-10-22 20:31:18 +09001633 latestVersion := LatestStubsVersionFor(actx.Config(), name)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001634 if version == "" && latestVersion != "" && versionVariantAvail {
1635 actx.AddVariationDependencies([]blueprint.Variation{
1636 {Mutator: "link", Variation: "shared"},
1637 {Mutator: "version", Variation: latestVersion},
1638 }, depTag, name)
Ivan Lozano183a3212019-10-18 14:18:45 -07001639 // Note that depTag.ExplicitlyVersioned is false in this case.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001640 }
1641 }
1642
Jiyong Park7ed9de32018-10-15 22:25:07 +09001643 // shared lib names without the #version suffix
1644 var sharedLibNames []string
1645
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001646 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001647 depTag := SharedDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001648 if inList(lib, deps.ReexportSharedLibHeaders) {
1649 depTag = sharedExportDepTag
1650 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001651
1652 if impl, ok := syspropImplLibraries[lib]; ok {
1653 lib = impl
1654 }
1655
Jiyong Park73c54ee2019-10-22 20:31:18 +09001656 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001657 sharedLibNames = append(sharedLibNames, name)
1658
Jiyong Park25fc6a92018-11-18 18:02:45 +09001659 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001660 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001661
Jiyong Park7ed9de32018-10-15 22:25:07 +09001662 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001663 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001664 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1665 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1666 // linking against both the stubs lib and the non-stubs lib at the same time.
1667 continue
1668 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001669 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001670 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001671
Dan Willemsen59339a22018-07-22 21:18:45 -07001672 actx.AddVariationDependencies([]blueprint.Variation{
1673 {Mutator: "link", Variation: "shared"},
1674 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001675
Colin Cross68861832016-07-08 10:41:41 -07001676 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001677
1678 for _, gen := range deps.GeneratedHeaders {
1679 depTag := genHeaderDepTag
1680 if inList(gen, deps.ReexportGeneratedHeaders) {
1681 depTag = genHeaderExportDepTag
1682 }
1683 actx.AddDependency(c, depTag, gen)
1684 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001685
Colin Cross42d48b72018-08-29 14:10:52 -07001686 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001687
1688 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001689 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001690 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001691 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001692 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001693 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001694 if deps.LinkerFlagsFile != "" {
1695 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1696 }
1697 if deps.DynamicLinker != "" {
1698 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001699 }
Dan Albert914449f2016-06-17 16:45:24 -07001700
1701 version := ctx.sdkVersion()
1702 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001703 {Mutator: "ndk_api", Variation: version},
1704 {Mutator: "link", Variation: "shared"},
1705 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001706 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001707 {Mutator: "ndk_api", Variation: version},
1708 {Mutator: "link", Variation: "shared"},
1709 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001710
1711 if vndkdep := c.vndkdep; vndkdep != nil {
1712 if vndkdep.isVndkExt() {
Inseob Kim64c43952019-08-26 16:52:35 +09001713 var baseModuleMode string
Logan Chienf3511742017-10-31 18:04:35 +08001714 if actx.DeviceConfig().VndkVersion() == "" {
1715 baseModuleMode = coreMode
Inseob Kim64c43952019-08-26 16:52:35 +09001716 } else {
1717 baseModuleMode = c.imageVariation()
Logan Chienf3511742017-10-31 18:04:35 +08001718 }
1719 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001720 {Mutator: "image", Variation: baseModuleMode},
1721 {Mutator: "link", Variation: "shared"},
1722 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001723 }
1724 }
Colin Cross6362e272015-10-29 15:25:03 -07001725}
Colin Cross21b9a242015-03-24 14:15:58 -07001726
Colin Crosse40b4ea2018-10-02 22:25:58 -07001727func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001728 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1729 c.beginMutator(ctx)
1730 }
1731}
1732
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001733// Whether a module can link to another module, taking into
1734// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07001735func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
1736 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001737 // Host code is not restricted
1738 return
1739 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001740
1741 // VNDK is cc.Module supported only for now.
1742 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001743 // Though vendor code is limited by the vendor mutator,
1744 // each vendor-available module needs to check
1745 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07001746 if ccTo, ok := to.(*Module); ok {
1747 if ccFrom.vndkdep != nil {
1748 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
1749 }
1750 } else {
1751 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001752 }
1753 return
1754 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001755 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001756 // Platform code can link to anything
1757 return
1758 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001759 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09001760 // Recovery code is not NDK
1761 return
1762 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001763 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001764 // These are always allowed
1765 return
1766 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001767 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001768 // These are allowed, but they don't set sdk_version
1769 return
1770 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001771 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001772 // These aren't real libraries, but are the stub shared libraries that are included in
1773 // the NDK.
1774 return
1775 }
Logan Chien834b9a62019-01-14 15:39:03 +08001776
Ivan Lozano52767be2019-10-18 14:49:46 -07001777 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08001778 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1779 // to link to libc++ (non-NDK and without sdk_version).
1780 return
1781 }
1782
Ivan Lozano52767be2019-10-18 14:49:46 -07001783 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001784 // NDK code linking to platform code is never okay.
1785 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001786 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001787 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001788 }
1789
1790 // At this point we know we have two NDK libraries, but we need to
1791 // check that we're not linking against anything built against a higher
1792 // API level, as it is only valid to link against older or equivalent
1793 // APIs.
1794
Inseob Kim01a28722018-04-11 09:48:45 +09001795 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07001796 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001797 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07001798 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001799 // Current can't be linked against by anything else.
1800 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001801 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09001802 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07001803 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001804 if err != nil {
1805 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001806 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001807 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001808 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001809 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001810 if err != nil {
1811 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001812 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001813 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001814 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001815
Inseob Kim01a28722018-04-11 09:48:45 +09001816 if toApi > fromApi {
1817 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001818 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001819 }
1820 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001821 }
Dan Albert202fe492017-12-15 13:56:59 -08001822
1823 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07001824 fromStl := from.SelectedStl()
1825 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08001826 if fromStl == "" || toStl == "" {
1827 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001828 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001829 // We can be permissive with the system "STL" since it is only the C++
1830 // ABI layer, but in the future we should make sure that everyone is
1831 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001832 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001833 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001834 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
1835 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08001836 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001837}
1838
Jiyong Park5fb8c102018-04-09 12:03:06 +09001839// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001840// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1841// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001842// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001843func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
1844 check := func(child, parent android.Module) bool {
1845 to, ok := child.(*Module)
1846 if !ok {
1847 // follow thru cc.Defaults, etc.
1848 return true
1849 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001850
Jooyung Hana70f0672019-01-18 15:20:43 +09001851 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1852 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001853 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001854
1855 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07001856 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09001857 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001858 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001859
Jooyung Han0302a842019-10-30 18:43:49 +09001860 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001861 return false
1862 }
1863
1864 var stringPath []string
1865 for _, m := range ctx.GetWalkPath() {
1866 stringPath = append(stringPath, m.Name())
1867 }
1868 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1869 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1870 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1871 return false
1872 }
1873 if module, ok := ctx.Module().(*Module); ok {
1874 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09001875 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001876 ctx.WalkDeps(check)
1877 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001878 }
1879 }
1880}
1881
Colin Crossc99deeb2016-04-11 15:06:20 -07001882// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001883func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001884 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001885
Ivan Lozano183a3212019-10-18 14:18:45 -07001886 directStaticDeps := []LinkableInterface{}
1887 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001888
Inseob Kim9516ee92019-05-09 10:56:13 +09001889 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
1890
Inseob Kim69378442019-06-03 19:10:47 +09001891 reexportExporter := func(exporter exportedFlagsProducer) {
1892 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
1893 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
1894 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
1895 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
1896 }
1897
Colin Crossd11fcda2017-10-23 17:59:01 -07001898 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001899 depName := ctx.OtherModuleName(dep)
1900 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001901
Ivan Lozano52767be2019-10-18 14:49:46 -07001902 ccDep, ok := dep.(LinkableInterface)
1903 if !ok {
1904
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001905 // handling for a few module types that aren't cc Module but that are also supported
1906 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001907 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001908 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001909 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1910 genRule.GeneratedSourceFiles()...)
1911 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001912 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001913 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001914 // Support exported headers from a generated_sources dependency
1915 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001916 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001917 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001918 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001919 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09001920 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09001921 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001922 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09001923 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
1924 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001925 // 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 +09001926 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001927
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001928 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001929 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001930 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001931 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001932 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001933 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001934 files := genRule.GeneratedSourceFiles()
1935 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001936 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001937 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001938 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 -07001939 }
1940 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001941 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001942 }
Colin Crossca860ac2016-01-04 14:34:37 -08001943 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001944 return
1945 }
1946
Colin Crossfe17f6f2019-03-28 19:30:56 -07001947 if depTag == android.ProtoPluginDepTag {
1948 return
1949 }
1950
Colin Crossd11fcda2017-10-23 17:59:01 -07001951 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001952 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1953 return
1954 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001955 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001956 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001957 return
1958 }
1959
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001960 // re-exporting flags
1961 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07001962 // reusing objects only make sense for cc.Modules.
1963 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001964 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07001965 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001966 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09001967 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08001968 return
1969 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001970 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001971
Jiyong Parke4bb9862019-02-01 00:31:10 +09001972 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07001973 // staticVariants are a cc.Module specific concept.
1974 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09001975 c.staticVariant = ccDep
1976 return
1977 }
1978 }
1979
Ivan Lozano183a3212019-10-18 14:18:45 -07001980 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
1981 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
1982 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001983 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07001984 if t, ok := depTag.(DependencyTag); ok {
1985 explicitlyVersioned = t.ExplicitlyVersioned
1986 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09001987 depTag = t
1988 }
1989
Ivan Lozano183a3212019-10-18 14:18:45 -07001990 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001991 depIsStatic := false
1992 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07001993 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09001994 depIsStatic = true
1995 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001996 if ccDep.CcLibrary() && !depIsStatic {
1997 depIsStubs := ccDep.BuildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001998 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001999 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002000 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002001
2002 var useThisDep bool
2003 if depIsStubs && explicitlyVersioned {
2004 // Always respect dependency to the versioned stubs (i.e. libX#10)
2005 useThisDep = true
2006 } else if !depHasStubs {
2007 // Use non-stub variant if that is the only choice
2008 // (i.e. depending on a lib without stubs.version property)
2009 useThisDep = true
2010 } else if c.IsForPlatform() {
2011 // If not building for APEX, use stubs only when it is from
2012 // an APEX (and not from platform)
2013 useThisDep = (depInPlatform != depIsStubs)
Ivan Lozano52767be2019-10-18 14:49:46 -07002014 if c.InRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09002015 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002016 // always link to non-stub variant
2017 useThisDep = !depIsStubs
2018 }
2019 } else {
2020 // If building for APEX, use stubs only when it is not from
2021 // the same APEX
2022 useThisDep = (depInSameApex != depIsStubs)
2023 }
2024
2025 if !useThisDep {
2026 return // stop processing this dep
2027 }
2028 }
2029
Ivan Lozano52767be2019-10-18 14:49:46 -07002030 // Exporting flags only makes sense for cc.Modules
2031 if _, ok := ccDep.(*Module); ok {
2032 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
2033 depPaths.IncludeDirs = append(depPaths.IncludeDirs, i.exportedDirs()...)
2034 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
2035 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedDeps()...)
2036 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002037
Ivan Lozano52767be2019-10-18 14:49:46 -07002038 if t.ReexportFlags {
2039 reexportExporter(i)
2040 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2041 // Re-exported shared library headers must be included as well since they can help us with type information
2042 // about template instantiations (instantiated from their headers).
2043 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2044 // scripts.
2045 c.sabi.Properties.ReexportedIncludes = append(
2046 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2047 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002048 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002049 }
Logan Chienf3511742017-10-31 18:04:35 +08002050 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002051 }
2052
Colin Cross26c34ed2016-09-30 17:10:16 -07002053 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002054 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002055
Ivan Lozano52767be2019-10-18 14:49:46 -07002056 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002057 depFile := android.OptionalPath{}
2058
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002059 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002060 case ndkStubDepTag, SharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002061 ptr = &depPaths.SharedLibs
2062 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002063 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002064 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002065
Jiyong Park64a44f22019-01-18 14:37:08 +09002066 case earlySharedDepTag:
2067 ptr = &depPaths.EarlySharedLibs
2068 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002069 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002070 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002071 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002072 ptr = &depPaths.LateSharedLibs
2073 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002074 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002075 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002076 ptr = nil
2077 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002078 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002079 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002080 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002081 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002082 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002083 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002084 return
2085 }
2086
Ivan Lozano52767be2019-10-18 14:49:46 -07002087 // Because the static library objects are included, this only makes sense
2088 // in the context of proper cc.Modules.
2089 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2090 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2091 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2092 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2093 for i := range missingDeps {
2094 missingDeps[i] += postfix
2095 }
2096 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002097 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002098 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2099 } else {
2100 ctx.ModuleErrorf(
2101 "non-cc.Modules cannot be included as whole static libraries.", depName)
2102 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002103 }
Colin Cross5950f382016-12-13 12:50:57 -08002104 case headerDepTag:
2105 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002106 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002107 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002108 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002109 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002110 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002111 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002112 case dynamicLinkerDepTag:
2113 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002114 }
2115
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002116 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002117 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002118 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002119 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002120 return
2121 }
2122
2123 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002124 // in static libraries act as if they were whole static libraries. The same goes for
2125 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002126 // This should only be done for cc.Modules
2127 if c, ok := ccDep.(*Module); ok {
2128 staticLib := c.linker.(libraryInterface)
2129 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2130 staticLib.objs().coverageFiles...)
2131 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2132 staticLib.objs().sAbiDumpFiles...)
2133 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002134 }
2135
Colin Cross26c34ed2016-09-30 17:10:16 -07002136 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002137 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002138 if !ctx.Config().AllowMissingDependencies() {
2139 ctx.ModuleErrorf("module %q missing output file", depName)
2140 } else {
2141 ctx.AddMissingDependencies([]string{depName})
2142 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002143 return
2144 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002145 *ptr = append(*ptr, linkFile.Path())
2146 }
2147
Colin Crossc99deeb2016-04-11 15:06:20 -07002148 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002149 dep := depFile
2150 if !dep.Valid() {
2151 dep = linkFile
2152 }
2153 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002154 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002155
Logan Chien43d34c32017-12-20 01:17:32 +08002156 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002157 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002158 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002159 libName = strings.TrimPrefix(libName, "prebuilt_")
Jooyung Han0302a842019-10-30 18:43:49 +09002160 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002161 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002162 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002163
Ivan Lozano52767be2019-10-18 14:49:46 -07002164 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002165 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2166 // core module instead.
2167 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002168 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002169 // The vendor module in Make will have been renamed to not conflict with the core
2170 // module, so update the dependency name here accordingly.
Inseob Kim64c43952019-08-26 16:52:35 +09002171 ret := libName + vendorSuffix
2172 vendorVersion := ctx.DeviceConfig().VndkVersion()
2173 if vendorVersion == "current" {
2174 vendorVersion = ctx.DeviceConfig().PlatformVndkVersion()
2175 }
2176 if c.Properties.VndkVersion != vendorVersion {
2177 ret += "." + c.Properties.VndkVersion
2178 }
2179 return ret
Jiyong Park374510b2018-03-19 18:23:01 +09002180 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002181 return libName + vendorPublicLibrarySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002182 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002183 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002184 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002185 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002186 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002187 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002188 }
Logan Chien43d34c32017-12-20 01:17:32 +08002189 }
2190
2191 // Export the shared libs to Make.
2192 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002193 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002194 if ccDep.CcLibrary() {
2195 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002196 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002197 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002198 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002199 c.Properties.ApexesProvidingSharedLibs = append(
2200 c.Properties.ApexesProvidingSharedLibs, an)
2201 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002202 }
2203 }
2204
Jiyong Park27b188b2017-07-18 13:23:39 +09002205 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002206 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002207 c.Properties.AndroidMkSharedLibs = append(
2208 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002209 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002210 c.Properties.AndroidMkSharedLibs = append(
2211 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002212 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002213 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002214 c.Properties.AndroidMkStaticLibs = append(
2215 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002216 case runtimeDepTag:
2217 c.Properties.AndroidMkRuntimeLibs = append(
2218 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002219 case wholeStaticDepTag:
2220 c.Properties.AndroidMkWholeStaticLibs = append(
2221 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002222 }
Colin Crossca860ac2016-01-04 14:34:37 -08002223 })
2224
Jeff Gaston294356f2017-09-27 17:05:30 -07002225 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002226 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002227
Colin Crossdd84e052017-05-17 13:44:16 -07002228 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002229 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002230 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2231 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002232 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Jiyong Park74955042019-10-22 20:19:51 +09002233 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2234 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002235 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002236 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002237
2238 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002239 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002240 }
Colin Crossdd84e052017-05-17 13:44:16 -07002241
Colin Crossca860ac2016-01-04 14:34:37 -08002242 return depPaths
2243}
2244
2245func (c *Module) InstallInData() bool {
2246 if c.installer == nil {
2247 return false
2248 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002249 return c.installer.inData()
2250}
2251
2252func (c *Module) InstallInSanitizerDir() bool {
2253 if c.installer == nil {
2254 return false
2255 }
2256 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002257 return true
2258 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002259 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002260}
2261
Jiyong Parkf9332f12018-02-01 00:54:12 +09002262func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002263 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002264}
2265
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002266func (c *Module) HostToolPath() android.OptionalPath {
2267 if c.installer == nil {
2268 return android.OptionalPath{}
2269 }
2270 return c.installer.hostToolPath()
2271}
2272
Nan Zhangd4e641b2017-07-12 12:55:28 -07002273func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2274 return c.outputFile
2275}
2276
Colin Cross41955e82019-05-29 14:40:35 -07002277func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2278 switch tag {
2279 case "":
2280 if c.outputFile.Valid() {
2281 return android.Paths{c.outputFile.Path()}, nil
2282 }
2283 return android.Paths{}, nil
2284 default:
2285 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002286 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002287}
2288
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002289func (c *Module) static() bool {
2290 if static, ok := c.linker.(interface {
2291 static() bool
2292 }); ok {
2293 return static.static()
2294 }
2295 return false
2296}
2297
Jiyong Park379de2f2018-12-19 02:47:14 +09002298func (c *Module) staticBinary() bool {
2299 if static, ok := c.linker.(interface {
2300 staticBinary() bool
2301 }); ok {
2302 return static.staticBinary()
2303 }
2304 return false
2305}
2306
Jiyong Park1d1119f2019-07-29 21:27:18 +09002307func (c *Module) header() bool {
2308 if h, ok := c.linker.(interface {
2309 header() bool
2310 }); ok {
2311 return h.header()
2312 }
2313 return false
2314}
2315
Jooyung Han38002912019-05-16 04:01:54 +09002316func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002317 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002318 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2319 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002320 return "native:vndk"
2321 }
Jooyung Han38002912019-05-16 04:01:54 +09002322 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002323 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002324 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002325 if Bool(c.VendorProperties.Vendor_available) {
2326 return "native:vndk"
2327 }
2328 return "native:vndk_private"
2329 }
2330 return "native:vendor"
Ivan Lozano52767be2019-10-18 14:49:46 -07002331 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002332 return "native:recovery"
2333 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2334 return "native:ndk:none:none"
2335 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2336 //family, link := getNdkStlFamilyAndLinkType(c)
2337 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002338 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002339 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002340 } else {
2341 return "native:platform"
2342 }
2343}
2344
Jiyong Park9d452992018-10-03 00:38:19 +09002345// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002346// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002347func (c *Module) IsInstallableToApex() bool {
2348 if shared, ok := c.linker.(interface {
2349 shared() bool
2350 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002351 // Stub libs and prebuilt libs in a versioned SDK are not
2352 // installable to APEX even though they are shared libs.
2353 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002354 } else if _, ok := c.linker.(testPerSrc); ok {
2355 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002356 }
2357 return false
2358}
2359
Jiyong Parka90ca002019-10-07 15:47:24 +09002360func (c *Module) AvailableFor(what string) bool {
2361 if linker, ok := c.linker.(interface {
2362 availableFor(string) bool
2363 }); ok {
2364 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2365 } else {
2366 return c.ApexModuleBase.AvailableFor(what)
2367 }
2368}
2369
Inseob Kim1f086e22019-05-09 13:29:15 +09002370func (c *Module) installable() bool {
2371 return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
2372}
2373
Jiyong Park3b1746a2019-01-29 11:15:04 +09002374func (c *Module) imageVariation() string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002375 if c.UseVndk() {
Inseob Kim64c43952019-08-26 16:52:35 +09002376 return vendorMode + "." + c.Properties.VndkVersion
Ivan Lozano52767be2019-10-18 14:49:46 -07002377 } else if c.InRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09002378 return recoveryMode
Jiyong Park3b1746a2019-01-29 11:15:04 +09002379 }
Inseob Kim64c43952019-08-26 16:52:35 +09002380 return coreMode
Jiyong Park3b1746a2019-01-29 11:15:04 +09002381}
2382
bralee3f49f4d2019-03-04 06:58:15 +08002383func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
Colin Cross41955e82019-05-29 14:40:35 -07002384 outputFiles, err := c.OutputFiles("")
2385 if err != nil {
2386 panic(err)
2387 }
2388 dpInfo.Srcs = append(dpInfo.Srcs, outputFiles.Strings()...)
bralee3f49f4d2019-03-04 06:58:15 +08002389}
2390
Logan Chien41eabe62019-04-10 13:33:58 +08002391func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2392 if c.linker != nil {
2393 if library, ok := c.linker.(*libraryDecorator); ok {
2394 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2395 }
2396 }
2397}
2398
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002399func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002400 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
2401 if cc, ok := dep.(*Module); ok && cc.IsStubs() && depTag.Shared {
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002402 // dynamic dep to a stubs lib crosses APEX boundary
2403 return false
2404 }
2405 }
2406 return true
2407}
2408
Colin Cross2ba19d92015-05-07 15:44:20 -07002409//
Colin Crosscfad1192015-11-02 16:43:11 -08002410// Defaults
2411//
Colin Crossca860ac2016-01-04 14:34:37 -08002412type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002413 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002414 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002415 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002416}
2417
Patrice Arrudac249c712019-03-19 17:00:29 -07002418// cc_defaults provides a set of properties that can be inherited by other cc
2419// modules. A module can use the properties from a cc_defaults using
2420// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2421// merged (when possible) by prepending the default module's values to the
2422// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002423func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002424 return DefaultsFactory()
2425}
2426
Colin Cross36242852017-06-23 15:06:31 -07002427func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002428 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002429
Colin Cross36242852017-06-23 15:06:31 -07002430 module.AddProperties(props...)
2431 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002432 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002433 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002434 &BaseCompilerProperties{},
2435 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002436 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002437 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002438 &StaticProperties{},
2439 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002440 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002441 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002442 &TestProperties{},
2443 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002444 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002445 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002446 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002447 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002448 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002449 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002450 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002451 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002452 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002453 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002454 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002455 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002456 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002457 )
Colin Crosscfad1192015-11-02 16:43:11 -08002458
Jooyung Hancc372c52019-09-25 15:18:44 +09002459 android.InitDefaultsModule(module)
Jiyong Park7916bfc2019-09-30 19:13:12 +09002460 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002461
2462 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002463}
2464
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002465const (
2466 // coreMode is the variant used for framework-private libraries, or
2467 // SDK libraries. (which framework-private libraries can use)
2468 coreMode = "core"
2469
Inseob Kim64c43952019-08-26 16:52:35 +09002470 // vendorMode is the variant prefix used for /vendor code that compiles
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002471 // against the VNDK.
2472 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09002473
2474 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002475)
2476
Jiyong Park6a43f042017-10-12 23:05:00 +09002477func squashVendorSrcs(m *Module) {
2478 if lib, ok := m.compiler.(*libraryDecorator); ok {
2479 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2480 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2481
2482 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2483 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2484 }
2485}
2486
Jiyong Parkf9332f12018-02-01 00:54:12 +09002487func squashRecoverySrcs(m *Module) {
2488 if lib, ok := m.compiler.(*libraryDecorator); ok {
2489 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2490 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2491
2492 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2493 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2494 }
2495}
2496
Jiyong Parkda6eb592018-12-19 17:12:36 +09002497func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002498 if mctx.Os() != android.Android {
2499 return
2500 }
2501
Jiyong Park7ed9de32018-10-15 22:25:07 +09002502 if g, ok := mctx.Module().(*genrule.Module); ok {
2503 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09002504 var coreVariantNeeded bool = false
2505 var vendorVariantNeeded bool = false
2506 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09002507 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09002508 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002509 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09002510 coreVariantNeeded = true
2511 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09002512 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09002513 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002514 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09002515 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002516 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002517 if Bool(props.Recovery_available) {
2518 recoveryVariantNeeded = true
2519 }
2520
Jiyong Park413cc742018-06-19 01:46:06 +09002521 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002522 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09002523 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09002524 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002525 recoveryVariantNeeded = false
2526 }
2527 }
2528
Jiyong Park3f736c92018-05-24 13:36:56 +09002529 var variants []string
2530 if coreVariantNeeded {
2531 variants = append(variants, coreMode)
2532 }
2533 if vendorVariantNeeded {
Inseob Kim64c43952019-08-26 16:52:35 +09002534 variants = append(variants, vendorMode+"."+mctx.DeviceConfig().PlatformVndkVersion())
2535 if vndkVersion := mctx.DeviceConfig().VndkVersion(); vndkVersion != "current" {
2536 variants = append(variants, vendorMode+"."+vndkVersion)
2537 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002538 }
2539 if recoveryVariantNeeded {
2540 variants = append(variants, recoveryMode)
2541 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002542 mod := mctx.CreateVariations(variants...)
2543 for i, v := range variants {
2544 if v == recoveryMode {
2545 m := mod[i].(*genrule.Module)
2546 m.Extra.(*GenruleExtraProperties).InRecovery = true
2547 }
2548 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002549 }
2550 }
2551
Ivan Lozano52767be2019-10-18 14:49:46 -07002552 //TODO When LinkableInterface supports VNDK, this should be mctx.Module().(LinkableInterface)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002553 m, ok := mctx.Module().(*Module)
2554 if !ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002555 if linkable, ok := mctx.Module().(LinkableInterface); ok {
2556 variations := []string{coreMode}
2557 if linkable.InRecovery() {
2558 variations = append(variations, recoveryMode)
2559 }
2560 mctx.CreateVariations(variations...)
2561 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002562 return
2563 }
2564
2565 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002566 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002567 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002568
2569 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002570 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002571 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002572 return
2573 }
Logan Chienf3511742017-10-31 18:04:35 +08002574
2575 if vndkdep := m.vndkdep; vndkdep != nil {
2576 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002577 if productSpecific {
2578 mctx.PropertyErrorf("product_specific",
2579 "product_specific must not be true when `vndk: {enabled: true}`")
2580 return
2581 }
Logan Chienf3511742017-10-31 18:04:35 +08002582 if vendorSpecific {
2583 if !vndkdep.isVndkExt() {
2584 mctx.PropertyErrorf("vndk",
2585 "must set `extends: \"...\"` to vndk extension")
2586 return
2587 }
2588 } else {
2589 if vndkdep.isVndkExt() {
2590 mctx.PropertyErrorf("vndk",
2591 "must set `vendor: true` to set `extends: %q`",
2592 m.getVndkExtendsModuleName())
2593 return
2594 }
2595 if m.VendorProperties.Vendor_available == nil {
2596 mctx.PropertyErrorf("vndk",
2597 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2598 return
2599 }
2600 }
2601 } else {
2602 if vndkdep.isVndkSp() {
2603 mctx.PropertyErrorf("vndk",
2604 "must set `enabled: true` to set `support_system_process: true`")
2605 return
2606 }
2607 if vndkdep.isVndkExt() {
2608 mctx.PropertyErrorf("vndk",
2609 "must set `enabled: true` to set `extends: %q`",
2610 m.getVndkExtendsModuleName())
2611 return
2612 }
Justin Yun8effde42017-06-23 19:24:43 +09002613 }
2614 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002615
Jiyong Parkf9332f12018-02-01 00:54:12 +09002616 var coreVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002617 var recoveryVariantNeeded bool = false
2618
Inseob Kim64c43952019-08-26 16:52:35 +09002619 var vendorVariants []string
2620
2621 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
2622 deviceVndkVersion := mctx.DeviceConfig().VndkVersion()
2623 if deviceVndkVersion == "current" {
2624 deviceVndkVersion = platformVndkVersion
2625 }
2626
Justin Yun71549282017-11-17 12:10:28 +09002627 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002628 // If the device isn't compiling against the VNDK, we always
2629 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002630 coreVariantNeeded = true
Justin Yun1282f422019-09-09 14:42:44 +09002631 } else if m.Target().NativeBridge == android.NativeBridgeEnabled {
2632 // Skip creating vendor variants for natvie bridge modules
2633 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002634 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2635 // LL-NDK stubs only exist in the vendor variant, since the
2636 // real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002637 vendorVariants = append(vendorVariants,
2638 platformVndkVersion,
2639 deviceVndkVersion,
2640 )
Jiyong Park2a454122017-10-19 15:59:33 +09002641 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2642 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002643 vendorVariants = append(vendorVariants,
2644 platformVndkVersion,
2645 deviceVndkVersion,
2646 )
2647 } else if lib, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002648 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2649 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kim64c43952019-08-26 16:52:35 +09002650 vendorVariants = append(vendorVariants, lib.version())
Ivan Lozano52767be2019-10-18 14:49:46 -07002651 } else if m.HasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002652 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002653 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002654 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002655 vendorVariants = append(vendorVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09002656 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
2657 // code is PLATFORM_VNDK_VERSION.
2658 // On the other hand, vendor_available modules which are not VNDK should
2659 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
2660 if !m.IsVndk() {
Inseob Kim64c43952019-08-26 16:52:35 +09002661 vendorVariants = append(vendorVariants, deviceVndkVersion)
2662 }
Logan Chienf3511742017-10-31 18:04:35 +08002663 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002664 // This will be available in /vendor (or /odm) only
Inseob Kim64c43952019-08-26 16:52:35 +09002665 vendorVariants = append(vendorVariants, deviceVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002666 } else {
2667 // This is either in /system (or similar: /data), or is a
2668 // modules built with the NDK. Modules built with the NDK
2669 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002670 coreVariantNeeded = true
2671 }
2672
2673 if Bool(m.Properties.Recovery_available) {
2674 recoveryVariantNeeded = true
2675 }
2676
2677 if m.ModuleBase.InstallInRecovery() {
2678 recoveryVariantNeeded = true
2679 coreVariantNeeded = false
2680 }
2681
Jiyong Park413cc742018-06-19 01:46:06 +09002682 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002683 primaryArch := mctx.Config().DevicePrimaryArchType()
2684 moduleArch := m.Target().Arch.ArchType
2685 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002686 recoveryVariantNeeded = false
2687 }
2688 }
2689
Jiyong Parkf9332f12018-02-01 00:54:12 +09002690 var variants []string
2691 if coreVariantNeeded {
2692 variants = append(variants, coreMode)
2693 }
Inseob Kim64c43952019-08-26 16:52:35 +09002694 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
2695 variants = append(variants, vendorMode+"."+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09002696 }
2697 if recoveryVariantNeeded {
2698 variants = append(variants, recoveryMode)
2699 }
2700 mod := mctx.CreateVariations(variants...)
2701 for i, v := range variants {
Inseob Kim64c43952019-08-26 16:52:35 +09002702 if strings.HasPrefix(v, vendorMode+".") {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002703 m := mod[i].(*Module)
Inseob Kim64c43952019-08-26 16:52:35 +09002704 m.Properties.VndkVersion = strings.TrimPrefix(v, vendorMode+".")
Jiyong Parkf9332f12018-02-01 00:54:12 +09002705 squashVendorSrcs(m)
2706 } else if v == recoveryMode {
2707 m := mod[i].(*Module)
2708 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002709 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002710 squashRecoverySrcs(m)
2711 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002712 }
2713}
2714
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002715func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002716 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002717 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2718 }
Colin Cross6510f912017-11-29 00:27:14 -08002719 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002720}
2721
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002722func kytheExtractAllFactory() android.Singleton {
2723 return &kytheExtractAllSingleton{}
2724}
2725
2726type kytheExtractAllSingleton struct {
2727}
2728
2729func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2730 var xrefTargets android.Paths
2731 ctx.VisitAllModules(func(module android.Module) {
2732 if ccModule, ok := module.(xref); ok {
2733 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
2734 }
2735 })
2736 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
2737 if len(xrefTargets) > 0 {
2738 ctx.Build(pctx, android.BuildParams{
2739 Rule: blueprint.Phony,
2740 Output: android.PathForPhony(ctx, "xref_cxx"),
2741 Inputs: xrefTargets,
2742 //Default: true,
2743 })
2744 }
2745}
2746
Colin Cross06a931b2015-10-28 17:23:31 -07002747var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002748var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002749var BoolPtr = proptools.BoolPtr
2750var String = proptools.String
2751var StringPtr = proptools.StringPtr