blob: 806a6edd0b1ad368d9c571c93a2664c4bb9778ac [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -07001// Copyright 2015 Google Inc. All rights reserved.
Colin Cross3f40fa42015-01-30 17:27:36 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17// This file contains the module types for compiling C/C++ for Android, and converts the properties
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
Colin Cross41955e82019-05-29 14:40:35 -070022 "fmt"
Logan Chien41eabe62019-04-10 13:33:58 +080023 "io"
Dan Albert9e10cd42016-08-03 14:12:14 -070024 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080025 "strings"
26
Colin Cross97ba0732015-03-23 17:50:24 -070027 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070028 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070029
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070031 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070032 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080033)
34
Colin Cross463a90e2015-06-17 14:20:06 -070035func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070036 android.RegisterModuleType("cc_defaults", defaultsFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070037
Colin Cross1e676be2016-10-12 14:38:15 -070038 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Inseob Kim64c43952019-08-26 16:52:35 +090039 ctx.BottomUp("vndk", VndkMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +090040 ctx.BottomUp("image", ImageMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070041 ctx.BottomUp("link", LinkageMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070042 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +010043 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090044 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070045 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimc0907f12019-02-08 21:00:45 +090046 ctx.BottomUp("sysprop", SyspropMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070047 })
Colin Cross16b23492016-01-06 14:41:07 -080048
Colin Cross1e676be2016-10-12 14:38:15 -070049 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
50 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
51 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080052
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070053 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
54 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
55
Mitch Phillipsbfeade62019-05-01 14:42:05 -070056 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
57 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
58
Jiyong Park1d1119f2019-07-29 21:27:18 +090059 // cfi mutator shouldn't run before sanitizers that return true for
60 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000061 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
62 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
63
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080064 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
65 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
66
Colin Cross1e676be2016-10-12 14:38:15 -070067 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
68 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080069
Colin Cross0b908332019-06-19 23:00:20 -070070 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090071 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080072
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080073 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080074 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070075
76 ctx.TopDown("lto_deps", ltoDepsMutator)
77 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090078
79 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070080 })
Colin Crossb98c8b02016-07-29 13:44:28 -070081
Sasha Smundak2a4549e2018-11-05 16:49:08 -080082 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Crossb98c8b02016-07-29 13:44:28 -070083 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070084}
85
Colin Crossca860ac2016-01-04 14:34:37 -080086type Deps struct {
87 SharedLibs, LateSharedLibs []string
88 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080089 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080090 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070091
Colin Cross5950f382016-12-13 12:50:57 -080092 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070093
Colin Cross81413472016-04-11 14:37:39 -070094 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070095
Dan Willemsenb40aab62016-04-20 14:21:14 -070096 GeneratedSources []string
97 GeneratedHeaders []string
98
Dan Willemsenb3454ab2016-09-28 17:34:58 -070099 ReexportGeneratedHeaders []string
100
Colin Cross97ba0732015-03-23 17:50:24 -0700101 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700102
103 // Used for host bionic
104 LinkerFlagsFile string
105 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700106}
107
Colin Crossca860ac2016-01-04 14:34:37 -0800108type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700109 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900110 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700111 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900112 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700113 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700114 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700115
Colin Cross26c34ed2016-09-30 17:10:16 -0700116 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700117 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800118 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700119 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700120
Colin Cross26c34ed2016-09-30 17:10:16 -0700121 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700122 GeneratedSources android.Paths
123 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700124
Inseob Kim69378442019-06-03 19:10:47 +0900125 Flags []string
126 IncludeDirs []string
127 SystemIncludeDirs []string
128 ReexportedDirs []string
129 ReexportedSystemDirs []string
130 ReexportedFlags []string
131 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700132
Colin Cross26c34ed2016-09-30 17:10:16 -0700133 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700134 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700135
136 // Path to the file container flags to use with the linker
137 LinkerFlagsFile android.OptionalPath
138
139 // Path to the dynamic linker binary
140 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700141}
142
Colin Crossca860ac2016-01-04 14:34:37 -0800143type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700144 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
145 ArFlags []string // Flags that apply to ar
146 AsFlags []string // Flags that apply to assembly source files
147 CFlags []string // Flags that apply to C and C++ source files
148 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
149 ConlyFlags []string // Flags that apply to C source files
150 CppFlags []string // Flags that apply to C++ source files
151 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700152 aidlFlags []string // Flags that apply to aidl source files
153 rsFlags []string // Flags that apply to renderscript source files
154 LdFlags []string // Flags that apply to linker command lines
155 libFlags []string // Flags to add libraries early to the link order
Pete Bentley99f2fc22019-08-02 14:02:20 +0100156 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700157 TidyFlags []string // Flags that apply to clang-tidy
158 SAbiFlags []string // Flags that apply to header-abi-dumper
159 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700160
Colin Crossc3199482017-03-30 15:03:04 -0700161 // Global include flags that apply to C, C++, and assembly source files
162 // These must be after any module include flags, which will be in GlobalFlags.
163 SystemIncludeFlags []string
164
Colin Crossb98c8b02016-07-29 13:44:28 -0700165 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700166 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800167 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800168 SAbiDump bool
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800169 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800170
171 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800172 DynamicLinker string
173
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700174 CFlagsDeps android.Paths // Files depended on by compiler flags
175 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800176
Dan Willemsen98ab3112019-08-27 21:20:40 -0700177 AssemblerWithCpp bool
178 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800179
Colin Cross19878da2019-03-28 14:45:07 -0700180 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700181 protoC bool // Whether to use C instead of C++
182 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700183
184 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700185}
186
Colin Crossca860ac2016-01-04 14:34:37 -0800187// Properties used to compile all C or C++ modules
188type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700189 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800190 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700191
192 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800193 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700194
Jiyong Parkde866cb2018-12-07 23:08:36 +0900195 AndroidMkSharedLibs []string `blueprint:"mutated"`
196 AndroidMkStaticLibs []string `blueprint:"mutated"`
197 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
198 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
199 HideFromMake bool `blueprint:"mutated"`
200 PreventInstall bool `blueprint:"mutated"`
201 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700202
Inseob Kim64c43952019-08-26 16:52:35 +0900203 VndkVersion string `blueprint:"mutated"`
204 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800205
206 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
207 // file
208 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900209
210 // Make this module available when building for recovery
211 Recovery_available *bool
212
213 InRecovery bool `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900214
215 // Allows this module to use non-APEX version of libraries. Useful
216 // for building binaries that are started before APEXes are activated.
217 Bootstrap *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700218}
219
220type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900221 // whether this module should be allowed to be directly depended by other
222 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
223 // If set to true, two variants will be built separately, one like
224 // normal, and the other limited to the set of libraries and headers
225 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700226 //
227 // The vendor variant may be used with a different (newer) /system,
228 // so it shouldn't have any unversioned runtime dependencies, or
229 // make assumptions about the system that may not be true in the
230 // future.
231 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900232 // If set to false, this module becomes inaccessible from /vendor modules.
233 //
234 // Default value is true when vndk: {enabled: true} or vendor: true.
235 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700236 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
237 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900238
239 // whether this module is capable of being loaded with other instance
240 // (possibly an older version) of the same module in the same process.
241 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
242 // can be double loaded in a vendor process if the library is also a
243 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
244 // explicitly marked as `double_loadable: true` by the owner, or the dependency
245 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
246 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800247}
248
Colin Crossca860ac2016-01-04 14:34:37 -0800249type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800250 static() bool
251 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900252 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700253 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700254 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800255 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700256 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800257 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900258 isLlndk(config android.Config) bool
259 isLlndkPublic(config android.Config) bool
260 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900261 isVndk() bool
262 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800263 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900264 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800265 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700266 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700267 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800268 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800269 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800270 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800271 useClangLld(actx ModuleContext) bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900272 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900273 hasStubsVariants() bool
274 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900275 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800276 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700277 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800278}
279
280type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700281 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800282 ModuleContextIntf
283}
284
285type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700286 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800287 ModuleContextIntf
288}
289
Colin Cross37047f12016-12-13 17:06:13 -0800290type DepsContext interface {
291 android.BottomUpMutatorContext
292 ModuleContextIntf
293}
294
Colin Crossca860ac2016-01-04 14:34:37 -0800295type feature interface {
296 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800297 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800298 flags(ctx ModuleContext, flags Flags) Flags
299 props() []interface{}
300}
301
302type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700303 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800304 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800305 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700306 compilerProps() []interface{}
307
Colin Cross76fada02016-07-27 10:31:13 -0700308 appendCflags([]string)
309 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700310 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800311}
312
313type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700314 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800315 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700316 linkerFlags(ctx ModuleContext, flags Flags) Flags
317 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800318 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700319
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700320 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700321 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900322 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700323
324 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900325 coverageOutputFilePath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800326}
327
328type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700329 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700330 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800331 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700332 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700333 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900334 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800335}
336
Colin Crossc99deeb2016-04-11 15:06:20 -0700337type dependencyTag struct {
338 blueprint.BaseDependencyTag
339 name string
340 library bool
Roland Levillainf89cd092019-07-29 16:22:59 +0100341 shared bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700342
343 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900344
345 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700346}
347
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800348type xref interface {
349 XrefCcFiles() android.Paths
350}
351
Colin Crossc99deeb2016-04-11 15:06:20 -0700352var (
Roland Levillainf89cd092019-07-29 16:22:59 +0100353 sharedDepTag = dependencyTag{name: "shared", library: true, shared: true}
354 sharedExportDepTag = dependencyTag{name: "shared", library: true, shared: true, reexportFlags: true}
355 earlySharedDepTag = dependencyTag{name: "early_shared", library: true, shared: true}
356 lateSharedDepTag = dependencyTag{name: "late shared", library: true, shared: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700357 staticDepTag = dependencyTag{name: "static", library: true}
358 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
359 lateStaticDepTag = dependencyTag{name: "late static", library: true}
360 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800361 headerDepTag = dependencyTag{name: "header", library: true}
362 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700363 genSourceDepTag = dependencyTag{name: "gen source"}
364 genHeaderDepTag = dependencyTag{name: "gen header"}
365 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
366 objDepTag = dependencyTag{name: "obj"}
367 crtBeginDepTag = dependencyTag{name: "crtbegin"}
368 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700369 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
370 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700371 reuseObjTag = dependencyTag{name: "reuse objects"}
Jiyong Parke4bb9862019-02-01 00:31:10 +0900372 staticVariantTag = dependencyTag{name: "static variant"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700373 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
374 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800375 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800376 runtimeDepTag = dependencyTag{name: "runtime lib"}
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -0700377 coverageDepTag = dependencyTag{name: "coverage"}
Roland Levillainf2fad972019-06-28 15:41:19 +0100378 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700379)
380
Roland Levillainf89cd092019-07-29 16:22:59 +0100381func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
382 ccDepTag, ok := depTag.(dependencyTag)
383 return ok && ccDepTag.shared
384}
385
386func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
387 ccDepTag, ok := depTag.(dependencyTag)
388 return ok && ccDepTag == runtimeDepTag
389}
390
391func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
392 ccDepTag, ok := depTag.(dependencyTag)
393 return ok && ccDepTag == testPerSrcDepTag
394}
395
Ivan Lozanoffee3342019-08-27 12:03:00 -0700396func SharedDepTag() dependencyTag {
397 return sharedDepTag
398}
399
400func StaticDepTag() dependencyTag {
401 return staticDepTag
402}
403
Ivan Lozanof1c84332019-09-20 11:00:37 -0700404func CrtBeginDepTag() dependencyTag {
405 return crtBeginDepTag
406}
407
408func CrtEndDepTag() dependencyTag {
409 return crtEndDepTag
410}
411
Colin Crossca860ac2016-01-04 14:34:37 -0800412// Module contains the properties and members used by all C/C++ module types, and implements
413// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
414// to construct the output file. Behavior can be customized with a Customizer interface
415type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700416 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700417 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900418 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900419 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700420
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700421 Properties BaseProperties
422 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700423
Colin Crossca860ac2016-01-04 14:34:37 -0800424 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700425 hod android.HostOrDeviceSupported
426 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700427
Colin Crossca860ac2016-01-04 14:34:37 -0800428 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700429 features []feature
430 compiler compiler
431 linker linker
432 installer installer
433 stl *stl
434 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800435 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800436 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900437 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700438 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700439 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800440 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800441
442 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700443
Colin Cross635c3b02016-05-18 15:37:25 -0700444 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800445
Colin Crossb98c8b02016-07-29 13:44:28 -0700446 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700447
448 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800449
450 // Flags used to compile this module
451 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700452
453 // 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 -0800454 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700455 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800456 depsInLinkOrder android.Paths
457
458 // only non-nil when this is a shared library that reuses the objects of a static library
459 staticVariant *Module
Inseob Kim9516ee92019-05-09 10:56:13 +0900460
461 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800462 // Kythe (source file indexer) paths for this compilation module
463 kytheFiles android.Paths
Colin Crossc472d572015-03-17 15:06:21 -0700464}
465
Jiyong Parkc20eee32018-09-05 22:36:17 +0900466func (c *Module) OutputFile() android.OptionalPath {
467 return c.outputFile
468}
469
Jiyong Park719b4462019-01-13 00:39:51 +0900470func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900471 if c.linker != nil {
472 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900473 }
474 return nil
475}
476
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900477func (c *Module) CoverageOutputFile() android.OptionalPath {
478 if c.linker != nil {
479 return c.linker.coverageOutputFilePath()
480 }
481 return android.OptionalPath{}
482}
483
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900484func (c *Module) RelativeInstallPath() string {
485 if c.installer != nil {
486 return c.installer.relativeInstallPath()
487 }
488 return ""
489}
490
Jooyung Han48dd4b52019-10-16 22:43:42 +0000491// IsVndkOnSystem returns true if a module is supposed to be a vndk library provided by system to vendor
492func (c *Module) IsVndkOnSystem() bool {
493 if linker, ok := c.linker.(libraryInterface); ok {
494 return linker.shared() && c.isVndk() && c.useVndk() && !c.isVndkExt()
495 }
496
497 return false
498}
499
Jooyung Han344d5432019-08-23 11:17:39 +0900500func (c *Module) VndkVersion() string {
501 return c.vndkVersion()
502}
503
Colin Cross36242852017-06-23 15:06:31 -0700504func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700505 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800506 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700507 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800508 }
509 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700510 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800511 }
512 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700513 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800514 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700515 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700516 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700517 }
Colin Cross16b23492016-01-06 14:41:07 -0800518 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700519 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800520 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800521 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700522 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800523 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800524 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700525 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800526 }
Justin Yun8effde42017-06-23 19:24:43 +0900527 if c.vndkdep != nil {
528 c.AddProperties(c.vndkdep.props()...)
529 }
Stephen Craneba090d12017-05-09 15:44:35 -0700530 if c.lto != nil {
531 c.AddProperties(c.lto.props()...)
532 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700533 if c.pgo != nil {
534 c.AddProperties(c.pgo.props()...)
535 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800536 if c.xom != nil {
537 c.AddProperties(c.xom.props()...)
538 }
Colin Crossca860ac2016-01-04 14:34:37 -0800539 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700540 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800541 }
Colin Crossc472d572015-03-17 15:06:21 -0700542
Colin Crossa9d8bee2018-10-02 13:59:46 -0700543 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
544 switch class {
545 case android.Device:
546 return ctx.Config().DevicePrefer32BitExecutables()
547 case android.HostCross:
548 // Windows builds always prefer 32-bit
549 return true
550 default:
551 return false
552 }
553 })
Colin Cross36242852017-06-23 15:06:31 -0700554 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900555
Jooyung Hancc372c52019-09-25 15:18:44 +0900556 android.InitDefaultableModule(c)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900557
558 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900559 android.InitSdkAwareModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900560
Colin Cross36242852017-06-23 15:06:31 -0700561 return c
Colin Crossc472d572015-03-17 15:06:21 -0700562}
563
Colin Crossb916a382016-07-29 17:28:03 -0700564// Returns true for dependency roots (binaries)
565// TODO(ccross): also handle dlopenable libraries
566func (c *Module) isDependencyRoot() bool {
567 if root, ok := c.linker.(interface {
568 isDependencyRoot() bool
569 }); ok {
570 return root.isDependencyRoot()
571 }
572 return false
573}
574
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700575func (c *Module) useVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900576 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700577}
578
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800579func (c *Module) isCoverageVariant() bool {
580 return c.coverage.Properties.IsCoverageVariant
581}
582
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800583func (c *Module) isNdk() bool {
584 return inList(c.Name(), ndkMigratedLibs)
585}
586
Inseob Kim9516ee92019-05-09 10:56:13 +0900587func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800588 // Returns true for both LLNDK (public) and LLNDK-private libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900589 return inList(c.Name(), *llndkLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800590}
591
Inseob Kim9516ee92019-05-09 10:56:13 +0900592func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800593 // Returns true only for LLNDK (public) libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900594 return c.isLlndk(config) && !c.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800595}
596
Inseob Kim9516ee92019-05-09 10:56:13 +0900597func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800598 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Inseob Kim9516ee92019-05-09 10:56:13 +0900599 return inList(c.Name(), *vndkPrivateLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800600}
601
Justin Yun8effde42017-06-23 19:24:43 +0900602func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800603 if vndkdep := c.vndkdep; vndkdep != nil {
604 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900605 }
606 return false
607}
608
Jooyung Han76106d92019-05-20 18:49:10 +0900609func (c *Module) vndkVersion() string {
Inseob Kim64c43952019-08-26 16:52:35 +0900610 return c.Properties.VndkVersion
Jooyung Han76106d92019-05-20 18:49:10 +0900611}
612
Yi Kong7e53c572018-02-14 18:16:12 +0800613func (c *Module) isPgoCompile() bool {
614 if pgo := c.pgo; pgo != nil {
615 return pgo.Properties.PgoCompile
616 }
617 return false
618}
619
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800620func (c *Module) isNDKStubLibrary() bool {
621 if _, ok := c.compiler.(*stubDecorator); ok {
622 return true
623 }
624 return false
625}
626
Logan Chienf3511742017-10-31 18:04:35 +0800627func (c *Module) isVndkSp() bool {
628 if vndkdep := c.vndkdep; vndkdep != nil {
629 return vndkdep.isVndkSp()
630 }
631 return false
632}
633
634func (c *Module) isVndkExt() bool {
635 if vndkdep := c.vndkdep; vndkdep != nil {
636 return vndkdep.isVndkExt()
637 }
638 return false
639}
640
Vic Yangefd249e2018-11-12 20:19:56 -0800641func (c *Module) mustUseVendorVariant() bool {
642 return c.isVndkSp() || inList(c.Name(), config.VndkMustUseVendorVariantList)
643}
644
Logan Chienf3511742017-10-31 18:04:35 +0800645func (c *Module) getVndkExtendsModuleName() string {
646 if vndkdep := c.vndkdep; vndkdep != nil {
647 return vndkdep.getVndkExtendsModuleName()
648 }
649 return ""
650}
651
Jiyong Park82e2bf32017-08-16 14:05:54 +0900652// Returns true only when this module is configured to have core and vendor
653// variants.
654func (c *Module) hasVendorVariant() bool {
655 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
656}
657
Jiyong Parkf9332f12018-02-01 00:54:12 +0900658func (c *Module) inRecovery() bool {
659 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
660}
661
662func (c *Module) onlyInRecovery() bool {
663 return c.ModuleBase.InstallInRecovery()
664}
665
Jiyong Park25fc6a92018-11-18 18:02:45 +0900666func (c *Module) IsStubs() bool {
667 if library, ok := c.linker.(*libraryDecorator); ok {
668 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900669 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
670 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900671 }
672 return false
673}
674
675func (c *Module) HasStubsVariants() bool {
676 if library, ok := c.linker.(*libraryDecorator); ok {
677 return len(library.Properties.Stubs.Versions) > 0
678 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700679 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
680 return len(library.Properties.Stubs.Versions) > 0
681 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900682 return false
683}
684
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900685func (c *Module) bootstrap() bool {
686 return Bool(c.Properties.Bootstrap)
687}
688
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700689func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700690 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
691 if c.Target().NativeBridge == android.NativeBridgeEnabled {
692 return false
693 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700694 return c.linker != nil && c.linker.nativeCoverage()
695}
696
Jiyong Parkf1194352019-02-25 11:05:47 +0900697func isBionic(name string) bool {
698 switch name {
699 case "libc", "libm", "libdl", "linker":
700 return true
701 }
702 return false
703}
704
Martin Stjernholm279de572019-09-10 23:18:20 +0100705func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700706 if name == "libclang_rt.hwasan-aarch64-android" {
707 return inList("hwaddress", config.SanitizeDevice())
708 }
709 return isBionic(name)
710}
711
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800712func (c *Module) XrefCcFiles() android.Paths {
713 return c.kytheFiles
714}
715
Colin Crossca860ac2016-01-04 14:34:37 -0800716type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700717 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800718 moduleContextImpl
719}
720
Colin Cross37047f12016-12-13 17:06:13 -0800721type depsContext struct {
722 android.BottomUpMutatorContext
723 moduleContextImpl
724}
725
Colin Crossca860ac2016-01-04 14:34:37 -0800726type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700727 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800728 moduleContextImpl
729}
730
Jiyong Park2db76922017-11-08 16:03:48 +0900731func (ctx *moduleContext) SocSpecific() bool {
732 return ctx.ModuleContext.SocSpecific() ||
733 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700734}
735
Colin Crossca860ac2016-01-04 14:34:37 -0800736type moduleContextImpl struct {
737 mod *Module
738 ctx BaseModuleContext
739}
740
Colin Crossb98c8b02016-07-29 13:44:28 -0700741func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800742 return ctx.mod.toolchain(ctx.ctx)
743}
744
745func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000746 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800747}
748
749func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900750 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800751}
752
Jiyong Park1d1119f2019-07-29 21:27:18 +0900753func (ctx *moduleContextImpl) header() bool {
754 return ctx.mod.header()
755}
756
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700757func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800758 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800759 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700760 }
761 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800762}
763
764func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700765 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700766 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900767 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700768 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900769 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
770 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
771 return "current"
772 }
773 return platform_vndk_ver
774 }
775 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800776 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900777 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700778 }
779 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800780}
781
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700782func (ctx *moduleContextImpl) useVndk() bool {
783 return ctx.mod.useVndk()
784}
Justin Yun8effde42017-06-23 19:24:43 +0900785
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800786func (ctx *moduleContextImpl) isNdk() bool {
787 return ctx.mod.isNdk()
788}
789
Inseob Kim9516ee92019-05-09 10:56:13 +0900790func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
791 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800792}
793
Inseob Kim9516ee92019-05-09 10:56:13 +0900794func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
795 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800796}
797
Inseob Kim9516ee92019-05-09 10:56:13 +0900798func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
799 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800800}
801
Logan Chienf3511742017-10-31 18:04:35 +0800802func (ctx *moduleContextImpl) isVndk() bool {
803 return ctx.mod.isVndk()
804}
805
Yi Kong7e53c572018-02-14 18:16:12 +0800806func (ctx *moduleContextImpl) isPgoCompile() bool {
807 return ctx.mod.isPgoCompile()
808}
809
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800810func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
811 return ctx.mod.isNDKStubLibrary()
812}
813
Justin Yun8effde42017-06-23 19:24:43 +0900814func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800815 return ctx.mod.isVndkSp()
816}
817
818func (ctx *moduleContextImpl) isVndkExt() bool {
819 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900820}
821
Vic Yangefd249e2018-11-12 20:19:56 -0800822func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
823 return ctx.mod.mustUseVendorVariant()
824}
825
Jiyong Parkf9332f12018-02-01 00:54:12 +0900826func (ctx *moduleContextImpl) inRecovery() bool {
827 return ctx.mod.inRecovery()
828}
829
Logan Chien2f2b8902018-07-10 15:01:19 +0800830// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800831func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +0800832 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
833 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800834 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800835
836 if ctx.ctx.Fuchsia() {
837 return false
838 }
839
Logan Chien2f2b8902018-07-10 15:01:19 +0800840 if sanitize := ctx.mod.sanitize; sanitize != nil {
841 if !sanitize.isVariantOnProductionDevice() {
842 return false
843 }
844 }
845 if !ctx.ctx.Device() {
846 // Host modules do not need ABI dumps.
847 return false
848 }
Logan Chienfa478c02018-12-28 16:25:39 +0800849 if !ctx.mod.IsForPlatform() {
850 // APEX variants do not need ABI dumps.
851 return false
852 }
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +0800853 if ctx.isStubs() {
854 // Stubs do not need ABI dumps.
855 return false
856 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800857 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800858}
859
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700860func (ctx *moduleContextImpl) selectedStl() string {
861 if stl := ctx.mod.stl; stl != nil {
862 return stl.Properties.SelectedStl
863 }
864 return ""
865}
866
Ivan Lozanobd721262018-11-27 14:33:03 -0800867func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
868 return ctx.mod.linker.useClangLld(actx)
869}
870
Colin Crossce75d2c2016-10-06 16:12:58 -0700871func (ctx *moduleContextImpl) baseModuleName() string {
872 return ctx.mod.ModuleBase.BaseModuleName()
873}
874
Logan Chienf3511742017-10-31 18:04:35 +0800875func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
876 return ctx.mod.getVndkExtendsModuleName()
877}
878
Jiyong Park58e364a2019-01-19 19:24:06 +0900879func (ctx *moduleContextImpl) apexName() string {
880 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900881}
882
Jiyong Parkb0788572018-12-20 22:10:17 +0900883func (ctx *moduleContextImpl) hasStubsVariants() bool {
884 return ctx.mod.HasStubsVariants()
885}
886
887func (ctx *moduleContextImpl) isStubs() bool {
888 return ctx.mod.IsStubs()
889}
890
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900891func (ctx *moduleContextImpl) bootstrap() bool {
892 return ctx.mod.bootstrap()
893}
894
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700895func (ctx *moduleContextImpl) nativeCoverage() bool {
896 return ctx.mod.nativeCoverage()
897}
898
Colin Cross635c3b02016-05-18 15:37:25 -0700899func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800900 return &Module{
901 hod: hod,
902 multilib: multilib,
903 }
904}
905
Colin Cross635c3b02016-05-18 15:37:25 -0700906func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800907 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700908 module.features = []feature{
909 &tidyFeature{},
910 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700911 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800912 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800913 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800914 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900915 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700916 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700917 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800918 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800919 return module
920}
921
Colin Crossce75d2c2016-10-06 16:12:58 -0700922func (c *Module) Prebuilt() *android.Prebuilt {
923 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
924 return p.prebuilt()
925 }
926 return nil
927}
928
929func (c *Module) Name() string {
930 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700931 if p, ok := c.linker.(interface {
932 Name(string) string
933 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700934 name = p.Name(name)
935 }
936 return name
937}
938
Alex Light3d673592019-01-18 14:37:31 -0800939func (c *Module) Symlinks() []string {
940 if p, ok := c.installer.(interface {
941 symlinkList() []string
942 }); ok {
943 return p.symlinkList()
944 }
945 return nil
946}
947
Jeff Gaston294356f2017-09-27 17:05:30 -0700948// orderDeps reorders dependencies into a list such that if module A depends on B, then
949// A will precede B in the resultant list.
950// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800951// Note that directSharedDeps should be the analogous static library for each shared lib dep
952func 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 -0700953 // If A depends on B, then
954 // Every list containing A will also contain B later in the list
955 // So, after concatenating all lists, the final instance of B will have come from the same
956 // original list as the final instance of A
957 // So, the final instance of B will be later in the concatenation than the final A
958 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
959 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800960 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700961 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800962 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
963 }
964 for _, dep := range directSharedDeps {
965 orderedAllDeps = append(orderedAllDeps, dep)
966 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700967 }
968
Colin Crossb6715442017-10-24 11:13:31 -0700969 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700970
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800971 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700972 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800973 // resultant list to only what the caller has chosen to include in directStaticDeps
974 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700975
976 return orderedAllDeps, orderedDeclaredDeps
977}
978
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800979func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
980 // convert Module to Path
981 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
982 staticDepFiles := []android.Path{}
983 for _, dep := range staticDeps {
984 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
985 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700986 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800987 sharedDepFiles := []android.Path{}
988 for _, sharedDep := range sharedDeps {
989 staticAnalogue := sharedDep.staticVariant
990 if staticAnalogue != nil {
991 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
992 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
993 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700994 }
995
996 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800997 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700998
999 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001000}
1001
Roland Levillainf89cd092019-07-29 16:22:59 +01001002func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1003 test, ok := c.linker.(testPerSrc)
1004 return ok && test.isAllTestsVariation()
1005}
1006
Colin Cross635c3b02016-05-18 15:37:25 -07001007func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001008 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001009 //
1010 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1011 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1012 // module and return early, as this module does not produce an output file per se.
1013 if c.IsTestPerSrcAllTestsVariation() {
1014 c.outputFile = android.OptionalPath{}
1015 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001016 }
1017
Jooyung Han38002912019-05-16 04:01:54 +09001018 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001019
Inseob Kim64c43952019-08-26 16:52:35 +09001020 c.Properties.SubName = ""
1021
1022 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1023 c.Properties.SubName += nativeBridgeSuffix
1024 }
1025
1026 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
1027 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1028 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1029 c.Properties.SubName += vendorSuffix
1030 } else if _, ok := c.linker.(*llndkStubDecorator); ok || (c.useVndk() && c.hasVendorVariant()) {
1031 // .vendor.{version} suffix is added only when we will have two variants: core and vendor.
1032 // The suffix is not added for vendor-only module.
1033 c.Properties.SubName += vendorSuffix
1034 vendorVersion := actx.DeviceConfig().VndkVersion()
1035 if vendorVersion == "current" {
1036 vendorVersion = actx.DeviceConfig().PlatformVndkVersion()
1037 }
1038 if c.Properties.VndkVersion != vendorVersion {
1039 c.Properties.SubName += "." + c.Properties.VndkVersion
1040 }
1041 } else if c.inRecovery() && !c.onlyInRecovery() {
1042 c.Properties.SubName += recoverySuffix
1043 }
1044
Colin Crossca860ac2016-01-04 14:34:37 -08001045 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001046 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001047 moduleContextImpl: moduleContextImpl{
1048 mod: c,
1049 },
1050 }
1051 ctx.ctx = ctx
1052
Colin Crossf18e1102017-11-16 14:33:08 -08001053 deps := c.depsToPaths(ctx)
1054 if ctx.Failed() {
1055 return
1056 }
1057
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001058 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1059 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1060 }
1061
Colin Crossca860ac2016-01-04 14:34:37 -08001062 flags := Flags{
1063 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001064 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001065 }
Colin Crossca860ac2016-01-04 14:34:37 -08001066 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001067 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001068 }
1069 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001070 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001071 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001072 if c.stl != nil {
1073 flags = c.stl.flags(ctx, flags)
1074 }
Colin Cross16b23492016-01-06 14:41:07 -08001075 if c.sanitize != nil {
1076 flags = c.sanitize.flags(ctx, flags)
1077 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001078 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001079 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001080 }
Stephen Craneba090d12017-05-09 15:44:35 -07001081 if c.lto != nil {
1082 flags = c.lto.flags(ctx, flags)
1083 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001084 if c.pgo != nil {
1085 flags = c.pgo.flags(ctx, flags)
1086 }
Ivan Lozano074ec482018-11-21 08:59:37 -08001087 if c.xom != nil {
1088 flags = c.xom.flags(ctx, flags)
1089 }
Colin Crossca860ac2016-01-04 14:34:37 -08001090 for _, feature := range c.features {
1091 flags = feature.flags(ctx, flags)
1092 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001093 if ctx.Failed() {
1094 return
1095 }
1096
Colin Crossb98c8b02016-07-29 13:44:28 -07001097 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
1098 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
1099 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001100
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001101 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001102
1103 for _, dir := range deps.IncludeDirs {
1104 flags.GlobalFlags = append(flags.GlobalFlags, "-I"+dir)
1105 }
1106 for _, dir := range deps.SystemIncludeDirs {
1107 flags.GlobalFlags = append(flags.GlobalFlags, "-isystem "+dir)
1108 }
1109
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001110 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001111 // We need access to all the flags seen by a source file.
1112 if c.sabi != nil {
1113 flags = c.sabi.flags(ctx, flags)
1114 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001115
1116 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.AsFlags)
1117
Colin Crossca860ac2016-01-04 14:34:37 -08001118 // Optimization to reduce size of build.ninja
1119 // Replace the long list of flags for each file with a module-local variable
1120 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
1121 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
1122 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
1123 flags.CFlags = []string{"$cflags"}
1124 flags.CppFlags = []string{"$cppflags"}
1125 flags.AsFlags = []string{"$asflags"}
1126
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001127 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001128 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001129 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001130 if ctx.Failed() {
1131 return
1132 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001133 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001134 }
1135
Colin Crossca860ac2016-01-04 14:34:37 -08001136 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001137 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001138 if ctx.Failed() {
1139 return
1140 }
Colin Cross635c3b02016-05-18 15:37:25 -07001141 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001142
1143 // If a lib is directly included in any of the APEXes, unhide the stubs
1144 // variant having the latest version gets visible to make. In addition,
1145 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1146 // force anything in the make world to link against the stubs library.
1147 // (unless it is explicitly referenced via .bootstrap suffix or the
1148 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001149 if c.HasStubsVariants() &&
1150 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001151 !c.inRecovery() && !c.useVndk() && !c.static() && !c.isCoverageVariant() &&
1152 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001153 c.Properties.HideFromMake = false // unhide
1154 // Note: this is still non-installable
1155 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001156 }
Colin Cross5049f022015-03-18 13:28:46 -07001157
Inseob Kim1f086e22019-05-09 13:29:15 +09001158 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001159 c.installer.install(ctx, c.outputFile.Path())
1160 if ctx.Failed() {
1161 return
Colin Crossca860ac2016-01-04 14:34:37 -08001162 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001163 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001164}
1165
Colin Cross0ea8ba82019-06-06 14:33:29 -07001166func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001167 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001168 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001169 }
Colin Crossca860ac2016-01-04 14:34:37 -08001170 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001171}
1172
Colin Crossca860ac2016-01-04 14:34:37 -08001173func (c *Module) begin(ctx BaseModuleContext) {
1174 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001175 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001176 }
Colin Crossca860ac2016-01-04 14:34:37 -08001177 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001178 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001179 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001180 if c.stl != nil {
1181 c.stl.begin(ctx)
1182 }
Colin Cross16b23492016-01-06 14:41:07 -08001183 if c.sanitize != nil {
1184 c.sanitize.begin(ctx)
1185 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001186 if c.coverage != nil {
1187 c.coverage.begin(ctx)
1188 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001189 if c.sabi != nil {
1190 c.sabi.begin(ctx)
1191 }
Justin Yun8effde42017-06-23 19:24:43 +09001192 if c.vndkdep != nil {
1193 c.vndkdep.begin(ctx)
1194 }
Stephen Craneba090d12017-05-09 15:44:35 -07001195 if c.lto != nil {
1196 c.lto.begin(ctx)
1197 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001198 if c.pgo != nil {
1199 c.pgo.begin(ctx)
1200 }
Colin Crossca860ac2016-01-04 14:34:37 -08001201 for _, feature := range c.features {
1202 feature.begin(ctx)
1203 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001204 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001205 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001206 if err != nil {
1207 ctx.PropertyErrorf("sdk_version", err.Error())
1208 }
Nan Zhang0007d812017-11-07 10:57:05 -08001209 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001210 }
Colin Crossca860ac2016-01-04 14:34:37 -08001211}
1212
Colin Cross37047f12016-12-13 17:06:13 -08001213func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001214 deps := Deps{}
1215
1216 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001217 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001218 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001219 // Add the PGO dependency (the clang_rt.profile runtime library), which
1220 // sometimes depends on symbols from libgcc, before libgcc gets added
1221 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001222 if c.pgo != nil {
1223 deps = c.pgo.deps(ctx, deps)
1224 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001225 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001226 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001227 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001228 if c.stl != nil {
1229 deps = c.stl.deps(ctx, deps)
1230 }
Colin Cross16b23492016-01-06 14:41:07 -08001231 if c.sanitize != nil {
1232 deps = c.sanitize.deps(ctx, deps)
1233 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001234 if c.coverage != nil {
1235 deps = c.coverage.deps(ctx, deps)
1236 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001237 if c.sabi != nil {
1238 deps = c.sabi.deps(ctx, deps)
1239 }
Justin Yun8effde42017-06-23 19:24:43 +09001240 if c.vndkdep != nil {
1241 deps = c.vndkdep.deps(ctx, deps)
1242 }
Stephen Craneba090d12017-05-09 15:44:35 -07001243 if c.lto != nil {
1244 deps = c.lto.deps(ctx, deps)
1245 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001246 for _, feature := range c.features {
1247 deps = feature.deps(ctx, deps)
1248 }
1249
Colin Crossb6715442017-10-24 11:13:31 -07001250 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1251 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1252 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1253 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1254 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1255 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001256 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001257
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001258 for _, lib := range deps.ReexportSharedLibHeaders {
1259 if !inList(lib, deps.SharedLibs) {
1260 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1261 }
1262 }
1263
1264 for _, lib := range deps.ReexportStaticLibHeaders {
1265 if !inList(lib, deps.StaticLibs) {
1266 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1267 }
1268 }
1269
Colin Cross5950f382016-12-13 12:50:57 -08001270 for _, lib := range deps.ReexportHeaderLibHeaders {
1271 if !inList(lib, deps.HeaderLibs) {
1272 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1273 }
1274 }
1275
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001276 for _, gen := range deps.ReexportGeneratedHeaders {
1277 if !inList(gen, deps.GeneratedHeaders) {
1278 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1279 }
1280 }
1281
Colin Crossc99deeb2016-04-11 15:06:20 -07001282 return deps
1283}
1284
Dan Albert7e9d2952016-08-04 13:02:36 -07001285func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001286 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001287 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001288 moduleContextImpl: moduleContextImpl{
1289 mod: c,
1290 },
1291 }
1292 ctx.ctx = ctx
1293
Colin Crossca860ac2016-01-04 14:34:37 -08001294 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001295}
1296
Jiyong Park7ed9de32018-10-15 22:25:07 +09001297// Split name#version into name and version
1298func stubsLibNameAndVersion(name string) (string, string) {
1299 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1300 version := name[sharp+1:]
1301 libname := name[:sharp]
1302 return libname, version
1303 }
1304 return name, ""
1305}
1306
Colin Cross1e676be2016-10-12 14:38:15 -07001307func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001308 ctx := &depsContext{
1309 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001310 moduleContextImpl: moduleContextImpl{
1311 mod: c,
1312 },
1313 }
1314 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001315
Colin Crossc99deeb2016-04-11 15:06:20 -07001316 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001317
Dan Albert914449f2016-06-17 16:45:24 -07001318 variantNdkLibs := []string{}
1319 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001320 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001321 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001322
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001323 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1324 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001325 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001326 // 1. Name of an NDK library that refers to a prebuilt module.
1327 // For each of these, it adds the name of the prebuilt module (which will be in
1328 // prebuilts/ndk) to the list of nonvariant libs.
1329 // 2. Name of an NDK library that refers to an ndk_library module.
1330 // For each of these, it adds the name of the ndk_library module to the list of
1331 // variant libs.
1332 // 3. Anything else (so anything that isn't an NDK library).
1333 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001334 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001335 // The caller can then know to add the variantLibs dependencies differently from the
1336 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001337
1338 llndkLibraries := llndkLibraries(actx.Config())
1339 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001340 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1341 variantLibs = []string{}
1342 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001343 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001344 // strip #version suffix out
1345 name, _ := stubsLibNameAndVersion(entry)
1346 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1347 if !inList(name, ndkMigratedLibs) {
1348 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001349 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001350 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001351 }
Inseob Kim9516ee92019-05-09 10:56:13 +09001352 } else if ctx.useVndk() && inList(name, *llndkLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001353 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001354 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001355 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001356 if actx.OtherModuleExists(vendorPublicLib) {
1357 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1358 } else {
1359 // This can happen if vendor_public_library module is defined in a
1360 // namespace that isn't visible to the current module. In that case,
1361 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001362 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001363 }
Dan Albert914449f2016-06-17 16:45:24 -07001364 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001365 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001366 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001367 }
1368 }
Dan Albert914449f2016-06-17 16:45:24 -07001369 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001370 }
1371
Dan Albert914449f2016-06-17 16:45:24 -07001372 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1373 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001374 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001375 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001376
Jiyong Park7e636d02019-01-28 16:16:54 +09001377 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001378 if c.linker != nil {
1379 if library, ok := c.linker.(*libraryDecorator); ok {
1380 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001381 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001382 }
1383 }
1384 }
1385
Colin Cross32ec36c2016-12-15 07:39:51 -08001386 for _, lib := range deps.HeaderLibs {
1387 depTag := headerDepTag
1388 if inList(lib, deps.ReexportHeaderLibHeaders) {
1389 depTag = headerExportDepTag
1390 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001391 if buildStubs {
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001392 actx.AddFarVariationDependencies(append(ctx.Target().Variations(),
1393 blueprint.Variation{Mutator: "image", Variation: c.imageVariation()}),
1394 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001395 } else {
1396 actx.AddVariationDependencies(nil, depTag, lib)
1397 }
1398 }
1399
1400 if buildStubs {
1401 // Stubs lib does not have dependency to other static/shared libraries.
1402 // Don't proceed.
1403 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001404 }
Colin Cross5950f382016-12-13 12:50:57 -08001405
Inseob Kimc0907f12019-02-08 21:00:45 +09001406 syspropImplLibraries := syspropImplLibraries(actx.Config())
1407
Jiyong Park5d1598f2019-02-25 22:14:17 +09001408 for _, lib := range deps.WholeStaticLibs {
1409 depTag := wholeStaticDepTag
1410 if impl, ok := syspropImplLibraries[lib]; ok {
1411 lib = impl
1412 }
1413 actx.AddVariationDependencies([]blueprint.Variation{
1414 {Mutator: "link", Variation: "static"},
1415 }, depTag, lib)
1416 }
1417
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001418 for _, lib := range deps.StaticLibs {
1419 depTag := staticDepTag
1420 if inList(lib, deps.ReexportStaticLibHeaders) {
1421 depTag = staticExportDepTag
1422 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001423
1424 if impl, ok := syspropImplLibraries[lib]; ok {
1425 lib = impl
1426 }
1427
Dan Willemsen59339a22018-07-22 21:18:45 -07001428 actx.AddVariationDependencies([]blueprint.Variation{
1429 {Mutator: "link", Variation: "static"},
1430 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001431 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001432
Dan Willemsen59339a22018-07-22 21:18:45 -07001433 actx.AddVariationDependencies([]blueprint.Variation{
1434 {Mutator: "link", Variation: "static"},
1435 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001436
Jiyong Park25fc6a92018-11-18 18:02:45 +09001437 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1438 var variations []blueprint.Variation
1439 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001440 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001441 if version != "" && versionVariantAvail {
1442 // Version is explicitly specified. i.e. libFoo#30
1443 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1444 depTag.explicitlyVersioned = true
1445 }
1446 actx.AddVariationDependencies(variations, depTag, name)
1447
1448 // If the version is not specified, add dependency to the latest stubs library.
1449 // The stubs library will be used when the depending module is built for APEX and
1450 // the dependent module is not in the same APEX.
1451 latestVersion := latestStubsVersionFor(actx.Config(), name)
1452 if version == "" && latestVersion != "" && versionVariantAvail {
1453 actx.AddVariationDependencies([]blueprint.Variation{
1454 {Mutator: "link", Variation: "shared"},
1455 {Mutator: "version", Variation: latestVersion},
1456 }, depTag, name)
1457 // Note that depTag.explicitlyVersioned is false in this case.
1458 }
1459 }
1460
Jiyong Park7ed9de32018-10-15 22:25:07 +09001461 // shared lib names without the #version suffix
1462 var sharedLibNames []string
1463
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001464 for _, lib := range deps.SharedLibs {
1465 depTag := sharedDepTag
1466 if inList(lib, deps.ReexportSharedLibHeaders) {
1467 depTag = sharedExportDepTag
1468 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001469
1470 if impl, ok := syspropImplLibraries[lib]; ok {
1471 lib = impl
1472 }
1473
1474 name, version := stubsLibNameAndVersion(lib)
1475 sharedLibNames = append(sharedLibNames, name)
1476
Jiyong Park25fc6a92018-11-18 18:02:45 +09001477 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001478 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001479
Jiyong Park7ed9de32018-10-15 22:25:07 +09001480 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001481 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001482 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1483 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1484 // linking against both the stubs lib and the non-stubs lib at the same time.
1485 continue
1486 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001487 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001488 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001489
Dan Willemsen59339a22018-07-22 21:18:45 -07001490 actx.AddVariationDependencies([]blueprint.Variation{
1491 {Mutator: "link", Variation: "shared"},
1492 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001493
Colin Cross68861832016-07-08 10:41:41 -07001494 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001495
1496 for _, gen := range deps.GeneratedHeaders {
1497 depTag := genHeaderDepTag
1498 if inList(gen, deps.ReexportGeneratedHeaders) {
1499 depTag = genHeaderExportDepTag
1500 }
1501 actx.AddDependency(c, depTag, gen)
1502 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001503
Colin Cross42d48b72018-08-29 14:10:52 -07001504 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001505
1506 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001507 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001508 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001509 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001510 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001511 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001512 if deps.LinkerFlagsFile != "" {
1513 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1514 }
1515 if deps.DynamicLinker != "" {
1516 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001517 }
Dan Albert914449f2016-06-17 16:45:24 -07001518
1519 version := ctx.sdkVersion()
1520 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001521 {Mutator: "ndk_api", Variation: version},
1522 {Mutator: "link", Variation: "shared"},
1523 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001524 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001525 {Mutator: "ndk_api", Variation: version},
1526 {Mutator: "link", Variation: "shared"},
1527 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001528
1529 if vndkdep := c.vndkdep; vndkdep != nil {
1530 if vndkdep.isVndkExt() {
Inseob Kim64c43952019-08-26 16:52:35 +09001531 var baseModuleMode string
Logan Chienf3511742017-10-31 18:04:35 +08001532 if actx.DeviceConfig().VndkVersion() == "" {
1533 baseModuleMode = coreMode
Inseob Kim64c43952019-08-26 16:52:35 +09001534 } else {
1535 baseModuleMode = c.imageVariation()
Logan Chienf3511742017-10-31 18:04:35 +08001536 }
1537 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001538 {Mutator: "image", Variation: baseModuleMode},
1539 {Mutator: "link", Variation: "shared"},
1540 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001541 }
1542 }
Colin Cross6362e272015-10-29 15:25:03 -07001543}
Colin Cross21b9a242015-03-24 14:15:58 -07001544
Colin Crosse40b4ea2018-10-02 22:25:58 -07001545func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001546 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1547 c.beginMutator(ctx)
1548 }
1549}
1550
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001551// Whether a module can link to another module, taking into
1552// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001553func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001554 if from.Target().Os != android.Android {
1555 // Host code is not restricted
1556 return
1557 }
Inseob Kim64c43952019-08-26 16:52:35 +09001558 if from.useVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001559 // Though vendor code is limited by the vendor mutator,
1560 // each vendor-available module needs to check
1561 // link-type for VNDK.
1562 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001563 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001564 }
1565 return
1566 }
Nan Zhang0007d812017-11-07 10:57:05 -08001567 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001568 // Platform code can link to anything
1569 return
1570 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001571 if from.inRecovery() {
1572 // Recovery code is not NDK
1573 return
1574 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001575 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1576 // These are always allowed
1577 return
1578 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001579 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1580 // These are allowed, but they don't set sdk_version
1581 return
1582 }
1583 if _, ok := to.linker.(*stubDecorator); ok {
1584 // These aren't real libraries, but are the stub shared libraries that are included in
1585 // the NDK.
1586 return
1587 }
Logan Chien834b9a62019-01-14 15:39:03 +08001588
1589 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" {
1590 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1591 // to link to libc++ (non-NDK and without sdk_version).
1592 return
1593 }
1594
Nan Zhang0007d812017-11-07 10:57:05 -08001595 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001596 // NDK code linking to platform code is never okay.
1597 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1598 ctx.OtherModuleName(to))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001599 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001600 }
1601
1602 // At this point we know we have two NDK libraries, but we need to
1603 // check that we're not linking against anything built against a higher
1604 // API level, as it is only valid to link against older or equivalent
1605 // APIs.
1606
Inseob Kim01a28722018-04-11 09:48:45 +09001607 // Current can link against anything.
1608 if String(from.Properties.Sdk_version) != "current" {
1609 // Otherwise we need to check.
1610 if String(to.Properties.Sdk_version) == "current" {
1611 // Current can't be linked against by anything else.
1612 ctx.ModuleErrorf("links %q built against newer API version %q",
1613 ctx.OtherModuleName(to), "current")
1614 } else {
1615 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1616 if err != nil {
1617 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001618 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001619 String(from.Properties.Sdk_version))
1620 }
1621 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1622 if err != nil {
1623 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001624 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001625 String(to.Properties.Sdk_version))
1626 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001627
Inseob Kim01a28722018-04-11 09:48:45 +09001628 if toApi > fromApi {
1629 ctx.ModuleErrorf("links %q built against newer API version %q",
1630 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1631 }
1632 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001633 }
Dan Albert202fe492017-12-15 13:56:59 -08001634
1635 // Also check that the two STL choices are compatible.
1636 fromStl := from.stl.Properties.SelectedStl
1637 toStl := to.stl.Properties.SelectedStl
1638 if fromStl == "" || toStl == "" {
1639 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001640 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001641 // We can be permissive with the system "STL" since it is only the C++
1642 // ABI layer, but in the future we should make sure that everyone is
1643 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001644 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001645 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1646 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1647 to.stl.Properties.SelectedStl)
1648 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001649}
1650
Jiyong Park5fb8c102018-04-09 12:03:06 +09001651// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001652// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1653// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001654// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001655func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
Inseob Kim9516ee92019-05-09 10:56:13 +09001656 llndkLibraries := llndkLibraries(ctx.Config())
Jooyung Hana70f0672019-01-18 15:20:43 +09001657 check := func(child, parent android.Module) bool {
1658 to, ok := child.(*Module)
1659 if !ok {
1660 // follow thru cc.Defaults, etc.
1661 return true
1662 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001663
Jooyung Hana70f0672019-01-18 15:20:43 +09001664 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1665 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001666 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001667
1668 // if target lib has no vendor variant, keep checking dependency graph
1669 if !to.hasVendorVariant() {
1670 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001671 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001672
Inseob Kim9516ee92019-05-09 10:56:13 +09001673 if to.isVndkSp() || inList(child.Name(), *llndkLibraries) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001674 return false
1675 }
1676
1677 var stringPath []string
1678 for _, m := range ctx.GetWalkPath() {
1679 stringPath = append(stringPath, m.Name())
1680 }
1681 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1682 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1683 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1684 return false
1685 }
1686 if module, ok := ctx.Module().(*Module); ok {
1687 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Inseob Kim9516ee92019-05-09 10:56:13 +09001688 if inList(ctx.ModuleName(), *llndkLibraries) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001689 ctx.WalkDeps(check)
1690 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001691 }
1692 }
1693}
1694
Colin Crossc99deeb2016-04-11 15:06:20 -07001695// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001696func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001697 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001698
Jeff Gaston294356f2017-09-27 17:05:30 -07001699 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001700 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001701
Inseob Kim9516ee92019-05-09 10:56:13 +09001702 llndkLibraries := llndkLibraries(ctx.Config())
1703 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
1704
Inseob Kim69378442019-06-03 19:10:47 +09001705 reexportExporter := func(exporter exportedFlagsProducer) {
1706 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
1707 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
1708 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
1709 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
1710 }
1711
Colin Crossd11fcda2017-10-23 17:59:01 -07001712 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001713 depName := ctx.OtherModuleName(dep)
1714 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001715
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001716 ccDep, _ := dep.(*Module)
1717 if ccDep == nil {
1718 // handling for a few module types that aren't cc Module but that are also supported
1719 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001720 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001721 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001722 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1723 genRule.GeneratedSourceFiles()...)
1724 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001725 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001726 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001727 // Support exported headers from a generated_sources dependency
1728 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001729 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001730 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001731 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001732 genRule.GeneratedDeps()...)
Inseob Kim69378442019-06-03 19:10:47 +09001733 dirs := genRule.GeneratedHeaderDirs().Strings()
1734 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001735 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09001736 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
1737 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001738 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
Inseob Kim69378442019-06-03 19:10:47 +09001739 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001740
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001741 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001742 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001743 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001744 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001745 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001746 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001747 files := genRule.GeneratedSourceFiles()
1748 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001749 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001750 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001751 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 -07001752 }
1753 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001754 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001755 }
Colin Crossca860ac2016-01-04 14:34:37 -08001756 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001757 return
1758 }
1759
Colin Crossfe17f6f2019-03-28 19:30:56 -07001760 if depTag == android.ProtoPluginDepTag {
1761 return
1762 }
1763
Colin Crossd11fcda2017-10-23 17:59:01 -07001764 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001765 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1766 return
1767 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001768 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001769 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001770 return
1771 }
1772
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001773 // re-exporting flags
1774 if depTag == reuseObjTag {
1775 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001776 c.staticVariant = ccDep
Inseob Kim69378442019-06-03 19:10:47 +09001777 objs, exporter := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001778 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09001779 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08001780 return
1781 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001782 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001783
Jiyong Parke4bb9862019-02-01 00:31:10 +09001784 if depTag == staticVariantTag {
1785 if _, ok := ccDep.compiler.(libraryInterface); ok {
1786 c.staticVariant = ccDep
1787 return
1788 }
1789 }
1790
Jiyong Park25fc6a92018-11-18 18:02:45 +09001791 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1792 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1793 // won't be matched to sharedDepTag and lateSharedDepTag.
1794 explicitlyVersioned := false
1795 if t, ok := depTag.(dependencyTag); ok {
1796 explicitlyVersioned = t.explicitlyVersioned
1797 t.explicitlyVersioned = false
1798 depTag = t
1799 }
1800
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001801 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001802 depIsStatic := false
1803 switch depTag {
1804 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1805 depIsStatic = true
1806 }
1807 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001808 depIsStubs := dependentLibrary.buildStubs()
1809 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001810 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001811 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001812
1813 var useThisDep bool
1814 if depIsStubs && explicitlyVersioned {
1815 // Always respect dependency to the versioned stubs (i.e. libX#10)
1816 useThisDep = true
1817 } else if !depHasStubs {
1818 // Use non-stub variant if that is the only choice
1819 // (i.e. depending on a lib without stubs.version property)
1820 useThisDep = true
1821 } else if c.IsForPlatform() {
1822 // If not building for APEX, use stubs only when it is from
1823 // an APEX (and not from platform)
1824 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001825 if c.inRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001826 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001827 // always link to non-stub variant
1828 useThisDep = !depIsStubs
1829 }
1830 } else {
1831 // If building for APEX, use stubs only when it is not from
1832 // the same APEX
1833 useThisDep = (depInSameApex != depIsStubs)
1834 }
1835
1836 if !useThisDep {
1837 return // stop processing this dep
1838 }
1839 }
1840
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001841 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Inseob Kim69378442019-06-03 19:10:47 +09001842 depPaths.IncludeDirs = append(depPaths.IncludeDirs, i.exportedDirs()...)
1843 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
1844 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedDeps()...)
1845 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001846
1847 if t.reexportFlags {
Inseob Kim69378442019-06-03 19:10:47 +09001848 reexportExporter(i)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001849 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
Jayant Chowdharyaf6eb712017-08-23 16:08:29 -07001850 // Re-exported shared library headers must be included as well since they can help us with type information
1851 // about template instantiations (instantiated from their headers).
Inseob Kim69378442019-06-03 19:10:47 +09001852 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
1853 // scripts.
1854 c.sabi.Properties.ReexportedIncludes = append(
1855 c.sabi.Properties.ReexportedIncludes, i.exportedDirs()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001856 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001857 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001858
Logan Chienf3511742017-10-31 18:04:35 +08001859 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001860 }
1861
Colin Cross26c34ed2016-09-30 17:10:16 -07001862 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001863 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001864
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001865 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001866 depFile := android.OptionalPath{}
1867
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001868 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001869 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001870 ptr = &depPaths.SharedLibs
1871 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001872 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001873 directSharedDeps = append(directSharedDeps, ccDep)
Jiyong Park64a44f22019-01-18 14:37:08 +09001874 case earlySharedDepTag:
1875 ptr = &depPaths.EarlySharedLibs
1876 depPtr = &depPaths.EarlySharedLibsDeps
1877 depFile = ccDep.linker.(libraryInterface).toc()
1878 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001879 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001880 ptr = &depPaths.LateSharedLibs
1881 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001882 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001883 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001884 ptr = nil
1885 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001886 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001887 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001888 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001889 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001890 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001891 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001892 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001893 return
1894 }
1895
1896 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001897 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001898 for i := range missingDeps {
1899 missingDeps[i] += postfix
1900 }
1901 ctx.AddMissingDependencies(missingDeps)
1902 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001903 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001904 case headerDepTag:
1905 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001906 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001907 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001908 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001909 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001910 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001911 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001912 case dynamicLinkerDepTag:
1913 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001914 }
1915
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001916 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001917 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001918 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001919 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001920 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001921 return
1922 }
1923
1924 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001925 // in static libraries act as if they were whole static libraries. The same goes for
1926 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001927 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1928 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001929 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1930 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001931
Dan Willemsen581341d2017-02-09 16:16:31 -08001932 }
1933
Colin Cross26c34ed2016-09-30 17:10:16 -07001934 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001935 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08001936 if !ctx.Config().AllowMissingDependencies() {
1937 ctx.ModuleErrorf("module %q missing output file", depName)
1938 } else {
1939 ctx.AddMissingDependencies([]string{depName})
1940 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001941 return
1942 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001943 *ptr = append(*ptr, linkFile.Path())
1944 }
1945
Colin Crossc99deeb2016-04-11 15:06:20 -07001946 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001947 dep := depFile
1948 if !dep.Valid() {
1949 dep = linkFile
1950 }
1951 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001952 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001953
Logan Chien43d34c32017-12-20 01:17:32 +08001954 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001955 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001956 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001957 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kim9516ee92019-05-09 10:56:13 +09001958 isLLndk := inList(libName, *llndkLibraries)
1959 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001960 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08001961
yidong.zhangd06ecc82019-08-02 15:49:24 +08001962 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.isVndk() && !ccDep.mustUseVendorVariant() && !c.inRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08001963 // The vendor module is a no-vendor-variant VNDK library. Depend on the
1964 // core module instead.
1965 return libName
1966 } else if c.useVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001967 // The vendor module in Make will have been renamed to not conflict with the core
1968 // module, so update the dependency name here accordingly.
Inseob Kim64c43952019-08-26 16:52:35 +09001969 ret := libName + vendorSuffix
1970 vendorVersion := ctx.DeviceConfig().VndkVersion()
1971 if vendorVersion == "current" {
1972 vendorVersion = ctx.DeviceConfig().PlatformVndkVersion()
1973 }
1974 if c.Properties.VndkVersion != vendorVersion {
1975 ret += "." + c.Properties.VndkVersion
1976 }
1977 return ret
Jiyong Park374510b2018-03-19 18:23:01 +09001978 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001979 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001980 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1981 return libName + recoverySuffix
dimitry1f33e402019-03-26 12:39:31 +01001982 } else if ccDep.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02001983 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001984 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001985 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001986 }
Logan Chien43d34c32017-12-20 01:17:32 +08001987 }
1988
1989 // Export the shared libs to Make.
1990 switch depTag {
Jiyong Park64a44f22019-01-18 14:37:08 +09001991 case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001992 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001993 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08001994 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09001995 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001996 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001997 c.Properties.ApexesProvidingSharedLibs = append(
1998 c.Properties.ApexesProvidingSharedLibs, an)
1999 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002000 }
2001 }
2002
Jiyong Park27b188b2017-07-18 13:23:39 +09002003 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002004 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002005 c.Properties.AndroidMkSharedLibs = append(
2006 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002007 case ndkStubDepTag, ndkLateStubDepTag:
2008 ndkStub := ccDep.linker.(*stubDecorator)
2009 c.Properties.AndroidMkSharedLibs = append(
2010 c.Properties.AndroidMkSharedLibs,
2011 depName+"."+ndkStub.properties.ApiLevel)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002012 case staticDepTag, staticExportDepTag, lateStaticDepTag:
2013 c.Properties.AndroidMkStaticLibs = append(
2014 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002015 case runtimeDepTag:
2016 c.Properties.AndroidMkRuntimeLibs = append(
2017 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002018 case wholeStaticDepTag:
2019 c.Properties.AndroidMkWholeStaticLibs = append(
2020 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002021 }
Colin Crossca860ac2016-01-04 14:34:37 -08002022 })
2023
Jeff Gaston294356f2017-09-27 17:05:30 -07002024 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002025 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002026
Colin Crossdd84e052017-05-17 13:44:16 -07002027 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002028 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Inseob Kim69378442019-06-03 19:10:47 +09002029 depPaths.IncludeDirs = android.FirstUniqueStrings(depPaths.IncludeDirs)
2030 depPaths.SystemIncludeDirs = android.FirstUniqueStrings(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002031 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kim69378442019-06-03 19:10:47 +09002032 depPaths.ReexportedDirs = android.FirstUniqueStrings(depPaths.ReexportedDirs)
2033 depPaths.ReexportedSystemDirs = android.FirstUniqueStrings(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002034 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002035 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002036
2037 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002038 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002039 }
Colin Crossdd84e052017-05-17 13:44:16 -07002040
Colin Crossca860ac2016-01-04 14:34:37 -08002041 return depPaths
2042}
2043
2044func (c *Module) InstallInData() bool {
2045 if c.installer == nil {
2046 return false
2047 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002048 return c.installer.inData()
2049}
2050
2051func (c *Module) InstallInSanitizerDir() bool {
2052 if c.installer == nil {
2053 return false
2054 }
2055 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002056 return true
2057 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002058 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002059}
2060
Jiyong Parkf9332f12018-02-01 00:54:12 +09002061func (c *Module) InstallInRecovery() bool {
2062 return c.inRecovery()
2063}
2064
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002065func (c *Module) HostToolPath() android.OptionalPath {
2066 if c.installer == nil {
2067 return android.OptionalPath{}
2068 }
2069 return c.installer.hostToolPath()
2070}
2071
Nan Zhangd4e641b2017-07-12 12:55:28 -07002072func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2073 return c.outputFile
2074}
2075
Colin Cross41955e82019-05-29 14:40:35 -07002076func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2077 switch tag {
2078 case "":
2079 if c.outputFile.Valid() {
2080 return android.Paths{c.outputFile.Path()}, nil
2081 }
2082 return android.Paths{}, nil
2083 default:
2084 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002085 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002086}
2087
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002088func (c *Module) static() bool {
2089 if static, ok := c.linker.(interface {
2090 static() bool
2091 }); ok {
2092 return static.static()
2093 }
2094 return false
2095}
2096
Jiyong Park379de2f2018-12-19 02:47:14 +09002097func (c *Module) staticBinary() bool {
2098 if static, ok := c.linker.(interface {
2099 staticBinary() bool
2100 }); ok {
2101 return static.staticBinary()
2102 }
2103 return false
2104}
2105
Jiyong Park1d1119f2019-07-29 21:27:18 +09002106func (c *Module) header() bool {
2107 if h, ok := c.linker.(interface {
2108 header() bool
2109 }); ok {
2110 return h.header()
2111 }
2112 return false
2113}
2114
Jooyung Han38002912019-05-16 04:01:54 +09002115func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
2116 name := actx.ModuleName()
Colin Crossb60190a2018-09-04 16:28:17 -07002117 if c.useVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002118 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2119 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002120 return "native:vndk"
2121 }
Jooyung Han38002912019-05-16 04:01:54 +09002122 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002123 }
Jooyung Han38002912019-05-16 04:01:54 +09002124 if c.isVndk() && !c.isVndkExt() {
2125 if Bool(c.VendorProperties.Vendor_available) {
2126 return "native:vndk"
2127 }
2128 return "native:vndk_private"
2129 }
2130 return "native:vendor"
Colin Crossb60190a2018-09-04 16:28:17 -07002131 } else if c.inRecovery() {
2132 return "native:recovery"
2133 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2134 return "native:ndk:none:none"
2135 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2136 //family, link := getNdkStlFamilyAndLinkType(c)
2137 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Jooyung Han38002912019-05-16 04:01:54 +09002138 } else if inList(name, *vndkUsingCoreVariantLibraries(actx.Config())) {
Vic Yangefd249e2018-11-12 20:19:56 -08002139 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002140 } else {
2141 return "native:platform"
2142 }
2143}
2144
Jiyong Park9d452992018-10-03 00:38:19 +09002145// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002146// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002147func (c *Module) IsInstallableToApex() bool {
2148 if shared, ok := c.linker.(interface {
2149 shared() bool
2150 }); ok {
2151 return shared.shared()
Roland Levillainf89cd092019-07-29 16:22:59 +01002152 } else if _, ok := c.linker.(testPerSrc); ok {
2153 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002154 }
2155 return false
2156}
2157
Jiyong Parka90ca002019-10-07 15:47:24 +09002158func (c *Module) AvailableFor(what string) bool {
2159 if linker, ok := c.linker.(interface {
2160 availableFor(string) bool
2161 }); ok {
2162 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2163 } else {
2164 return c.ApexModuleBase.AvailableFor(what)
2165 }
2166}
2167
Inseob Kim1f086e22019-05-09 13:29:15 +09002168func (c *Module) installable() bool {
2169 return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
2170}
2171
Jiyong Park3b1746a2019-01-29 11:15:04 +09002172func (c *Module) imageVariation() string {
Jiyong Park3b1746a2019-01-29 11:15:04 +09002173 if c.useVndk() {
Inseob Kim64c43952019-08-26 16:52:35 +09002174 return vendorMode + "." + c.Properties.VndkVersion
Jiyong Park3b1746a2019-01-29 11:15:04 +09002175 } else if c.inRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09002176 return recoveryMode
Jiyong Park3b1746a2019-01-29 11:15:04 +09002177 }
Inseob Kim64c43952019-08-26 16:52:35 +09002178 return coreMode
Jiyong Park3b1746a2019-01-29 11:15:04 +09002179}
2180
bralee3f49f4d2019-03-04 06:58:15 +08002181func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
Colin Cross41955e82019-05-29 14:40:35 -07002182 outputFiles, err := c.OutputFiles("")
2183 if err != nil {
2184 panic(err)
2185 }
2186 dpInfo.Srcs = append(dpInfo.Srcs, outputFiles.Strings()...)
bralee3f49f4d2019-03-04 06:58:15 +08002187}
2188
Logan Chien41eabe62019-04-10 13:33:58 +08002189func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2190 if c.linker != nil {
2191 if library, ok := c.linker.(*libraryDecorator); ok {
2192 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2193 }
2194 }
2195}
2196
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002197func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
2198 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(dependencyTag); ok {
2199 if cc, ok := dep.(*Module); ok && cc.IsStubs() && depTag.shared {
2200 // dynamic dep to a stubs lib crosses APEX boundary
2201 return false
2202 }
2203 }
2204 return true
2205}
2206
Colin Cross2ba19d92015-05-07 15:44:20 -07002207//
Colin Crosscfad1192015-11-02 16:43:11 -08002208// Defaults
2209//
Colin Crossca860ac2016-01-04 14:34:37 -08002210type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002211 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002212 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002213 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002214}
2215
Patrice Arrudac249c712019-03-19 17:00:29 -07002216// cc_defaults provides a set of properties that can be inherited by other cc
2217// modules. A module can use the properties from a cc_defaults using
2218// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2219// merged (when possible) by prepending the default module's values to the
2220// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002221func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002222 return DefaultsFactory()
2223}
2224
Colin Cross36242852017-06-23 15:06:31 -07002225func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002226 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002227
Colin Cross36242852017-06-23 15:06:31 -07002228 module.AddProperties(props...)
2229 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002230 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002231 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002232 &BaseCompilerProperties{},
2233 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002234 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002235 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002236 &StaticProperties{},
2237 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002238 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002239 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002240 &TestProperties{},
2241 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002242 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002243 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002244 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002245 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002246 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002247 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002248 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002249 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002250 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002251 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002252 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002253 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002254 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002255 )
Colin Crosscfad1192015-11-02 16:43:11 -08002256
Jooyung Hancc372c52019-09-25 15:18:44 +09002257 android.InitDefaultsModule(module)
Jiyong Park7916bfc2019-09-30 19:13:12 +09002258 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002259
2260 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002261}
2262
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002263const (
2264 // coreMode is the variant used for framework-private libraries, or
2265 // SDK libraries. (which framework-private libraries can use)
2266 coreMode = "core"
2267
Inseob Kim64c43952019-08-26 16:52:35 +09002268 // vendorMode is the variant prefix used for /vendor code that compiles
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002269 // against the VNDK.
2270 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09002271
2272 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002273)
2274
Jiyong Park6a43f042017-10-12 23:05:00 +09002275func squashVendorSrcs(m *Module) {
2276 if lib, ok := m.compiler.(*libraryDecorator); ok {
2277 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2278 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2279
2280 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2281 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2282 }
2283}
2284
Jiyong Parkf9332f12018-02-01 00:54:12 +09002285func squashRecoverySrcs(m *Module) {
2286 if lib, ok := m.compiler.(*libraryDecorator); ok {
2287 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2288 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2289
2290 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2291 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2292 }
2293}
2294
Jiyong Parkda6eb592018-12-19 17:12:36 +09002295func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002296 if mctx.Os() != android.Android {
2297 return
2298 }
2299
Jiyong Park7ed9de32018-10-15 22:25:07 +09002300 if g, ok := mctx.Module().(*genrule.Module); ok {
2301 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09002302 var coreVariantNeeded bool = false
2303 var vendorVariantNeeded bool = false
2304 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09002305 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09002306 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002307 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09002308 coreVariantNeeded = true
2309 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09002310 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09002311 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002312 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09002313 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002314 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002315 if Bool(props.Recovery_available) {
2316 recoveryVariantNeeded = true
2317 }
2318
Jiyong Park413cc742018-06-19 01:46:06 +09002319 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002320 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09002321 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09002322 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002323 recoveryVariantNeeded = false
2324 }
2325 }
2326
Jiyong Park3f736c92018-05-24 13:36:56 +09002327 var variants []string
2328 if coreVariantNeeded {
2329 variants = append(variants, coreMode)
2330 }
2331 if vendorVariantNeeded {
Inseob Kim64c43952019-08-26 16:52:35 +09002332 variants = append(variants, vendorMode+"."+mctx.DeviceConfig().PlatformVndkVersion())
2333 if vndkVersion := mctx.DeviceConfig().VndkVersion(); vndkVersion != "current" {
2334 variants = append(variants, vendorMode+"."+vndkVersion)
2335 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002336 }
2337 if recoveryVariantNeeded {
2338 variants = append(variants, recoveryMode)
2339 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002340 mod := mctx.CreateVariations(variants...)
2341 for i, v := range variants {
2342 if v == recoveryMode {
2343 m := mod[i].(*genrule.Module)
2344 m.Extra.(*GenruleExtraProperties).InRecovery = true
2345 }
2346 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002347 }
2348 }
2349
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002350 m, ok := mctx.Module().(*Module)
2351 if !ok {
2352 return
2353 }
2354
2355 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002356 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002357 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002358
2359 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002360 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002361 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002362 return
2363 }
Logan Chienf3511742017-10-31 18:04:35 +08002364
2365 if vndkdep := m.vndkdep; vndkdep != nil {
2366 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002367 if productSpecific {
2368 mctx.PropertyErrorf("product_specific",
2369 "product_specific must not be true when `vndk: {enabled: true}`")
2370 return
2371 }
Logan Chienf3511742017-10-31 18:04:35 +08002372 if vendorSpecific {
2373 if !vndkdep.isVndkExt() {
2374 mctx.PropertyErrorf("vndk",
2375 "must set `extends: \"...\"` to vndk extension")
2376 return
2377 }
2378 } else {
2379 if vndkdep.isVndkExt() {
2380 mctx.PropertyErrorf("vndk",
2381 "must set `vendor: true` to set `extends: %q`",
2382 m.getVndkExtendsModuleName())
2383 return
2384 }
2385 if m.VendorProperties.Vendor_available == nil {
2386 mctx.PropertyErrorf("vndk",
2387 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2388 return
2389 }
2390 }
2391 } else {
2392 if vndkdep.isVndkSp() {
2393 mctx.PropertyErrorf("vndk",
2394 "must set `enabled: true` to set `support_system_process: true`")
2395 return
2396 }
2397 if vndkdep.isVndkExt() {
2398 mctx.PropertyErrorf("vndk",
2399 "must set `enabled: true` to set `extends: %q`",
2400 m.getVndkExtendsModuleName())
2401 return
2402 }
Justin Yun8effde42017-06-23 19:24:43 +09002403 }
2404 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002405
Jiyong Parkf9332f12018-02-01 00:54:12 +09002406 var coreVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002407 var recoveryVariantNeeded bool = false
2408
Inseob Kim64c43952019-08-26 16:52:35 +09002409 var vendorVariants []string
2410
2411 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
2412 deviceVndkVersion := mctx.DeviceConfig().VndkVersion()
2413 if deviceVndkVersion == "current" {
2414 deviceVndkVersion = platformVndkVersion
2415 }
2416
Justin Yun71549282017-11-17 12:10:28 +09002417 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002418 // If the device isn't compiling against the VNDK, we always
2419 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002420 coreVariantNeeded = true
Justin Yun1282f422019-09-09 14:42:44 +09002421 } else if m.Target().NativeBridge == android.NativeBridgeEnabled {
2422 // Skip creating vendor variants for natvie bridge modules
2423 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002424 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2425 // LL-NDK stubs only exist in the vendor variant, since the
2426 // real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002427 vendorVariants = append(vendorVariants,
2428 platformVndkVersion,
2429 deviceVndkVersion,
2430 )
Jiyong Park2a454122017-10-19 15:59:33 +09002431 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2432 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002433 vendorVariants = append(vendorVariants,
2434 platformVndkVersion,
2435 deviceVndkVersion,
2436 )
2437 } else if lib, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002438 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2439 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kim64c43952019-08-26 16:52:35 +09002440 vendorVariants = append(vendorVariants, lib.version())
Logan Chienf3511742017-10-31 18:04:35 +08002441 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002442 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002443 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002444 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002445 vendorVariants = append(vendorVariants, platformVndkVersion)
2446 if m.isVndk() {
2447 vendorVariants = append(vendorVariants, deviceVndkVersion)
2448 }
Logan Chienf3511742017-10-31 18:04:35 +08002449 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002450 // This will be available in /vendor (or /odm) only
Inseob Kim64c43952019-08-26 16:52:35 +09002451 vendorVariants = append(vendorVariants, deviceVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002452 } else {
2453 // This is either in /system (or similar: /data), or is a
2454 // modules built with the NDK. Modules built with the NDK
2455 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002456 coreVariantNeeded = true
2457 }
2458
2459 if Bool(m.Properties.Recovery_available) {
2460 recoveryVariantNeeded = true
2461 }
2462
2463 if m.ModuleBase.InstallInRecovery() {
2464 recoveryVariantNeeded = true
2465 coreVariantNeeded = false
2466 }
2467
Jiyong Park413cc742018-06-19 01:46:06 +09002468 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002469 primaryArch := mctx.Config().DevicePrimaryArchType()
2470 moduleArch := m.Target().Arch.ArchType
2471 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002472 recoveryVariantNeeded = false
2473 }
2474 }
2475
Jiyong Parkf9332f12018-02-01 00:54:12 +09002476 var variants []string
2477 if coreVariantNeeded {
2478 variants = append(variants, coreMode)
2479 }
Inseob Kim64c43952019-08-26 16:52:35 +09002480 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
2481 variants = append(variants, vendorMode+"."+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09002482 }
2483 if recoveryVariantNeeded {
2484 variants = append(variants, recoveryMode)
2485 }
2486 mod := mctx.CreateVariations(variants...)
2487 for i, v := range variants {
Inseob Kim64c43952019-08-26 16:52:35 +09002488 if strings.HasPrefix(v, vendorMode+".") {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002489 m := mod[i].(*Module)
Inseob Kim64c43952019-08-26 16:52:35 +09002490 m.Properties.VndkVersion = strings.TrimPrefix(v, vendorMode+".")
Jiyong Parkf9332f12018-02-01 00:54:12 +09002491 squashVendorSrcs(m)
2492 } else if v == recoveryMode {
2493 m := mod[i].(*Module)
2494 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002495 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002496 squashRecoverySrcs(m)
2497 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002498 }
2499}
2500
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002501func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002502 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002503 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2504 }
Colin Cross6510f912017-11-29 00:27:14 -08002505 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002506}
2507
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002508func kytheExtractAllFactory() android.Singleton {
2509 return &kytheExtractAllSingleton{}
2510}
2511
2512type kytheExtractAllSingleton struct {
2513}
2514
2515func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2516 var xrefTargets android.Paths
2517 ctx.VisitAllModules(func(module android.Module) {
2518 if ccModule, ok := module.(xref); ok {
2519 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
2520 }
2521 })
2522 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
2523 if len(xrefTargets) > 0 {
2524 ctx.Build(pctx, android.BuildParams{
2525 Rule: blueprint.Phony,
2526 Output: android.PathForPhony(ctx, "xref_cxx"),
2527 Inputs: xrefTargets,
2528 //Default: true,
2529 })
2530 }
2531}
2532
Colin Cross06a931b2015-10-28 17:23:31 -07002533var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002534var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002535var BoolPtr = proptools.BoolPtr
2536var String = proptools.String
2537var StringPtr = proptools.StringPtr