blob: e80e2a297b8dd9c81e8fe9ba0c306a9deb5b852b [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -07001// Copyright 2015 Google Inc. All rights reserved.
Colin Cross3f40fa42015-01-30 17:27:36 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17// This file contains the module types for compiling C/C++ for Android, and converts the properties
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
Colin Cross41955e82019-05-29 14:40:35 -070022 "fmt"
Logan Chien41eabe62019-04-10 13:33:58 +080023 "io"
Dan Albert9e10cd42016-08-03 14:12:14 -070024 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080025 "strings"
26
Colin Cross97ba0732015-03-23 17:50:24 -070027 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070028 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070029
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070031 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070032 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080033)
34
Colin Cross463a90e2015-06-17 14:20:06 -070035func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070036 android.RegisterModuleType("cc_defaults", defaultsFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070037
Colin Cross1e676be2016-10-12 14:38:15 -070038 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Inseob Kim64c43952019-08-26 16:52:35 +090039 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070040 ctx.BottomUp("link", LinkageMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070041 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +010042 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090043 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070044 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimc0907f12019-02-08 21:00:45 +090045 ctx.BottomUp("sysprop", SyspropMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070046 })
Colin Cross16b23492016-01-06 14:41:07 -080047
Colin Cross1e676be2016-10-12 14:38:15 -070048 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
49 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
50 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080051
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070052 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
53 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
54
Mitch Phillipsbfeade62019-05-01 14:42:05 -070055 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
56 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
57
Jiyong Park1d1119f2019-07-29 21:27:18 +090058 // cfi mutator shouldn't run before sanitizers that return true for
59 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000060 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
61 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
62
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080063 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
64 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
65
Colin Cross1e676be2016-10-12 14:38:15 -070066 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
67 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080068
Colin Cross0b908332019-06-19 23:00:20 -070069 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090070 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080071
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080072 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080073 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070074
75 ctx.TopDown("lto_deps", ltoDepsMutator)
76 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090077
78 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070079 })
Colin Crossb98c8b02016-07-29 13:44:28 -070080
Sasha Smundak2a4549e2018-11-05 16:49:08 -080081 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Crossb98c8b02016-07-29 13:44:28 -070082 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070083}
84
Colin Crossca860ac2016-01-04 14:34:37 -080085type Deps struct {
86 SharedLibs, LateSharedLibs []string
87 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080088 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080089 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070090
Colin Cross5950f382016-12-13 12:50:57 -080091 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070092
Colin Cross81413472016-04-11 14:37:39 -070093 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070094
Dan Willemsenb40aab62016-04-20 14:21:14 -070095 GeneratedSources []string
96 GeneratedHeaders []string
97
Dan Willemsenb3454ab2016-09-28 17:34:58 -070098 ReexportGeneratedHeaders []string
99
Colin Cross97ba0732015-03-23 17:50:24 -0700100 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700101
102 // Used for host bionic
103 LinkerFlagsFile string
104 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700105}
106
Colin Crossca860ac2016-01-04 14:34:37 -0800107type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700108 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900109 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700110 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900111 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700112 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700113 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700114
Colin Cross26c34ed2016-09-30 17:10:16 -0700115 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700116 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800117 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700118 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700119
Colin Cross26c34ed2016-09-30 17:10:16 -0700120 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700121 GeneratedSources android.Paths
122 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700123
Inseob Kim69378442019-06-03 19:10:47 +0900124 Flags []string
Jiyong Park74955042019-10-22 20:19:51 +0900125 IncludeDirs android.Paths
126 SystemIncludeDirs android.Paths
127 ReexportedDirs android.Paths
128 ReexportedSystemDirs android.Paths
Inseob Kim69378442019-06-03 19:10:47 +0900129 ReexportedFlags []string
130 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700131
Colin Cross26c34ed2016-09-30 17:10:16 -0700132 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700133 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700134
135 // Path to the file container flags to use with the linker
136 LinkerFlagsFile android.OptionalPath
137
138 // Path to the dynamic linker binary
139 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700140}
141
Colin Cross4af21ed2019-11-04 09:37:55 -0800142// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
143// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
144// command line so they can be overridden by the local module flags).
145type LocalOrGlobalFlags struct {
146 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700147 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800148 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700149 CFlags []string // Flags that apply to C and C++ source files
150 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
151 ConlyFlags []string // Flags that apply to C source files
152 CppFlags []string // Flags that apply to C++ source files
153 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700154 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800155}
156
157type Flags struct {
158 Local LocalOrGlobalFlags
159 Global LocalOrGlobalFlags
160
161 aidlFlags []string // Flags that apply to aidl source files
162 rsFlags []string // Flags that apply to renderscript source files
163 libFlags []string // Flags to add libraries early to the link order
164 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
165 TidyFlags []string // Flags that apply to clang-tidy
166 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700167
Colin Crossc3199482017-03-30 15:03:04 -0700168 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800169 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700170 SystemIncludeFlags []string
171
Colin Crossb98c8b02016-07-29 13:44:28 -0700172 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700173 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800174 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800175 SAbiDump bool
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800176 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800177
178 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800179 DynamicLinker string
180
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700181 CFlagsDeps android.Paths // Files depended on by compiler flags
182 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800183
Dan Willemsen98ab3112019-08-27 21:20:40 -0700184 AssemblerWithCpp bool
185 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800186
Colin Cross19878da2019-03-28 14:45:07 -0700187 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700188 protoC bool // Whether to use C instead of C++
189 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700190
191 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700192}
193
Colin Crossca860ac2016-01-04 14:34:37 -0800194// Properties used to compile all C or C++ modules
195type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700196 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800197 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700198
199 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800200 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700201
Jiyong Parkde866cb2018-12-07 23:08:36 +0900202 AndroidMkSharedLibs []string `blueprint:"mutated"`
203 AndroidMkStaticLibs []string `blueprint:"mutated"`
204 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
205 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
206 HideFromMake bool `blueprint:"mutated"`
207 PreventInstall bool `blueprint:"mutated"`
208 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700209
Inseob Kim64c43952019-08-26 16:52:35 +0900210 VndkVersion string `blueprint:"mutated"`
211 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800212
213 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
214 // file
215 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900216
217 // Make this module available when building for recovery
218 Recovery_available *bool
219
Colin Crossae6c5202019-11-20 13:35:50 -0800220 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800221 CoreVariantNeeded bool `blueprint:"mutated"`
222 RecoveryVariantNeeded bool `blueprint:"mutated"`
223 VendorVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900224
225 // Allows this module to use non-APEX version of libraries. Useful
226 // for building binaries that are started before APEXes are activated.
227 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900228
229 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
230 // see soong/cc/config/vndk.go
231 MustUseVendorVariant bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700232}
233
234type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900235 // whether this module should be allowed to be directly depended by other
236 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
237 // If set to true, two variants will be built separately, one like
238 // normal, and the other limited to the set of libraries and headers
239 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700240 //
241 // The vendor variant may be used with a different (newer) /system,
242 // so it shouldn't have any unversioned runtime dependencies, or
243 // make assumptions about the system that may not be true in the
244 // future.
245 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900246 // If set to false, this module becomes inaccessible from /vendor modules.
247 //
248 // Default value is true when vndk: {enabled: true} or vendor: true.
249 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700250 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
251 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900252
253 // whether this module is capable of being loaded with other instance
254 // (possibly an older version) of the same module in the same process.
255 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
256 // can be double loaded in a vendor process if the library is also a
257 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
258 // explicitly marked as `double_loadable: true` by the owner, or the dependency
259 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
260 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800261}
262
Colin Crossca860ac2016-01-04 14:34:37 -0800263type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800264 static() bool
265 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900266 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700267 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700268 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800269 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700270 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800271 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900272 isLlndk(config android.Config) bool
273 isLlndkPublic(config android.Config) bool
274 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900275 isVndk() bool
276 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800277 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900278 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800279 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700280 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700281 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800282 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800283 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800284 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800285 useClangLld(actx ModuleContext) bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900286 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900287 hasStubsVariants() bool
288 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900289 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800290 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700291 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800292}
293
294type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700295 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800296 ModuleContextIntf
297}
298
299type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700300 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800301 ModuleContextIntf
302}
303
Colin Cross37047f12016-12-13 17:06:13 -0800304type DepsContext interface {
305 android.BottomUpMutatorContext
306 ModuleContextIntf
307}
308
Colin Crossca860ac2016-01-04 14:34:37 -0800309type feature interface {
310 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800311 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800312 flags(ctx ModuleContext, flags Flags) Flags
313 props() []interface{}
314}
315
316type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700317 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800318 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800319 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700320 compilerProps() []interface{}
321
Colin Cross76fada02016-07-27 10:31:13 -0700322 appendCflags([]string)
323 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700324 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800325}
326
327type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700328 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800329 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700330 linkerFlags(ctx ModuleContext, flags Flags) Flags
331 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800332 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700333
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700334 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700335 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900336 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700337
338 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900339 coverageOutputFilePath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800340}
341
342type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700343 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700344 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800345 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700346 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700347 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900348 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800349}
350
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800351type xref interface {
352 XrefCcFiles() android.Paths
353}
354
Colin Crossc99deeb2016-04-11 15:06:20 -0700355var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700356 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
357 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
358 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
359 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
360 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
361 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
362 headerDepTag = DependencyTag{Name: "header", Library: true}
363 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
364 genSourceDepTag = DependencyTag{Name: "gen source"}
365 genHeaderDepTag = DependencyTag{Name: "gen header"}
366 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
367 objDepTag = DependencyTag{Name: "obj"}
368 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
369 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
370 reuseObjTag = DependencyTag{Name: "reuse objects"}
371 staticVariantTag = DependencyTag{Name: "static variant"}
372 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
373 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
374 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
375 runtimeDepTag = DependencyTag{Name: "runtime lib"}
376 coverageDepTag = DependencyTag{Name: "coverage"}
377 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700378)
379
Roland Levillainf89cd092019-07-29 16:22:59 +0100380func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700381 ccDepTag, ok := depTag.(DependencyTag)
382 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100383}
384
385func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700386 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100387 return ok && ccDepTag == runtimeDepTag
388}
389
390func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700391 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100392 return ok && ccDepTag == testPerSrcDepTag
393}
394
Colin Crossca860ac2016-01-04 14:34:37 -0800395// Module contains the properties and members used by all C/C++ module types, and implements
396// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
397// to construct the output file. Behavior can be customized with a Customizer interface
398type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700399 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700400 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900401 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900402 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700403
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700404 Properties BaseProperties
405 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700406
Colin Crossca860ac2016-01-04 14:34:37 -0800407 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700408 hod android.HostOrDeviceSupported
409 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700410
Colin Crossca860ac2016-01-04 14:34:37 -0800411 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700412 features []feature
413 compiler compiler
414 linker linker
415 installer installer
416 stl *stl
417 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800418 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800419 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900420 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700421 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700422 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800423 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800424
425 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700426
Colin Cross635c3b02016-05-18 15:37:25 -0700427 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800428
Colin Crossb98c8b02016-07-29 13:44:28 -0700429 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700430
431 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800432
433 // Flags used to compile this module
434 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700435
436 // 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 -0800437 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700438 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800439 depsInLinkOrder android.Paths
440
441 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700442 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900443
444 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800445 // Kythe (source file indexer) paths for this compilation module
446 kytheFiles android.Paths
Colin Crossc472d572015-03-17 15:06:21 -0700447}
448
Ivan Lozano52767be2019-10-18 14:49:46 -0700449func (c *Module) Toc() android.OptionalPath {
450 if c.linker != nil {
451 if library, ok := c.linker.(libraryInterface); ok {
452 return library.toc()
453 }
454 }
455 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
456}
457
458func (c *Module) ApiLevel() string {
459 if c.linker != nil {
460 if stub, ok := c.linker.(*stubDecorator); ok {
461 return stub.properties.ApiLevel
462 }
463 }
464 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
465}
466
467func (c *Module) Static() bool {
468 if c.linker != nil {
469 if library, ok := c.linker.(libraryInterface); ok {
470 return library.static()
471 }
472 }
473 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
474}
475
476func (c *Module) Shared() bool {
477 if c.linker != nil {
478 if library, ok := c.linker.(libraryInterface); ok {
479 return library.shared()
480 }
481 }
482 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
483}
484
485func (c *Module) SelectedStl() string {
486 return c.stl.Properties.SelectedStl
487}
488
489func (c *Module) ToolchainLibrary() bool {
490 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
491 return true
492 }
493 return false
494}
495
496func (c *Module) NdkPrebuiltStl() bool {
497 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
498 return true
499 }
500 return false
501}
502
503func (c *Module) StubDecorator() bool {
504 if _, ok := c.linker.(*stubDecorator); ok {
505 return true
506 }
507 return false
508}
509
510func (c *Module) SdkVersion() string {
511 return String(c.Properties.Sdk_version)
512}
513
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800514func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700515 if c.linker != nil {
516 if library, ok := c.linker.(exportedFlagsProducer); ok {
517 return library.exportedDirs()
518 }
519 }
520 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
521}
522
523func (c *Module) HasStaticVariant() bool {
524 if c.staticVariant != nil {
525 return true
526 }
527 return false
528}
529
530func (c *Module) GetStaticVariant() LinkableInterface {
531 return c.staticVariant
532}
533
534func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
535 c.depsInLinkOrder = depsInLinkOrder
536}
537
538func (c *Module) GetDepsInLinkOrder() []android.Path {
539 return c.depsInLinkOrder
540}
541
542func (c *Module) StubsVersions() []string {
543 if c.linker != nil {
544 if library, ok := c.linker.(*libraryDecorator); ok {
545 return library.Properties.Stubs.Versions
546 }
547 }
548 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
549}
550
551func (c *Module) CcLibrary() bool {
552 if c.linker != nil {
553 if _, ok := c.linker.(*libraryDecorator); ok {
554 return true
555 }
556 }
557 return false
558}
559
560func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700561 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700562 return true
563 }
564 return false
565}
566
Ivan Lozano2b262972019-11-21 12:30:50 -0800567func (c *Module) NonCcVariants() bool {
568 return false
569}
570
Ivan Lozano183a3212019-10-18 14:18:45 -0700571func (c *Module) SetBuildStubs() {
572 if c.linker != nil {
573 if library, ok := c.linker.(*libraryDecorator); ok {
574 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700575 c.Properties.HideFromMake = true
576 c.sanitize = nil
577 c.stl = nil
578 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700579 return
580 }
581 }
582 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
583}
584
Ivan Lozano52767be2019-10-18 14:49:46 -0700585func (c *Module) BuildStubs() bool {
586 if c.linker != nil {
587 if library, ok := c.linker.(*libraryDecorator); ok {
588 return library.buildStubs()
589 }
590 }
591 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
592}
593
Ivan Lozano183a3212019-10-18 14:18:45 -0700594func (c *Module) SetStubsVersions(version string) {
595 if c.linker != nil {
596 if library, ok := c.linker.(*libraryDecorator); ok {
597 library.MutatedProperties.StubsVersion = version
598 return
599 }
600 }
601 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
602}
603
604func (c *Module) SetStatic() {
605 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700606 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700607 library.setStatic()
608 return
609 }
610 }
611 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
612}
613
614func (c *Module) SetShared() {
615 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700616 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700617 library.setShared()
618 return
619 }
620 }
621 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
622}
623
624func (c *Module) BuildStaticVariant() bool {
625 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700626 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700627 return library.buildStatic()
628 }
629 }
630 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
631}
632
633func (c *Module) BuildSharedVariant() bool {
634 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700635 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700636 return library.buildShared()
637 }
638 }
639 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
640}
641
642func (c *Module) Module() android.Module {
643 return c
644}
645
Jiyong Parkc20eee32018-09-05 22:36:17 +0900646func (c *Module) OutputFile() android.OptionalPath {
647 return c.outputFile
648}
649
Ivan Lozano183a3212019-10-18 14:18:45 -0700650var _ LinkableInterface = (*Module)(nil)
651
Jiyong Park719b4462019-01-13 00:39:51 +0900652func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900653 if c.linker != nil {
654 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900655 }
656 return nil
657}
658
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900659func (c *Module) CoverageOutputFile() android.OptionalPath {
660 if c.linker != nil {
661 return c.linker.coverageOutputFilePath()
662 }
663 return android.OptionalPath{}
664}
665
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900666func (c *Module) RelativeInstallPath() string {
667 if c.installer != nil {
668 return c.installer.relativeInstallPath()
669 }
670 return ""
671}
672
Jooyung Han344d5432019-08-23 11:17:39 +0900673func (c *Module) VndkVersion() string {
674 return c.vndkVersion()
675}
676
Colin Cross36242852017-06-23 15:06:31 -0700677func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700678 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800679 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700680 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800681 }
682 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700683 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800684 }
685 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700686 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800687 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700688 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700689 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700690 }
Colin Cross16b23492016-01-06 14:41:07 -0800691 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700692 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800693 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800694 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700695 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800696 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800697 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700698 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800699 }
Justin Yun8effde42017-06-23 19:24:43 +0900700 if c.vndkdep != nil {
701 c.AddProperties(c.vndkdep.props()...)
702 }
Stephen Craneba090d12017-05-09 15:44:35 -0700703 if c.lto != nil {
704 c.AddProperties(c.lto.props()...)
705 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700706 if c.pgo != nil {
707 c.AddProperties(c.pgo.props()...)
708 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800709 if c.xom != nil {
710 c.AddProperties(c.xom.props()...)
711 }
Colin Crossca860ac2016-01-04 14:34:37 -0800712 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700713 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800714 }
Colin Crossc472d572015-03-17 15:06:21 -0700715
Colin Crossa9d8bee2018-10-02 13:59:46 -0700716 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
717 switch class {
718 case android.Device:
719 return ctx.Config().DevicePrefer32BitExecutables()
720 case android.HostCross:
721 // Windows builds always prefer 32-bit
722 return true
723 default:
724 return false
725 }
726 })
Colin Cross36242852017-06-23 15:06:31 -0700727 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900728 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900729 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900730 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900731
Colin Cross36242852017-06-23 15:06:31 -0700732 return c
Colin Crossc472d572015-03-17 15:06:21 -0700733}
734
Colin Crossb916a382016-07-29 17:28:03 -0700735// Returns true for dependency roots (binaries)
736// TODO(ccross): also handle dlopenable libraries
737func (c *Module) isDependencyRoot() bool {
738 if root, ok := c.linker.(interface {
739 isDependencyRoot() bool
740 }); ok {
741 return root.isDependencyRoot()
742 }
743 return false
744}
745
Ivan Lozano52767be2019-10-18 14:49:46 -0700746func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900747 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700748}
749
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800750func (c *Module) isCoverageVariant() bool {
751 return c.coverage.Properties.IsCoverageVariant
752}
753
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800754func (c *Module) isNdk() bool {
755 return inList(c.Name(), ndkMigratedLibs)
756}
757
Inseob Kim9516ee92019-05-09 10:56:13 +0900758func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800759 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900760 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800761}
762
Inseob Kim9516ee92019-05-09 10:56:13 +0900763func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800764 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900765 name := c.BaseModuleName()
766 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800767}
768
Inseob Kim9516ee92019-05-09 10:56:13 +0900769func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800770 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900771 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800772}
773
Ivan Lozano52767be2019-10-18 14:49:46 -0700774func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800775 if vndkdep := c.vndkdep; vndkdep != nil {
776 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900777 }
778 return false
779}
780
Jooyung Han76106d92019-05-20 18:49:10 +0900781func (c *Module) vndkVersion() string {
Inseob Kim64c43952019-08-26 16:52:35 +0900782 return c.Properties.VndkVersion
Jooyung Han76106d92019-05-20 18:49:10 +0900783}
784
Yi Kong7e53c572018-02-14 18:16:12 +0800785func (c *Module) isPgoCompile() bool {
786 if pgo := c.pgo; pgo != nil {
787 return pgo.Properties.PgoCompile
788 }
789 return false
790}
791
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800792func (c *Module) isNDKStubLibrary() bool {
793 if _, ok := c.compiler.(*stubDecorator); ok {
794 return true
795 }
796 return false
797}
798
Logan Chienf3511742017-10-31 18:04:35 +0800799func (c *Module) isVndkSp() bool {
800 if vndkdep := c.vndkdep; vndkdep != nil {
801 return vndkdep.isVndkSp()
802 }
803 return false
804}
805
806func (c *Module) isVndkExt() bool {
807 if vndkdep := c.vndkdep; vndkdep != nil {
808 return vndkdep.isVndkExt()
809 }
810 return false
811}
812
Ivan Lozano52767be2019-10-18 14:49:46 -0700813func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900814 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800815}
816
Logan Chienf3511742017-10-31 18:04:35 +0800817func (c *Module) getVndkExtendsModuleName() string {
818 if vndkdep := c.vndkdep; vndkdep != nil {
819 return vndkdep.getVndkExtendsModuleName()
820 }
821 return ""
822}
823
Jiyong Park82e2bf32017-08-16 14:05:54 +0900824// Returns true only when this module is configured to have core and vendor
825// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700826func (c *Module) HasVendorVariant() bool {
827 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900828}
829
Ivan Lozano52767be2019-10-18 14:49:46 -0700830func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800831 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900832}
833
Ivan Lozano52767be2019-10-18 14:49:46 -0700834func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900835 return c.ModuleBase.InstallInRecovery()
836}
837
Jiyong Park25fc6a92018-11-18 18:02:45 +0900838func (c *Module) IsStubs() bool {
839 if library, ok := c.linker.(*libraryDecorator); ok {
840 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900841 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
842 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900843 }
844 return false
845}
846
847func (c *Module) HasStubsVariants() bool {
848 if library, ok := c.linker.(*libraryDecorator); ok {
849 return len(library.Properties.Stubs.Versions) > 0
850 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700851 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
852 return len(library.Properties.Stubs.Versions) > 0
853 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900854 return false
855}
856
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900857func (c *Module) bootstrap() bool {
858 return Bool(c.Properties.Bootstrap)
859}
860
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700861func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700862 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
863 if c.Target().NativeBridge == android.NativeBridgeEnabled {
864 return false
865 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700866 return c.linker != nil && c.linker.nativeCoverage()
867}
868
Jiyong Park73c54ee2019-10-22 20:31:18 +0900869func (c *Module) ExportedIncludeDirs() android.Paths {
870 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
871 return flagsProducer.exportedDirs()
872 }
Jiyong Park232e7852019-11-04 12:23:40 +0900873 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900874}
875
876func (c *Module) ExportedSystemIncludeDirs() android.Paths {
877 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
878 return flagsProducer.exportedSystemDirs()
879 }
Jiyong Park232e7852019-11-04 12:23:40 +0900880 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900881}
882
883func (c *Module) ExportedFlags() []string {
884 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
885 return flagsProducer.exportedFlags()
886 }
Jiyong Park232e7852019-11-04 12:23:40 +0900887 return nil
888}
889
890func (c *Module) ExportedDeps() android.Paths {
891 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
892 return flagsProducer.exportedDeps()
893 }
894 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900895}
896
Jiyong Parkf1194352019-02-25 11:05:47 +0900897func isBionic(name string) bool {
898 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +0000899 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +0900900 return true
901 }
902 return false
903}
904
Martin Stjernholm279de572019-09-10 23:18:20 +0100905func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700906 if name == "libclang_rt.hwasan-aarch64-android" {
907 return inList("hwaddress", config.SanitizeDevice())
908 }
909 return isBionic(name)
910}
911
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800912func (c *Module) XrefCcFiles() android.Paths {
913 return c.kytheFiles
914}
915
Colin Crossca860ac2016-01-04 14:34:37 -0800916type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700917 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800918 moduleContextImpl
919}
920
Colin Cross37047f12016-12-13 17:06:13 -0800921type depsContext struct {
922 android.BottomUpMutatorContext
923 moduleContextImpl
924}
925
Colin Crossca860ac2016-01-04 14:34:37 -0800926type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700927 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800928 moduleContextImpl
929}
930
Jiyong Park2db76922017-11-08 16:03:48 +0900931func (ctx *moduleContext) SocSpecific() bool {
932 return ctx.ModuleContext.SocSpecific() ||
Ivan Lozano52767be2019-10-18 14:49:46 -0700933 (ctx.mod.HasVendorVariant() && ctx.mod.UseVndk() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700934}
935
Colin Crossca860ac2016-01-04 14:34:37 -0800936type moduleContextImpl struct {
937 mod *Module
938 ctx BaseModuleContext
939}
940
Colin Crossb98c8b02016-07-29 13:44:28 -0700941func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800942 return ctx.mod.toolchain(ctx.ctx)
943}
944
945func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000946 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800947}
948
949func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900950 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800951}
952
Jiyong Park1d1119f2019-07-29 21:27:18 +0900953func (ctx *moduleContextImpl) header() bool {
954 return ctx.mod.header()
955}
956
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700957func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800958 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800959 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700960 }
961 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800962}
963
964func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700965 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700966 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900967 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700968 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900969 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
970 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
971 return "current"
972 }
973 return platform_vndk_ver
974 }
975 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800976 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900977 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700978 }
979 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800980}
981
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700982func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700983 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700984}
Justin Yun8effde42017-06-23 19:24:43 +0900985
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800986func (ctx *moduleContextImpl) isNdk() bool {
987 return ctx.mod.isNdk()
988}
989
Inseob Kim9516ee92019-05-09 10:56:13 +0900990func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
991 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800992}
993
Inseob Kim9516ee92019-05-09 10:56:13 +0900994func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
995 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800996}
997
Inseob Kim9516ee92019-05-09 10:56:13 +0900998func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
999 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001000}
1001
Logan Chienf3511742017-10-31 18:04:35 +08001002func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001003 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001004}
1005
Yi Kong7e53c572018-02-14 18:16:12 +08001006func (ctx *moduleContextImpl) isPgoCompile() bool {
1007 return ctx.mod.isPgoCompile()
1008}
1009
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001010func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1011 return ctx.mod.isNDKStubLibrary()
1012}
1013
Justin Yun8effde42017-06-23 19:24:43 +09001014func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001015 return ctx.mod.isVndkSp()
1016}
1017
1018func (ctx *moduleContextImpl) isVndkExt() bool {
1019 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001020}
1021
Vic Yangefd249e2018-11-12 20:19:56 -08001022func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001023 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001024}
1025
Jiyong Parkf9332f12018-02-01 00:54:12 +09001026func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001027 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001028}
1029
Logan Chien2f2b8902018-07-10 15:01:19 +08001030// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001031func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001032 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1033 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001034 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001035
1036 if ctx.ctx.Fuchsia() {
1037 return false
1038 }
1039
Logan Chien2f2b8902018-07-10 15:01:19 +08001040 if sanitize := ctx.mod.sanitize; sanitize != nil {
1041 if !sanitize.isVariantOnProductionDevice() {
1042 return false
1043 }
1044 }
1045 if !ctx.ctx.Device() {
1046 // Host modules do not need ABI dumps.
1047 return false
1048 }
Logan Chienfa478c02018-12-28 16:25:39 +08001049 if !ctx.mod.IsForPlatform() {
1050 // APEX variants do not need ABI dumps.
1051 return false
1052 }
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001053 if ctx.isStubs() {
1054 // Stubs do not need ABI dumps.
1055 return false
1056 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001057 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001058}
1059
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001060func (ctx *moduleContextImpl) selectedStl() string {
1061 if stl := ctx.mod.stl; stl != nil {
1062 return stl.Properties.SelectedStl
1063 }
1064 return ""
1065}
1066
Ivan Lozanobd721262018-11-27 14:33:03 -08001067func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1068 return ctx.mod.linker.useClangLld(actx)
1069}
1070
Colin Crossce75d2c2016-10-06 16:12:58 -07001071func (ctx *moduleContextImpl) baseModuleName() string {
1072 return ctx.mod.ModuleBase.BaseModuleName()
1073}
1074
Logan Chienf3511742017-10-31 18:04:35 +08001075func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1076 return ctx.mod.getVndkExtendsModuleName()
1077}
1078
Jiyong Park58e364a2019-01-19 19:24:06 +09001079func (ctx *moduleContextImpl) apexName() string {
1080 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001081}
1082
Jiyong Parkb0788572018-12-20 22:10:17 +09001083func (ctx *moduleContextImpl) hasStubsVariants() bool {
1084 return ctx.mod.HasStubsVariants()
1085}
1086
1087func (ctx *moduleContextImpl) isStubs() bool {
1088 return ctx.mod.IsStubs()
1089}
1090
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001091func (ctx *moduleContextImpl) bootstrap() bool {
1092 return ctx.mod.bootstrap()
1093}
1094
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001095func (ctx *moduleContextImpl) nativeCoverage() bool {
1096 return ctx.mod.nativeCoverage()
1097}
1098
Colin Cross635c3b02016-05-18 15:37:25 -07001099func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001100 return &Module{
1101 hod: hod,
1102 multilib: multilib,
1103 }
1104}
1105
Colin Cross635c3b02016-05-18 15:37:25 -07001106func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001107 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001108 module.features = []feature{
1109 &tidyFeature{},
1110 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001111 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001112 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001113 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001114 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001115 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001116 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001117 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -08001118 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -08001119 return module
1120}
1121
Colin Crossce75d2c2016-10-06 16:12:58 -07001122func (c *Module) Prebuilt() *android.Prebuilt {
1123 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1124 return p.prebuilt()
1125 }
1126 return nil
1127}
1128
1129func (c *Module) Name() string {
1130 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001131 if p, ok := c.linker.(interface {
1132 Name(string) string
1133 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001134 name = p.Name(name)
1135 }
1136 return name
1137}
1138
Alex Light3d673592019-01-18 14:37:31 -08001139func (c *Module) Symlinks() []string {
1140 if p, ok := c.installer.(interface {
1141 symlinkList() []string
1142 }); ok {
1143 return p.symlinkList()
1144 }
1145 return nil
1146}
1147
Jeff Gaston294356f2017-09-27 17:05:30 -07001148// orderDeps reorders dependencies into a list such that if module A depends on B, then
1149// A will precede B in the resultant list.
1150// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001151// Note that directSharedDeps should be the analogous static library for each shared lib dep
1152func 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 -07001153 // If A depends on B, then
1154 // Every list containing A will also contain B later in the list
1155 // So, after concatenating all lists, the final instance of B will have come from the same
1156 // original list as the final instance of A
1157 // So, the final instance of B will be later in the concatenation than the final A
1158 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1159 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001160 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001161 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001162 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1163 }
1164 for _, dep := range directSharedDeps {
1165 orderedAllDeps = append(orderedAllDeps, dep)
1166 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001167 }
1168
Colin Crossb6715442017-10-24 11:13:31 -07001169 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001170
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001171 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001172 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001173 // resultant list to only what the caller has chosen to include in directStaticDeps
1174 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001175
1176 return orderedAllDeps, orderedDeclaredDeps
1177}
1178
Ivan Lozano183a3212019-10-18 14:18:45 -07001179func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001180 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001181 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001182 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1183 staticDepFiles := []android.Path{}
1184 for _, dep := range staticDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001185 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1186 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
Jeff Gaston294356f2017-09-27 17:05:30 -07001187 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001188 sharedDepFiles := []android.Path{}
1189 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001190 if sharedDep.HasStaticVariant() {
1191 staticAnalogue := sharedDep.GetStaticVariant()
1192 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1193 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001194 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001195 }
1196
1197 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001198 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1199 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001200
1201 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001202}
1203
Roland Levillainf89cd092019-07-29 16:22:59 +01001204func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1205 test, ok := c.linker.(testPerSrc)
1206 return ok && test.isAllTestsVariation()
1207}
1208
Colin Cross635c3b02016-05-18 15:37:25 -07001209func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001210 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001211 //
1212 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1213 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1214 // module and return early, as this module does not produce an output file per se.
1215 if c.IsTestPerSrcAllTestsVariation() {
1216 c.outputFile = android.OptionalPath{}
1217 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001218 }
1219
Jooyung Han38002912019-05-16 04:01:54 +09001220 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001221
Inseob Kim64c43952019-08-26 16:52:35 +09001222 c.Properties.SubName = ""
1223
1224 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1225 c.Properties.SubName += nativeBridgeSuffix
1226 }
1227
1228 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
1229 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1230 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1231 c.Properties.SubName += vendorSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001232 } else if _, ok := c.linker.(*llndkStubDecorator); ok || (c.UseVndk() && c.HasVendorVariant()) {
Inseob Kim64c43952019-08-26 16:52:35 +09001233 // .vendor.{version} suffix is added only when we will have two variants: core and vendor.
1234 // The suffix is not added for vendor-only module.
1235 c.Properties.SubName += vendorSuffix
1236 vendorVersion := actx.DeviceConfig().VndkVersion()
1237 if vendorVersion == "current" {
1238 vendorVersion = actx.DeviceConfig().PlatformVndkVersion()
1239 }
1240 if c.Properties.VndkVersion != vendorVersion {
1241 c.Properties.SubName += "." + c.Properties.VndkVersion
1242 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001243 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001244 c.Properties.SubName += recoverySuffix
1245 }
1246
Colin Crossca860ac2016-01-04 14:34:37 -08001247 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001248 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001249 moduleContextImpl: moduleContextImpl{
1250 mod: c,
1251 },
1252 }
1253 ctx.ctx = ctx
1254
Colin Crossf18e1102017-11-16 14:33:08 -08001255 deps := c.depsToPaths(ctx)
1256 if ctx.Failed() {
1257 return
1258 }
1259
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001260 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1261 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1262 }
1263
Colin Crossca860ac2016-01-04 14:34:37 -08001264 flags := Flags{
1265 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001266 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001267 }
Colin Crossca860ac2016-01-04 14:34:37 -08001268 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001269 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001270 }
1271 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001272 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001273 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001274 if c.stl != nil {
1275 flags = c.stl.flags(ctx, flags)
1276 }
Colin Cross16b23492016-01-06 14:41:07 -08001277 if c.sanitize != nil {
1278 flags = c.sanitize.flags(ctx, flags)
1279 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001280 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001281 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001282 }
Stephen Craneba090d12017-05-09 15:44:35 -07001283 if c.lto != nil {
1284 flags = c.lto.flags(ctx, flags)
1285 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001286 if c.pgo != nil {
1287 flags = c.pgo.flags(ctx, flags)
1288 }
Ivan Lozano074ec482018-11-21 08:59:37 -08001289 if c.xom != nil {
1290 flags = c.xom.flags(ctx, flags)
1291 }
Colin Crossca860ac2016-01-04 14:34:37 -08001292 for _, feature := range c.features {
1293 flags = feature.flags(ctx, flags)
1294 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001295 if ctx.Failed() {
1296 return
1297 }
1298
Colin Cross4af21ed2019-11-04 09:37:55 -08001299 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1300 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1301 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001302
Colin Cross4af21ed2019-11-04 09:37:55 -08001303 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001304
1305 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001306 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001307 }
1308 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001309 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001310 }
1311
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001312 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001313 // We need access to all the flags seen by a source file.
1314 if c.sabi != nil {
1315 flags = c.sabi.flags(ctx, flags)
1316 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001317
Colin Cross4af21ed2019-11-04 09:37:55 -08001318 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001319
Colin Crossca860ac2016-01-04 14:34:37 -08001320 // Optimization to reduce size of build.ninja
1321 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001322 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1323 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1324 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1325 flags.Local.CFlags = []string{"$cflags"}
1326 flags.Local.CppFlags = []string{"$cppflags"}
1327 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001328
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001329 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001330 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001331 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001332 if ctx.Failed() {
1333 return
1334 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001335 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001336 }
1337
Colin Crossca860ac2016-01-04 14:34:37 -08001338 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001339 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001340 if ctx.Failed() {
1341 return
1342 }
Colin Cross635c3b02016-05-18 15:37:25 -07001343 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001344
1345 // If a lib is directly included in any of the APEXes, unhide the stubs
1346 // variant having the latest version gets visible to make. In addition,
1347 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1348 // force anything in the make world to link against the stubs library.
1349 // (unless it is explicitly referenced via .bootstrap suffix or the
1350 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001351 if c.HasStubsVariants() &&
1352 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001353 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001354 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001355 c.Properties.HideFromMake = false // unhide
1356 // Note: this is still non-installable
1357 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001358 }
Colin Cross5049f022015-03-18 13:28:46 -07001359
Inseob Kim1f086e22019-05-09 13:29:15 +09001360 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001361 c.installer.install(ctx, c.outputFile.Path())
1362 if ctx.Failed() {
1363 return
Colin Crossca860ac2016-01-04 14:34:37 -08001364 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001365 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001366}
1367
Colin Cross0ea8ba82019-06-06 14:33:29 -07001368func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001369 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001370 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001371 }
Colin Crossca860ac2016-01-04 14:34:37 -08001372 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001373}
1374
Colin Crossca860ac2016-01-04 14:34:37 -08001375func (c *Module) begin(ctx BaseModuleContext) {
1376 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001377 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001378 }
Colin Crossca860ac2016-01-04 14:34:37 -08001379 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001380 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001381 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001382 if c.stl != nil {
1383 c.stl.begin(ctx)
1384 }
Colin Cross16b23492016-01-06 14:41:07 -08001385 if c.sanitize != nil {
1386 c.sanitize.begin(ctx)
1387 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001388 if c.coverage != nil {
1389 c.coverage.begin(ctx)
1390 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001391 if c.sabi != nil {
1392 c.sabi.begin(ctx)
1393 }
Justin Yun8effde42017-06-23 19:24:43 +09001394 if c.vndkdep != nil {
1395 c.vndkdep.begin(ctx)
1396 }
Stephen Craneba090d12017-05-09 15:44:35 -07001397 if c.lto != nil {
1398 c.lto.begin(ctx)
1399 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001400 if c.pgo != nil {
1401 c.pgo.begin(ctx)
1402 }
Colin Crossca860ac2016-01-04 14:34:37 -08001403 for _, feature := range c.features {
1404 feature.begin(ctx)
1405 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001406 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001407 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001408 if err != nil {
1409 ctx.PropertyErrorf("sdk_version", err.Error())
1410 }
Nan Zhang0007d812017-11-07 10:57:05 -08001411 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001412 }
Colin Crossca860ac2016-01-04 14:34:37 -08001413}
1414
Colin Cross37047f12016-12-13 17:06:13 -08001415func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001416 deps := Deps{}
1417
1418 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001419 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001420 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001421 // Add the PGO dependency (the clang_rt.profile runtime library), which
1422 // sometimes depends on symbols from libgcc, before libgcc gets added
1423 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001424 if c.pgo != nil {
1425 deps = c.pgo.deps(ctx, deps)
1426 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001427 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001428 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001429 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001430 if c.stl != nil {
1431 deps = c.stl.deps(ctx, deps)
1432 }
Colin Cross16b23492016-01-06 14:41:07 -08001433 if c.sanitize != nil {
1434 deps = c.sanitize.deps(ctx, deps)
1435 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001436 if c.coverage != nil {
1437 deps = c.coverage.deps(ctx, deps)
1438 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001439 if c.sabi != nil {
1440 deps = c.sabi.deps(ctx, deps)
1441 }
Justin Yun8effde42017-06-23 19:24:43 +09001442 if c.vndkdep != nil {
1443 deps = c.vndkdep.deps(ctx, deps)
1444 }
Stephen Craneba090d12017-05-09 15:44:35 -07001445 if c.lto != nil {
1446 deps = c.lto.deps(ctx, deps)
1447 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001448 for _, feature := range c.features {
1449 deps = feature.deps(ctx, deps)
1450 }
1451
Colin Crossb6715442017-10-24 11:13:31 -07001452 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1453 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1454 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1455 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1456 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1457 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001458 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001459
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001460 for _, lib := range deps.ReexportSharedLibHeaders {
1461 if !inList(lib, deps.SharedLibs) {
1462 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1463 }
1464 }
1465
1466 for _, lib := range deps.ReexportStaticLibHeaders {
1467 if !inList(lib, deps.StaticLibs) {
1468 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1469 }
1470 }
1471
Colin Cross5950f382016-12-13 12:50:57 -08001472 for _, lib := range deps.ReexportHeaderLibHeaders {
1473 if !inList(lib, deps.HeaderLibs) {
1474 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1475 }
1476 }
1477
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001478 for _, gen := range deps.ReexportGeneratedHeaders {
1479 if !inList(gen, deps.GeneratedHeaders) {
1480 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1481 }
1482 }
1483
Colin Crossc99deeb2016-04-11 15:06:20 -07001484 return deps
1485}
1486
Dan Albert7e9d2952016-08-04 13:02:36 -07001487func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001488 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001489 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001490 moduleContextImpl: moduleContextImpl{
1491 mod: c,
1492 },
1493 }
1494 ctx.ctx = ctx
1495
Colin Crossca860ac2016-01-04 14:34:37 -08001496 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001497}
1498
Jiyong Park7ed9de32018-10-15 22:25:07 +09001499// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001500func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001501 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1502 version := name[sharp+1:]
1503 libname := name[:sharp]
1504 return libname, version
1505 }
1506 return name, ""
1507}
1508
Colin Cross1e676be2016-10-12 14:38:15 -07001509func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001510 ctx := &depsContext{
1511 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001512 moduleContextImpl: moduleContextImpl{
1513 mod: c,
1514 },
1515 }
1516 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001517
Colin Crossc99deeb2016-04-11 15:06:20 -07001518 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001519
Dan Albert914449f2016-06-17 16:45:24 -07001520 variantNdkLibs := []string{}
1521 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001522 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001523 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001524
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001525 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1526 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001527 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001528 // 1. Name of an NDK library that refers to a prebuilt module.
1529 // For each of these, it adds the name of the prebuilt module (which will be in
1530 // prebuilts/ndk) to the list of nonvariant libs.
1531 // 2. Name of an NDK library that refers to an ndk_library module.
1532 // For each of these, it adds the name of the ndk_library module to the list of
1533 // variant libs.
1534 // 3. Anything else (so anything that isn't an NDK library).
1535 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001536 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001537 // The caller can then know to add the variantLibs dependencies differently from the
1538 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001539
Inseob Kim9516ee92019-05-09 10:56:13 +09001540 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001541 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1542 variantLibs = []string{}
1543 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001544 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001545 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001546 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001547 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1548 if !inList(name, ndkMigratedLibs) {
1549 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001550 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001551 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001552 }
Jooyung Han0302a842019-10-30 18:43:49 +09001553 } else if ctx.useVndk() && isLlndkLibrary(name, ctx.Config()) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001554 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001555 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001556 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001557 if actx.OtherModuleExists(vendorPublicLib) {
1558 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1559 } else {
1560 // This can happen if vendor_public_library module is defined in a
1561 // namespace that isn't visible to the current module. In that case,
1562 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001563 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001564 }
Dan Albert914449f2016-06-17 16:45:24 -07001565 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001566 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001567 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001568 }
1569 }
Dan Albert914449f2016-06-17 16:45:24 -07001570 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001571 }
1572
Dan Albert914449f2016-06-17 16:45:24 -07001573 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1574 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001575 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001576 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001577
Jiyong Park7e636d02019-01-28 16:16:54 +09001578 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001579 if c.linker != nil {
1580 if library, ok := c.linker.(*libraryDecorator); ok {
1581 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001582 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001583 }
1584 }
1585 }
1586
Colin Cross32ec36c2016-12-15 07:39:51 -08001587 for _, lib := range deps.HeaderLibs {
1588 depTag := headerDepTag
1589 if inList(lib, deps.ReexportHeaderLibHeaders) {
1590 depTag = headerExportDepTag
1591 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001592 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001593 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001594 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001595 } else {
1596 actx.AddVariationDependencies(nil, depTag, lib)
1597 }
1598 }
1599
1600 if buildStubs {
1601 // Stubs lib does not have dependency to other static/shared libraries.
1602 // Don't proceed.
1603 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001604 }
Colin Cross5950f382016-12-13 12:50:57 -08001605
Inseob Kimc0907f12019-02-08 21:00:45 +09001606 syspropImplLibraries := syspropImplLibraries(actx.Config())
1607
Jiyong Park5d1598f2019-02-25 22:14:17 +09001608 for _, lib := range deps.WholeStaticLibs {
1609 depTag := wholeStaticDepTag
1610 if impl, ok := syspropImplLibraries[lib]; ok {
1611 lib = impl
1612 }
1613 actx.AddVariationDependencies([]blueprint.Variation{
1614 {Mutator: "link", Variation: "static"},
1615 }, depTag, lib)
1616 }
1617
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001618 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001619 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001620 if inList(lib, deps.ReexportStaticLibHeaders) {
1621 depTag = staticExportDepTag
1622 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001623
1624 if impl, ok := syspropImplLibraries[lib]; ok {
1625 lib = impl
1626 }
1627
Dan Willemsen59339a22018-07-22 21:18:45 -07001628 actx.AddVariationDependencies([]blueprint.Variation{
1629 {Mutator: "link", Variation: "static"},
1630 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001631 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001632
Dan Willemsen59339a22018-07-22 21:18:45 -07001633 actx.AddVariationDependencies([]blueprint.Variation{
1634 {Mutator: "link", Variation: "static"},
1635 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001636
Ivan Lozano183a3212019-10-18 14:18:45 -07001637 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001638 var variations []blueprint.Variation
1639 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Ivan Lozano52767be2019-10-18 14:49:46 -07001640 versionVariantAvail := !ctx.useVndk() && !c.InRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001641 if version != "" && versionVariantAvail {
1642 // Version is explicitly specified. i.e. libFoo#30
1643 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001644 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001645 }
1646 actx.AddVariationDependencies(variations, depTag, name)
1647
1648 // If the version is not specified, add dependency to the latest stubs library.
1649 // The stubs library will be used when the depending module is built for APEX and
1650 // the dependent module is not in the same APEX.
Jiyong Park73c54ee2019-10-22 20:31:18 +09001651 latestVersion := LatestStubsVersionFor(actx.Config(), name)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001652 if version == "" && latestVersion != "" && versionVariantAvail {
1653 actx.AddVariationDependencies([]blueprint.Variation{
1654 {Mutator: "link", Variation: "shared"},
1655 {Mutator: "version", Variation: latestVersion},
1656 }, depTag, name)
Ivan Lozano183a3212019-10-18 14:18:45 -07001657 // Note that depTag.ExplicitlyVersioned is false in this case.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001658 }
1659 }
1660
Jiyong Park7ed9de32018-10-15 22:25:07 +09001661 // shared lib names without the #version suffix
1662 var sharedLibNames []string
1663
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001664 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001665 depTag := SharedDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001666 if inList(lib, deps.ReexportSharedLibHeaders) {
1667 depTag = sharedExportDepTag
1668 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001669
1670 if impl, ok := syspropImplLibraries[lib]; ok {
1671 lib = impl
1672 }
1673
Jiyong Park73c54ee2019-10-22 20:31:18 +09001674 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001675 sharedLibNames = append(sharedLibNames, name)
1676
Jiyong Park25fc6a92018-11-18 18:02:45 +09001677 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001678 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001679
Jiyong Park7ed9de32018-10-15 22:25:07 +09001680 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001681 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001682 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1683 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1684 // linking against both the stubs lib and the non-stubs lib at the same time.
1685 continue
1686 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001687 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001688 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001689
Dan Willemsen59339a22018-07-22 21:18:45 -07001690 actx.AddVariationDependencies([]blueprint.Variation{
1691 {Mutator: "link", Variation: "shared"},
1692 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001693
Colin Cross68861832016-07-08 10:41:41 -07001694 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001695
1696 for _, gen := range deps.GeneratedHeaders {
1697 depTag := genHeaderDepTag
1698 if inList(gen, deps.ReexportGeneratedHeaders) {
1699 depTag = genHeaderExportDepTag
1700 }
1701 actx.AddDependency(c, depTag, gen)
1702 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001703
Colin Cross42d48b72018-08-29 14:10:52 -07001704 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001705
1706 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001707 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001708 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001709 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001710 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001711 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001712 if deps.LinkerFlagsFile != "" {
1713 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1714 }
1715 if deps.DynamicLinker != "" {
1716 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001717 }
Dan Albert914449f2016-06-17 16:45:24 -07001718
1719 version := ctx.sdkVersion()
1720 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001721 {Mutator: "ndk_api", Variation: version},
1722 {Mutator: "link", Variation: "shared"},
1723 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001724 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001725 {Mutator: "ndk_api", Variation: version},
1726 {Mutator: "link", Variation: "shared"},
1727 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001728
1729 if vndkdep := c.vndkdep; vndkdep != nil {
1730 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08001731 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08001732 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07001733 {Mutator: "link", Variation: "shared"},
1734 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001735 }
1736 }
Colin Cross6362e272015-10-29 15:25:03 -07001737}
Colin Cross21b9a242015-03-24 14:15:58 -07001738
Colin Crosse40b4ea2018-10-02 22:25:58 -07001739func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001740 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1741 c.beginMutator(ctx)
1742 }
1743}
1744
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001745// Whether a module can link to another module, taking into
1746// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07001747func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
1748 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001749 // Host code is not restricted
1750 return
1751 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001752
1753 // VNDK is cc.Module supported only for now.
1754 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001755 // Though vendor code is limited by the vendor mutator,
1756 // each vendor-available module needs to check
1757 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07001758 if ccTo, ok := to.(*Module); ok {
1759 if ccFrom.vndkdep != nil {
1760 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
1761 }
1762 } else {
1763 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001764 }
1765 return
1766 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001767 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001768 // Platform code can link to anything
1769 return
1770 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001771 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09001772 // Recovery code is not NDK
1773 return
1774 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001775 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001776 // These are always allowed
1777 return
1778 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001779 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001780 // These are allowed, but they don't set sdk_version
1781 return
1782 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001783 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001784 // These aren't real libraries, but are the stub shared libraries that are included in
1785 // the NDK.
1786 return
1787 }
Logan Chien834b9a62019-01-14 15:39:03 +08001788
Ivan Lozano52767be2019-10-18 14:49:46 -07001789 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08001790 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1791 // to link to libc++ (non-NDK and without sdk_version).
1792 return
1793 }
1794
Ivan Lozano52767be2019-10-18 14:49:46 -07001795 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001796 // NDK code linking to platform code is never okay.
1797 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001798 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001799 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001800 }
1801
1802 // At this point we know we have two NDK libraries, but we need to
1803 // check that we're not linking against anything built against a higher
1804 // API level, as it is only valid to link against older or equivalent
1805 // APIs.
1806
Inseob Kim01a28722018-04-11 09:48:45 +09001807 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07001808 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001809 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07001810 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001811 // Current can't be linked against by anything else.
1812 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001813 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09001814 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07001815 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001816 if err != nil {
1817 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001818 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001819 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001820 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001821 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001822 if err != nil {
1823 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001824 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001825 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001826 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001827
Inseob Kim01a28722018-04-11 09:48:45 +09001828 if toApi > fromApi {
1829 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001830 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001831 }
1832 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001833 }
Dan Albert202fe492017-12-15 13:56:59 -08001834
1835 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07001836 fromStl := from.SelectedStl()
1837 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08001838 if fromStl == "" || toStl == "" {
1839 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001840 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001841 // We can be permissive with the system "STL" since it is only the C++
1842 // ABI layer, but in the future we should make sure that everyone is
1843 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001844 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001845 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001846 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
1847 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08001848 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001849}
1850
Jiyong Park5fb8c102018-04-09 12:03:06 +09001851// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001852// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1853// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001854// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001855func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
1856 check := func(child, parent android.Module) bool {
1857 to, ok := child.(*Module)
1858 if !ok {
1859 // follow thru cc.Defaults, etc.
1860 return true
1861 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001862
Jooyung Hana70f0672019-01-18 15:20:43 +09001863 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1864 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001865 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001866
1867 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07001868 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09001869 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001870 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001871
Jooyung Han0302a842019-10-30 18:43:49 +09001872 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001873 return false
1874 }
1875
1876 var stringPath []string
1877 for _, m := range ctx.GetWalkPath() {
1878 stringPath = append(stringPath, m.Name())
1879 }
1880 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1881 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1882 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1883 return false
1884 }
1885 if module, ok := ctx.Module().(*Module); ok {
1886 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09001887 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001888 ctx.WalkDeps(check)
1889 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001890 }
1891 }
1892}
1893
Colin Crossc99deeb2016-04-11 15:06:20 -07001894// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001895func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001896 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001897
Ivan Lozano183a3212019-10-18 14:18:45 -07001898 directStaticDeps := []LinkableInterface{}
1899 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001900
Inseob Kim9516ee92019-05-09 10:56:13 +09001901 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
1902
Inseob Kim69378442019-06-03 19:10:47 +09001903 reexportExporter := func(exporter exportedFlagsProducer) {
1904 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
1905 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
1906 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
1907 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
1908 }
1909
Colin Crossd11fcda2017-10-23 17:59:01 -07001910 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001911 depName := ctx.OtherModuleName(dep)
1912 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001913
Ivan Lozano52767be2019-10-18 14:49:46 -07001914 ccDep, ok := dep.(LinkableInterface)
1915 if !ok {
1916
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001917 // handling for a few module types that aren't cc Module but that are also supported
1918 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001919 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001920 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001921 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1922 genRule.GeneratedSourceFiles()...)
1923 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001924 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001925 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001926 // Support exported headers from a generated_sources dependency
1927 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001928 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001929 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001930 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001931 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09001932 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09001933 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001934 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09001935 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
1936 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001937 // 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 +09001938 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001939
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001940 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001941 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001942 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001943 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001944 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001945 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001946 files := genRule.GeneratedSourceFiles()
1947 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001948 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001949 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001950 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 -07001951 }
1952 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001953 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001954 }
Colin Crossca860ac2016-01-04 14:34:37 -08001955 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001956 return
1957 }
1958
Colin Crossfe17f6f2019-03-28 19:30:56 -07001959 if depTag == android.ProtoPluginDepTag {
1960 return
1961 }
1962
Colin Crossd11fcda2017-10-23 17:59:01 -07001963 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001964 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1965 return
1966 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001967 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001968 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001969 return
1970 }
1971
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001972 // re-exporting flags
1973 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07001974 // reusing objects only make sense for cc.Modules.
1975 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001976 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07001977 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001978 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09001979 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08001980 return
1981 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001982 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001983
Jiyong Parke4bb9862019-02-01 00:31:10 +09001984 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07001985 // staticVariants are a cc.Module specific concept.
1986 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09001987 c.staticVariant = ccDep
1988 return
1989 }
1990 }
1991
Ivan Lozano183a3212019-10-18 14:18:45 -07001992 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
1993 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
1994 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001995 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07001996 if t, ok := depTag.(DependencyTag); ok {
1997 explicitlyVersioned = t.ExplicitlyVersioned
1998 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09001999 depTag = t
2000 }
2001
Ivan Lozano183a3212019-10-18 14:18:45 -07002002 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002003 depIsStatic := false
2004 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002005 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002006 depIsStatic = true
2007 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002008 if ccDep.CcLibrary() && !depIsStatic {
2009 depIsStubs := ccDep.BuildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09002010 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002011 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002012 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002013
2014 var useThisDep bool
2015 if depIsStubs && explicitlyVersioned {
2016 // Always respect dependency to the versioned stubs (i.e. libX#10)
2017 useThisDep = true
2018 } else if !depHasStubs {
2019 // Use non-stub variant if that is the only choice
2020 // (i.e. depending on a lib without stubs.version property)
2021 useThisDep = true
2022 } else if c.IsForPlatform() {
2023 // If not building for APEX, use stubs only when it is from
2024 // an APEX (and not from platform)
2025 useThisDep = (depInPlatform != depIsStubs)
Ivan Lozano52767be2019-10-18 14:49:46 -07002026 if c.InRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09002027 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002028 // always link to non-stub variant
2029 useThisDep = !depIsStubs
2030 }
2031 } else {
2032 // If building for APEX, use stubs only when it is not from
2033 // the same APEX
2034 useThisDep = (depInSameApex != depIsStubs)
2035 }
2036
2037 if !useThisDep {
2038 return // stop processing this dep
2039 }
2040 }
2041
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002042 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2043
Ivan Lozano52767be2019-10-18 14:49:46 -07002044 // Exporting flags only makes sense for cc.Modules
2045 if _, ok := ccDep.(*Module); ok {
2046 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002047 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
2048 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedDeps()...)
2049 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002050
Ivan Lozano52767be2019-10-18 14:49:46 -07002051 if t.ReexportFlags {
2052 reexportExporter(i)
2053 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2054 // Re-exported shared library headers must be included as well since they can help us with type information
2055 // about template instantiations (instantiated from their headers).
2056 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2057 // scripts.
2058 c.sabi.Properties.ReexportedIncludes = append(
2059 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2060 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002061 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002062 }
Logan Chienf3511742017-10-31 18:04:35 +08002063 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002064 }
2065
Colin Cross26c34ed2016-09-30 17:10:16 -07002066 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002067 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002068
Ivan Lozano52767be2019-10-18 14:49:46 -07002069 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002070 depFile := android.OptionalPath{}
2071
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002072 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002073 case ndkStubDepTag, SharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002074 ptr = &depPaths.SharedLibs
2075 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002076 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002077 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002078
Jiyong Park64a44f22019-01-18 14:37:08 +09002079 case earlySharedDepTag:
2080 ptr = &depPaths.EarlySharedLibs
2081 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002082 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002083 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002084 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002085 ptr = &depPaths.LateSharedLibs
2086 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002087 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002088 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002089 ptr = nil
2090 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002091 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002092 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002093 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002094 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002095 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002096 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002097 return
2098 }
2099
Ivan Lozano52767be2019-10-18 14:49:46 -07002100 // Because the static library objects are included, this only makes sense
2101 // in the context of proper cc.Modules.
2102 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2103 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2104 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2105 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2106 for i := range missingDeps {
2107 missingDeps[i] += postfix
2108 }
2109 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002110 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002111 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2112 } else {
2113 ctx.ModuleErrorf(
2114 "non-cc.Modules cannot be included as whole static libraries.", depName)
2115 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002116 }
Colin Cross5950f382016-12-13 12:50:57 -08002117 case headerDepTag:
2118 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002119 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002120 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002121 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002122 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002123 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002124 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002125 case dynamicLinkerDepTag:
2126 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002127 }
2128
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002129 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002130 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002131 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002132 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002133 return
2134 }
2135
2136 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002137 // in static libraries act as if they were whole static libraries. The same goes for
2138 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002139 // This should only be done for cc.Modules
2140 if c, ok := ccDep.(*Module); ok {
2141 staticLib := c.linker.(libraryInterface)
2142 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2143 staticLib.objs().coverageFiles...)
2144 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2145 staticLib.objs().sAbiDumpFiles...)
2146 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002147 }
2148
Colin Cross26c34ed2016-09-30 17:10:16 -07002149 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002150 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002151 if !ctx.Config().AllowMissingDependencies() {
2152 ctx.ModuleErrorf("module %q missing output file", depName)
2153 } else {
2154 ctx.AddMissingDependencies([]string{depName})
2155 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002156 return
2157 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002158 *ptr = append(*ptr, linkFile.Path())
2159 }
2160
Colin Crossc99deeb2016-04-11 15:06:20 -07002161 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002162 dep := depFile
2163 if !dep.Valid() {
2164 dep = linkFile
2165 }
2166 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002167 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002168
Logan Chien43d34c32017-12-20 01:17:32 +08002169 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002170 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002171 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002172 libName = strings.TrimPrefix(libName, "prebuilt_")
Jooyung Han0302a842019-10-30 18:43:49 +09002173 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002174 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002175 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002176
Ivan Lozano52767be2019-10-18 14:49:46 -07002177 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002178 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2179 // core module instead.
2180 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002181 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002182 // The vendor module in Make will have been renamed to not conflict with the core
2183 // module, so update the dependency name here accordingly.
Inseob Kim64c43952019-08-26 16:52:35 +09002184 ret := libName + vendorSuffix
2185 vendorVersion := ctx.DeviceConfig().VndkVersion()
2186 if vendorVersion == "current" {
2187 vendorVersion = ctx.DeviceConfig().PlatformVndkVersion()
2188 }
2189 if c.Properties.VndkVersion != vendorVersion {
2190 ret += "." + c.Properties.VndkVersion
2191 }
2192 return ret
Jiyong Park374510b2018-03-19 18:23:01 +09002193 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002194 return libName + vendorPublicLibrarySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002195 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002196 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002197 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002198 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002199 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002200 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002201 }
Logan Chien43d34c32017-12-20 01:17:32 +08002202 }
2203
2204 // Export the shared libs to Make.
2205 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002206 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002207 if ccDep.CcLibrary() {
2208 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002209 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002210 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002211 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002212 c.Properties.ApexesProvidingSharedLibs = append(
2213 c.Properties.ApexesProvidingSharedLibs, an)
2214 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002215 }
2216 }
2217
Jiyong Park27b188b2017-07-18 13:23:39 +09002218 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002219 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002220 c.Properties.AndroidMkSharedLibs = append(
2221 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002222 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002223 c.Properties.AndroidMkSharedLibs = append(
2224 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002225 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002226 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002227 c.Properties.AndroidMkStaticLibs = append(
2228 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002229 case runtimeDepTag:
2230 c.Properties.AndroidMkRuntimeLibs = append(
2231 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002232 case wholeStaticDepTag:
2233 c.Properties.AndroidMkWholeStaticLibs = append(
2234 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002235 }
Colin Crossca860ac2016-01-04 14:34:37 -08002236 })
2237
Jeff Gaston294356f2017-09-27 17:05:30 -07002238 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002239 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002240
Colin Crossdd84e052017-05-17 13:44:16 -07002241 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002242 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002243 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2244 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002245 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Jiyong Park74955042019-10-22 20:19:51 +09002246 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2247 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002248 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002249 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002250
2251 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002252 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002253 }
Colin Crossdd84e052017-05-17 13:44:16 -07002254
Colin Crossca860ac2016-01-04 14:34:37 -08002255 return depPaths
2256}
2257
2258func (c *Module) InstallInData() bool {
2259 if c.installer == nil {
2260 return false
2261 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002262 return c.installer.inData()
2263}
2264
2265func (c *Module) InstallInSanitizerDir() bool {
2266 if c.installer == nil {
2267 return false
2268 }
2269 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002270 return true
2271 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002272 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002273}
2274
Jiyong Parkf9332f12018-02-01 00:54:12 +09002275func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002276 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002277}
2278
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002279func (c *Module) HostToolPath() android.OptionalPath {
2280 if c.installer == nil {
2281 return android.OptionalPath{}
2282 }
2283 return c.installer.hostToolPath()
2284}
2285
Nan Zhangd4e641b2017-07-12 12:55:28 -07002286func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2287 return c.outputFile
2288}
2289
Colin Cross41955e82019-05-29 14:40:35 -07002290func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2291 switch tag {
2292 case "":
2293 if c.outputFile.Valid() {
2294 return android.Paths{c.outputFile.Path()}, nil
2295 }
2296 return android.Paths{}, nil
2297 default:
2298 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002299 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002300}
2301
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002302func (c *Module) static() bool {
2303 if static, ok := c.linker.(interface {
2304 static() bool
2305 }); ok {
2306 return static.static()
2307 }
2308 return false
2309}
2310
Jiyong Park379de2f2018-12-19 02:47:14 +09002311func (c *Module) staticBinary() bool {
2312 if static, ok := c.linker.(interface {
2313 staticBinary() bool
2314 }); ok {
2315 return static.staticBinary()
2316 }
2317 return false
2318}
2319
Jiyong Park1d1119f2019-07-29 21:27:18 +09002320func (c *Module) header() bool {
2321 if h, ok := c.linker.(interface {
2322 header() bool
2323 }); ok {
2324 return h.header()
2325 }
2326 return false
2327}
2328
Jooyung Han38002912019-05-16 04:01:54 +09002329func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002330 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002331 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2332 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002333 return "native:vndk"
2334 }
Jooyung Han38002912019-05-16 04:01:54 +09002335 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002336 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002337 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002338 if Bool(c.VendorProperties.Vendor_available) {
2339 return "native:vndk"
2340 }
2341 return "native:vndk_private"
2342 }
2343 return "native:vendor"
Ivan Lozano52767be2019-10-18 14:49:46 -07002344 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002345 return "native:recovery"
2346 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2347 return "native:ndk:none:none"
2348 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2349 //family, link := getNdkStlFamilyAndLinkType(c)
2350 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002351 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002352 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002353 } else {
2354 return "native:platform"
2355 }
2356}
2357
Jiyong Park9d452992018-10-03 00:38:19 +09002358// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002359// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002360func (c *Module) IsInstallableToApex() bool {
2361 if shared, ok := c.linker.(interface {
2362 shared() bool
2363 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002364 // Stub libs and prebuilt libs in a versioned SDK are not
2365 // installable to APEX even though they are shared libs.
2366 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002367 } else if _, ok := c.linker.(testPerSrc); ok {
2368 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002369 }
2370 return false
2371}
2372
Jiyong Parka90ca002019-10-07 15:47:24 +09002373func (c *Module) AvailableFor(what string) bool {
2374 if linker, ok := c.linker.(interface {
2375 availableFor(string) bool
2376 }); ok {
2377 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2378 } else {
2379 return c.ApexModuleBase.AvailableFor(what)
2380 }
2381}
2382
Inseob Kim1f086e22019-05-09 13:29:15 +09002383func (c *Module) installable() bool {
2384 return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
2385}
2386
bralee3f49f4d2019-03-04 06:58:15 +08002387func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
Colin Cross41955e82019-05-29 14:40:35 -07002388 outputFiles, err := c.OutputFiles("")
2389 if err != nil {
2390 panic(err)
2391 }
2392 dpInfo.Srcs = append(dpInfo.Srcs, outputFiles.Strings()...)
bralee3f49f4d2019-03-04 06:58:15 +08002393}
2394
Logan Chien41eabe62019-04-10 13:33:58 +08002395func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2396 if c.linker != nil {
2397 if library, ok := c.linker.(*libraryDecorator); ok {
2398 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2399 }
2400 }
2401}
2402
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002403func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002404 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
2405 if cc, ok := dep.(*Module); ok && cc.IsStubs() && depTag.Shared {
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002406 // dynamic dep to a stubs lib crosses APEX boundary
2407 return false
2408 }
2409 }
2410 return true
2411}
2412
Colin Cross2ba19d92015-05-07 15:44:20 -07002413//
Colin Crosscfad1192015-11-02 16:43:11 -08002414// Defaults
2415//
Colin Crossca860ac2016-01-04 14:34:37 -08002416type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002417 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002418 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002419 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002420}
2421
Patrice Arrudac249c712019-03-19 17:00:29 -07002422// cc_defaults provides a set of properties that can be inherited by other cc
2423// modules. A module can use the properties from a cc_defaults using
2424// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2425// merged (when possible) by prepending the default module's values to the
2426// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002427func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002428 return DefaultsFactory()
2429}
2430
Colin Cross36242852017-06-23 15:06:31 -07002431func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002432 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002433
Colin Cross36242852017-06-23 15:06:31 -07002434 module.AddProperties(props...)
2435 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002436 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002437 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002438 &BaseCompilerProperties{},
2439 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002440 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002441 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002442 &StaticProperties{},
2443 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002444 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002445 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002446 &TestProperties{},
2447 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002448 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002449 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002450 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002451 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002452 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002453 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002454 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002455 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002456 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002457 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002458 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002459 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002460 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002461 )
Colin Crosscfad1192015-11-02 16:43:11 -08002462
Jooyung Hancc372c52019-09-25 15:18:44 +09002463 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002464
2465 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002466}
2467
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002468const (
Colin Cross7228ecd2019-11-18 16:00:16 -08002469 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002470 // against the VNDK.
Colin Cross7228ecd2019-11-18 16:00:16 -08002471 VendorVariationPrefix = "vendor."
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002472)
2473
Jiyong Park6a43f042017-10-12 23:05:00 +09002474func squashVendorSrcs(m *Module) {
2475 if lib, ok := m.compiler.(*libraryDecorator); ok {
2476 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2477 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2478
2479 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2480 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2481 }
2482}
2483
Jiyong Parkf9332f12018-02-01 00:54:12 +09002484func squashRecoverySrcs(m *Module) {
2485 if lib, ok := m.compiler.(*libraryDecorator); ok {
2486 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2487 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2488
2489 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2490 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2491 }
2492}
2493
Colin Cross7228ecd2019-11-18 16:00:16 -08002494var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002495
Colin Cross7228ecd2019-11-18 16:00:16 -08002496func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002497 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002498 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002499 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002500
2501 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002502 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002503 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002504 }
Logan Chienf3511742017-10-31 18:04:35 +08002505
2506 if vndkdep := m.vndkdep; vndkdep != nil {
2507 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002508 if productSpecific {
2509 mctx.PropertyErrorf("product_specific",
2510 "product_specific must not be true when `vndk: {enabled: true}`")
Justin Yun9357f4a2018-11-28 15:14:47 +09002511 }
Logan Chienf3511742017-10-31 18:04:35 +08002512 if vendorSpecific {
2513 if !vndkdep.isVndkExt() {
2514 mctx.PropertyErrorf("vndk",
2515 "must set `extends: \"...\"` to vndk extension")
Logan Chienf3511742017-10-31 18:04:35 +08002516 }
2517 } else {
2518 if vndkdep.isVndkExt() {
2519 mctx.PropertyErrorf("vndk",
2520 "must set `vendor: true` to set `extends: %q`",
2521 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002522 }
2523 if m.VendorProperties.Vendor_available == nil {
2524 mctx.PropertyErrorf("vndk",
2525 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08002526 }
2527 }
2528 } else {
2529 if vndkdep.isVndkSp() {
2530 mctx.PropertyErrorf("vndk",
2531 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08002532 }
2533 if vndkdep.isVndkExt() {
2534 mctx.PropertyErrorf("vndk",
2535 "must set `enabled: true` to set `extends: %q`",
2536 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002537 }
Justin Yun8effde42017-06-23 19:24:43 +09002538 }
2539 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002540
Jiyong Parkf9332f12018-02-01 00:54:12 +09002541 var coreVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002542 var recoveryVariantNeeded bool = false
2543
Inseob Kim64c43952019-08-26 16:52:35 +09002544 var vendorVariants []string
2545
2546 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
2547 deviceVndkVersion := mctx.DeviceConfig().VndkVersion()
2548 if deviceVndkVersion == "current" {
2549 deviceVndkVersion = platformVndkVersion
2550 }
2551
Justin Yun71549282017-11-17 12:10:28 +09002552 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002553 // If the device isn't compiling against the VNDK, we always
2554 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002555 coreVariantNeeded = true
Justin Yun1282f422019-09-09 14:42:44 +09002556 } else if m.Target().NativeBridge == android.NativeBridgeEnabled {
2557 // Skip creating vendor variants for natvie bridge modules
2558 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002559 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2560 // LL-NDK stubs only exist in the vendor variant, since the
2561 // real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002562 vendorVariants = append(vendorVariants,
2563 platformVndkVersion,
2564 deviceVndkVersion,
2565 )
Jiyong Park2a454122017-10-19 15:59:33 +09002566 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2567 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002568 vendorVariants = append(vendorVariants,
2569 platformVndkVersion,
2570 deviceVndkVersion,
2571 )
2572 } else if lib, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002573 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2574 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kim64c43952019-08-26 16:52:35 +09002575 vendorVariants = append(vendorVariants, lib.version())
Ivan Lozano52767be2019-10-18 14:49:46 -07002576 } else if m.HasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002577 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002578 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002579 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002580 vendorVariants = append(vendorVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09002581 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
2582 // code is PLATFORM_VNDK_VERSION.
2583 // On the other hand, vendor_available modules which are not VNDK should
2584 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
2585 if !m.IsVndk() {
Inseob Kim64c43952019-08-26 16:52:35 +09002586 vendorVariants = append(vendorVariants, deviceVndkVersion)
2587 }
Logan Chienf3511742017-10-31 18:04:35 +08002588 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002589 // This will be available in /vendor (or /odm) only
Inseob Kim64c43952019-08-26 16:52:35 +09002590 vendorVariants = append(vendorVariants, deviceVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002591 } else {
2592 // This is either in /system (or similar: /data), or is a
2593 // modules built with the NDK. Modules built with the NDK
2594 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002595 coreVariantNeeded = true
2596 }
2597
2598 if Bool(m.Properties.Recovery_available) {
2599 recoveryVariantNeeded = true
2600 }
2601
2602 if m.ModuleBase.InstallInRecovery() {
2603 recoveryVariantNeeded = true
2604 coreVariantNeeded = false
2605 }
2606
Jiyong Park413cc742018-06-19 01:46:06 +09002607 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002608 primaryArch := mctx.Config().DevicePrimaryArchType()
2609 moduleArch := m.Target().Arch.ArchType
2610 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002611 recoveryVariantNeeded = false
2612 }
2613 }
2614
Inseob Kim64c43952019-08-26 16:52:35 +09002615 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Colin Cross7228ecd2019-11-18 16:00:16 -08002616 m.Properties.VendorVariants = append(m.Properties.VendorVariants, VendorVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09002617 }
Colin Cross7228ecd2019-11-18 16:00:16 -08002618
2619 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
2620 m.Properties.CoreVariantNeeded = coreVariantNeeded
2621}
2622
2623func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
2624 return c.Properties.CoreVariantNeeded
2625}
2626
2627func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
2628 return c.Properties.RecoveryVariantNeeded
2629}
2630
2631func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
2632 return c.Properties.VendorVariants
2633}
2634
2635func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
2636 m := module.(*Module)
2637 if variant == android.RecoveryVariation {
2638 m.MakeAsPlatform()
2639 squashRecoverySrcs(m)
2640 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
2641 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
2642 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002643 }
2644}
2645
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002646func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002647 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002648 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2649 }
Colin Cross6510f912017-11-29 00:27:14 -08002650 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002651}
2652
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002653func kytheExtractAllFactory() android.Singleton {
2654 return &kytheExtractAllSingleton{}
2655}
2656
2657type kytheExtractAllSingleton struct {
2658}
2659
2660func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2661 var xrefTargets android.Paths
2662 ctx.VisitAllModules(func(module android.Module) {
2663 if ccModule, ok := module.(xref); ok {
2664 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
2665 }
2666 })
2667 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
2668 if len(xrefTargets) > 0 {
2669 ctx.Build(pctx, android.BuildParams{
2670 Rule: blueprint.Phony,
2671 Output: android.PathForPhony(ctx, "xref_cxx"),
2672 Inputs: xrefTargets,
2673 //Default: true,
2674 })
2675 }
2676}
2677
Colin Cross06a931b2015-10-28 17:23:31 -07002678var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002679var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002680var BoolPtr = proptools.BoolPtr
2681var String = proptools.String
2682var StringPtr = proptools.StringPtr