blob: f306a007e65d082a1f480c9be53742ad9a96f333 [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -07001// Copyright 2015 Google Inc. All rights reserved.
Colin Cross3f40fa42015-01-30 17:27:36 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17// This file contains the module types for compiling C/C++ for Android, and converts the properties
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
Colin Cross41955e82019-05-29 14:40:35 -070022 "fmt"
Logan Chien41eabe62019-04-10 13:33:58 +080023 "io"
Dan Albert9e10cd42016-08-03 14:12:14 -070024 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080025 "strings"
26
Colin Cross97ba0732015-03-23 17:50:24 -070027 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070028 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070029
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070031 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070032 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080033)
34
Colin Cross463a90e2015-06-17 14:20:06 -070035func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070036 android.RegisterModuleType("cc_defaults", defaultsFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070037
Colin Cross1e676be2016-10-12 14:38:15 -070038 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Inseob Kim64c43952019-08-26 16:52:35 +090039 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Cross7228ecd2019-11-18 16:00:16 -080040 ctx.BottomUp("image", android.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 Cross4af21ed2019-11-04 09:37:55 -0800143// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
144// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
145// command line so they can be overridden by the local module flags).
146type LocalOrGlobalFlags struct {
147 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700148 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800149 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700150 CFlags []string // Flags that apply to C and C++ source files
151 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
152 ConlyFlags []string // Flags that apply to C source files
153 CppFlags []string // Flags that apply to C++ source files
154 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700155 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800156}
157
158type Flags struct {
159 Local LocalOrGlobalFlags
160 Global LocalOrGlobalFlags
161
162 aidlFlags []string // Flags that apply to aidl source files
163 rsFlags []string // Flags that apply to renderscript source files
164 libFlags []string // Flags to add libraries early to the link order
165 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
166 TidyFlags []string // Flags that apply to clang-tidy
167 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700168
Colin Crossc3199482017-03-30 15:03:04 -0700169 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800170 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700171 SystemIncludeFlags []string
172
Colin Crossb98c8b02016-07-29 13:44:28 -0700173 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700174 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800175 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800176 SAbiDump bool
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800177 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800178
179 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800180 DynamicLinker string
181
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700182 CFlagsDeps android.Paths // Files depended on by compiler flags
183 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800184
Dan Willemsen98ab3112019-08-27 21:20:40 -0700185 AssemblerWithCpp bool
186 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800187
Colin Cross19878da2019-03-28 14:45:07 -0700188 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700189 protoC bool // Whether to use C instead of C++
190 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700191
192 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700193}
194
Colin Crossca860ac2016-01-04 14:34:37 -0800195// Properties used to compile all C or C++ modules
196type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700197 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800198 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700199
200 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800201 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700202
Jiyong Parkde866cb2018-12-07 23:08:36 +0900203 AndroidMkSharedLibs []string `blueprint:"mutated"`
204 AndroidMkStaticLibs []string `blueprint:"mutated"`
205 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
206 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
207 HideFromMake bool `blueprint:"mutated"`
208 PreventInstall bool `blueprint:"mutated"`
209 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700210
Inseob Kim64c43952019-08-26 16:52:35 +0900211 VndkVersion string `blueprint:"mutated"`
212 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800213
214 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
215 // file
216 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900217
218 // Make this module available when building for recovery
219 Recovery_available *bool
220
Colin Cross7228ecd2019-11-18 16:00:16 -0800221 // Set by ImageMutator
222 CoreVariantNeeded bool `blueprint:"mutated"`
223 RecoveryVariantNeeded bool `blueprint:"mutated"`
224 VendorVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900225
226 // Allows this module to use non-APEX version of libraries. Useful
227 // for building binaries that are started before APEXes are activated.
228 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900229
230 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
231 // see soong/cc/config/vndk.go
232 MustUseVendorVariant bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700233}
234
235type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900236 // whether this module should be allowed to be directly depended by other
237 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
238 // If set to true, two variants will be built separately, one like
239 // normal, and the other limited to the set of libraries and headers
240 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700241 //
242 // The vendor variant may be used with a different (newer) /system,
243 // so it shouldn't have any unversioned runtime dependencies, or
244 // make assumptions about the system that may not be true in the
245 // future.
246 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900247 // If set to false, this module becomes inaccessible from /vendor modules.
248 //
249 // Default value is true when vndk: {enabled: true} or vendor: true.
250 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700251 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
252 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900253
254 // whether this module is capable of being loaded with other instance
255 // (possibly an older version) of the same module in the same process.
256 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
257 // can be double loaded in a vendor process if the library is also a
258 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
259 // explicitly marked as `double_loadable: true` by the owner, or the dependency
260 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
261 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800262}
263
Colin Crossca860ac2016-01-04 14:34:37 -0800264type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800265 static() bool
266 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900267 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700268 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700269 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800270 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700271 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800272 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900273 isLlndk(config android.Config) bool
274 isLlndkPublic(config android.Config) bool
275 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900276 isVndk() bool
277 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800278 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900279 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800280 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700281 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700282 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800283 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800284 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800285 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800286 useClangLld(actx ModuleContext) bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900287 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900288 hasStubsVariants() bool
289 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900290 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800291 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700292 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800293}
294
295type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700296 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800297 ModuleContextIntf
298}
299
300type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700301 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800302 ModuleContextIntf
303}
304
Colin Cross37047f12016-12-13 17:06:13 -0800305type DepsContext interface {
306 android.BottomUpMutatorContext
307 ModuleContextIntf
308}
309
Colin Crossca860ac2016-01-04 14:34:37 -0800310type feature interface {
311 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800312 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800313 flags(ctx ModuleContext, flags Flags) Flags
314 props() []interface{}
315}
316
317type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700318 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800319 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800320 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700321 compilerProps() []interface{}
322
Colin Cross76fada02016-07-27 10:31:13 -0700323 appendCflags([]string)
324 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700325 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800326}
327
328type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700329 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800330 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700331 linkerFlags(ctx ModuleContext, flags Flags) Flags
332 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800333 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700334
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700335 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700336 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900337 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700338
339 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900340 coverageOutputFilePath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800341}
342
343type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700344 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700345 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800346 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700347 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700348 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900349 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800350}
351
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800352type xref interface {
353 XrefCcFiles() android.Paths
354}
355
Colin Crossc99deeb2016-04-11 15:06:20 -0700356var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700357 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
358 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
359 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
360 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
361 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
362 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
363 headerDepTag = DependencyTag{Name: "header", Library: true}
364 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
365 genSourceDepTag = DependencyTag{Name: "gen source"}
366 genHeaderDepTag = DependencyTag{Name: "gen header"}
367 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
368 objDepTag = DependencyTag{Name: "obj"}
369 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
370 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
371 reuseObjTag = DependencyTag{Name: "reuse objects"}
372 staticVariantTag = DependencyTag{Name: "static variant"}
373 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
374 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
375 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
376 runtimeDepTag = DependencyTag{Name: "runtime lib"}
377 coverageDepTag = DependencyTag{Name: "coverage"}
378 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700379)
380
Roland Levillainf89cd092019-07-29 16:22:59 +0100381func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700382 ccDepTag, ok := depTag.(DependencyTag)
383 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100384}
385
386func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700387 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100388 return ok && ccDepTag == runtimeDepTag
389}
390
391func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700392 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100393 return ok && ccDepTag == testPerSrcDepTag
394}
395
Colin Crossca860ac2016-01-04 14:34:37 -0800396// Module contains the properties and members used by all C/C++ module types, and implements
397// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
398// to construct the output file. Behavior can be customized with a Customizer interface
399type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700400 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700401 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900402 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900403 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700404
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700405 Properties BaseProperties
406 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700407
Colin Crossca860ac2016-01-04 14:34:37 -0800408 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700409 hod android.HostOrDeviceSupported
410 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700411
Colin Crossca860ac2016-01-04 14:34:37 -0800412 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700413 features []feature
414 compiler compiler
415 linker linker
416 installer installer
417 stl *stl
418 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800419 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800420 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900421 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700422 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700423 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800424 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800425
426 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700427
Colin Cross635c3b02016-05-18 15:37:25 -0700428 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800429
Colin Crossb98c8b02016-07-29 13:44:28 -0700430 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700431
432 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800433
434 // Flags used to compile this module
435 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700436
437 // 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 -0800438 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700439 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800440 depsInLinkOrder android.Paths
441
442 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700443 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900444
445 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800446 // Kythe (source file indexer) paths for this compilation module
447 kytheFiles android.Paths
Colin Crossc472d572015-03-17 15:06:21 -0700448}
449
Ivan Lozano52767be2019-10-18 14:49:46 -0700450func (c *Module) Toc() android.OptionalPath {
451 if c.linker != nil {
452 if library, ok := c.linker.(libraryInterface); ok {
453 return library.toc()
454 }
455 }
456 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
457}
458
459func (c *Module) ApiLevel() string {
460 if c.linker != nil {
461 if stub, ok := c.linker.(*stubDecorator); ok {
462 return stub.properties.ApiLevel
463 }
464 }
465 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
466}
467
468func (c *Module) Static() bool {
469 if c.linker != nil {
470 if library, ok := c.linker.(libraryInterface); ok {
471 return library.static()
472 }
473 }
474 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
475}
476
477func (c *Module) Shared() bool {
478 if c.linker != nil {
479 if library, ok := c.linker.(libraryInterface); ok {
480 return library.shared()
481 }
482 }
483 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
484}
485
486func (c *Module) SelectedStl() string {
487 return c.stl.Properties.SelectedStl
488}
489
490func (c *Module) ToolchainLibrary() bool {
491 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
492 return true
493 }
494 return false
495}
496
497func (c *Module) NdkPrebuiltStl() bool {
498 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
499 return true
500 }
501 return false
502}
503
504func (c *Module) StubDecorator() bool {
505 if _, ok := c.linker.(*stubDecorator); ok {
506 return true
507 }
508 return false
509}
510
511func (c *Module) SdkVersion() string {
512 return String(c.Properties.Sdk_version)
513}
514
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800515func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700516 if c.linker != nil {
517 if library, ok := c.linker.(exportedFlagsProducer); ok {
518 return library.exportedDirs()
519 }
520 }
521 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
522}
523
524func (c *Module) HasStaticVariant() bool {
525 if c.staticVariant != nil {
526 return true
527 }
528 return false
529}
530
531func (c *Module) GetStaticVariant() LinkableInterface {
532 return c.staticVariant
533}
534
535func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
536 c.depsInLinkOrder = depsInLinkOrder
537}
538
539func (c *Module) GetDepsInLinkOrder() []android.Path {
540 return c.depsInLinkOrder
541}
542
543func (c *Module) StubsVersions() []string {
544 if c.linker != nil {
545 if library, ok := c.linker.(*libraryDecorator); ok {
546 return library.Properties.Stubs.Versions
547 }
548 }
549 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
550}
551
552func (c *Module) CcLibrary() bool {
553 if c.linker != nil {
554 if _, ok := c.linker.(*libraryDecorator); ok {
555 return true
556 }
557 }
558 return false
559}
560
561func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700562 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700563 return true
564 }
565 return false
566}
567
Ivan Lozano2b262972019-11-21 12:30:50 -0800568func (c *Module) NonCcVariants() bool {
569 return false
570}
571
Ivan Lozano183a3212019-10-18 14:18:45 -0700572func (c *Module) SetBuildStubs() {
573 if c.linker != nil {
574 if library, ok := c.linker.(*libraryDecorator); ok {
575 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700576 c.Properties.HideFromMake = true
577 c.sanitize = nil
578 c.stl = nil
579 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700580 return
581 }
582 }
583 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
584}
585
Ivan Lozano52767be2019-10-18 14:49:46 -0700586func (c *Module) BuildStubs() bool {
587 if c.linker != nil {
588 if library, ok := c.linker.(*libraryDecorator); ok {
589 return library.buildStubs()
590 }
591 }
592 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
593}
594
Ivan Lozano183a3212019-10-18 14:18:45 -0700595func (c *Module) SetStubsVersions(version string) {
596 if c.linker != nil {
597 if library, ok := c.linker.(*libraryDecorator); ok {
598 library.MutatedProperties.StubsVersion = version
599 return
600 }
601 }
602 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
603}
604
605func (c *Module) SetStatic() {
606 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700607 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700608 library.setStatic()
609 return
610 }
611 }
612 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
613}
614
615func (c *Module) SetShared() {
616 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700617 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700618 library.setShared()
619 return
620 }
621 }
622 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
623}
624
625func (c *Module) BuildStaticVariant() bool {
626 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700627 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700628 return library.buildStatic()
629 }
630 }
631 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
632}
633
634func (c *Module) BuildSharedVariant() bool {
635 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700636 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700637 return library.buildShared()
638 }
639 }
640 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
641}
642
643func (c *Module) Module() android.Module {
644 return c
645}
646
Jiyong Parkc20eee32018-09-05 22:36:17 +0900647func (c *Module) OutputFile() android.OptionalPath {
648 return c.outputFile
649}
650
Ivan Lozano183a3212019-10-18 14:18:45 -0700651var _ LinkableInterface = (*Module)(nil)
652
Jiyong Park719b4462019-01-13 00:39:51 +0900653func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900654 if c.linker != nil {
655 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900656 }
657 return nil
658}
659
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900660func (c *Module) CoverageOutputFile() android.OptionalPath {
661 if c.linker != nil {
662 return c.linker.coverageOutputFilePath()
663 }
664 return android.OptionalPath{}
665}
666
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900667func (c *Module) RelativeInstallPath() string {
668 if c.installer != nil {
669 return c.installer.relativeInstallPath()
670 }
671 return ""
672}
673
Jooyung Han344d5432019-08-23 11:17:39 +0900674func (c *Module) VndkVersion() string {
675 return c.vndkVersion()
676}
677
Colin Cross36242852017-06-23 15:06:31 -0700678func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700679 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800680 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700681 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800682 }
683 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700684 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800685 }
686 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700687 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800688 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700689 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700690 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700691 }
Colin Cross16b23492016-01-06 14:41:07 -0800692 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700693 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800694 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800695 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700696 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800697 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800698 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700699 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800700 }
Justin Yun8effde42017-06-23 19:24:43 +0900701 if c.vndkdep != nil {
702 c.AddProperties(c.vndkdep.props()...)
703 }
Stephen Craneba090d12017-05-09 15:44:35 -0700704 if c.lto != nil {
705 c.AddProperties(c.lto.props()...)
706 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700707 if c.pgo != nil {
708 c.AddProperties(c.pgo.props()...)
709 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800710 if c.xom != nil {
711 c.AddProperties(c.xom.props()...)
712 }
Colin Crossca860ac2016-01-04 14:34:37 -0800713 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700714 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800715 }
Colin Crossc472d572015-03-17 15:06:21 -0700716
Colin Crossa9d8bee2018-10-02 13:59:46 -0700717 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
718 switch class {
719 case android.Device:
720 return ctx.Config().DevicePrefer32BitExecutables()
721 case android.HostCross:
722 // Windows builds always prefer 32-bit
723 return true
724 default:
725 return false
726 }
727 })
Colin Cross36242852017-06-23 15:06:31 -0700728 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900729 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900730 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900731 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900732
Colin Cross36242852017-06-23 15:06:31 -0700733 return c
Colin Crossc472d572015-03-17 15:06:21 -0700734}
735
Colin Crossb916a382016-07-29 17:28:03 -0700736// Returns true for dependency roots (binaries)
737// TODO(ccross): also handle dlopenable libraries
738func (c *Module) isDependencyRoot() bool {
739 if root, ok := c.linker.(interface {
740 isDependencyRoot() bool
741 }); ok {
742 return root.isDependencyRoot()
743 }
744 return false
745}
746
Ivan Lozano52767be2019-10-18 14:49:46 -0700747func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900748 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700749}
750
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800751func (c *Module) isCoverageVariant() bool {
752 return c.coverage.Properties.IsCoverageVariant
753}
754
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800755func (c *Module) isNdk() bool {
756 return inList(c.Name(), ndkMigratedLibs)
757}
758
Inseob Kim9516ee92019-05-09 10:56:13 +0900759func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800760 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900761 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800762}
763
Inseob Kim9516ee92019-05-09 10:56:13 +0900764func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800765 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900766 name := c.BaseModuleName()
767 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800768}
769
Inseob Kim9516ee92019-05-09 10:56:13 +0900770func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800771 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900772 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800773}
774
Ivan Lozano52767be2019-10-18 14:49:46 -0700775func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800776 if vndkdep := c.vndkdep; vndkdep != nil {
777 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900778 }
779 return false
780}
781
Jooyung Han76106d92019-05-20 18:49:10 +0900782func (c *Module) vndkVersion() string {
Inseob Kim64c43952019-08-26 16:52:35 +0900783 return c.Properties.VndkVersion
Jooyung Han76106d92019-05-20 18:49:10 +0900784}
785
Yi Kong7e53c572018-02-14 18:16:12 +0800786func (c *Module) isPgoCompile() bool {
787 if pgo := c.pgo; pgo != nil {
788 return pgo.Properties.PgoCompile
789 }
790 return false
791}
792
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800793func (c *Module) isNDKStubLibrary() bool {
794 if _, ok := c.compiler.(*stubDecorator); ok {
795 return true
796 }
797 return false
798}
799
Logan Chienf3511742017-10-31 18:04:35 +0800800func (c *Module) isVndkSp() bool {
801 if vndkdep := c.vndkdep; vndkdep != nil {
802 return vndkdep.isVndkSp()
803 }
804 return false
805}
806
807func (c *Module) isVndkExt() bool {
808 if vndkdep := c.vndkdep; vndkdep != nil {
809 return vndkdep.isVndkExt()
810 }
811 return false
812}
813
Ivan Lozano52767be2019-10-18 14:49:46 -0700814func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900815 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800816}
817
Logan Chienf3511742017-10-31 18:04:35 +0800818func (c *Module) getVndkExtendsModuleName() string {
819 if vndkdep := c.vndkdep; vndkdep != nil {
820 return vndkdep.getVndkExtendsModuleName()
821 }
822 return ""
823}
824
Jiyong Park82e2bf32017-08-16 14:05:54 +0900825// Returns true only when this module is configured to have core and vendor
826// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700827func (c *Module) HasVendorVariant() bool {
828 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900829}
830
Ivan Lozano52767be2019-10-18 14:49:46 -0700831func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800832 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900833}
834
Ivan Lozano52767be2019-10-18 14:49:46 -0700835func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900836 return c.ModuleBase.InstallInRecovery()
837}
838
Jiyong Park25fc6a92018-11-18 18:02:45 +0900839func (c *Module) IsStubs() bool {
840 if library, ok := c.linker.(*libraryDecorator); ok {
841 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900842 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
843 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900844 }
845 return false
846}
847
848func (c *Module) HasStubsVariants() bool {
849 if library, ok := c.linker.(*libraryDecorator); ok {
850 return len(library.Properties.Stubs.Versions) > 0
851 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700852 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
853 return len(library.Properties.Stubs.Versions) > 0
854 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900855 return false
856}
857
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900858func (c *Module) bootstrap() bool {
859 return Bool(c.Properties.Bootstrap)
860}
861
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700862func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700863 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
864 if c.Target().NativeBridge == android.NativeBridgeEnabled {
865 return false
866 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700867 return c.linker != nil && c.linker.nativeCoverage()
868}
869
Jiyong Park73c54ee2019-10-22 20:31:18 +0900870func (c *Module) ExportedIncludeDirs() android.Paths {
871 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
872 return flagsProducer.exportedDirs()
873 }
Jiyong Park232e7852019-11-04 12:23:40 +0900874 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900875}
876
877func (c *Module) ExportedSystemIncludeDirs() android.Paths {
878 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
879 return flagsProducer.exportedSystemDirs()
880 }
Jiyong Park232e7852019-11-04 12:23:40 +0900881 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900882}
883
884func (c *Module) ExportedFlags() []string {
885 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
886 return flagsProducer.exportedFlags()
887 }
Jiyong Park232e7852019-11-04 12:23:40 +0900888 return nil
889}
890
891func (c *Module) ExportedDeps() android.Paths {
892 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
893 return flagsProducer.exportedDeps()
894 }
895 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900896}
897
Jiyong Parkf1194352019-02-25 11:05:47 +0900898func isBionic(name string) bool {
899 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +0000900 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +0900901 return true
902 }
903 return false
904}
905
Martin Stjernholm279de572019-09-10 23:18:20 +0100906func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700907 if name == "libclang_rt.hwasan-aarch64-android" {
908 return inList("hwaddress", config.SanitizeDevice())
909 }
910 return isBionic(name)
911}
912
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800913func (c *Module) XrefCcFiles() android.Paths {
914 return c.kytheFiles
915}
916
Colin Crossca860ac2016-01-04 14:34:37 -0800917type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700918 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800919 moduleContextImpl
920}
921
Colin Cross37047f12016-12-13 17:06:13 -0800922type depsContext struct {
923 android.BottomUpMutatorContext
924 moduleContextImpl
925}
926
Colin Crossca860ac2016-01-04 14:34:37 -0800927type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700928 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800929 moduleContextImpl
930}
931
Jiyong Park2db76922017-11-08 16:03:48 +0900932func (ctx *moduleContext) SocSpecific() bool {
933 return ctx.ModuleContext.SocSpecific() ||
Ivan Lozano52767be2019-10-18 14:49:46 -0700934 (ctx.mod.HasVendorVariant() && ctx.mod.UseVndk() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700935}
936
Colin Crossca860ac2016-01-04 14:34:37 -0800937type moduleContextImpl struct {
938 mod *Module
939 ctx BaseModuleContext
940}
941
Colin Crossb98c8b02016-07-29 13:44:28 -0700942func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800943 return ctx.mod.toolchain(ctx.ctx)
944}
945
946func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000947 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800948}
949
950func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900951 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800952}
953
Jiyong Park1d1119f2019-07-29 21:27:18 +0900954func (ctx *moduleContextImpl) header() bool {
955 return ctx.mod.header()
956}
957
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700958func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800959 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800960 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700961 }
962 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800963}
964
965func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700966 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700967 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900968 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700969 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900970 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
971 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
972 return "current"
973 }
974 return platform_vndk_ver
975 }
976 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800977 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900978 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700979 }
980 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800981}
982
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700983func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700984 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700985}
Justin Yun8effde42017-06-23 19:24:43 +0900986
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800987func (ctx *moduleContextImpl) isNdk() bool {
988 return ctx.mod.isNdk()
989}
990
Inseob Kim9516ee92019-05-09 10:56:13 +0900991func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
992 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800993}
994
Inseob Kim9516ee92019-05-09 10:56:13 +0900995func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
996 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800997}
998
Inseob Kim9516ee92019-05-09 10:56:13 +0900999func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1000 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001001}
1002
Logan Chienf3511742017-10-31 18:04:35 +08001003func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001004 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001005}
1006
Yi Kong7e53c572018-02-14 18:16:12 +08001007func (ctx *moduleContextImpl) isPgoCompile() bool {
1008 return ctx.mod.isPgoCompile()
1009}
1010
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001011func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1012 return ctx.mod.isNDKStubLibrary()
1013}
1014
Justin Yun8effde42017-06-23 19:24:43 +09001015func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001016 return ctx.mod.isVndkSp()
1017}
1018
1019func (ctx *moduleContextImpl) isVndkExt() bool {
1020 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001021}
1022
Vic Yangefd249e2018-11-12 20:19:56 -08001023func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001024 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001025}
1026
Jiyong Parkf9332f12018-02-01 00:54:12 +09001027func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001028 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001029}
1030
Logan Chien2f2b8902018-07-10 15:01:19 +08001031// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001032func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001033 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1034 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001035 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001036
1037 if ctx.ctx.Fuchsia() {
1038 return false
1039 }
1040
Logan Chien2f2b8902018-07-10 15:01:19 +08001041 if sanitize := ctx.mod.sanitize; sanitize != nil {
1042 if !sanitize.isVariantOnProductionDevice() {
1043 return false
1044 }
1045 }
1046 if !ctx.ctx.Device() {
1047 // Host modules do not need ABI dumps.
1048 return false
1049 }
Logan Chienfa478c02018-12-28 16:25:39 +08001050 if !ctx.mod.IsForPlatform() {
1051 // APEX variants do not need ABI dumps.
1052 return false
1053 }
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001054 if ctx.isStubs() {
1055 // Stubs do not need ABI dumps.
1056 return false
1057 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001058 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001059}
1060
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001061func (ctx *moduleContextImpl) selectedStl() string {
1062 if stl := ctx.mod.stl; stl != nil {
1063 return stl.Properties.SelectedStl
1064 }
1065 return ""
1066}
1067
Ivan Lozanobd721262018-11-27 14:33:03 -08001068func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1069 return ctx.mod.linker.useClangLld(actx)
1070}
1071
Colin Crossce75d2c2016-10-06 16:12:58 -07001072func (ctx *moduleContextImpl) baseModuleName() string {
1073 return ctx.mod.ModuleBase.BaseModuleName()
1074}
1075
Logan Chienf3511742017-10-31 18:04:35 +08001076func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1077 return ctx.mod.getVndkExtendsModuleName()
1078}
1079
Jiyong Park58e364a2019-01-19 19:24:06 +09001080func (ctx *moduleContextImpl) apexName() string {
1081 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001082}
1083
Jiyong Parkb0788572018-12-20 22:10:17 +09001084func (ctx *moduleContextImpl) hasStubsVariants() bool {
1085 return ctx.mod.HasStubsVariants()
1086}
1087
1088func (ctx *moduleContextImpl) isStubs() bool {
1089 return ctx.mod.IsStubs()
1090}
1091
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001092func (ctx *moduleContextImpl) bootstrap() bool {
1093 return ctx.mod.bootstrap()
1094}
1095
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001096func (ctx *moduleContextImpl) nativeCoverage() bool {
1097 return ctx.mod.nativeCoverage()
1098}
1099
Colin Cross635c3b02016-05-18 15:37:25 -07001100func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001101 return &Module{
1102 hod: hod,
1103 multilib: multilib,
1104 }
1105}
1106
Colin Cross635c3b02016-05-18 15:37:25 -07001107func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001108 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001109 module.features = []feature{
1110 &tidyFeature{},
1111 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001112 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001113 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001114 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001115 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001116 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001117 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001118 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -08001119 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -08001120 return module
1121}
1122
Colin Crossce75d2c2016-10-06 16:12:58 -07001123func (c *Module) Prebuilt() *android.Prebuilt {
1124 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1125 return p.prebuilt()
1126 }
1127 return nil
1128}
1129
1130func (c *Module) Name() string {
1131 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001132 if p, ok := c.linker.(interface {
1133 Name(string) string
1134 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001135 name = p.Name(name)
1136 }
1137 return name
1138}
1139
Alex Light3d673592019-01-18 14:37:31 -08001140func (c *Module) Symlinks() []string {
1141 if p, ok := c.installer.(interface {
1142 symlinkList() []string
1143 }); ok {
1144 return p.symlinkList()
1145 }
1146 return nil
1147}
1148
Jeff Gaston294356f2017-09-27 17:05:30 -07001149// orderDeps reorders dependencies into a list such that if module A depends on B, then
1150// A will precede B in the resultant list.
1151// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001152// Note that directSharedDeps should be the analogous static library for each shared lib dep
1153func 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 -07001154 // If A depends on B, then
1155 // Every list containing A will also contain B later in the list
1156 // So, after concatenating all lists, the final instance of B will have come from the same
1157 // original list as the final instance of A
1158 // So, the final instance of B will be later in the concatenation than the final A
1159 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1160 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001161 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001162 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001163 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1164 }
1165 for _, dep := range directSharedDeps {
1166 orderedAllDeps = append(orderedAllDeps, dep)
1167 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001168 }
1169
Colin Crossb6715442017-10-24 11:13:31 -07001170 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001171
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001172 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001173 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001174 // resultant list to only what the caller has chosen to include in directStaticDeps
1175 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001176
1177 return orderedAllDeps, orderedDeclaredDeps
1178}
1179
Ivan Lozano183a3212019-10-18 14:18:45 -07001180func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001181 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001182 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001183 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1184 staticDepFiles := []android.Path{}
1185 for _, dep := range staticDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001186 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1187 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
Jeff Gaston294356f2017-09-27 17:05:30 -07001188 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001189 sharedDepFiles := []android.Path{}
1190 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001191 if sharedDep.HasStaticVariant() {
1192 staticAnalogue := sharedDep.GetStaticVariant()
1193 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1194 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001195 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001196 }
1197
1198 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001199 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1200 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001201
1202 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001203}
1204
Roland Levillainf89cd092019-07-29 16:22:59 +01001205func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1206 test, ok := c.linker.(testPerSrc)
1207 return ok && test.isAllTestsVariation()
1208}
1209
Colin Cross635c3b02016-05-18 15:37:25 -07001210func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001211 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001212 //
1213 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1214 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1215 // module and return early, as this module does not produce an output file per se.
1216 if c.IsTestPerSrcAllTestsVariation() {
1217 c.outputFile = android.OptionalPath{}
1218 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001219 }
1220
Jooyung Han38002912019-05-16 04:01:54 +09001221 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001222
Inseob Kim64c43952019-08-26 16:52:35 +09001223 c.Properties.SubName = ""
1224
1225 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1226 c.Properties.SubName += nativeBridgeSuffix
1227 }
1228
1229 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
1230 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1231 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1232 c.Properties.SubName += vendorSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001233 } else if _, ok := c.linker.(*llndkStubDecorator); ok || (c.UseVndk() && c.HasVendorVariant()) {
Inseob Kim64c43952019-08-26 16:52:35 +09001234 // .vendor.{version} suffix is added only when we will have two variants: core and vendor.
1235 // The suffix is not added for vendor-only module.
1236 c.Properties.SubName += vendorSuffix
1237 vendorVersion := actx.DeviceConfig().VndkVersion()
1238 if vendorVersion == "current" {
1239 vendorVersion = actx.DeviceConfig().PlatformVndkVersion()
1240 }
1241 if c.Properties.VndkVersion != vendorVersion {
1242 c.Properties.SubName += "." + c.Properties.VndkVersion
1243 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001244 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001245 c.Properties.SubName += recoverySuffix
1246 }
1247
Colin Crossca860ac2016-01-04 14:34:37 -08001248 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001249 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001250 moduleContextImpl: moduleContextImpl{
1251 mod: c,
1252 },
1253 }
1254 ctx.ctx = ctx
1255
Colin Crossf18e1102017-11-16 14:33:08 -08001256 deps := c.depsToPaths(ctx)
1257 if ctx.Failed() {
1258 return
1259 }
1260
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001261 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1262 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1263 }
1264
Colin Crossca860ac2016-01-04 14:34:37 -08001265 flags := Flags{
1266 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001267 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001268 }
Colin Crossca860ac2016-01-04 14:34:37 -08001269 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001270 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001271 }
1272 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001273 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001274 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001275 if c.stl != nil {
1276 flags = c.stl.flags(ctx, flags)
1277 }
Colin Cross16b23492016-01-06 14:41:07 -08001278 if c.sanitize != nil {
1279 flags = c.sanitize.flags(ctx, flags)
1280 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001281 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001282 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001283 }
Stephen Craneba090d12017-05-09 15:44:35 -07001284 if c.lto != nil {
1285 flags = c.lto.flags(ctx, flags)
1286 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001287 if c.pgo != nil {
1288 flags = c.pgo.flags(ctx, flags)
1289 }
Ivan Lozano074ec482018-11-21 08:59:37 -08001290 if c.xom != nil {
1291 flags = c.xom.flags(ctx, flags)
1292 }
Colin Crossca860ac2016-01-04 14:34:37 -08001293 for _, feature := range c.features {
1294 flags = feature.flags(ctx, flags)
1295 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001296 if ctx.Failed() {
1297 return
1298 }
1299
Colin Cross4af21ed2019-11-04 09:37:55 -08001300 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1301 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1302 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001303
Colin Cross4af21ed2019-11-04 09:37:55 -08001304 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001305
1306 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001307 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001308 }
1309 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001310 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001311 }
1312
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001313 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001314 // We need access to all the flags seen by a source file.
1315 if c.sabi != nil {
1316 flags = c.sabi.flags(ctx, flags)
1317 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001318
Colin Cross4af21ed2019-11-04 09:37:55 -08001319 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001320
Colin Crossca860ac2016-01-04 14:34:37 -08001321 // Optimization to reduce size of build.ninja
1322 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001323 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1324 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1325 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1326 flags.Local.CFlags = []string{"$cflags"}
1327 flags.Local.CppFlags = []string{"$cppflags"}
1328 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001329
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001330 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001331 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001332 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001333 if ctx.Failed() {
1334 return
1335 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001336 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001337 }
1338
Colin Crossca860ac2016-01-04 14:34:37 -08001339 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001340 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001341 if ctx.Failed() {
1342 return
1343 }
Colin Cross635c3b02016-05-18 15:37:25 -07001344 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001345
1346 // If a lib is directly included in any of the APEXes, unhide the stubs
1347 // variant having the latest version gets visible to make. In addition,
1348 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1349 // force anything in the make world to link against the stubs library.
1350 // (unless it is explicitly referenced via .bootstrap suffix or the
1351 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001352 if c.HasStubsVariants() &&
1353 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001354 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001355 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001356 c.Properties.HideFromMake = false // unhide
1357 // Note: this is still non-installable
1358 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001359 }
Colin Cross5049f022015-03-18 13:28:46 -07001360
Inseob Kim1f086e22019-05-09 13:29:15 +09001361 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001362 c.installer.install(ctx, c.outputFile.Path())
1363 if ctx.Failed() {
1364 return
Colin Crossca860ac2016-01-04 14:34:37 -08001365 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001366 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001367}
1368
Colin Cross0ea8ba82019-06-06 14:33:29 -07001369func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001370 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001371 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001372 }
Colin Crossca860ac2016-01-04 14:34:37 -08001373 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001374}
1375
Colin Crossca860ac2016-01-04 14:34:37 -08001376func (c *Module) begin(ctx BaseModuleContext) {
1377 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001378 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001379 }
Colin Crossca860ac2016-01-04 14:34:37 -08001380 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001381 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001382 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001383 if c.stl != nil {
1384 c.stl.begin(ctx)
1385 }
Colin Cross16b23492016-01-06 14:41:07 -08001386 if c.sanitize != nil {
1387 c.sanitize.begin(ctx)
1388 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001389 if c.coverage != nil {
1390 c.coverage.begin(ctx)
1391 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001392 if c.sabi != nil {
1393 c.sabi.begin(ctx)
1394 }
Justin Yun8effde42017-06-23 19:24:43 +09001395 if c.vndkdep != nil {
1396 c.vndkdep.begin(ctx)
1397 }
Stephen Craneba090d12017-05-09 15:44:35 -07001398 if c.lto != nil {
1399 c.lto.begin(ctx)
1400 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001401 if c.pgo != nil {
1402 c.pgo.begin(ctx)
1403 }
Colin Crossca860ac2016-01-04 14:34:37 -08001404 for _, feature := range c.features {
1405 feature.begin(ctx)
1406 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001407 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001408 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001409 if err != nil {
1410 ctx.PropertyErrorf("sdk_version", err.Error())
1411 }
Nan Zhang0007d812017-11-07 10:57:05 -08001412 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001413 }
Colin Crossca860ac2016-01-04 14:34:37 -08001414}
1415
Colin Cross37047f12016-12-13 17:06:13 -08001416func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001417 deps := Deps{}
1418
1419 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001420 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001421 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001422 // Add the PGO dependency (the clang_rt.profile runtime library), which
1423 // sometimes depends on symbols from libgcc, before libgcc gets added
1424 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001425 if c.pgo != nil {
1426 deps = c.pgo.deps(ctx, deps)
1427 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001428 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001429 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001430 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001431 if c.stl != nil {
1432 deps = c.stl.deps(ctx, deps)
1433 }
Colin Cross16b23492016-01-06 14:41:07 -08001434 if c.sanitize != nil {
1435 deps = c.sanitize.deps(ctx, deps)
1436 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001437 if c.coverage != nil {
1438 deps = c.coverage.deps(ctx, deps)
1439 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001440 if c.sabi != nil {
1441 deps = c.sabi.deps(ctx, deps)
1442 }
Justin Yun8effde42017-06-23 19:24:43 +09001443 if c.vndkdep != nil {
1444 deps = c.vndkdep.deps(ctx, deps)
1445 }
Stephen Craneba090d12017-05-09 15:44:35 -07001446 if c.lto != nil {
1447 deps = c.lto.deps(ctx, deps)
1448 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001449 for _, feature := range c.features {
1450 deps = feature.deps(ctx, deps)
1451 }
1452
Colin Crossb6715442017-10-24 11:13:31 -07001453 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1454 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1455 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1456 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1457 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1458 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001459 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001460
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001461 for _, lib := range deps.ReexportSharedLibHeaders {
1462 if !inList(lib, deps.SharedLibs) {
1463 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1464 }
1465 }
1466
1467 for _, lib := range deps.ReexportStaticLibHeaders {
1468 if !inList(lib, deps.StaticLibs) {
1469 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1470 }
1471 }
1472
Colin Cross5950f382016-12-13 12:50:57 -08001473 for _, lib := range deps.ReexportHeaderLibHeaders {
1474 if !inList(lib, deps.HeaderLibs) {
1475 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1476 }
1477 }
1478
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001479 for _, gen := range deps.ReexportGeneratedHeaders {
1480 if !inList(gen, deps.GeneratedHeaders) {
1481 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1482 }
1483 }
1484
Colin Crossc99deeb2016-04-11 15:06:20 -07001485 return deps
1486}
1487
Dan Albert7e9d2952016-08-04 13:02:36 -07001488func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001489 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001490 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001491 moduleContextImpl: moduleContextImpl{
1492 mod: c,
1493 },
1494 }
1495 ctx.ctx = ctx
1496
Colin Crossca860ac2016-01-04 14:34:37 -08001497 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001498}
1499
Jiyong Park7ed9de32018-10-15 22:25:07 +09001500// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001501func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001502 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1503 version := name[sharp+1:]
1504 libname := name[:sharp]
1505 return libname, version
1506 }
1507 return name, ""
1508}
1509
Colin Cross1e676be2016-10-12 14:38:15 -07001510func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001511 ctx := &depsContext{
1512 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001513 moduleContextImpl: moduleContextImpl{
1514 mod: c,
1515 },
1516 }
1517 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001518
Colin Crossc99deeb2016-04-11 15:06:20 -07001519 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001520
Dan Albert914449f2016-06-17 16:45:24 -07001521 variantNdkLibs := []string{}
1522 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001523 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001524 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001525
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001526 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1527 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001528 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001529 // 1. Name of an NDK library that refers to a prebuilt module.
1530 // For each of these, it adds the name of the prebuilt module (which will be in
1531 // prebuilts/ndk) to the list of nonvariant libs.
1532 // 2. Name of an NDK library that refers to an ndk_library module.
1533 // For each of these, it adds the name of the ndk_library module to the list of
1534 // variant libs.
1535 // 3. Anything else (so anything that isn't an NDK library).
1536 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001537 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001538 // The caller can then know to add the variantLibs dependencies differently from the
1539 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001540
Inseob Kim9516ee92019-05-09 10:56:13 +09001541 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001542 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1543 variantLibs = []string{}
1544 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001545 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001546 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001547 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001548 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1549 if !inList(name, ndkMigratedLibs) {
1550 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001551 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001552 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001553 }
Jooyung Han0302a842019-10-30 18:43:49 +09001554 } else if ctx.useVndk() && isLlndkLibrary(name, ctx.Config()) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001555 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001556 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001557 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001558 if actx.OtherModuleExists(vendorPublicLib) {
1559 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1560 } else {
1561 // This can happen if vendor_public_library module is defined in a
1562 // namespace that isn't visible to the current module. In that case,
1563 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001564 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001565 }
Dan Albert914449f2016-06-17 16:45:24 -07001566 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001567 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001568 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001569 }
1570 }
Dan Albert914449f2016-06-17 16:45:24 -07001571 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001572 }
1573
Dan Albert914449f2016-06-17 16:45:24 -07001574 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1575 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001576 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001577 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001578
Jiyong Park7e636d02019-01-28 16:16:54 +09001579 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001580 if c.linker != nil {
1581 if library, ok := c.linker.(*libraryDecorator); ok {
1582 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001583 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001584 }
1585 }
1586 }
1587
Colin Cross32ec36c2016-12-15 07:39:51 -08001588 for _, lib := range deps.HeaderLibs {
1589 depTag := headerDepTag
1590 if inList(lib, deps.ReexportHeaderLibHeaders) {
1591 depTag = headerExportDepTag
1592 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001593 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001594 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001595 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001596 } else {
1597 actx.AddVariationDependencies(nil, depTag, lib)
1598 }
1599 }
1600
1601 if buildStubs {
1602 // Stubs lib does not have dependency to other static/shared libraries.
1603 // Don't proceed.
1604 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001605 }
Colin Cross5950f382016-12-13 12:50:57 -08001606
Inseob Kimc0907f12019-02-08 21:00:45 +09001607 syspropImplLibraries := syspropImplLibraries(actx.Config())
1608
Jiyong Park5d1598f2019-02-25 22:14:17 +09001609 for _, lib := range deps.WholeStaticLibs {
1610 depTag := wholeStaticDepTag
1611 if impl, ok := syspropImplLibraries[lib]; ok {
1612 lib = impl
1613 }
1614 actx.AddVariationDependencies([]blueprint.Variation{
1615 {Mutator: "link", Variation: "static"},
1616 }, depTag, lib)
1617 }
1618
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001619 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001620 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001621 if inList(lib, deps.ReexportStaticLibHeaders) {
1622 depTag = staticExportDepTag
1623 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001624
1625 if impl, ok := syspropImplLibraries[lib]; ok {
1626 lib = impl
1627 }
1628
Dan Willemsen59339a22018-07-22 21:18:45 -07001629 actx.AddVariationDependencies([]blueprint.Variation{
1630 {Mutator: "link", Variation: "static"},
1631 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001632 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001633
Dan Willemsen59339a22018-07-22 21:18:45 -07001634 actx.AddVariationDependencies([]blueprint.Variation{
1635 {Mutator: "link", Variation: "static"},
1636 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001637
Ivan Lozano183a3212019-10-18 14:18:45 -07001638 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001639 var variations []blueprint.Variation
1640 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Ivan Lozano52767be2019-10-18 14:49:46 -07001641 versionVariantAvail := !ctx.useVndk() && !c.InRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001642 if version != "" && versionVariantAvail {
1643 // Version is explicitly specified. i.e. libFoo#30
1644 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001645 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001646 }
1647 actx.AddVariationDependencies(variations, depTag, name)
1648
1649 // If the version is not specified, add dependency to the latest stubs library.
1650 // The stubs library will be used when the depending module is built for APEX and
1651 // the dependent module is not in the same APEX.
Jiyong Park73c54ee2019-10-22 20:31:18 +09001652 latestVersion := LatestStubsVersionFor(actx.Config(), name)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001653 if version == "" && latestVersion != "" && versionVariantAvail {
1654 actx.AddVariationDependencies([]blueprint.Variation{
1655 {Mutator: "link", Variation: "shared"},
1656 {Mutator: "version", Variation: latestVersion},
1657 }, depTag, name)
Ivan Lozano183a3212019-10-18 14:18:45 -07001658 // Note that depTag.ExplicitlyVersioned is false in this case.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001659 }
1660 }
1661
Jiyong Park7ed9de32018-10-15 22:25:07 +09001662 // shared lib names without the #version suffix
1663 var sharedLibNames []string
1664
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001665 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001666 depTag := SharedDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001667 if inList(lib, deps.ReexportSharedLibHeaders) {
1668 depTag = sharedExportDepTag
1669 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001670
1671 if impl, ok := syspropImplLibraries[lib]; ok {
1672 lib = impl
1673 }
1674
Jiyong Park73c54ee2019-10-22 20:31:18 +09001675 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001676 sharedLibNames = append(sharedLibNames, name)
1677
Jiyong Park25fc6a92018-11-18 18:02:45 +09001678 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001679 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001680
Jiyong Park7ed9de32018-10-15 22:25:07 +09001681 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001682 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001683 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1684 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1685 // linking against both the stubs lib and the non-stubs lib at the same time.
1686 continue
1687 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001688 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001689 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001690
Dan Willemsen59339a22018-07-22 21:18:45 -07001691 actx.AddVariationDependencies([]blueprint.Variation{
1692 {Mutator: "link", Variation: "shared"},
1693 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001694
Colin Cross68861832016-07-08 10:41:41 -07001695 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001696
1697 for _, gen := range deps.GeneratedHeaders {
1698 depTag := genHeaderDepTag
1699 if inList(gen, deps.ReexportGeneratedHeaders) {
1700 depTag = genHeaderExportDepTag
1701 }
1702 actx.AddDependency(c, depTag, gen)
1703 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001704
Colin Cross42d48b72018-08-29 14:10:52 -07001705 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001706
1707 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001708 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001709 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001710 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001711 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001712 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001713 if deps.LinkerFlagsFile != "" {
1714 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1715 }
1716 if deps.DynamicLinker != "" {
1717 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001718 }
Dan Albert914449f2016-06-17 16:45:24 -07001719
1720 version := ctx.sdkVersion()
1721 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001722 {Mutator: "ndk_api", Variation: version},
1723 {Mutator: "link", Variation: "shared"},
1724 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001725 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001726 {Mutator: "ndk_api", Variation: version},
1727 {Mutator: "link", Variation: "shared"},
1728 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001729
1730 if vndkdep := c.vndkdep; vndkdep != nil {
1731 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08001732 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08001733 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07001734 {Mutator: "link", Variation: "shared"},
1735 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001736 }
1737 }
Colin Cross6362e272015-10-29 15:25:03 -07001738}
Colin Cross21b9a242015-03-24 14:15:58 -07001739
Colin Crosse40b4ea2018-10-02 22:25:58 -07001740func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001741 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1742 c.beginMutator(ctx)
1743 }
1744}
1745
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001746// Whether a module can link to another module, taking into
1747// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07001748func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
1749 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001750 // Host code is not restricted
1751 return
1752 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001753
1754 // VNDK is cc.Module supported only for now.
1755 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001756 // Though vendor code is limited by the vendor mutator,
1757 // each vendor-available module needs to check
1758 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07001759 if ccTo, ok := to.(*Module); ok {
1760 if ccFrom.vndkdep != nil {
1761 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
1762 }
1763 } else {
1764 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001765 }
1766 return
1767 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001768 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001769 // Platform code can link to anything
1770 return
1771 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001772 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09001773 // Recovery code is not NDK
1774 return
1775 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001776 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001777 // These are always allowed
1778 return
1779 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001780 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001781 // These are allowed, but they don't set sdk_version
1782 return
1783 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001784 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001785 // These aren't real libraries, but are the stub shared libraries that are included in
1786 // the NDK.
1787 return
1788 }
Logan Chien834b9a62019-01-14 15:39:03 +08001789
Ivan Lozano52767be2019-10-18 14:49:46 -07001790 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08001791 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1792 // to link to libc++ (non-NDK and without sdk_version).
1793 return
1794 }
1795
Ivan Lozano52767be2019-10-18 14:49:46 -07001796 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001797 // NDK code linking to platform code is never okay.
1798 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001799 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001800 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001801 }
1802
1803 // At this point we know we have two NDK libraries, but we need to
1804 // check that we're not linking against anything built against a higher
1805 // API level, as it is only valid to link against older or equivalent
1806 // APIs.
1807
Inseob Kim01a28722018-04-11 09:48:45 +09001808 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07001809 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001810 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07001811 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001812 // Current can't be linked against by anything else.
1813 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001814 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09001815 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07001816 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001817 if err != nil {
1818 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001819 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001820 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001821 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001822 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001823 if err != nil {
1824 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001825 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001826 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001827 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001828
Inseob Kim01a28722018-04-11 09:48:45 +09001829 if toApi > fromApi {
1830 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001831 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001832 }
1833 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001834 }
Dan Albert202fe492017-12-15 13:56:59 -08001835
1836 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07001837 fromStl := from.SelectedStl()
1838 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08001839 if fromStl == "" || toStl == "" {
1840 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001841 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001842 // We can be permissive with the system "STL" since it is only the C++
1843 // ABI layer, but in the future we should make sure that everyone is
1844 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001845 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001846 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001847 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
1848 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08001849 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001850}
1851
Jiyong Park5fb8c102018-04-09 12:03:06 +09001852// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001853// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1854// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001855// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001856func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
1857 check := func(child, parent android.Module) bool {
1858 to, ok := child.(*Module)
1859 if !ok {
1860 // follow thru cc.Defaults, etc.
1861 return true
1862 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001863
Jooyung Hana70f0672019-01-18 15:20:43 +09001864 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1865 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001866 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001867
1868 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07001869 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09001870 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001871 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001872
Jooyung Han0302a842019-10-30 18:43:49 +09001873 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001874 return false
1875 }
1876
1877 var stringPath []string
1878 for _, m := range ctx.GetWalkPath() {
1879 stringPath = append(stringPath, m.Name())
1880 }
1881 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1882 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1883 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1884 return false
1885 }
1886 if module, ok := ctx.Module().(*Module); ok {
1887 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09001888 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001889 ctx.WalkDeps(check)
1890 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001891 }
1892 }
1893}
1894
Colin Crossc99deeb2016-04-11 15:06:20 -07001895// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001896func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001897 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001898
Ivan Lozano183a3212019-10-18 14:18:45 -07001899 directStaticDeps := []LinkableInterface{}
1900 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001901
Inseob Kim9516ee92019-05-09 10:56:13 +09001902 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
1903
Inseob Kim69378442019-06-03 19:10:47 +09001904 reexportExporter := func(exporter exportedFlagsProducer) {
1905 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
1906 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
1907 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
1908 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
1909 }
1910
Colin Crossd11fcda2017-10-23 17:59:01 -07001911 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001912 depName := ctx.OtherModuleName(dep)
1913 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001914
Ivan Lozano52767be2019-10-18 14:49:46 -07001915 ccDep, ok := dep.(LinkableInterface)
1916 if !ok {
1917
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001918 // handling for a few module types that aren't cc Module but that are also supported
1919 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001920 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001921 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001922 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1923 genRule.GeneratedSourceFiles()...)
1924 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001925 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001926 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001927 // Support exported headers from a generated_sources dependency
1928 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001929 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001930 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001931 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001932 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09001933 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09001934 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001935 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09001936 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
1937 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001938 // 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 +09001939 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001940
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001941 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001942 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001943 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001944 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001945 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001946 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001947 files := genRule.GeneratedSourceFiles()
1948 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001949 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001950 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001951 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 -07001952 }
1953 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001954 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001955 }
Colin Crossca860ac2016-01-04 14:34:37 -08001956 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001957 return
1958 }
1959
Colin Crossfe17f6f2019-03-28 19:30:56 -07001960 if depTag == android.ProtoPluginDepTag {
1961 return
1962 }
1963
Colin Crossd11fcda2017-10-23 17:59:01 -07001964 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001965 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1966 return
1967 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001968 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001969 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001970 return
1971 }
1972
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001973 // re-exporting flags
1974 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07001975 // reusing objects only make sense for cc.Modules.
1976 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001977 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07001978 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001979 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09001980 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08001981 return
1982 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001983 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001984
Jiyong Parke4bb9862019-02-01 00:31:10 +09001985 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07001986 // staticVariants are a cc.Module specific concept.
1987 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09001988 c.staticVariant = ccDep
1989 return
1990 }
1991 }
1992
Ivan Lozano183a3212019-10-18 14:18:45 -07001993 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
1994 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
1995 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001996 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07001997 if t, ok := depTag.(DependencyTag); ok {
1998 explicitlyVersioned = t.ExplicitlyVersioned
1999 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002000 depTag = t
2001 }
2002
Ivan Lozano183a3212019-10-18 14:18:45 -07002003 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002004 depIsStatic := false
2005 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002006 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002007 depIsStatic = true
2008 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002009 if ccDep.CcLibrary() && !depIsStatic {
2010 depIsStubs := ccDep.BuildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09002011 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002012 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002013 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002014
2015 var useThisDep bool
2016 if depIsStubs && explicitlyVersioned {
2017 // Always respect dependency to the versioned stubs (i.e. libX#10)
2018 useThisDep = true
2019 } else if !depHasStubs {
2020 // Use non-stub variant if that is the only choice
2021 // (i.e. depending on a lib without stubs.version property)
2022 useThisDep = true
2023 } else if c.IsForPlatform() {
2024 // If not building for APEX, use stubs only when it is from
2025 // an APEX (and not from platform)
2026 useThisDep = (depInPlatform != depIsStubs)
Ivan Lozano52767be2019-10-18 14:49:46 -07002027 if c.InRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09002028 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002029 // always link to non-stub variant
2030 useThisDep = !depIsStubs
2031 }
2032 } else {
2033 // If building for APEX, use stubs only when it is not from
2034 // the same APEX
2035 useThisDep = (depInSameApex != depIsStubs)
2036 }
2037
2038 if !useThisDep {
2039 return // stop processing this dep
2040 }
2041 }
2042
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002043 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2044
Ivan Lozano52767be2019-10-18 14:49:46 -07002045 // Exporting flags only makes sense for cc.Modules
2046 if _, ok := ccDep.(*Module); ok {
2047 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002048 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
2049 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedDeps()...)
2050 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002051
Ivan Lozano52767be2019-10-18 14:49:46 -07002052 if t.ReexportFlags {
2053 reexportExporter(i)
2054 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2055 // Re-exported shared library headers must be included as well since they can help us with type information
2056 // about template instantiations (instantiated from their headers).
2057 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2058 // scripts.
2059 c.sabi.Properties.ReexportedIncludes = append(
2060 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2061 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002062 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002063 }
Logan Chienf3511742017-10-31 18:04:35 +08002064 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002065 }
2066
Colin Cross26c34ed2016-09-30 17:10:16 -07002067 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002068 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002069
Ivan Lozano52767be2019-10-18 14:49:46 -07002070 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002071 depFile := android.OptionalPath{}
2072
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002073 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002074 case ndkStubDepTag, SharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002075 ptr = &depPaths.SharedLibs
2076 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002077 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002078 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002079
Jiyong Park64a44f22019-01-18 14:37:08 +09002080 case earlySharedDepTag:
2081 ptr = &depPaths.EarlySharedLibs
2082 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002083 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002084 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002085 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002086 ptr = &depPaths.LateSharedLibs
2087 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002088 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002089 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002090 ptr = nil
2091 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002092 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002093 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002094 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002095 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002096 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002097 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002098 return
2099 }
2100
Ivan Lozano52767be2019-10-18 14:49:46 -07002101 // Because the static library objects are included, this only makes sense
2102 // in the context of proper cc.Modules.
2103 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2104 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2105 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2106 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2107 for i := range missingDeps {
2108 missingDeps[i] += postfix
2109 }
2110 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002111 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002112 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2113 } else {
2114 ctx.ModuleErrorf(
2115 "non-cc.Modules cannot be included as whole static libraries.", depName)
2116 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002117 }
Colin Cross5950f382016-12-13 12:50:57 -08002118 case headerDepTag:
2119 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002120 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002121 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002122 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002123 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002124 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002125 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002126 case dynamicLinkerDepTag:
2127 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002128 }
2129
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002130 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002131 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002132 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002133 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002134 return
2135 }
2136
2137 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002138 // in static libraries act as if they were whole static libraries. The same goes for
2139 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002140 // This should only be done for cc.Modules
2141 if c, ok := ccDep.(*Module); ok {
2142 staticLib := c.linker.(libraryInterface)
2143 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2144 staticLib.objs().coverageFiles...)
2145 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2146 staticLib.objs().sAbiDumpFiles...)
2147 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002148 }
2149
Colin Cross26c34ed2016-09-30 17:10:16 -07002150 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002151 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002152 if !ctx.Config().AllowMissingDependencies() {
2153 ctx.ModuleErrorf("module %q missing output file", depName)
2154 } else {
2155 ctx.AddMissingDependencies([]string{depName})
2156 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002157 return
2158 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002159 *ptr = append(*ptr, linkFile.Path())
2160 }
2161
Colin Crossc99deeb2016-04-11 15:06:20 -07002162 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002163 dep := depFile
2164 if !dep.Valid() {
2165 dep = linkFile
2166 }
2167 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002168 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002169
Logan Chien43d34c32017-12-20 01:17:32 +08002170 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002171 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002172 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002173 libName = strings.TrimPrefix(libName, "prebuilt_")
Jooyung Han0302a842019-10-30 18:43:49 +09002174 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002175 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002176 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002177
Ivan Lozano52767be2019-10-18 14:49:46 -07002178 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002179 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2180 // core module instead.
2181 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002182 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002183 // The vendor module in Make will have been renamed to not conflict with the core
2184 // module, so update the dependency name here accordingly.
Inseob Kim64c43952019-08-26 16:52:35 +09002185 ret := libName + vendorSuffix
2186 vendorVersion := ctx.DeviceConfig().VndkVersion()
2187 if vendorVersion == "current" {
2188 vendorVersion = ctx.DeviceConfig().PlatformVndkVersion()
2189 }
2190 if c.Properties.VndkVersion != vendorVersion {
2191 ret += "." + c.Properties.VndkVersion
2192 }
2193 return ret
Jiyong Park374510b2018-03-19 18:23:01 +09002194 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002195 return libName + vendorPublicLibrarySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002196 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002197 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002198 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002199 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002200 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002201 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002202 }
Logan Chien43d34c32017-12-20 01:17:32 +08002203 }
2204
2205 // Export the shared libs to Make.
2206 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002207 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002208 if ccDep.CcLibrary() {
2209 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002210 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002211 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002212 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002213 c.Properties.ApexesProvidingSharedLibs = append(
2214 c.Properties.ApexesProvidingSharedLibs, an)
2215 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002216 }
2217 }
2218
Jiyong Park27b188b2017-07-18 13:23:39 +09002219 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002220 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002221 c.Properties.AndroidMkSharedLibs = append(
2222 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002223 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002224 c.Properties.AndroidMkSharedLibs = append(
2225 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002226 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002227 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002228 c.Properties.AndroidMkStaticLibs = append(
2229 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002230 case runtimeDepTag:
2231 c.Properties.AndroidMkRuntimeLibs = append(
2232 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002233 case wholeStaticDepTag:
2234 c.Properties.AndroidMkWholeStaticLibs = append(
2235 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002236 }
Colin Crossca860ac2016-01-04 14:34:37 -08002237 })
2238
Jeff Gaston294356f2017-09-27 17:05:30 -07002239 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002240 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002241
Colin Crossdd84e052017-05-17 13:44:16 -07002242 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002243 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002244 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2245 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002246 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Jiyong Park74955042019-10-22 20:19:51 +09002247 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2248 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002249 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002250 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002251
2252 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002253 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002254 }
Colin Crossdd84e052017-05-17 13:44:16 -07002255
Colin Crossca860ac2016-01-04 14:34:37 -08002256 return depPaths
2257}
2258
2259func (c *Module) InstallInData() bool {
2260 if c.installer == nil {
2261 return false
2262 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002263 return c.installer.inData()
2264}
2265
2266func (c *Module) InstallInSanitizerDir() bool {
2267 if c.installer == nil {
2268 return false
2269 }
2270 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002271 return true
2272 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002273 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002274}
2275
Jiyong Parkf9332f12018-02-01 00:54:12 +09002276func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002277 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002278}
2279
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002280func (c *Module) HostToolPath() android.OptionalPath {
2281 if c.installer == nil {
2282 return android.OptionalPath{}
2283 }
2284 return c.installer.hostToolPath()
2285}
2286
Nan Zhangd4e641b2017-07-12 12:55:28 -07002287func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2288 return c.outputFile
2289}
2290
Colin Cross41955e82019-05-29 14:40:35 -07002291func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2292 switch tag {
2293 case "":
2294 if c.outputFile.Valid() {
2295 return android.Paths{c.outputFile.Path()}, nil
2296 }
2297 return android.Paths{}, nil
2298 default:
2299 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002300 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002301}
2302
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002303func (c *Module) static() bool {
2304 if static, ok := c.linker.(interface {
2305 static() bool
2306 }); ok {
2307 return static.static()
2308 }
2309 return false
2310}
2311
Jiyong Park379de2f2018-12-19 02:47:14 +09002312func (c *Module) staticBinary() bool {
2313 if static, ok := c.linker.(interface {
2314 staticBinary() bool
2315 }); ok {
2316 return static.staticBinary()
2317 }
2318 return false
2319}
2320
Jiyong Park1d1119f2019-07-29 21:27:18 +09002321func (c *Module) header() bool {
2322 if h, ok := c.linker.(interface {
2323 header() bool
2324 }); ok {
2325 return h.header()
2326 }
2327 return false
2328}
2329
Jooyung Han38002912019-05-16 04:01:54 +09002330func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002331 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002332 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2333 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002334 return "native:vndk"
2335 }
Jooyung Han38002912019-05-16 04:01:54 +09002336 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002337 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002338 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002339 if Bool(c.VendorProperties.Vendor_available) {
2340 return "native:vndk"
2341 }
2342 return "native:vndk_private"
2343 }
2344 return "native:vendor"
Ivan Lozano52767be2019-10-18 14:49:46 -07002345 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002346 return "native:recovery"
2347 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2348 return "native:ndk:none:none"
2349 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2350 //family, link := getNdkStlFamilyAndLinkType(c)
2351 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002352 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002353 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002354 } else {
2355 return "native:platform"
2356 }
2357}
2358
Jiyong Park9d452992018-10-03 00:38:19 +09002359// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002360// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002361func (c *Module) IsInstallableToApex() bool {
2362 if shared, ok := c.linker.(interface {
2363 shared() bool
2364 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002365 // Stub libs and prebuilt libs in a versioned SDK are not
2366 // installable to APEX even though they are shared libs.
2367 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002368 } else if _, ok := c.linker.(testPerSrc); ok {
2369 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002370 }
2371 return false
2372}
2373
Jiyong Parka90ca002019-10-07 15:47:24 +09002374func (c *Module) AvailableFor(what string) bool {
2375 if linker, ok := c.linker.(interface {
2376 availableFor(string) bool
2377 }); ok {
2378 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2379 } else {
2380 return c.ApexModuleBase.AvailableFor(what)
2381 }
2382}
2383
Inseob Kim1f086e22019-05-09 13:29:15 +09002384func (c *Module) installable() bool {
2385 return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
2386}
2387
bralee3f49f4d2019-03-04 06:58:15 +08002388func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
Colin Cross41955e82019-05-29 14:40:35 -07002389 outputFiles, err := c.OutputFiles("")
2390 if err != nil {
2391 panic(err)
2392 }
2393 dpInfo.Srcs = append(dpInfo.Srcs, outputFiles.Strings()...)
bralee3f49f4d2019-03-04 06:58:15 +08002394}
2395
Logan Chien41eabe62019-04-10 13:33:58 +08002396func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2397 if c.linker != nil {
2398 if library, ok := c.linker.(*libraryDecorator); ok {
2399 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2400 }
2401 }
2402}
2403
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002404func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002405 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
2406 if cc, ok := dep.(*Module); ok && cc.IsStubs() && depTag.Shared {
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002407 // dynamic dep to a stubs lib crosses APEX boundary
2408 return false
2409 }
2410 }
2411 return true
2412}
2413
Colin Cross2ba19d92015-05-07 15:44:20 -07002414//
Colin Crosscfad1192015-11-02 16:43:11 -08002415// Defaults
2416//
Colin Crossca860ac2016-01-04 14:34:37 -08002417type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002418 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002419 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002420 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002421}
2422
Patrice Arrudac249c712019-03-19 17:00:29 -07002423// cc_defaults provides a set of properties that can be inherited by other cc
2424// modules. A module can use the properties from a cc_defaults using
2425// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2426// merged (when possible) by prepending the default module's values to the
2427// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002428func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002429 return DefaultsFactory()
2430}
2431
Colin Cross36242852017-06-23 15:06:31 -07002432func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002433 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002434
Colin Cross36242852017-06-23 15:06:31 -07002435 module.AddProperties(props...)
2436 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002437 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002438 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002439 &BaseCompilerProperties{},
2440 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002441 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002442 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002443 &StaticProperties{},
2444 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002445 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002446 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002447 &TestProperties{},
2448 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002449 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002450 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002451 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002452 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002453 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002454 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002455 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002456 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002457 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002458 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002459 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002460 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002461 &android.ProtoProperties{},
Jooyung Han18020ea2019-11-13 10:50:48 +09002462 &android.ApexProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002463 )
Colin Crosscfad1192015-11-02 16:43:11 -08002464
Jooyung Hancc372c52019-09-25 15:18:44 +09002465 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002466
2467 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002468}
2469
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002470const (
Colin Cross7228ecd2019-11-18 16:00:16 -08002471 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002472 // against the VNDK.
Colin Cross7228ecd2019-11-18 16:00:16 -08002473 VendorVariationPrefix = "vendor."
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002474)
2475
Jiyong Park6a43f042017-10-12 23:05:00 +09002476func squashVendorSrcs(m *Module) {
2477 if lib, ok := m.compiler.(*libraryDecorator); ok {
2478 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2479 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2480
2481 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2482 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2483 }
2484}
2485
Jiyong Parkf9332f12018-02-01 00:54:12 +09002486func squashRecoverySrcs(m *Module) {
2487 if lib, ok := m.compiler.(*libraryDecorator); ok {
2488 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2489 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2490
2491 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2492 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2493 }
2494}
2495
Colin Cross7228ecd2019-11-18 16:00:16 -08002496var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002497
Colin Cross7228ecd2019-11-18 16:00:16 -08002498func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002499 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002500 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002501 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002502
2503 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002504 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002505 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002506 }
Logan Chienf3511742017-10-31 18:04:35 +08002507
2508 if vndkdep := m.vndkdep; vndkdep != nil {
2509 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002510 if productSpecific {
2511 mctx.PropertyErrorf("product_specific",
2512 "product_specific must not be true when `vndk: {enabled: true}`")
Justin Yun9357f4a2018-11-28 15:14:47 +09002513 }
Logan Chienf3511742017-10-31 18:04:35 +08002514 if vendorSpecific {
2515 if !vndkdep.isVndkExt() {
2516 mctx.PropertyErrorf("vndk",
2517 "must set `extends: \"...\"` to vndk extension")
Logan Chienf3511742017-10-31 18:04:35 +08002518 }
2519 } else {
2520 if vndkdep.isVndkExt() {
2521 mctx.PropertyErrorf("vndk",
2522 "must set `vendor: true` to set `extends: %q`",
2523 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002524 }
2525 if m.VendorProperties.Vendor_available == nil {
2526 mctx.PropertyErrorf("vndk",
2527 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08002528 }
2529 }
2530 } else {
2531 if vndkdep.isVndkSp() {
2532 mctx.PropertyErrorf("vndk",
2533 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08002534 }
2535 if vndkdep.isVndkExt() {
2536 mctx.PropertyErrorf("vndk",
2537 "must set `enabled: true` to set `extends: %q`",
2538 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002539 }
Justin Yun8effde42017-06-23 19:24:43 +09002540 }
2541 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002542
Jiyong Parkf9332f12018-02-01 00:54:12 +09002543 var coreVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002544 var recoveryVariantNeeded bool = false
2545
Inseob Kim64c43952019-08-26 16:52:35 +09002546 var vendorVariants []string
2547
2548 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
2549 deviceVndkVersion := mctx.DeviceConfig().VndkVersion()
2550 if deviceVndkVersion == "current" {
2551 deviceVndkVersion = platformVndkVersion
2552 }
2553
Justin Yun71549282017-11-17 12:10:28 +09002554 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002555 // If the device isn't compiling against the VNDK, we always
2556 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002557 coreVariantNeeded = true
Justin Yun1282f422019-09-09 14:42:44 +09002558 } else if m.Target().NativeBridge == android.NativeBridgeEnabled {
2559 // Skip creating vendor variants for natvie bridge modules
2560 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002561 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2562 // LL-NDK stubs only exist in the vendor variant, since the
2563 // real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002564 vendorVariants = append(vendorVariants,
2565 platformVndkVersion,
2566 deviceVndkVersion,
2567 )
Jiyong Park2a454122017-10-19 15:59:33 +09002568 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2569 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002570 vendorVariants = append(vendorVariants,
2571 platformVndkVersion,
2572 deviceVndkVersion,
2573 )
2574 } else if lib, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002575 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2576 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kim64c43952019-08-26 16:52:35 +09002577 vendorVariants = append(vendorVariants, lib.version())
Ivan Lozano52767be2019-10-18 14:49:46 -07002578 } else if m.HasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002579 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002580 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002581 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002582 vendorVariants = append(vendorVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09002583 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
2584 // code is PLATFORM_VNDK_VERSION.
2585 // On the other hand, vendor_available modules which are not VNDK should
2586 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
2587 if !m.IsVndk() {
Inseob Kim64c43952019-08-26 16:52:35 +09002588 vendorVariants = append(vendorVariants, deviceVndkVersion)
2589 }
Logan Chienf3511742017-10-31 18:04:35 +08002590 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002591 // This will be available in /vendor (or /odm) only
Inseob Kim64c43952019-08-26 16:52:35 +09002592 vendorVariants = append(vendorVariants, deviceVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002593 } else {
2594 // This is either in /system (or similar: /data), or is a
2595 // modules built with the NDK. Modules built with the NDK
2596 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002597 coreVariantNeeded = true
2598 }
2599
2600 if Bool(m.Properties.Recovery_available) {
2601 recoveryVariantNeeded = true
2602 }
2603
2604 if m.ModuleBase.InstallInRecovery() {
2605 recoveryVariantNeeded = true
2606 coreVariantNeeded = false
2607 }
2608
Jiyong Park413cc742018-06-19 01:46:06 +09002609 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002610 primaryArch := mctx.Config().DevicePrimaryArchType()
2611 moduleArch := m.Target().Arch.ArchType
2612 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002613 recoveryVariantNeeded = false
2614 }
2615 }
2616
Inseob Kim64c43952019-08-26 16:52:35 +09002617 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Colin Cross7228ecd2019-11-18 16:00:16 -08002618 m.Properties.VendorVariants = append(m.Properties.VendorVariants, VendorVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09002619 }
Colin Cross7228ecd2019-11-18 16:00:16 -08002620
2621 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
2622 m.Properties.CoreVariantNeeded = coreVariantNeeded
2623}
2624
2625func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
2626 return c.Properties.CoreVariantNeeded
2627}
2628
2629func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
2630 return c.Properties.RecoveryVariantNeeded
2631}
2632
2633func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
2634 return c.Properties.VendorVariants
2635}
2636
2637func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
2638 m := module.(*Module)
2639 if variant == android.RecoveryVariation {
2640 m.MakeAsPlatform()
2641 squashRecoverySrcs(m)
2642 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
2643 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
2644 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002645 }
2646}
2647
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002648func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002649 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002650 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2651 }
Colin Cross6510f912017-11-29 00:27:14 -08002652 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002653}
2654
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002655func kytheExtractAllFactory() android.Singleton {
2656 return &kytheExtractAllSingleton{}
2657}
2658
2659type kytheExtractAllSingleton struct {
2660}
2661
2662func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2663 var xrefTargets android.Paths
2664 ctx.VisitAllModules(func(module android.Module) {
2665 if ccModule, ok := module.(xref); ok {
2666 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
2667 }
2668 })
2669 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
2670 if len(xrefTargets) > 0 {
2671 ctx.Build(pctx, android.BuildParams{
2672 Rule: blueprint.Phony,
2673 Output: android.PathForPhony(ctx, "xref_cxx"),
2674 Inputs: xrefTargets,
2675 //Default: true,
2676 })
2677 }
2678}
2679
Colin Cross06a931b2015-10-28 17:23:31 -07002680var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002681var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002682var BoolPtr = proptools.BoolPtr
2683var String = proptools.String
2684var StringPtr = proptools.StringPtr