blob: cba191fd5559651f744260d2547e3cfd326d2190 [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) {
Jiyong Parkda6eb592018-12-19 17:12:36 +090039 ctx.BottomUp("image", ImageMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070040 ctx.BottomUp("link", LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +090041 ctx.BottomUp("vndk", VndkMutator).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
156 TidyFlags []string // Flags that apply to clang-tidy
157 SAbiFlags []string // Flags that apply to header-abi-dumper
158 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700159
Colin Crossc3199482017-03-30 15:03:04 -0700160 // Global include flags that apply to C, C++, and assembly source files
161 // These must be after any module include flags, which will be in GlobalFlags.
162 SystemIncludeFlags []string
163
Colin Crossb98c8b02016-07-29 13:44:28 -0700164 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700165 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800166 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800167 SAbiDump bool
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800168 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800169
170 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800171 DynamicLinker string
172
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700173 CFlagsDeps android.Paths // Files depended on by compiler flags
174 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800175
176 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800177
Colin Cross19878da2019-03-28 14:45:07 -0700178 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700179 protoC bool // Whether to use C instead of C++
180 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700181
182 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700183}
184
Colin Cross81413472016-04-11 14:37:39 -0700185type ObjectLinkerProperties struct {
Paul Duffina37832a2019-07-18 12:31:26 +0100186 // list of modules that should only provide headers for this module.
187 Header_libs []string `android:"arch_variant,variant_prepend"`
188
Colin Cross81413472016-04-11 14:37:39 -0700189 // names of other cc_object modules to link into this module using partial linking
190 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700191
192 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800193 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700194}
195
Colin Crossca860ac2016-01-04 14:34:37 -0800196// Properties used to compile all C or C++ modules
197type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700198 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800199 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700200
201 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800202 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700203
Jiyong Parkde866cb2018-12-07 23:08:36 +0900204 AndroidMkSharedLibs []string `blueprint:"mutated"`
205 AndroidMkStaticLibs []string `blueprint:"mutated"`
206 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
207 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
208 HideFromMake bool `blueprint:"mutated"`
209 PreventInstall bool `blueprint:"mutated"`
210 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700211
212 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800213
214 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
215 // file
216 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900217
218 // Make this module available when building for recovery
219 Recovery_available *bool
220
221 InRecovery bool `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900222
223 // Allows this module to use non-APEX version of libraries. Useful
224 // for building binaries that are started before APEXes are activated.
225 Bootstrap *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700226}
227
228type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900229 // whether this module should be allowed to be directly depended by other
230 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
231 // If set to true, two variants will be built separately, one like
232 // normal, and the other limited to the set of libraries and headers
233 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700234 //
235 // The vendor variant may be used with a different (newer) /system,
236 // so it shouldn't have any unversioned runtime dependencies, or
237 // make assumptions about the system that may not be true in the
238 // future.
239 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900240 // If set to false, this module becomes inaccessible from /vendor modules.
241 //
242 // Default value is true when vndk: {enabled: true} or vendor: true.
243 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700244 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
245 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900246
247 // whether this module is capable of being loaded with other instance
248 // (possibly an older version) of the same module in the same process.
249 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
250 // can be double loaded in a vendor process if the library is also a
251 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
252 // explicitly marked as `double_loadable: true` by the owner, or the dependency
253 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
254 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800255}
256
Colin Crossca860ac2016-01-04 14:34:37 -0800257type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800258 static() bool
259 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900260 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700261 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700262 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800263 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700264 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800265 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900266 isLlndk(config android.Config) bool
267 isLlndkPublic(config android.Config) bool
268 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900269 isVndk() bool
270 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800271 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900272 inRecovery() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900273 shouldCreateVndkSourceAbiDump(config android.Config) bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700274 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700275 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800276 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800277 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800278 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800279 useClangLld(actx ModuleContext) bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900280 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900281 hasStubsVariants() bool
282 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900283 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800284 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700285 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800286}
287
288type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700289 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800290 ModuleContextIntf
291}
292
293type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700294 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800295 ModuleContextIntf
296}
297
Colin Cross37047f12016-12-13 17:06:13 -0800298type DepsContext interface {
299 android.BottomUpMutatorContext
300 ModuleContextIntf
301}
302
Colin Crossca860ac2016-01-04 14:34:37 -0800303type feature interface {
304 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800305 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800306 flags(ctx ModuleContext, flags Flags) Flags
307 props() []interface{}
308}
309
310type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700311 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800312 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800313 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700314 compilerProps() []interface{}
315
Colin Cross76fada02016-07-27 10:31:13 -0700316 appendCflags([]string)
317 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700318 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800319}
320
321type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700322 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800323 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700324 linkerFlags(ctx ModuleContext, flags Flags) Flags
325 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800326 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700327
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700328 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700329 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900330 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700331
332 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800333}
334
335type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700336 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700337 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800338 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700339 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700340 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900341 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800342}
343
Colin Crossc99deeb2016-04-11 15:06:20 -0700344type dependencyTag struct {
345 blueprint.BaseDependencyTag
346 name string
347 library bool
Roland Levillainf89cd092019-07-29 16:22:59 +0100348 shared bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700349
350 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900351
352 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700353}
354
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800355type xref interface {
356 XrefCcFiles() android.Paths
357}
358
Colin Crossc99deeb2016-04-11 15:06:20 -0700359var (
Roland Levillainf89cd092019-07-29 16:22:59 +0100360 sharedDepTag = dependencyTag{name: "shared", library: true, shared: true}
361 sharedExportDepTag = dependencyTag{name: "shared", library: true, shared: true, reexportFlags: true}
362 earlySharedDepTag = dependencyTag{name: "early_shared", library: true, shared: true}
363 lateSharedDepTag = dependencyTag{name: "late shared", library: true, shared: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700364 staticDepTag = dependencyTag{name: "static", library: true}
365 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
366 lateStaticDepTag = dependencyTag{name: "late static", library: true}
367 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800368 headerDepTag = dependencyTag{name: "header", library: true}
369 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700370 genSourceDepTag = dependencyTag{name: "gen source"}
371 genHeaderDepTag = dependencyTag{name: "gen header"}
372 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
373 objDepTag = dependencyTag{name: "obj"}
374 crtBeginDepTag = dependencyTag{name: "crtbegin"}
375 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700376 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
377 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700378 reuseObjTag = dependencyTag{name: "reuse objects"}
Jiyong Parke4bb9862019-02-01 00:31:10 +0900379 staticVariantTag = dependencyTag{name: "static variant"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700380 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
381 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800382 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800383 runtimeDepTag = dependencyTag{name: "runtime lib"}
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -0700384 coverageDepTag = dependencyTag{name: "coverage"}
Roland Levillainf2fad972019-06-28 15:41:19 +0100385 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700386)
387
Roland Levillainf89cd092019-07-29 16:22:59 +0100388func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
389 ccDepTag, ok := depTag.(dependencyTag)
390 return ok && ccDepTag.shared
391}
392
393func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
394 ccDepTag, ok := depTag.(dependencyTag)
395 return ok && ccDepTag == runtimeDepTag
396}
397
398func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
399 ccDepTag, ok := depTag.(dependencyTag)
400 return ok && ccDepTag == testPerSrcDepTag
401}
402
Colin Crossca860ac2016-01-04 14:34:37 -0800403// Module contains the properties and members used by all C/C++ module types, and implements
404// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
405// to construct the output file. Behavior can be customized with a Customizer interface
406type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700407 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700408 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900409 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700410
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700411 Properties BaseProperties
412 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700413
Colin Crossca860ac2016-01-04 14:34:37 -0800414 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700415 hod android.HostOrDeviceSupported
416 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700417
Colin Crossca860ac2016-01-04 14:34:37 -0800418 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700419 features []feature
420 compiler compiler
421 linker linker
422 installer installer
423 stl *stl
424 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800425 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800426 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900427 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700428 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700429 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800430 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800431
432 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700433
Colin Cross635c3b02016-05-18 15:37:25 -0700434 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800435
Colin Crossb98c8b02016-07-29 13:44:28 -0700436 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700437
438 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800439
440 // Flags used to compile this module
441 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700442
443 // 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 -0800444 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700445 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800446 depsInLinkOrder android.Paths
447
448 // only non-nil when this is a shared library that reuses the objects of a static library
449 staticVariant *Module
Inseob Kim9516ee92019-05-09 10:56:13 +0900450
451 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800452 // Kythe (source file indexer) paths for this compilation module
453 kytheFiles android.Paths
Colin Crossc472d572015-03-17 15:06:21 -0700454}
455
Jiyong Parkc20eee32018-09-05 22:36:17 +0900456func (c *Module) OutputFile() android.OptionalPath {
457 return c.outputFile
458}
459
Jiyong Park719b4462019-01-13 00:39:51 +0900460func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900461 if c.linker != nil {
462 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900463 }
464 return nil
465}
466
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900467func (c *Module) RelativeInstallPath() string {
468 if c.installer != nil {
469 return c.installer.relativeInstallPath()
470 }
471 return ""
472}
473
Colin Cross36242852017-06-23 15:06:31 -0700474func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700475 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800476 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700477 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800478 }
479 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700480 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800481 }
482 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700483 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800484 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700485 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700486 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700487 }
Colin Cross16b23492016-01-06 14:41:07 -0800488 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700489 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800490 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800491 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700492 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800493 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800494 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700495 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800496 }
Justin Yun8effde42017-06-23 19:24:43 +0900497 if c.vndkdep != nil {
498 c.AddProperties(c.vndkdep.props()...)
499 }
Stephen Craneba090d12017-05-09 15:44:35 -0700500 if c.lto != nil {
501 c.AddProperties(c.lto.props()...)
502 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700503 if c.pgo != nil {
504 c.AddProperties(c.pgo.props()...)
505 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800506 if c.xom != nil {
507 c.AddProperties(c.xom.props()...)
508 }
Colin Crossca860ac2016-01-04 14:34:37 -0800509 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700510 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800511 }
Colin Crossc472d572015-03-17 15:06:21 -0700512
Colin Crossa9d8bee2018-10-02 13:59:46 -0700513 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
514 switch class {
515 case android.Device:
516 return ctx.Config().DevicePrefer32BitExecutables()
517 case android.HostCross:
518 // Windows builds always prefer 32-bit
519 return true
520 default:
521 return false
522 }
523 })
Colin Cross36242852017-06-23 15:06:31 -0700524 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700525
Colin Cross1f44a3a2017-07-07 14:33:33 -0700526 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700527
Jiyong Park9d452992018-10-03 00:38:19 +0900528 android.InitApexModule(c)
529
Colin Cross36242852017-06-23 15:06:31 -0700530 return c
Colin Crossc472d572015-03-17 15:06:21 -0700531}
532
Colin Crossb916a382016-07-29 17:28:03 -0700533// Returns true for dependency roots (binaries)
534// TODO(ccross): also handle dlopenable libraries
535func (c *Module) isDependencyRoot() bool {
536 if root, ok := c.linker.(interface {
537 isDependencyRoot() bool
538 }); ok {
539 return root.isDependencyRoot()
540 }
541 return false
542}
543
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700544func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700545 return c.Properties.UseVndk
546}
547
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800548func (c *Module) isCoverageVariant() bool {
549 return c.coverage.Properties.IsCoverageVariant
550}
551
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800552func (c *Module) isNdk() bool {
553 return inList(c.Name(), ndkMigratedLibs)
554}
555
Inseob Kim9516ee92019-05-09 10:56:13 +0900556func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800557 // Returns true for both LLNDK (public) and LLNDK-private libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900558 return inList(c.Name(), *llndkLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800559}
560
Inseob Kim9516ee92019-05-09 10:56:13 +0900561func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800562 // Returns true only for LLNDK (public) libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900563 return c.isLlndk(config) && !c.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800564}
565
Inseob Kim9516ee92019-05-09 10:56:13 +0900566func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800567 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Inseob Kim9516ee92019-05-09 10:56:13 +0900568 return inList(c.Name(), *vndkPrivateLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800569}
570
Justin Yun8effde42017-06-23 19:24:43 +0900571func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800572 if vndkdep := c.vndkdep; vndkdep != nil {
573 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900574 }
575 return false
576}
577
Jooyung Han76106d92019-05-20 18:49:10 +0900578func (c *Module) vndkVersion() string {
579 if vndkdep := c.vndkdep; vndkdep != nil {
580 return vndkdep.Properties.Vndk.Version
581 }
582 return ""
583}
584
Yi Kong7e53c572018-02-14 18:16:12 +0800585func (c *Module) isPgoCompile() bool {
586 if pgo := c.pgo; pgo != nil {
587 return pgo.Properties.PgoCompile
588 }
589 return false
590}
591
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800592func (c *Module) isNDKStubLibrary() bool {
593 if _, ok := c.compiler.(*stubDecorator); ok {
594 return true
595 }
596 return false
597}
598
Logan Chienf3511742017-10-31 18:04:35 +0800599func (c *Module) isVndkSp() bool {
600 if vndkdep := c.vndkdep; vndkdep != nil {
601 return vndkdep.isVndkSp()
602 }
603 return false
604}
605
606func (c *Module) isVndkExt() bool {
607 if vndkdep := c.vndkdep; vndkdep != nil {
608 return vndkdep.isVndkExt()
609 }
610 return false
611}
612
Vic Yangefd249e2018-11-12 20:19:56 -0800613func (c *Module) mustUseVendorVariant() bool {
614 return c.isVndkSp() || inList(c.Name(), config.VndkMustUseVendorVariantList)
615}
616
Logan Chienf3511742017-10-31 18:04:35 +0800617func (c *Module) getVndkExtendsModuleName() string {
618 if vndkdep := c.vndkdep; vndkdep != nil {
619 return vndkdep.getVndkExtendsModuleName()
620 }
621 return ""
622}
623
Jiyong Park82e2bf32017-08-16 14:05:54 +0900624// Returns true only when this module is configured to have core and vendor
625// variants.
626func (c *Module) hasVendorVariant() bool {
627 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
628}
629
Jiyong Parkf9332f12018-02-01 00:54:12 +0900630func (c *Module) inRecovery() bool {
631 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
632}
633
634func (c *Module) onlyInRecovery() bool {
635 return c.ModuleBase.InstallInRecovery()
636}
637
Jiyong Park25fc6a92018-11-18 18:02:45 +0900638func (c *Module) IsStubs() bool {
639 if library, ok := c.linker.(*libraryDecorator); ok {
640 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900641 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
642 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900643 }
644 return false
645}
646
647func (c *Module) HasStubsVariants() bool {
648 if library, ok := c.linker.(*libraryDecorator); ok {
649 return len(library.Properties.Stubs.Versions) > 0
650 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700651 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
652 return len(library.Properties.Stubs.Versions) > 0
653 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900654 return false
655}
656
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900657func (c *Module) bootstrap() bool {
658 return Bool(c.Properties.Bootstrap)
659}
660
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700661func (c *Module) nativeCoverage() bool {
662 return c.linker != nil && c.linker.nativeCoverage()
663}
664
Jiyong Parkf1194352019-02-25 11:05:47 +0900665func isBionic(name string) bool {
666 switch name {
667 case "libc", "libm", "libdl", "linker":
668 return true
669 }
670 return false
671}
672
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700673func installToBootstrap(name string, config android.Config) bool {
674 if name == "libclang_rt.hwasan-aarch64-android" {
675 return inList("hwaddress", config.SanitizeDevice())
676 }
677 return isBionic(name)
678}
679
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800680func (c *Module) XrefCcFiles() android.Paths {
681 return c.kytheFiles
682}
683
Colin Crossca860ac2016-01-04 14:34:37 -0800684type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700685 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800686 moduleContextImpl
687}
688
Colin Cross37047f12016-12-13 17:06:13 -0800689type depsContext struct {
690 android.BottomUpMutatorContext
691 moduleContextImpl
692}
693
Colin Crossca860ac2016-01-04 14:34:37 -0800694type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700695 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800696 moduleContextImpl
697}
698
Jiyong Park2db76922017-11-08 16:03:48 +0900699func (ctx *moduleContext) SocSpecific() bool {
700 return ctx.ModuleContext.SocSpecific() ||
701 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700702}
703
Colin Crossca860ac2016-01-04 14:34:37 -0800704type moduleContextImpl struct {
705 mod *Module
706 ctx BaseModuleContext
707}
708
Colin Crossb98c8b02016-07-29 13:44:28 -0700709func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800710 return ctx.mod.toolchain(ctx.ctx)
711}
712
713func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000714 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800715}
716
717func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900718 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800719}
720
Jiyong Park1d1119f2019-07-29 21:27:18 +0900721func (ctx *moduleContextImpl) header() bool {
722 return ctx.mod.header()
723}
724
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700725func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800726 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800727 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700728 }
729 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800730}
731
732func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700733 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700734 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900735 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700736 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900737 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
738 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
739 return "current"
740 }
741 return platform_vndk_ver
742 }
743 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800744 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900745 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700746 }
747 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800748}
749
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700750func (ctx *moduleContextImpl) useVndk() bool {
751 return ctx.mod.useVndk()
752}
Justin Yun8effde42017-06-23 19:24:43 +0900753
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800754func (ctx *moduleContextImpl) isNdk() bool {
755 return ctx.mod.isNdk()
756}
757
Inseob Kim9516ee92019-05-09 10:56:13 +0900758func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
759 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800760}
761
Inseob Kim9516ee92019-05-09 10:56:13 +0900762func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
763 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800764}
765
Inseob Kim9516ee92019-05-09 10:56:13 +0900766func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
767 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800768}
769
Logan Chienf3511742017-10-31 18:04:35 +0800770func (ctx *moduleContextImpl) isVndk() bool {
771 return ctx.mod.isVndk()
772}
773
Yi Kong7e53c572018-02-14 18:16:12 +0800774func (ctx *moduleContextImpl) isPgoCompile() bool {
775 return ctx.mod.isPgoCompile()
776}
777
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800778func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
779 return ctx.mod.isNDKStubLibrary()
780}
781
Justin Yun8effde42017-06-23 19:24:43 +0900782func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800783 return ctx.mod.isVndkSp()
784}
785
786func (ctx *moduleContextImpl) isVndkExt() bool {
787 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900788}
789
Vic Yangefd249e2018-11-12 20:19:56 -0800790func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
791 return ctx.mod.mustUseVendorVariant()
792}
793
Jiyong Parkf9332f12018-02-01 00:54:12 +0900794func (ctx *moduleContextImpl) inRecovery() bool {
795 return ctx.mod.inRecovery()
796}
797
Logan Chien2f2b8902018-07-10 15:01:19 +0800798// Check whether ABI dumps should be created for this module.
Inseob Kim9516ee92019-05-09 10:56:13 +0900799func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump(config android.Config) bool {
Logan Chien2f2b8902018-07-10 15:01:19 +0800800 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
801 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800802 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800803
804 if ctx.ctx.Fuchsia() {
805 return false
806 }
807
Logan Chien2f2b8902018-07-10 15:01:19 +0800808 if sanitize := ctx.mod.sanitize; sanitize != nil {
809 if !sanitize.isVariantOnProductionDevice() {
810 return false
811 }
812 }
813 if !ctx.ctx.Device() {
814 // Host modules do not need ABI dumps.
815 return false
816 }
Logan Chienfa478c02018-12-28 16:25:39 +0800817 if !ctx.mod.IsForPlatform() {
818 // APEX variants do not need ABI dumps.
819 return false
820 }
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +0800821 if ctx.isStubs() {
822 // Stubs do not need ABI dumps.
823 return false
824 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800825 if ctx.isNdk() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800826 return true
827 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900828 if ctx.isLlndkPublic(config) {
Logan Chienf4b79c62018-08-02 02:27:02 +0800829 return true
830 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900831 if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate(config) {
Logan Chien2f2b8902018-07-10 15:01:19 +0800832 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
833 // VNDK-private.
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800834 return true
Logan Chien2f2b8902018-07-10 15:01:19 +0800835 }
836 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800837}
838
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700839func (ctx *moduleContextImpl) selectedStl() string {
840 if stl := ctx.mod.stl; stl != nil {
841 return stl.Properties.SelectedStl
842 }
843 return ""
844}
845
Ivan Lozanobd721262018-11-27 14:33:03 -0800846func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
847 return ctx.mod.linker.useClangLld(actx)
848}
849
Colin Crossce75d2c2016-10-06 16:12:58 -0700850func (ctx *moduleContextImpl) baseModuleName() string {
851 return ctx.mod.ModuleBase.BaseModuleName()
852}
853
Logan Chienf3511742017-10-31 18:04:35 +0800854func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
855 return ctx.mod.getVndkExtendsModuleName()
856}
857
Jiyong Park58e364a2019-01-19 19:24:06 +0900858func (ctx *moduleContextImpl) apexName() string {
859 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900860}
861
Jiyong Parkb0788572018-12-20 22:10:17 +0900862func (ctx *moduleContextImpl) hasStubsVariants() bool {
863 return ctx.mod.HasStubsVariants()
864}
865
866func (ctx *moduleContextImpl) isStubs() bool {
867 return ctx.mod.IsStubs()
868}
869
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900870func (ctx *moduleContextImpl) bootstrap() bool {
871 return ctx.mod.bootstrap()
872}
873
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700874func (ctx *moduleContextImpl) nativeCoverage() bool {
875 return ctx.mod.nativeCoverage()
876}
877
Colin Cross635c3b02016-05-18 15:37:25 -0700878func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800879 return &Module{
880 hod: hod,
881 multilib: multilib,
882 }
883}
884
Colin Cross635c3b02016-05-18 15:37:25 -0700885func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800886 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700887 module.features = []feature{
888 &tidyFeature{},
889 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700890 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800891 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800892 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800893 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900894 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700895 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700896 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800897 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800898 return module
899}
900
Colin Crossce75d2c2016-10-06 16:12:58 -0700901func (c *Module) Prebuilt() *android.Prebuilt {
902 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
903 return p.prebuilt()
904 }
905 return nil
906}
907
908func (c *Module) Name() string {
909 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700910 if p, ok := c.linker.(interface {
911 Name(string) string
912 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700913 name = p.Name(name)
914 }
915 return name
916}
917
Alex Light3d673592019-01-18 14:37:31 -0800918func (c *Module) Symlinks() []string {
919 if p, ok := c.installer.(interface {
920 symlinkList() []string
921 }); ok {
922 return p.symlinkList()
923 }
924 return nil
925}
926
Jeff Gaston294356f2017-09-27 17:05:30 -0700927// orderDeps reorders dependencies into a list such that if module A depends on B, then
928// A will precede B in the resultant list.
929// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800930// Note that directSharedDeps should be the analogous static library for each shared lib dep
931func 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 -0700932 // If A depends on B, then
933 // Every list containing A will also contain B later in the list
934 // So, after concatenating all lists, the final instance of B will have come from the same
935 // original list as the final instance of A
936 // So, the final instance of B will be later in the concatenation than the final A
937 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
938 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800939 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700940 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800941 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
942 }
943 for _, dep := range directSharedDeps {
944 orderedAllDeps = append(orderedAllDeps, dep)
945 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700946 }
947
Colin Crossb6715442017-10-24 11:13:31 -0700948 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700949
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800950 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700951 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800952 // resultant list to only what the caller has chosen to include in directStaticDeps
953 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700954
955 return orderedAllDeps, orderedDeclaredDeps
956}
957
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800958func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
959 // convert Module to Path
960 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
961 staticDepFiles := []android.Path{}
962 for _, dep := range staticDeps {
963 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
964 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700965 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800966 sharedDepFiles := []android.Path{}
967 for _, sharedDep := range sharedDeps {
968 staticAnalogue := sharedDep.staticVariant
969 if staticAnalogue != nil {
970 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
971 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
972 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700973 }
974
975 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800976 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700977
978 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700979}
980
Roland Levillainf89cd092019-07-29 16:22:59 +0100981func (c *Module) IsTestPerSrcAllTestsVariation() bool {
982 test, ok := c.linker.(testPerSrc)
983 return ok && test.isAllTestsVariation()
984}
985
Colin Cross635c3b02016-05-18 15:37:25 -0700986func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +0100987 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +0100988 //
989 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
990 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
991 // module and return early, as this module does not produce an output file per se.
992 if c.IsTestPerSrcAllTestsVariation() {
993 c.outputFile = android.OptionalPath{}
994 return
Roland Levillainf2fad972019-06-28 15:41:19 +0100995 }
996
Jooyung Han38002912019-05-16 04:01:54 +0900997 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +0900998
Colin Crossca860ac2016-01-04 14:34:37 -0800999 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001000 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001001 moduleContextImpl: moduleContextImpl{
1002 mod: c,
1003 },
1004 }
1005 ctx.ctx = ctx
1006
Colin Crossf18e1102017-11-16 14:33:08 -08001007 deps := c.depsToPaths(ctx)
1008 if ctx.Failed() {
1009 return
1010 }
1011
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001012 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1013 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1014 }
1015
Colin Crossca860ac2016-01-04 14:34:37 -08001016 flags := Flags{
1017 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001018 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001019 }
Colin Crossca860ac2016-01-04 14:34:37 -08001020 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001021 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001022 }
1023 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001024 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001025 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001026 if c.stl != nil {
1027 flags = c.stl.flags(ctx, flags)
1028 }
Colin Cross16b23492016-01-06 14:41:07 -08001029 if c.sanitize != nil {
1030 flags = c.sanitize.flags(ctx, flags)
1031 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001032 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001033 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001034 }
Stephen Craneba090d12017-05-09 15:44:35 -07001035 if c.lto != nil {
1036 flags = c.lto.flags(ctx, flags)
1037 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001038 if c.pgo != nil {
1039 flags = c.pgo.flags(ctx, flags)
1040 }
Ivan Lozano074ec482018-11-21 08:59:37 -08001041 if c.xom != nil {
1042 flags = c.xom.flags(ctx, flags)
1043 }
Colin Crossca860ac2016-01-04 14:34:37 -08001044 for _, feature := range c.features {
1045 flags = feature.flags(ctx, flags)
1046 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001047 if ctx.Failed() {
1048 return
1049 }
1050
Colin Crossb98c8b02016-07-29 13:44:28 -07001051 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
1052 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
1053 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001054
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001055 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001056
1057 for _, dir := range deps.IncludeDirs {
1058 flags.GlobalFlags = append(flags.GlobalFlags, "-I"+dir)
1059 }
1060 for _, dir := range deps.SystemIncludeDirs {
1061 flags.GlobalFlags = append(flags.GlobalFlags, "-isystem "+dir)
1062 }
1063
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001064 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001065 // We need access to all the flags seen by a source file.
1066 if c.sabi != nil {
1067 flags = c.sabi.flags(ctx, flags)
1068 }
Colin Crossca860ac2016-01-04 14:34:37 -08001069 // Optimization to reduce size of build.ninja
1070 // Replace the long list of flags for each file with a module-local variable
1071 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
1072 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
1073 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
1074 flags.CFlags = []string{"$cflags"}
1075 flags.CppFlags = []string{"$cppflags"}
1076 flags.AsFlags = []string{"$asflags"}
1077
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001078 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001079 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001080 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001081 if ctx.Failed() {
1082 return
1083 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001084 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001085 }
1086
Colin Crossca860ac2016-01-04 14:34:37 -08001087 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001088 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001089 if ctx.Failed() {
1090 return
1091 }
Colin Cross635c3b02016-05-18 15:37:25 -07001092 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001093
1094 // If a lib is directly included in any of the APEXes, unhide the stubs
1095 // variant having the latest version gets visible to make. In addition,
1096 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1097 // force anything in the make world to link against the stubs library.
1098 // (unless it is explicitly referenced via .bootstrap suffix or the
1099 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001100 if c.HasStubsVariants() &&
1101 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001102 !c.inRecovery() && !c.useVndk() && !c.static() && !c.isCoverageVariant() &&
1103 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001104 c.Properties.HideFromMake = false // unhide
1105 // Note: this is still non-installable
1106 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001107 }
Colin Cross5049f022015-03-18 13:28:46 -07001108
Inseob Kim1f086e22019-05-09 13:29:15 +09001109 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001110 c.installer.install(ctx, c.outputFile.Path())
1111 if ctx.Failed() {
1112 return
Colin Crossca860ac2016-01-04 14:34:37 -08001113 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001114 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001115}
1116
Colin Cross0ea8ba82019-06-06 14:33:29 -07001117func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001118 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001119 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001120 }
Colin Crossca860ac2016-01-04 14:34:37 -08001121 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001122}
1123
Colin Crossca860ac2016-01-04 14:34:37 -08001124func (c *Module) begin(ctx BaseModuleContext) {
1125 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001126 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001127 }
Colin Crossca860ac2016-01-04 14:34:37 -08001128 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001129 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001130 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001131 if c.stl != nil {
1132 c.stl.begin(ctx)
1133 }
Colin Cross16b23492016-01-06 14:41:07 -08001134 if c.sanitize != nil {
1135 c.sanitize.begin(ctx)
1136 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001137 if c.coverage != nil {
1138 c.coverage.begin(ctx)
1139 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001140 if c.sabi != nil {
1141 c.sabi.begin(ctx)
1142 }
Justin Yun8effde42017-06-23 19:24:43 +09001143 if c.vndkdep != nil {
1144 c.vndkdep.begin(ctx)
1145 }
Stephen Craneba090d12017-05-09 15:44:35 -07001146 if c.lto != nil {
1147 c.lto.begin(ctx)
1148 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001149 if c.pgo != nil {
1150 c.pgo.begin(ctx)
1151 }
Colin Crossca860ac2016-01-04 14:34:37 -08001152 for _, feature := range c.features {
1153 feature.begin(ctx)
1154 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001155 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001156 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001157 if err != nil {
1158 ctx.PropertyErrorf("sdk_version", err.Error())
1159 }
Nan Zhang0007d812017-11-07 10:57:05 -08001160 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001161 }
Colin Crossca860ac2016-01-04 14:34:37 -08001162}
1163
Colin Cross37047f12016-12-13 17:06:13 -08001164func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001165 deps := Deps{}
1166
1167 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001168 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001169 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001170 // Add the PGO dependency (the clang_rt.profile runtime library), which
1171 // sometimes depends on symbols from libgcc, before libgcc gets added
1172 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001173 if c.pgo != nil {
1174 deps = c.pgo.deps(ctx, deps)
1175 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001176 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001177 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001178 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001179 if c.stl != nil {
1180 deps = c.stl.deps(ctx, deps)
1181 }
Colin Cross16b23492016-01-06 14:41:07 -08001182 if c.sanitize != nil {
1183 deps = c.sanitize.deps(ctx, deps)
1184 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001185 if c.coverage != nil {
1186 deps = c.coverage.deps(ctx, deps)
1187 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001188 if c.sabi != nil {
1189 deps = c.sabi.deps(ctx, deps)
1190 }
Justin Yun8effde42017-06-23 19:24:43 +09001191 if c.vndkdep != nil {
1192 deps = c.vndkdep.deps(ctx, deps)
1193 }
Stephen Craneba090d12017-05-09 15:44:35 -07001194 if c.lto != nil {
1195 deps = c.lto.deps(ctx, deps)
1196 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001197 for _, feature := range c.features {
1198 deps = feature.deps(ctx, deps)
1199 }
1200
Colin Crossb6715442017-10-24 11:13:31 -07001201 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1202 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1203 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1204 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1205 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1206 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001207 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001208
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001209 for _, lib := range deps.ReexportSharedLibHeaders {
1210 if !inList(lib, deps.SharedLibs) {
1211 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1212 }
1213 }
1214
1215 for _, lib := range deps.ReexportStaticLibHeaders {
1216 if !inList(lib, deps.StaticLibs) {
1217 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1218 }
1219 }
1220
Colin Cross5950f382016-12-13 12:50:57 -08001221 for _, lib := range deps.ReexportHeaderLibHeaders {
1222 if !inList(lib, deps.HeaderLibs) {
1223 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1224 }
1225 }
1226
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001227 for _, gen := range deps.ReexportGeneratedHeaders {
1228 if !inList(gen, deps.GeneratedHeaders) {
1229 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1230 }
1231 }
1232
Colin Crossc99deeb2016-04-11 15:06:20 -07001233 return deps
1234}
1235
Dan Albert7e9d2952016-08-04 13:02:36 -07001236func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001237 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001238 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001239 moduleContextImpl: moduleContextImpl{
1240 mod: c,
1241 },
1242 }
1243 ctx.ctx = ctx
1244
Colin Crossca860ac2016-01-04 14:34:37 -08001245 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001246}
1247
Jiyong Park7ed9de32018-10-15 22:25:07 +09001248// Split name#version into name and version
1249func stubsLibNameAndVersion(name string) (string, string) {
1250 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1251 version := name[sharp+1:]
1252 libname := name[:sharp]
1253 return libname, version
1254 }
1255 return name, ""
1256}
1257
Colin Cross1e676be2016-10-12 14:38:15 -07001258func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001259 ctx := &depsContext{
1260 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001261 moduleContextImpl: moduleContextImpl{
1262 mod: c,
1263 },
1264 }
1265 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001266
Colin Crossc99deeb2016-04-11 15:06:20 -07001267 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001268
Dan Albert914449f2016-06-17 16:45:24 -07001269 variantNdkLibs := []string{}
1270 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001271 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001272 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001273
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001274 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1275 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001276 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001277 // 1. Name of an NDK library that refers to a prebuilt module.
1278 // For each of these, it adds the name of the prebuilt module (which will be in
1279 // prebuilts/ndk) to the list of nonvariant libs.
1280 // 2. Name of an NDK library that refers to an ndk_library module.
1281 // For each of these, it adds the name of the ndk_library module to the list of
1282 // variant libs.
1283 // 3. Anything else (so anything that isn't an NDK library).
1284 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001285 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001286 // The caller can then know to add the variantLibs dependencies differently from the
1287 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001288
1289 llndkLibraries := llndkLibraries(actx.Config())
1290 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001291 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1292 variantLibs = []string{}
1293 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001294 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001295 // strip #version suffix out
1296 name, _ := stubsLibNameAndVersion(entry)
1297 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1298 if !inList(name, ndkMigratedLibs) {
1299 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001300 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001301 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001302 }
Inseob Kim9516ee92019-05-09 10:56:13 +09001303 } else if ctx.useVndk() && inList(name, *llndkLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001304 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001305 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001306 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001307 if actx.OtherModuleExists(vendorPublicLib) {
1308 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1309 } else {
1310 // This can happen if vendor_public_library module is defined in a
1311 // namespace that isn't visible to the current module. In that case,
1312 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001313 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001314 }
Dan Albert914449f2016-06-17 16:45:24 -07001315 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001316 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001317 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001318 }
1319 }
Dan Albert914449f2016-06-17 16:45:24 -07001320 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001321 }
1322
Dan Albert914449f2016-06-17 16:45:24 -07001323 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1324 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001325 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001326 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001327
Jiyong Park7e636d02019-01-28 16:16:54 +09001328 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001329 if c.linker != nil {
1330 if library, ok := c.linker.(*libraryDecorator); ok {
1331 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001332 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001333 }
1334 }
1335 }
1336
Colin Cross32ec36c2016-12-15 07:39:51 -08001337 for _, lib := range deps.HeaderLibs {
1338 depTag := headerDepTag
1339 if inList(lib, deps.ReexportHeaderLibHeaders) {
1340 depTag = headerExportDepTag
1341 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001342 if buildStubs {
Jiyong Park7e636d02019-01-28 16:16:54 +09001343 actx.AddFarVariationDependencies([]blueprint.Variation{
1344 {Mutator: "arch", Variation: ctx.Target().String()},
Jiyong Park3b1746a2019-01-29 11:15:04 +09001345 {Mutator: "image", Variation: c.imageVariation()},
Jiyong Park7e636d02019-01-28 16:16:54 +09001346 }, depTag, lib)
1347 } else {
1348 actx.AddVariationDependencies(nil, depTag, lib)
1349 }
1350 }
1351
1352 if buildStubs {
1353 // Stubs lib does not have dependency to other static/shared libraries.
1354 // Don't proceed.
1355 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001356 }
Colin Cross5950f382016-12-13 12:50:57 -08001357
Inseob Kimc0907f12019-02-08 21:00:45 +09001358 syspropImplLibraries := syspropImplLibraries(actx.Config())
1359
Jiyong Park5d1598f2019-02-25 22:14:17 +09001360 for _, lib := range deps.WholeStaticLibs {
1361 depTag := wholeStaticDepTag
1362 if impl, ok := syspropImplLibraries[lib]; ok {
1363 lib = impl
1364 }
1365 actx.AddVariationDependencies([]blueprint.Variation{
1366 {Mutator: "link", Variation: "static"},
1367 }, depTag, lib)
1368 }
1369
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001370 for _, lib := range deps.StaticLibs {
1371 depTag := staticDepTag
1372 if inList(lib, deps.ReexportStaticLibHeaders) {
1373 depTag = staticExportDepTag
1374 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001375
1376 if impl, ok := syspropImplLibraries[lib]; ok {
1377 lib = impl
1378 }
1379
Dan Willemsen59339a22018-07-22 21:18:45 -07001380 actx.AddVariationDependencies([]blueprint.Variation{
1381 {Mutator: "link", Variation: "static"},
1382 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001383 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001384
Dan Willemsen59339a22018-07-22 21:18:45 -07001385 actx.AddVariationDependencies([]blueprint.Variation{
1386 {Mutator: "link", Variation: "static"},
1387 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001388
Jiyong Park25fc6a92018-11-18 18:02:45 +09001389 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1390 var variations []blueprint.Variation
1391 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001392 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001393 if version != "" && versionVariantAvail {
1394 // Version is explicitly specified. i.e. libFoo#30
1395 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1396 depTag.explicitlyVersioned = true
1397 }
1398 actx.AddVariationDependencies(variations, depTag, name)
1399
1400 // If the version is not specified, add dependency to the latest stubs library.
1401 // The stubs library will be used when the depending module is built for APEX and
1402 // the dependent module is not in the same APEX.
1403 latestVersion := latestStubsVersionFor(actx.Config(), name)
1404 if version == "" && latestVersion != "" && versionVariantAvail {
1405 actx.AddVariationDependencies([]blueprint.Variation{
1406 {Mutator: "link", Variation: "shared"},
1407 {Mutator: "version", Variation: latestVersion},
1408 }, depTag, name)
1409 // Note that depTag.explicitlyVersioned is false in this case.
1410 }
1411 }
1412
Jiyong Park7ed9de32018-10-15 22:25:07 +09001413 // shared lib names without the #version suffix
1414 var sharedLibNames []string
1415
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001416 for _, lib := range deps.SharedLibs {
1417 depTag := sharedDepTag
1418 if inList(lib, deps.ReexportSharedLibHeaders) {
1419 depTag = sharedExportDepTag
1420 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001421
1422 if impl, ok := syspropImplLibraries[lib]; ok {
1423 lib = impl
1424 }
1425
1426 name, version := stubsLibNameAndVersion(lib)
1427 sharedLibNames = append(sharedLibNames, name)
1428
Jiyong Park25fc6a92018-11-18 18:02:45 +09001429 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001430 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001431
Jiyong Park7ed9de32018-10-15 22:25:07 +09001432 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001433 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001434 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1435 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1436 // linking against both the stubs lib and the non-stubs lib at the same time.
1437 continue
1438 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001439 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001440 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001441
Dan Willemsen59339a22018-07-22 21:18:45 -07001442 actx.AddVariationDependencies([]blueprint.Variation{
1443 {Mutator: "link", Variation: "shared"},
1444 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001445
Colin Cross68861832016-07-08 10:41:41 -07001446 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001447
1448 for _, gen := range deps.GeneratedHeaders {
1449 depTag := genHeaderDepTag
1450 if inList(gen, deps.ReexportGeneratedHeaders) {
1451 depTag = genHeaderExportDepTag
1452 }
1453 actx.AddDependency(c, depTag, gen)
1454 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001455
Colin Cross42d48b72018-08-29 14:10:52 -07001456 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001457
1458 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001459 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001460 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001461 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001462 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001463 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001464 if deps.LinkerFlagsFile != "" {
1465 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1466 }
1467 if deps.DynamicLinker != "" {
1468 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001469 }
Dan Albert914449f2016-06-17 16:45:24 -07001470
1471 version := ctx.sdkVersion()
1472 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001473 {Mutator: "ndk_api", Variation: version},
1474 {Mutator: "link", Variation: "shared"},
1475 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001476 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001477 {Mutator: "ndk_api", Variation: version},
1478 {Mutator: "link", Variation: "shared"},
1479 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001480
1481 if vndkdep := c.vndkdep; vndkdep != nil {
1482 if vndkdep.isVndkExt() {
1483 baseModuleMode := vendorMode
1484 if actx.DeviceConfig().VndkVersion() == "" {
1485 baseModuleMode = coreMode
1486 }
1487 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001488 {Mutator: "image", Variation: baseModuleMode},
1489 {Mutator: "link", Variation: "shared"},
1490 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001491 }
1492 }
Colin Cross6362e272015-10-29 15:25:03 -07001493}
Colin Cross21b9a242015-03-24 14:15:58 -07001494
Colin Crosse40b4ea2018-10-02 22:25:58 -07001495func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001496 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1497 c.beginMutator(ctx)
1498 }
1499}
1500
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001501// Whether a module can link to another module, taking into
1502// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001503func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001504 if from.Target().Os != android.Android {
1505 // Host code is not restricted
1506 return
1507 }
1508 if from.Properties.UseVndk {
1509 // Though vendor code is limited by the vendor mutator,
1510 // each vendor-available module needs to check
1511 // link-type for VNDK.
1512 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001513 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001514 }
1515 return
1516 }
Nan Zhang0007d812017-11-07 10:57:05 -08001517 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001518 // Platform code can link to anything
1519 return
1520 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001521 if from.inRecovery() {
1522 // Recovery code is not NDK
1523 return
1524 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001525 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1526 // These are always allowed
1527 return
1528 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001529 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1530 // These are allowed, but they don't set sdk_version
1531 return
1532 }
1533 if _, ok := to.linker.(*stubDecorator); ok {
1534 // These aren't real libraries, but are the stub shared libraries that are included in
1535 // the NDK.
1536 return
1537 }
Logan Chien834b9a62019-01-14 15:39:03 +08001538
1539 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" {
1540 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1541 // to link to libc++ (non-NDK and without sdk_version).
1542 return
1543 }
1544
Nan Zhang0007d812017-11-07 10:57:05 -08001545 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001546 // NDK code linking to platform code is never okay.
1547 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1548 ctx.OtherModuleName(to))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001549 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001550 }
1551
1552 // At this point we know we have two NDK libraries, but we need to
1553 // check that we're not linking against anything built against a higher
1554 // API level, as it is only valid to link against older or equivalent
1555 // APIs.
1556
Inseob Kim01a28722018-04-11 09:48:45 +09001557 // Current can link against anything.
1558 if String(from.Properties.Sdk_version) != "current" {
1559 // Otherwise we need to check.
1560 if String(to.Properties.Sdk_version) == "current" {
1561 // Current can't be linked against by anything else.
1562 ctx.ModuleErrorf("links %q built against newer API version %q",
1563 ctx.OtherModuleName(to), "current")
1564 } else {
1565 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1566 if err != nil {
1567 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001568 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001569 String(from.Properties.Sdk_version))
1570 }
1571 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1572 if err != nil {
1573 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001574 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001575 String(to.Properties.Sdk_version))
1576 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001577
Inseob Kim01a28722018-04-11 09:48:45 +09001578 if toApi > fromApi {
1579 ctx.ModuleErrorf("links %q built against newer API version %q",
1580 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1581 }
1582 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001583 }
Dan Albert202fe492017-12-15 13:56:59 -08001584
1585 // Also check that the two STL choices are compatible.
1586 fromStl := from.stl.Properties.SelectedStl
1587 toStl := to.stl.Properties.SelectedStl
1588 if fromStl == "" || toStl == "" {
1589 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001590 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001591 // We can be permissive with the system "STL" since it is only the C++
1592 // ABI layer, but in the future we should make sure that everyone is
1593 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001594 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001595 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1596 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1597 to.stl.Properties.SelectedStl)
1598 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001599}
1600
Jiyong Park5fb8c102018-04-09 12:03:06 +09001601// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001602// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1603// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001604// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001605func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
Inseob Kim9516ee92019-05-09 10:56:13 +09001606 llndkLibraries := llndkLibraries(ctx.Config())
Jooyung Hana70f0672019-01-18 15:20:43 +09001607 check := func(child, parent android.Module) bool {
1608 to, ok := child.(*Module)
1609 if !ok {
1610 // follow thru cc.Defaults, etc.
1611 return true
1612 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001613
Jooyung Hana70f0672019-01-18 15:20:43 +09001614 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1615 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001616 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001617
1618 // if target lib has no vendor variant, keep checking dependency graph
1619 if !to.hasVendorVariant() {
1620 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001621 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001622
Inseob Kim9516ee92019-05-09 10:56:13 +09001623 if to.isVndkSp() || inList(child.Name(), *llndkLibraries) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001624 return false
1625 }
1626
1627 var stringPath []string
1628 for _, m := range ctx.GetWalkPath() {
1629 stringPath = append(stringPath, m.Name())
1630 }
1631 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1632 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1633 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1634 return false
1635 }
1636 if module, ok := ctx.Module().(*Module); ok {
1637 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Inseob Kim9516ee92019-05-09 10:56:13 +09001638 if inList(ctx.ModuleName(), *llndkLibraries) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001639 ctx.WalkDeps(check)
1640 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001641 }
1642 }
1643}
1644
Colin Crossc99deeb2016-04-11 15:06:20 -07001645// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001646func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001647 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001648
Jeff Gaston294356f2017-09-27 17:05:30 -07001649 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001650 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001651
Inseob Kim9516ee92019-05-09 10:56:13 +09001652 llndkLibraries := llndkLibraries(ctx.Config())
1653 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
1654
Inseob Kim69378442019-06-03 19:10:47 +09001655 reexportExporter := func(exporter exportedFlagsProducer) {
1656 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
1657 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
1658 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
1659 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
1660 }
1661
Colin Crossd11fcda2017-10-23 17:59:01 -07001662 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001663 depName := ctx.OtherModuleName(dep)
1664 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001665
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001666 ccDep, _ := dep.(*Module)
1667 if ccDep == nil {
1668 // handling for a few module types that aren't cc Module but that are also supported
1669 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001670 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001671 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001672 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1673 genRule.GeneratedSourceFiles()...)
1674 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001675 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001676 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001677 // Support exported headers from a generated_sources dependency
1678 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001679 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001680 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001681 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001682 genRule.GeneratedDeps()...)
Inseob Kim69378442019-06-03 19:10:47 +09001683 dirs := genRule.GeneratedHeaderDirs().Strings()
1684 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001685 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09001686 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
1687 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001688 // 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 +09001689 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001690
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001691 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001692 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001693 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001694 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001695 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001696 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001697 files := genRule.GeneratedSourceFiles()
1698 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001699 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001700 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001701 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 -07001702 }
1703 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001704 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001705 }
Colin Crossca860ac2016-01-04 14:34:37 -08001706 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001707 return
1708 }
1709
Colin Crossfe17f6f2019-03-28 19:30:56 -07001710 if depTag == android.ProtoPluginDepTag {
1711 return
1712 }
1713
Colin Crossd11fcda2017-10-23 17:59:01 -07001714 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001715 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1716 return
1717 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001718 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001719 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001720 return
1721 }
1722
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001723 // re-exporting flags
1724 if depTag == reuseObjTag {
1725 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001726 c.staticVariant = ccDep
Inseob Kim69378442019-06-03 19:10:47 +09001727 objs, exporter := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001728 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09001729 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08001730 return
1731 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001732 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001733
Jiyong Parke4bb9862019-02-01 00:31:10 +09001734 if depTag == staticVariantTag {
1735 if _, ok := ccDep.compiler.(libraryInterface); ok {
1736 c.staticVariant = ccDep
1737 return
1738 }
1739 }
1740
Jiyong Park25fc6a92018-11-18 18:02:45 +09001741 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1742 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1743 // won't be matched to sharedDepTag and lateSharedDepTag.
1744 explicitlyVersioned := false
1745 if t, ok := depTag.(dependencyTag); ok {
1746 explicitlyVersioned = t.explicitlyVersioned
1747 t.explicitlyVersioned = false
1748 depTag = t
1749 }
1750
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001751 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001752 depIsStatic := false
1753 switch depTag {
1754 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1755 depIsStatic = true
1756 }
1757 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001758 depIsStubs := dependentLibrary.buildStubs()
1759 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001760 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001761 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001762
1763 var useThisDep bool
1764 if depIsStubs && explicitlyVersioned {
1765 // Always respect dependency to the versioned stubs (i.e. libX#10)
1766 useThisDep = true
1767 } else if !depHasStubs {
1768 // Use non-stub variant if that is the only choice
1769 // (i.e. depending on a lib without stubs.version property)
1770 useThisDep = true
1771 } else if c.IsForPlatform() {
1772 // If not building for APEX, use stubs only when it is from
1773 // an APEX (and not from platform)
1774 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001775 if c.inRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001776 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001777 // always link to non-stub variant
1778 useThisDep = !depIsStubs
1779 }
1780 } else {
1781 // If building for APEX, use stubs only when it is not from
1782 // the same APEX
1783 useThisDep = (depInSameApex != depIsStubs)
1784 }
1785
1786 if !useThisDep {
1787 return // stop processing this dep
1788 }
1789 }
1790
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001791 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Inseob Kim69378442019-06-03 19:10:47 +09001792 depPaths.IncludeDirs = append(depPaths.IncludeDirs, i.exportedDirs()...)
1793 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
1794 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedDeps()...)
1795 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001796
1797 if t.reexportFlags {
Inseob Kim69378442019-06-03 19:10:47 +09001798 reexportExporter(i)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001799 // 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 -07001800 // Re-exported shared library headers must be included as well since they can help us with type information
1801 // about template instantiations (instantiated from their headers).
Inseob Kim69378442019-06-03 19:10:47 +09001802 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
1803 // scripts.
1804 c.sabi.Properties.ReexportedIncludes = append(
1805 c.sabi.Properties.ReexportedIncludes, i.exportedDirs()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001806 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001807 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001808
Logan Chienf3511742017-10-31 18:04:35 +08001809 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001810 }
1811
Colin Cross26c34ed2016-09-30 17:10:16 -07001812 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001813 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001814
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001815 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001816 depFile := android.OptionalPath{}
1817
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001818 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001819 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001820 ptr = &depPaths.SharedLibs
1821 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001822 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001823 directSharedDeps = append(directSharedDeps, ccDep)
Jiyong Park64a44f22019-01-18 14:37:08 +09001824 case earlySharedDepTag:
1825 ptr = &depPaths.EarlySharedLibs
1826 depPtr = &depPaths.EarlySharedLibsDeps
1827 depFile = ccDep.linker.(libraryInterface).toc()
1828 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001829 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001830 ptr = &depPaths.LateSharedLibs
1831 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001832 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001833 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001834 ptr = nil
1835 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001836 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001837 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001838 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001839 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001840 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001841 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001842 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001843 return
1844 }
1845
1846 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001847 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001848 for i := range missingDeps {
1849 missingDeps[i] += postfix
1850 }
1851 ctx.AddMissingDependencies(missingDeps)
1852 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001853 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001854 case headerDepTag:
1855 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001856 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001857 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001858 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001859 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001860 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001861 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001862 case dynamicLinkerDepTag:
1863 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001864 }
1865
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001866 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001867 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001868 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001869 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001870 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001871 return
1872 }
1873
1874 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001875 // in static libraries act as if they were whole static libraries. The same goes for
1876 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001877 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1878 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001879 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1880 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001881
Dan Willemsen581341d2017-02-09 16:16:31 -08001882 }
1883
Colin Cross26c34ed2016-09-30 17:10:16 -07001884 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001885 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001886 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001887 return
1888 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001889 *ptr = append(*ptr, linkFile.Path())
1890 }
1891
Colin Crossc99deeb2016-04-11 15:06:20 -07001892 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001893 dep := depFile
1894 if !dep.Valid() {
1895 dep = linkFile
1896 }
1897 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001898 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001899
Logan Chien43d34c32017-12-20 01:17:32 +08001900 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001901 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001902 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001903 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kim9516ee92019-05-09 10:56:13 +09001904 isLLndk := inList(libName, *llndkLibraries)
1905 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001906 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08001907
1908 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.isVndk() && !ccDep.mustUseVendorVariant() {
1909 // The vendor module is a no-vendor-variant VNDK library. Depend on the
1910 // core module instead.
1911 return libName
1912 } else if c.useVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001913 // The vendor module in Make will have been renamed to not conflict with the core
1914 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001915 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001916 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001917 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001918 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1919 return libName + recoverySuffix
dimitry1f33e402019-03-26 12:39:31 +01001920 } else if ccDep.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02001921 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001922 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001923 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001924 }
Logan Chien43d34c32017-12-20 01:17:32 +08001925 }
1926
1927 // Export the shared libs to Make.
1928 switch depTag {
Jiyong Park64a44f22019-01-18 14:37:08 +09001929 case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001930 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001931 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08001932 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09001933 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001934 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001935 c.Properties.ApexesProvidingSharedLibs = append(
1936 c.Properties.ApexesProvidingSharedLibs, an)
1937 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09001938 }
1939 }
1940
Jiyong Park27b188b2017-07-18 13:23:39 +09001941 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001942 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001943 c.Properties.AndroidMkSharedLibs = append(
1944 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08001945 case ndkStubDepTag, ndkLateStubDepTag:
1946 ndkStub := ccDep.linker.(*stubDecorator)
1947 c.Properties.AndroidMkSharedLibs = append(
1948 c.Properties.AndroidMkSharedLibs,
1949 depName+"."+ndkStub.properties.ApiLevel)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001950 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1951 c.Properties.AndroidMkStaticLibs = append(
1952 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001953 case runtimeDepTag:
1954 c.Properties.AndroidMkRuntimeLibs = append(
1955 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001956 case wholeStaticDepTag:
1957 c.Properties.AndroidMkWholeStaticLibs = append(
1958 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001959 }
Colin Crossca860ac2016-01-04 14:34:37 -08001960 })
1961
Jeff Gaston294356f2017-09-27 17:05:30 -07001962 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001963 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001964
Colin Crossdd84e052017-05-17 13:44:16 -07001965 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001966 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Inseob Kim69378442019-06-03 19:10:47 +09001967 depPaths.IncludeDirs = android.FirstUniqueStrings(depPaths.IncludeDirs)
1968 depPaths.SystemIncludeDirs = android.FirstUniqueStrings(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001969 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kim69378442019-06-03 19:10:47 +09001970 depPaths.ReexportedDirs = android.FirstUniqueStrings(depPaths.ReexportedDirs)
1971 depPaths.ReexportedSystemDirs = android.FirstUniqueStrings(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07001972 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09001973 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001974
1975 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09001976 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001977 }
Colin Crossdd84e052017-05-17 13:44:16 -07001978
Colin Crossca860ac2016-01-04 14:34:37 -08001979 return depPaths
1980}
1981
1982func (c *Module) InstallInData() bool {
1983 if c.installer == nil {
1984 return false
1985 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001986 return c.installer.inData()
1987}
1988
1989func (c *Module) InstallInSanitizerDir() bool {
1990 if c.installer == nil {
1991 return false
1992 }
1993 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001994 return true
1995 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001996 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001997}
1998
Jiyong Parkf9332f12018-02-01 00:54:12 +09001999func (c *Module) InstallInRecovery() bool {
2000 return c.inRecovery()
2001}
2002
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002003func (c *Module) HostToolPath() android.OptionalPath {
2004 if c.installer == nil {
2005 return android.OptionalPath{}
2006 }
2007 return c.installer.hostToolPath()
2008}
2009
Nan Zhangd4e641b2017-07-12 12:55:28 -07002010func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2011 return c.outputFile
2012}
2013
Colin Cross41955e82019-05-29 14:40:35 -07002014func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2015 switch tag {
2016 case "":
2017 if c.outputFile.Valid() {
2018 return android.Paths{c.outputFile.Path()}, nil
2019 }
2020 return android.Paths{}, nil
2021 default:
2022 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002023 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002024}
2025
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002026func (c *Module) static() bool {
2027 if static, ok := c.linker.(interface {
2028 static() bool
2029 }); ok {
2030 return static.static()
2031 }
2032 return false
2033}
2034
Jiyong Park379de2f2018-12-19 02:47:14 +09002035func (c *Module) staticBinary() bool {
2036 if static, ok := c.linker.(interface {
2037 staticBinary() bool
2038 }); ok {
2039 return static.staticBinary()
2040 }
2041 return false
2042}
2043
Jiyong Park1d1119f2019-07-29 21:27:18 +09002044func (c *Module) header() bool {
2045 if h, ok := c.linker.(interface {
2046 header() bool
2047 }); ok {
2048 return h.header()
2049 }
2050 return false
2051}
2052
Jooyung Han38002912019-05-16 04:01:54 +09002053func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
2054 name := actx.ModuleName()
Colin Crossb60190a2018-09-04 16:28:17 -07002055 if c.useVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002056 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2057 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002058 return "native:vndk"
2059 }
Jooyung Han38002912019-05-16 04:01:54 +09002060 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002061 }
Jooyung Han38002912019-05-16 04:01:54 +09002062 if c.isVndk() && !c.isVndkExt() {
2063 if Bool(c.VendorProperties.Vendor_available) {
2064 return "native:vndk"
2065 }
2066 return "native:vndk_private"
2067 }
2068 return "native:vendor"
Colin Crossb60190a2018-09-04 16:28:17 -07002069 } else if c.inRecovery() {
2070 return "native:recovery"
2071 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2072 return "native:ndk:none:none"
2073 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2074 //family, link := getNdkStlFamilyAndLinkType(c)
2075 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Jooyung Han38002912019-05-16 04:01:54 +09002076 } else if inList(name, *vndkUsingCoreVariantLibraries(actx.Config())) {
Vic Yangefd249e2018-11-12 20:19:56 -08002077 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002078 } else {
2079 return "native:platform"
2080 }
2081}
2082
Jiyong Park9d452992018-10-03 00:38:19 +09002083// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002084// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002085func (c *Module) IsInstallableToApex() bool {
2086 if shared, ok := c.linker.(interface {
2087 shared() bool
2088 }); ok {
2089 return shared.shared()
Roland Levillainf89cd092019-07-29 16:22:59 +01002090 } else if _, ok := c.linker.(testPerSrc); ok {
2091 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002092 }
2093 return false
2094}
2095
Inseob Kim1f086e22019-05-09 13:29:15 +09002096func (c *Module) installable() bool {
2097 return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
2098}
2099
Jiyong Park3b1746a2019-01-29 11:15:04 +09002100func (c *Module) imageVariation() string {
2101 variation := "core"
2102 if c.useVndk() {
2103 variation = "vendor"
2104 } else if c.inRecovery() {
2105 variation = "recovery"
2106 }
2107 return variation
2108}
2109
bralee3f49f4d2019-03-04 06:58:15 +08002110func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
Colin Cross41955e82019-05-29 14:40:35 -07002111 outputFiles, err := c.OutputFiles("")
2112 if err != nil {
2113 panic(err)
2114 }
2115 dpInfo.Srcs = append(dpInfo.Srcs, outputFiles.Strings()...)
bralee3f49f4d2019-03-04 06:58:15 +08002116}
2117
Logan Chien41eabe62019-04-10 13:33:58 +08002118func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2119 if c.linker != nil {
2120 if library, ok := c.linker.(*libraryDecorator); ok {
2121 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2122 }
2123 }
2124}
2125
Colin Cross2ba19d92015-05-07 15:44:20 -07002126//
Colin Crosscfad1192015-11-02 16:43:11 -08002127// Defaults
2128//
Colin Crossca860ac2016-01-04 14:34:37 -08002129type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002130 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002131 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002132 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002133}
2134
Patrice Arrudac249c712019-03-19 17:00:29 -07002135// cc_defaults provides a set of properties that can be inherited by other cc
2136// modules. A module can use the properties from a cc_defaults using
2137// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2138// merged (when possible) by prepending the default module's values to the
2139// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002140func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002141 return DefaultsFactory()
2142}
2143
Colin Cross36242852017-06-23 15:06:31 -07002144func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002145 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002146
Colin Cross36242852017-06-23 15:06:31 -07002147 module.AddProperties(props...)
2148 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002149 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002150 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002151 &BaseCompilerProperties{},
2152 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002153 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002154 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002155 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002156 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002157 &TestProperties{},
2158 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002159 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002160 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002161 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002162 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002163 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002164 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002165 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002166 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002167 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002168 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002169 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002170 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002171 )
Colin Crosscfad1192015-11-02 16:43:11 -08002172
Colin Cross1f44a3a2017-07-07 14:33:33 -07002173 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09002174 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002175
2176 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002177}
2178
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002179const (
2180 // coreMode is the variant used for framework-private libraries, or
2181 // SDK libraries. (which framework-private libraries can use)
2182 coreMode = "core"
2183
2184 // vendorMode is the variant used for /vendor code that compiles
2185 // against the VNDK.
2186 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09002187
2188 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002189)
2190
Jiyong Park6a43f042017-10-12 23:05:00 +09002191func squashVendorSrcs(m *Module) {
2192 if lib, ok := m.compiler.(*libraryDecorator); ok {
2193 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2194 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2195
2196 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2197 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2198 }
2199}
2200
Jiyong Parkf9332f12018-02-01 00:54:12 +09002201func squashRecoverySrcs(m *Module) {
2202 if lib, ok := m.compiler.(*libraryDecorator); ok {
2203 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2204 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2205
2206 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2207 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2208 }
2209}
2210
Jiyong Parkda6eb592018-12-19 17:12:36 +09002211func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002212 if mctx.Os() != android.Android {
2213 return
2214 }
2215
Jiyong Park7ed9de32018-10-15 22:25:07 +09002216 if g, ok := mctx.Module().(*genrule.Module); ok {
2217 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09002218 var coreVariantNeeded bool = false
2219 var vendorVariantNeeded bool = false
2220 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09002221 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09002222 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002223 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09002224 coreVariantNeeded = true
2225 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09002226 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09002227 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002228 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09002229 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002230 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002231 if Bool(props.Recovery_available) {
2232 recoveryVariantNeeded = true
2233 }
2234
Jiyong Park413cc742018-06-19 01:46:06 +09002235 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002236 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09002237 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09002238 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002239 recoveryVariantNeeded = false
2240 }
2241 }
2242
Jiyong Park3f736c92018-05-24 13:36:56 +09002243 var variants []string
2244 if coreVariantNeeded {
2245 variants = append(variants, coreMode)
2246 }
2247 if vendorVariantNeeded {
2248 variants = append(variants, vendorMode)
2249 }
2250 if recoveryVariantNeeded {
2251 variants = append(variants, recoveryMode)
2252 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002253 mod := mctx.CreateVariations(variants...)
2254 for i, v := range variants {
2255 if v == recoveryMode {
2256 m := mod[i].(*genrule.Module)
2257 m.Extra.(*GenruleExtraProperties).InRecovery = true
2258 }
2259 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002260 }
2261 }
2262
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002263 m, ok := mctx.Module().(*Module)
2264 if !ok {
2265 return
2266 }
2267
2268 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002269 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002270 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002271
2272 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002273 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002274 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002275 return
2276 }
Logan Chienf3511742017-10-31 18:04:35 +08002277
2278 if vndkdep := m.vndkdep; vndkdep != nil {
2279 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002280 if productSpecific {
2281 mctx.PropertyErrorf("product_specific",
2282 "product_specific must not be true when `vndk: {enabled: true}`")
2283 return
2284 }
Logan Chienf3511742017-10-31 18:04:35 +08002285 if vendorSpecific {
2286 if !vndkdep.isVndkExt() {
2287 mctx.PropertyErrorf("vndk",
2288 "must set `extends: \"...\"` to vndk extension")
2289 return
2290 }
2291 } else {
2292 if vndkdep.isVndkExt() {
2293 mctx.PropertyErrorf("vndk",
2294 "must set `vendor: true` to set `extends: %q`",
2295 m.getVndkExtendsModuleName())
2296 return
2297 }
2298 if m.VendorProperties.Vendor_available == nil {
2299 mctx.PropertyErrorf("vndk",
2300 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2301 return
2302 }
2303 }
2304 } else {
2305 if vndkdep.isVndkSp() {
2306 mctx.PropertyErrorf("vndk",
2307 "must set `enabled: true` to set `support_system_process: true`")
2308 return
2309 }
2310 if vndkdep.isVndkExt() {
2311 mctx.PropertyErrorf("vndk",
2312 "must set `enabled: true` to set `extends: %q`",
2313 m.getVndkExtendsModuleName())
2314 return
2315 }
Justin Yun8effde42017-06-23 19:24:43 +09002316 }
2317 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002318
Jiyong Parkf9332f12018-02-01 00:54:12 +09002319 var coreVariantNeeded bool = false
2320 var vendorVariantNeeded bool = false
2321 var recoveryVariantNeeded bool = false
2322
Justin Yun71549282017-11-17 12:10:28 +09002323 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002324 // If the device isn't compiling against the VNDK, we always
2325 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002326 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002327 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2328 // LL-NDK stubs only exist in the vendor variant, since the
2329 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002330 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09002331 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2332 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09002333 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09002334 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002335 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2336 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002337 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002338 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002339 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002340 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002341 coreVariantNeeded = true
2342 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002343 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002344 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09002345 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002346 } else {
2347 // This is either in /system (or similar: /data), or is a
2348 // modules built with the NDK. Modules built with the NDK
2349 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002350 coreVariantNeeded = true
2351 }
2352
2353 if Bool(m.Properties.Recovery_available) {
2354 recoveryVariantNeeded = true
2355 }
2356
2357 if m.ModuleBase.InstallInRecovery() {
2358 recoveryVariantNeeded = true
2359 coreVariantNeeded = false
2360 }
2361
Jiyong Park413cc742018-06-19 01:46:06 +09002362 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002363 primaryArch := mctx.Config().DevicePrimaryArchType()
2364 moduleArch := m.Target().Arch.ArchType
2365 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002366 recoveryVariantNeeded = false
2367 }
2368 }
2369
Jiyong Parkf9332f12018-02-01 00:54:12 +09002370 var variants []string
2371 if coreVariantNeeded {
2372 variants = append(variants, coreMode)
2373 }
2374 if vendorVariantNeeded {
2375 variants = append(variants, vendorMode)
2376 }
2377 if recoveryVariantNeeded {
2378 variants = append(variants, recoveryMode)
2379 }
2380 mod := mctx.CreateVariations(variants...)
2381 for i, v := range variants {
2382 if v == vendorMode {
2383 m := mod[i].(*Module)
2384 m.Properties.UseVndk = true
2385 squashVendorSrcs(m)
2386 } else if v == recoveryMode {
2387 m := mod[i].(*Module)
2388 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002389 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002390 squashRecoverySrcs(m)
2391 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002392 }
2393}
2394
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002395func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002396 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002397 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2398 }
Colin Cross6510f912017-11-29 00:27:14 -08002399 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002400}
2401
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002402func kytheExtractAllFactory() android.Singleton {
2403 return &kytheExtractAllSingleton{}
2404}
2405
2406type kytheExtractAllSingleton struct {
2407}
2408
2409func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2410 var xrefTargets android.Paths
2411 ctx.VisitAllModules(func(module android.Module) {
2412 if ccModule, ok := module.(xref); ok {
2413 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
2414 }
2415 })
2416 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
2417 if len(xrefTargets) > 0 {
2418 ctx.Build(pctx, android.BuildParams{
2419 Rule: blueprint.Phony,
2420 Output: android.PathForPhony(ctx, "xref_cxx"),
2421 Inputs: xrefTargets,
2422 //Default: true,
2423 })
2424 }
2425}
2426
Colin Cross06a931b2015-10-28 17:23:31 -07002427var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002428var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002429var BoolPtr = proptools.BoolPtr
2430var String = proptools.String
2431var StringPtr = proptools.StringPtr