blob: f97ef5aeaf2d49a97849c199b707859b78d700e0 [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
Pete Bentley99f2fc22019-08-02 14:02:20 +0100156 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700157 TidyFlags []string // Flags that apply to clang-tidy
158 SAbiFlags []string // Flags that apply to header-abi-dumper
159 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700160
Colin Crossc3199482017-03-30 15:03:04 -0700161 // Global include flags that apply to C, C++, and assembly source files
162 // These must be after any module include flags, which will be in GlobalFlags.
163 SystemIncludeFlags []string
164
Colin Crossb98c8b02016-07-29 13:44:28 -0700165 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700166 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800167 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800168 SAbiDump bool
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800169 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800170
171 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800172 DynamicLinker string
173
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700174 CFlagsDeps android.Paths // Files depended on by compiler flags
175 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800176
Dan Willemsen98ab3112019-08-27 21:20:40 -0700177 AssemblerWithCpp bool
178 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800179
Colin Cross19878da2019-03-28 14:45:07 -0700180 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700181 protoC bool // Whether to use C instead of C++
182 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700183
184 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700185}
186
Colin Crossca860ac2016-01-04 14:34:37 -0800187// Properties used to compile all C or C++ modules
188type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700189 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800190 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700191
192 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800193 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700194
Jiyong Parkde866cb2018-12-07 23:08:36 +0900195 AndroidMkSharedLibs []string `blueprint:"mutated"`
196 AndroidMkStaticLibs []string `blueprint:"mutated"`
197 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
198 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
199 HideFromMake bool `blueprint:"mutated"`
200 PreventInstall bool `blueprint:"mutated"`
201 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700202
203 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800204
205 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
206 // file
207 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900208
209 // Make this module available when building for recovery
210 Recovery_available *bool
211
212 InRecovery bool `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900213
214 // Allows this module to use non-APEX version of libraries. Useful
215 // for building binaries that are started before APEXes are activated.
216 Bootstrap *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700217}
218
219type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900220 // whether this module should be allowed to be directly depended by other
221 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
222 // If set to true, two variants will be built separately, one like
223 // normal, and the other limited to the set of libraries and headers
224 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700225 //
226 // The vendor variant may be used with a different (newer) /system,
227 // so it shouldn't have any unversioned runtime dependencies, or
228 // make assumptions about the system that may not be true in the
229 // future.
230 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900231 // If set to false, this module becomes inaccessible from /vendor modules.
232 //
233 // Default value is true when vndk: {enabled: true} or vendor: true.
234 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700235 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
236 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900237
238 // whether this module is capable of being loaded with other instance
239 // (possibly an older version) of the same module in the same process.
240 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
241 // can be double loaded in a vendor process if the library is also a
242 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
243 // explicitly marked as `double_loadable: true` by the owner, or the dependency
244 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
245 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800246}
247
Colin Crossca860ac2016-01-04 14:34:37 -0800248type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800249 static() bool
250 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900251 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700252 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700253 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800254 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700255 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800256 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900257 isLlndk(config android.Config) bool
258 isLlndkPublic(config android.Config) bool
259 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900260 isVndk() bool
261 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800262 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900263 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800264 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700265 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700266 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800267 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800268 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800269 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800270 useClangLld(actx ModuleContext) bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900271 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900272 hasStubsVariants() bool
273 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900274 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800275 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700276 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800277}
278
279type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700280 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800281 ModuleContextIntf
282}
283
284type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700285 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800286 ModuleContextIntf
287}
288
Colin Cross37047f12016-12-13 17:06:13 -0800289type DepsContext interface {
290 android.BottomUpMutatorContext
291 ModuleContextIntf
292}
293
Colin Crossca860ac2016-01-04 14:34:37 -0800294type feature interface {
295 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800296 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800297 flags(ctx ModuleContext, flags Flags) Flags
298 props() []interface{}
299}
300
301type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700302 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800303 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800304 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700305 compilerProps() []interface{}
306
Colin Cross76fada02016-07-27 10:31:13 -0700307 appendCflags([]string)
308 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700309 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800310}
311
312type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700313 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800314 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700315 linkerFlags(ctx ModuleContext, flags Flags) Flags
316 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800317 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700318
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700319 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700320 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900321 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700322
323 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900324 coverageOutputFilePath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800325}
326
327type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700328 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700329 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800330 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700331 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700332 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900333 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800334}
335
Colin Crossc99deeb2016-04-11 15:06:20 -0700336type dependencyTag struct {
337 blueprint.BaseDependencyTag
338 name string
339 library bool
Roland Levillainf89cd092019-07-29 16:22:59 +0100340 shared bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700341
342 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900343
344 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700345}
346
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800347type xref interface {
348 XrefCcFiles() android.Paths
349}
350
Colin Crossc99deeb2016-04-11 15:06:20 -0700351var (
Roland Levillainf89cd092019-07-29 16:22:59 +0100352 sharedDepTag = dependencyTag{name: "shared", library: true, shared: true}
353 sharedExportDepTag = dependencyTag{name: "shared", library: true, shared: true, reexportFlags: true}
354 earlySharedDepTag = dependencyTag{name: "early_shared", library: true, shared: true}
355 lateSharedDepTag = dependencyTag{name: "late shared", library: true, shared: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700356 staticDepTag = dependencyTag{name: "static", library: true}
357 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
358 lateStaticDepTag = dependencyTag{name: "late static", library: true}
359 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800360 headerDepTag = dependencyTag{name: "header", library: true}
361 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700362 genSourceDepTag = dependencyTag{name: "gen source"}
363 genHeaderDepTag = dependencyTag{name: "gen header"}
364 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
365 objDepTag = dependencyTag{name: "obj"}
366 crtBeginDepTag = dependencyTag{name: "crtbegin"}
367 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700368 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
369 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700370 reuseObjTag = dependencyTag{name: "reuse objects"}
Jiyong Parke4bb9862019-02-01 00:31:10 +0900371 staticVariantTag = dependencyTag{name: "static variant"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700372 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
373 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800374 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800375 runtimeDepTag = dependencyTag{name: "runtime lib"}
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -0700376 coverageDepTag = dependencyTag{name: "coverage"}
Roland Levillainf2fad972019-06-28 15:41:19 +0100377 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700378)
379
Roland Levillainf89cd092019-07-29 16:22:59 +0100380func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
381 ccDepTag, ok := depTag.(dependencyTag)
382 return ok && ccDepTag.shared
383}
384
385func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
386 ccDepTag, ok := depTag.(dependencyTag)
387 return ok && ccDepTag == runtimeDepTag
388}
389
390func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
391 ccDepTag, ok := depTag.(dependencyTag)
392 return ok && ccDepTag == testPerSrcDepTag
393}
394
Ivan Lozanoffee3342019-08-27 12:03:00 -0700395func SharedDepTag() dependencyTag {
396 return sharedDepTag
397}
398
399func StaticDepTag() dependencyTag {
400 return staticDepTag
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 Parkee9a98d2019-08-09 14:44:36 +0900467func (c *Module) CoverageOutputFile() android.OptionalPath {
468 if c.linker != nil {
469 return c.linker.coverageOutputFilePath()
470 }
471 return android.OptionalPath{}
472}
473
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900474func (c *Module) RelativeInstallPath() string {
475 if c.installer != nil {
476 return c.installer.relativeInstallPath()
477 }
478 return ""
479}
480
Colin Cross36242852017-06-23 15:06:31 -0700481func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700482 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800483 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700484 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800485 }
486 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700487 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800488 }
489 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700490 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800491 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700492 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700493 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700494 }
Colin Cross16b23492016-01-06 14:41:07 -0800495 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700496 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800497 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800498 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700499 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800500 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800501 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700502 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800503 }
Justin Yun8effde42017-06-23 19:24:43 +0900504 if c.vndkdep != nil {
505 c.AddProperties(c.vndkdep.props()...)
506 }
Stephen Craneba090d12017-05-09 15:44:35 -0700507 if c.lto != nil {
508 c.AddProperties(c.lto.props()...)
509 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700510 if c.pgo != nil {
511 c.AddProperties(c.pgo.props()...)
512 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800513 if c.xom != nil {
514 c.AddProperties(c.xom.props()...)
515 }
Colin Crossca860ac2016-01-04 14:34:37 -0800516 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700517 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800518 }
Colin Crossc472d572015-03-17 15:06:21 -0700519
Colin Crossa9d8bee2018-10-02 13:59:46 -0700520 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
521 switch class {
522 case android.Device:
523 return ctx.Config().DevicePrefer32BitExecutables()
524 case android.HostCross:
525 // Windows builds always prefer 32-bit
526 return true
527 default:
528 return false
529 }
530 })
Colin Cross36242852017-06-23 15:06:31 -0700531 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700532
Colin Cross1f44a3a2017-07-07 14:33:33 -0700533 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700534
Jiyong Park9d452992018-10-03 00:38:19 +0900535 android.InitApexModule(c)
536
Colin Cross36242852017-06-23 15:06:31 -0700537 return c
Colin Crossc472d572015-03-17 15:06:21 -0700538}
539
Colin Crossb916a382016-07-29 17:28:03 -0700540// Returns true for dependency roots (binaries)
541// TODO(ccross): also handle dlopenable libraries
542func (c *Module) isDependencyRoot() bool {
543 if root, ok := c.linker.(interface {
544 isDependencyRoot() bool
545 }); ok {
546 return root.isDependencyRoot()
547 }
548 return false
549}
550
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700551func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700552 return c.Properties.UseVndk
553}
554
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800555func (c *Module) isCoverageVariant() bool {
556 return c.coverage.Properties.IsCoverageVariant
557}
558
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800559func (c *Module) isNdk() bool {
560 return inList(c.Name(), ndkMigratedLibs)
561}
562
Inseob Kim9516ee92019-05-09 10:56:13 +0900563func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800564 // Returns true for both LLNDK (public) and LLNDK-private libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900565 return inList(c.Name(), *llndkLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800566}
567
Inseob Kim9516ee92019-05-09 10:56:13 +0900568func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800569 // Returns true only for LLNDK (public) libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900570 return c.isLlndk(config) && !c.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800571}
572
Inseob Kim9516ee92019-05-09 10:56:13 +0900573func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800574 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Inseob Kim9516ee92019-05-09 10:56:13 +0900575 return inList(c.Name(), *vndkPrivateLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800576}
577
Justin Yun8effde42017-06-23 19:24:43 +0900578func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800579 if vndkdep := c.vndkdep; vndkdep != nil {
580 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900581 }
582 return false
583}
584
Jooyung Han76106d92019-05-20 18:49:10 +0900585func (c *Module) vndkVersion() string {
586 if vndkdep := c.vndkdep; vndkdep != nil {
587 return vndkdep.Properties.Vndk.Version
588 }
589 return ""
590}
591
Yi Kong7e53c572018-02-14 18:16:12 +0800592func (c *Module) isPgoCompile() bool {
593 if pgo := c.pgo; pgo != nil {
594 return pgo.Properties.PgoCompile
595 }
596 return false
597}
598
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800599func (c *Module) isNDKStubLibrary() bool {
600 if _, ok := c.compiler.(*stubDecorator); ok {
601 return true
602 }
603 return false
604}
605
Logan Chienf3511742017-10-31 18:04:35 +0800606func (c *Module) isVndkSp() bool {
607 if vndkdep := c.vndkdep; vndkdep != nil {
608 return vndkdep.isVndkSp()
609 }
610 return false
611}
612
613func (c *Module) isVndkExt() bool {
614 if vndkdep := c.vndkdep; vndkdep != nil {
615 return vndkdep.isVndkExt()
616 }
617 return false
618}
619
Vic Yangefd249e2018-11-12 20:19:56 -0800620func (c *Module) mustUseVendorVariant() bool {
621 return c.isVndkSp() || inList(c.Name(), config.VndkMustUseVendorVariantList)
622}
623
Logan Chienf3511742017-10-31 18:04:35 +0800624func (c *Module) getVndkExtendsModuleName() string {
625 if vndkdep := c.vndkdep; vndkdep != nil {
626 return vndkdep.getVndkExtendsModuleName()
627 }
628 return ""
629}
630
Jiyong Park82e2bf32017-08-16 14:05:54 +0900631// Returns true only when this module is configured to have core and vendor
632// variants.
633func (c *Module) hasVendorVariant() bool {
634 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
635}
636
Jiyong Parkf9332f12018-02-01 00:54:12 +0900637func (c *Module) inRecovery() bool {
638 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
639}
640
641func (c *Module) onlyInRecovery() bool {
642 return c.ModuleBase.InstallInRecovery()
643}
644
Jiyong Park25fc6a92018-11-18 18:02:45 +0900645func (c *Module) IsStubs() bool {
646 if library, ok := c.linker.(*libraryDecorator); ok {
647 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900648 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
649 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900650 }
651 return false
652}
653
654func (c *Module) HasStubsVariants() bool {
655 if library, ok := c.linker.(*libraryDecorator); ok {
656 return len(library.Properties.Stubs.Versions) > 0
657 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700658 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
659 return len(library.Properties.Stubs.Versions) > 0
660 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900661 return false
662}
663
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900664func (c *Module) bootstrap() bool {
665 return Bool(c.Properties.Bootstrap)
666}
667
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700668func (c *Module) nativeCoverage() bool {
669 return c.linker != nil && c.linker.nativeCoverage()
670}
671
Jiyong Parkf1194352019-02-25 11:05:47 +0900672func isBionic(name string) bool {
673 switch name {
674 case "libc", "libm", "libdl", "linker":
675 return true
676 }
677 return false
678}
679
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700680func installToBootstrap(name string, config android.Config) bool {
681 if name == "libclang_rt.hwasan-aarch64-android" {
682 return inList("hwaddress", config.SanitizeDevice())
683 }
684 return isBionic(name)
685}
686
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800687func (c *Module) XrefCcFiles() android.Paths {
688 return c.kytheFiles
689}
690
Colin Crossca860ac2016-01-04 14:34:37 -0800691type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700692 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800693 moduleContextImpl
694}
695
Colin Cross37047f12016-12-13 17:06:13 -0800696type depsContext struct {
697 android.BottomUpMutatorContext
698 moduleContextImpl
699}
700
Colin Crossca860ac2016-01-04 14:34:37 -0800701type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700702 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800703 moduleContextImpl
704}
705
Jiyong Park2db76922017-11-08 16:03:48 +0900706func (ctx *moduleContext) SocSpecific() bool {
707 return ctx.ModuleContext.SocSpecific() ||
708 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700709}
710
Colin Crossca860ac2016-01-04 14:34:37 -0800711type moduleContextImpl struct {
712 mod *Module
713 ctx BaseModuleContext
714}
715
Colin Crossb98c8b02016-07-29 13:44:28 -0700716func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800717 return ctx.mod.toolchain(ctx.ctx)
718}
719
720func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000721 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800722}
723
724func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900725 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800726}
727
Jiyong Park1d1119f2019-07-29 21:27:18 +0900728func (ctx *moduleContextImpl) header() bool {
729 return ctx.mod.header()
730}
731
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700732func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800733 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800734 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700735 }
736 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800737}
738
739func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700740 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700741 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900742 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700743 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900744 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
745 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
746 return "current"
747 }
748 return platform_vndk_ver
749 }
750 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800751 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900752 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700753 }
754 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800755}
756
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700757func (ctx *moduleContextImpl) useVndk() bool {
758 return ctx.mod.useVndk()
759}
Justin Yun8effde42017-06-23 19:24:43 +0900760
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800761func (ctx *moduleContextImpl) isNdk() bool {
762 return ctx.mod.isNdk()
763}
764
Inseob Kim9516ee92019-05-09 10:56:13 +0900765func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
766 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800767}
768
Inseob Kim9516ee92019-05-09 10:56:13 +0900769func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
770 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800771}
772
Inseob Kim9516ee92019-05-09 10:56:13 +0900773func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
774 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800775}
776
Logan Chienf3511742017-10-31 18:04:35 +0800777func (ctx *moduleContextImpl) isVndk() bool {
778 return ctx.mod.isVndk()
779}
780
Yi Kong7e53c572018-02-14 18:16:12 +0800781func (ctx *moduleContextImpl) isPgoCompile() bool {
782 return ctx.mod.isPgoCompile()
783}
784
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800785func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
786 return ctx.mod.isNDKStubLibrary()
787}
788
Justin Yun8effde42017-06-23 19:24:43 +0900789func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800790 return ctx.mod.isVndkSp()
791}
792
793func (ctx *moduleContextImpl) isVndkExt() bool {
794 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900795}
796
Vic Yangefd249e2018-11-12 20:19:56 -0800797func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
798 return ctx.mod.mustUseVendorVariant()
799}
800
Jiyong Parkf9332f12018-02-01 00:54:12 +0900801func (ctx *moduleContextImpl) inRecovery() bool {
802 return ctx.mod.inRecovery()
803}
804
Logan Chien2f2b8902018-07-10 15:01:19 +0800805// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800806func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +0800807 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
808 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800809 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800810
811 if ctx.ctx.Fuchsia() {
812 return false
813 }
814
Logan Chien2f2b8902018-07-10 15:01:19 +0800815 if sanitize := ctx.mod.sanitize; sanitize != nil {
816 if !sanitize.isVariantOnProductionDevice() {
817 return false
818 }
819 }
820 if !ctx.ctx.Device() {
821 // Host modules do not need ABI dumps.
822 return false
823 }
Logan Chienfa478c02018-12-28 16:25:39 +0800824 if !ctx.mod.IsForPlatform() {
825 // APEX variants do not need ABI dumps.
826 return false
827 }
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +0800828 if ctx.isStubs() {
829 // Stubs do not need ABI dumps.
830 return false
831 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800832 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800833}
834
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700835func (ctx *moduleContextImpl) selectedStl() string {
836 if stl := ctx.mod.stl; stl != nil {
837 return stl.Properties.SelectedStl
838 }
839 return ""
840}
841
Ivan Lozanobd721262018-11-27 14:33:03 -0800842func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
843 return ctx.mod.linker.useClangLld(actx)
844}
845
Colin Crossce75d2c2016-10-06 16:12:58 -0700846func (ctx *moduleContextImpl) baseModuleName() string {
847 return ctx.mod.ModuleBase.BaseModuleName()
848}
849
Logan Chienf3511742017-10-31 18:04:35 +0800850func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
851 return ctx.mod.getVndkExtendsModuleName()
852}
853
Jiyong Park58e364a2019-01-19 19:24:06 +0900854func (ctx *moduleContextImpl) apexName() string {
855 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900856}
857
Jiyong Parkb0788572018-12-20 22:10:17 +0900858func (ctx *moduleContextImpl) hasStubsVariants() bool {
859 return ctx.mod.HasStubsVariants()
860}
861
862func (ctx *moduleContextImpl) isStubs() bool {
863 return ctx.mod.IsStubs()
864}
865
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900866func (ctx *moduleContextImpl) bootstrap() bool {
867 return ctx.mod.bootstrap()
868}
869
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700870func (ctx *moduleContextImpl) nativeCoverage() bool {
871 return ctx.mod.nativeCoverage()
872}
873
Colin Cross635c3b02016-05-18 15:37:25 -0700874func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800875 return &Module{
876 hod: hod,
877 multilib: multilib,
878 }
879}
880
Colin Cross635c3b02016-05-18 15:37:25 -0700881func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800882 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700883 module.features = []feature{
884 &tidyFeature{},
885 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700886 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800887 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800888 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800889 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900890 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700891 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700892 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800893 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800894 return module
895}
896
Colin Crossce75d2c2016-10-06 16:12:58 -0700897func (c *Module) Prebuilt() *android.Prebuilt {
898 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
899 return p.prebuilt()
900 }
901 return nil
902}
903
904func (c *Module) Name() string {
905 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700906 if p, ok := c.linker.(interface {
907 Name(string) string
908 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700909 name = p.Name(name)
910 }
911 return name
912}
913
Alex Light3d673592019-01-18 14:37:31 -0800914func (c *Module) Symlinks() []string {
915 if p, ok := c.installer.(interface {
916 symlinkList() []string
917 }); ok {
918 return p.symlinkList()
919 }
920 return nil
921}
922
Jeff Gaston294356f2017-09-27 17:05:30 -0700923// orderDeps reorders dependencies into a list such that if module A depends on B, then
924// A will precede B in the resultant list.
925// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800926// Note that directSharedDeps should be the analogous static library for each shared lib dep
927func 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 -0700928 // If A depends on B, then
929 // Every list containing A will also contain B later in the list
930 // So, after concatenating all lists, the final instance of B will have come from the same
931 // original list as the final instance of A
932 // So, the final instance of B will be later in the concatenation than the final A
933 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
934 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800935 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700936 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800937 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
938 }
939 for _, dep := range directSharedDeps {
940 orderedAllDeps = append(orderedAllDeps, dep)
941 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700942 }
943
Colin Crossb6715442017-10-24 11:13:31 -0700944 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700945
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800946 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700947 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800948 // resultant list to only what the caller has chosen to include in directStaticDeps
949 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700950
951 return orderedAllDeps, orderedDeclaredDeps
952}
953
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800954func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
955 // convert Module to Path
956 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
957 staticDepFiles := []android.Path{}
958 for _, dep := range staticDeps {
959 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
960 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700961 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800962 sharedDepFiles := []android.Path{}
963 for _, sharedDep := range sharedDeps {
964 staticAnalogue := sharedDep.staticVariant
965 if staticAnalogue != nil {
966 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
967 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
968 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700969 }
970
971 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800972 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700973
974 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700975}
976
Roland Levillainf89cd092019-07-29 16:22:59 +0100977func (c *Module) IsTestPerSrcAllTestsVariation() bool {
978 test, ok := c.linker.(testPerSrc)
979 return ok && test.isAllTestsVariation()
980}
981
Colin Cross635c3b02016-05-18 15:37:25 -0700982func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +0100983 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +0100984 //
985 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
986 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
987 // module and return early, as this module does not produce an output file per se.
988 if c.IsTestPerSrcAllTestsVariation() {
989 c.outputFile = android.OptionalPath{}
990 return
Roland Levillainf2fad972019-06-28 15:41:19 +0100991 }
992
Jooyung Han38002912019-05-16 04:01:54 +0900993 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +0900994
Colin Crossca860ac2016-01-04 14:34:37 -0800995 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700996 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800997 moduleContextImpl: moduleContextImpl{
998 mod: c,
999 },
1000 }
1001 ctx.ctx = ctx
1002
Colin Crossf18e1102017-11-16 14:33:08 -08001003 deps := c.depsToPaths(ctx)
1004 if ctx.Failed() {
1005 return
1006 }
1007
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001008 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1009 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1010 }
1011
Colin Crossca860ac2016-01-04 14:34:37 -08001012 flags := Flags{
1013 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001014 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001015 }
Colin Crossca860ac2016-01-04 14:34:37 -08001016 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001017 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001018 }
1019 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001020 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001021 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001022 if c.stl != nil {
1023 flags = c.stl.flags(ctx, flags)
1024 }
Colin Cross16b23492016-01-06 14:41:07 -08001025 if c.sanitize != nil {
1026 flags = c.sanitize.flags(ctx, flags)
1027 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001028 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001029 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001030 }
Stephen Craneba090d12017-05-09 15:44:35 -07001031 if c.lto != nil {
1032 flags = c.lto.flags(ctx, flags)
1033 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001034 if c.pgo != nil {
1035 flags = c.pgo.flags(ctx, flags)
1036 }
Ivan Lozano074ec482018-11-21 08:59:37 -08001037 if c.xom != nil {
1038 flags = c.xom.flags(ctx, flags)
1039 }
Colin Crossca860ac2016-01-04 14:34:37 -08001040 for _, feature := range c.features {
1041 flags = feature.flags(ctx, flags)
1042 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001043 if ctx.Failed() {
1044 return
1045 }
1046
Colin Crossb98c8b02016-07-29 13:44:28 -07001047 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
1048 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
1049 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001050
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001051 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001052
1053 for _, dir := range deps.IncludeDirs {
1054 flags.GlobalFlags = append(flags.GlobalFlags, "-I"+dir)
1055 }
1056 for _, dir := range deps.SystemIncludeDirs {
1057 flags.GlobalFlags = append(flags.GlobalFlags, "-isystem "+dir)
1058 }
1059
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001060 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001061 // We need access to all the flags seen by a source file.
1062 if c.sabi != nil {
1063 flags = c.sabi.flags(ctx, flags)
1064 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001065
1066 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.AsFlags)
1067
Colin Crossca860ac2016-01-04 14:34:37 -08001068 // Optimization to reduce size of build.ninja
1069 // Replace the long list of flags for each file with a module-local variable
1070 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
1071 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
1072 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
1073 flags.CFlags = []string{"$cflags"}
1074 flags.CppFlags = []string{"$cppflags"}
1075 flags.AsFlags = []string{"$asflags"}
1076
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001077 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001078 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001079 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001080 if ctx.Failed() {
1081 return
1082 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001083 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001084 }
1085
Colin Crossca860ac2016-01-04 14:34:37 -08001086 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001087 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001088 if ctx.Failed() {
1089 return
1090 }
Colin Cross635c3b02016-05-18 15:37:25 -07001091 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001092
1093 // If a lib is directly included in any of the APEXes, unhide the stubs
1094 // variant having the latest version gets visible to make. In addition,
1095 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1096 // force anything in the make world to link against the stubs library.
1097 // (unless it is explicitly referenced via .bootstrap suffix or the
1098 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001099 if c.HasStubsVariants() &&
1100 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001101 !c.inRecovery() && !c.useVndk() && !c.static() && !c.isCoverageVariant() &&
1102 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001103 c.Properties.HideFromMake = false // unhide
1104 // Note: this is still non-installable
1105 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001106 }
Colin Cross5049f022015-03-18 13:28:46 -07001107
Inseob Kim1f086e22019-05-09 13:29:15 +09001108 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001109 c.installer.install(ctx, c.outputFile.Path())
1110 if ctx.Failed() {
1111 return
Colin Crossca860ac2016-01-04 14:34:37 -08001112 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001113 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001114}
1115
Colin Cross0ea8ba82019-06-06 14:33:29 -07001116func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001117 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001118 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001119 }
Colin Crossca860ac2016-01-04 14:34:37 -08001120 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001121}
1122
Colin Crossca860ac2016-01-04 14:34:37 -08001123func (c *Module) begin(ctx BaseModuleContext) {
1124 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001125 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001126 }
Colin Crossca860ac2016-01-04 14:34:37 -08001127 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001128 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001129 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001130 if c.stl != nil {
1131 c.stl.begin(ctx)
1132 }
Colin Cross16b23492016-01-06 14:41:07 -08001133 if c.sanitize != nil {
1134 c.sanitize.begin(ctx)
1135 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001136 if c.coverage != nil {
1137 c.coverage.begin(ctx)
1138 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001139 if c.sabi != nil {
1140 c.sabi.begin(ctx)
1141 }
Justin Yun8effde42017-06-23 19:24:43 +09001142 if c.vndkdep != nil {
1143 c.vndkdep.begin(ctx)
1144 }
Stephen Craneba090d12017-05-09 15:44:35 -07001145 if c.lto != nil {
1146 c.lto.begin(ctx)
1147 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001148 if c.pgo != nil {
1149 c.pgo.begin(ctx)
1150 }
Colin Crossca860ac2016-01-04 14:34:37 -08001151 for _, feature := range c.features {
1152 feature.begin(ctx)
1153 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001154 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001155 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001156 if err != nil {
1157 ctx.PropertyErrorf("sdk_version", err.Error())
1158 }
Nan Zhang0007d812017-11-07 10:57:05 -08001159 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001160 }
Colin Crossca860ac2016-01-04 14:34:37 -08001161}
1162
Colin Cross37047f12016-12-13 17:06:13 -08001163func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001164 deps := Deps{}
1165
1166 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001167 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001168 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001169 // Add the PGO dependency (the clang_rt.profile runtime library), which
1170 // sometimes depends on symbols from libgcc, before libgcc gets added
1171 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001172 if c.pgo != nil {
1173 deps = c.pgo.deps(ctx, deps)
1174 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001175 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001176 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001177 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001178 if c.stl != nil {
1179 deps = c.stl.deps(ctx, deps)
1180 }
Colin Cross16b23492016-01-06 14:41:07 -08001181 if c.sanitize != nil {
1182 deps = c.sanitize.deps(ctx, deps)
1183 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001184 if c.coverage != nil {
1185 deps = c.coverage.deps(ctx, deps)
1186 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001187 if c.sabi != nil {
1188 deps = c.sabi.deps(ctx, deps)
1189 }
Justin Yun8effde42017-06-23 19:24:43 +09001190 if c.vndkdep != nil {
1191 deps = c.vndkdep.deps(ctx, deps)
1192 }
Stephen Craneba090d12017-05-09 15:44:35 -07001193 if c.lto != nil {
1194 deps = c.lto.deps(ctx, deps)
1195 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001196 for _, feature := range c.features {
1197 deps = feature.deps(ctx, deps)
1198 }
1199
Colin Crossb6715442017-10-24 11:13:31 -07001200 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1201 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1202 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1203 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1204 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1205 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001206 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001207
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001208 for _, lib := range deps.ReexportSharedLibHeaders {
1209 if !inList(lib, deps.SharedLibs) {
1210 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1211 }
1212 }
1213
1214 for _, lib := range deps.ReexportStaticLibHeaders {
1215 if !inList(lib, deps.StaticLibs) {
1216 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1217 }
1218 }
1219
Colin Cross5950f382016-12-13 12:50:57 -08001220 for _, lib := range deps.ReexportHeaderLibHeaders {
1221 if !inList(lib, deps.HeaderLibs) {
1222 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1223 }
1224 }
1225
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001226 for _, gen := range deps.ReexportGeneratedHeaders {
1227 if !inList(gen, deps.GeneratedHeaders) {
1228 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1229 }
1230 }
1231
Colin Crossc99deeb2016-04-11 15:06:20 -07001232 return deps
1233}
1234
Dan Albert7e9d2952016-08-04 13:02:36 -07001235func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001236 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001237 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001238 moduleContextImpl: moduleContextImpl{
1239 mod: c,
1240 },
1241 }
1242 ctx.ctx = ctx
1243
Colin Crossca860ac2016-01-04 14:34:37 -08001244 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001245}
1246
Jiyong Park7ed9de32018-10-15 22:25:07 +09001247// Split name#version into name and version
1248func stubsLibNameAndVersion(name string) (string, string) {
1249 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1250 version := name[sharp+1:]
1251 libname := name[:sharp]
1252 return libname, version
1253 }
1254 return name, ""
1255}
1256
Colin Cross1e676be2016-10-12 14:38:15 -07001257func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001258 ctx := &depsContext{
1259 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001260 moduleContextImpl: moduleContextImpl{
1261 mod: c,
1262 },
1263 }
1264 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001265
Colin Crossc99deeb2016-04-11 15:06:20 -07001266 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001267
Dan Albert914449f2016-06-17 16:45:24 -07001268 variantNdkLibs := []string{}
1269 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001270 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001271 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001272
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001273 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1274 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001275 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001276 // 1. Name of an NDK library that refers to a prebuilt module.
1277 // For each of these, it adds the name of the prebuilt module (which will be in
1278 // prebuilts/ndk) to the list of nonvariant libs.
1279 // 2. Name of an NDK library that refers to an ndk_library module.
1280 // For each of these, it adds the name of the ndk_library module to the list of
1281 // variant libs.
1282 // 3. Anything else (so anything that isn't an NDK library).
1283 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001284 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001285 // The caller can then know to add the variantLibs dependencies differently from the
1286 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001287
1288 llndkLibraries := llndkLibraries(actx.Config())
1289 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001290 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1291 variantLibs = []string{}
1292 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001293 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001294 // strip #version suffix out
1295 name, _ := stubsLibNameAndVersion(entry)
1296 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1297 if !inList(name, ndkMigratedLibs) {
1298 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001299 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001300 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001301 }
Inseob Kim9516ee92019-05-09 10:56:13 +09001302 } else if ctx.useVndk() && inList(name, *llndkLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001303 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001304 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001305 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001306 if actx.OtherModuleExists(vendorPublicLib) {
1307 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1308 } else {
1309 // This can happen if vendor_public_library module is defined in a
1310 // namespace that isn't visible to the current module. In that case,
1311 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001312 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001313 }
Dan Albert914449f2016-06-17 16:45:24 -07001314 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001315 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001316 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001317 }
1318 }
Dan Albert914449f2016-06-17 16:45:24 -07001319 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001320 }
1321
Dan Albert914449f2016-06-17 16:45:24 -07001322 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1323 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001324 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001325 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001326
Jiyong Park7e636d02019-01-28 16:16:54 +09001327 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001328 if c.linker != nil {
1329 if library, ok := c.linker.(*libraryDecorator); ok {
1330 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001331 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001332 }
1333 }
1334 }
1335
Colin Cross32ec36c2016-12-15 07:39:51 -08001336 for _, lib := range deps.HeaderLibs {
1337 depTag := headerDepTag
1338 if inList(lib, deps.ReexportHeaderLibHeaders) {
1339 depTag = headerExportDepTag
1340 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001341 if buildStubs {
Jiyong Park7e636d02019-01-28 16:16:54 +09001342 actx.AddFarVariationDependencies([]blueprint.Variation{
1343 {Mutator: "arch", Variation: ctx.Target().String()},
Jiyong Park3b1746a2019-01-29 11:15:04 +09001344 {Mutator: "image", Variation: c.imageVariation()},
Jiyong Park7e636d02019-01-28 16:16:54 +09001345 }, depTag, lib)
1346 } else {
1347 actx.AddVariationDependencies(nil, depTag, lib)
1348 }
1349 }
1350
1351 if buildStubs {
1352 // Stubs lib does not have dependency to other static/shared libraries.
1353 // Don't proceed.
1354 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001355 }
Colin Cross5950f382016-12-13 12:50:57 -08001356
Inseob Kimc0907f12019-02-08 21:00:45 +09001357 syspropImplLibraries := syspropImplLibraries(actx.Config())
1358
Jiyong Park5d1598f2019-02-25 22:14:17 +09001359 for _, lib := range deps.WholeStaticLibs {
1360 depTag := wholeStaticDepTag
1361 if impl, ok := syspropImplLibraries[lib]; ok {
1362 lib = impl
1363 }
1364 actx.AddVariationDependencies([]blueprint.Variation{
1365 {Mutator: "link", Variation: "static"},
1366 }, depTag, lib)
1367 }
1368
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001369 for _, lib := range deps.StaticLibs {
1370 depTag := staticDepTag
1371 if inList(lib, deps.ReexportStaticLibHeaders) {
1372 depTag = staticExportDepTag
1373 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001374
1375 if impl, ok := syspropImplLibraries[lib]; ok {
1376 lib = impl
1377 }
1378
Dan Willemsen59339a22018-07-22 21:18:45 -07001379 actx.AddVariationDependencies([]blueprint.Variation{
1380 {Mutator: "link", Variation: "static"},
1381 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001382 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001383
Dan Willemsen59339a22018-07-22 21:18:45 -07001384 actx.AddVariationDependencies([]blueprint.Variation{
1385 {Mutator: "link", Variation: "static"},
1386 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001387
Jiyong Park25fc6a92018-11-18 18:02:45 +09001388 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1389 var variations []blueprint.Variation
1390 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001391 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001392 if version != "" && versionVariantAvail {
1393 // Version is explicitly specified. i.e. libFoo#30
1394 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1395 depTag.explicitlyVersioned = true
1396 }
1397 actx.AddVariationDependencies(variations, depTag, name)
1398
1399 // If the version is not specified, add dependency to the latest stubs library.
1400 // The stubs library will be used when the depending module is built for APEX and
1401 // the dependent module is not in the same APEX.
1402 latestVersion := latestStubsVersionFor(actx.Config(), name)
1403 if version == "" && latestVersion != "" && versionVariantAvail {
1404 actx.AddVariationDependencies([]blueprint.Variation{
1405 {Mutator: "link", Variation: "shared"},
1406 {Mutator: "version", Variation: latestVersion},
1407 }, depTag, name)
1408 // Note that depTag.explicitlyVersioned is false in this case.
1409 }
1410 }
1411
Jiyong Park7ed9de32018-10-15 22:25:07 +09001412 // shared lib names without the #version suffix
1413 var sharedLibNames []string
1414
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001415 for _, lib := range deps.SharedLibs {
1416 depTag := sharedDepTag
1417 if inList(lib, deps.ReexportSharedLibHeaders) {
1418 depTag = sharedExportDepTag
1419 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001420
1421 if impl, ok := syspropImplLibraries[lib]; ok {
1422 lib = impl
1423 }
1424
1425 name, version := stubsLibNameAndVersion(lib)
1426 sharedLibNames = append(sharedLibNames, name)
1427
Jiyong Park25fc6a92018-11-18 18:02:45 +09001428 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001429 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001430
Jiyong Park7ed9de32018-10-15 22:25:07 +09001431 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001432 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001433 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1434 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1435 // linking against both the stubs lib and the non-stubs lib at the same time.
1436 continue
1437 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001438 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001439 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001440
Dan Willemsen59339a22018-07-22 21:18:45 -07001441 actx.AddVariationDependencies([]blueprint.Variation{
1442 {Mutator: "link", Variation: "shared"},
1443 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001444
Colin Cross68861832016-07-08 10:41:41 -07001445 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001446
1447 for _, gen := range deps.GeneratedHeaders {
1448 depTag := genHeaderDepTag
1449 if inList(gen, deps.ReexportGeneratedHeaders) {
1450 depTag = genHeaderExportDepTag
1451 }
1452 actx.AddDependency(c, depTag, gen)
1453 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001454
Colin Cross42d48b72018-08-29 14:10:52 -07001455 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001456
1457 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001458 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001459 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001460 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001461 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001462 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001463 if deps.LinkerFlagsFile != "" {
1464 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1465 }
1466 if deps.DynamicLinker != "" {
1467 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001468 }
Dan Albert914449f2016-06-17 16:45:24 -07001469
1470 version := ctx.sdkVersion()
1471 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001472 {Mutator: "ndk_api", Variation: version},
1473 {Mutator: "link", Variation: "shared"},
1474 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001475 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001476 {Mutator: "ndk_api", Variation: version},
1477 {Mutator: "link", Variation: "shared"},
1478 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001479
1480 if vndkdep := c.vndkdep; vndkdep != nil {
1481 if vndkdep.isVndkExt() {
1482 baseModuleMode := vendorMode
1483 if actx.DeviceConfig().VndkVersion() == "" {
1484 baseModuleMode = coreMode
1485 }
1486 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001487 {Mutator: "image", Variation: baseModuleMode},
1488 {Mutator: "link", Variation: "shared"},
1489 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001490 }
1491 }
Colin Cross6362e272015-10-29 15:25:03 -07001492}
Colin Cross21b9a242015-03-24 14:15:58 -07001493
Colin Crosse40b4ea2018-10-02 22:25:58 -07001494func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001495 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1496 c.beginMutator(ctx)
1497 }
1498}
1499
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001500// Whether a module can link to another module, taking into
1501// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001502func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001503 if from.Target().Os != android.Android {
1504 // Host code is not restricted
1505 return
1506 }
1507 if from.Properties.UseVndk {
1508 // Though vendor code is limited by the vendor mutator,
1509 // each vendor-available module needs to check
1510 // link-type for VNDK.
1511 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001512 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001513 }
1514 return
1515 }
Nan Zhang0007d812017-11-07 10:57:05 -08001516 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001517 // Platform code can link to anything
1518 return
1519 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001520 if from.inRecovery() {
1521 // Recovery code is not NDK
1522 return
1523 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001524 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1525 // These are always allowed
1526 return
1527 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001528 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1529 // These are allowed, but they don't set sdk_version
1530 return
1531 }
1532 if _, ok := to.linker.(*stubDecorator); ok {
1533 // These aren't real libraries, but are the stub shared libraries that are included in
1534 // the NDK.
1535 return
1536 }
Logan Chien834b9a62019-01-14 15:39:03 +08001537
1538 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" {
1539 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1540 // to link to libc++ (non-NDK and without sdk_version).
1541 return
1542 }
1543
Nan Zhang0007d812017-11-07 10:57:05 -08001544 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001545 // NDK code linking to platform code is never okay.
1546 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1547 ctx.OtherModuleName(to))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001548 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001549 }
1550
1551 // At this point we know we have two NDK libraries, but we need to
1552 // check that we're not linking against anything built against a higher
1553 // API level, as it is only valid to link against older or equivalent
1554 // APIs.
1555
Inseob Kim01a28722018-04-11 09:48:45 +09001556 // Current can link against anything.
1557 if String(from.Properties.Sdk_version) != "current" {
1558 // Otherwise we need to check.
1559 if String(to.Properties.Sdk_version) == "current" {
1560 // Current can't be linked against by anything else.
1561 ctx.ModuleErrorf("links %q built against newer API version %q",
1562 ctx.OtherModuleName(to), "current")
1563 } else {
1564 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1565 if err != nil {
1566 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001567 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001568 String(from.Properties.Sdk_version))
1569 }
1570 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1571 if err != nil {
1572 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001573 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001574 String(to.Properties.Sdk_version))
1575 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001576
Inseob Kim01a28722018-04-11 09:48:45 +09001577 if toApi > fromApi {
1578 ctx.ModuleErrorf("links %q built against newer API version %q",
1579 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1580 }
1581 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001582 }
Dan Albert202fe492017-12-15 13:56:59 -08001583
1584 // Also check that the two STL choices are compatible.
1585 fromStl := from.stl.Properties.SelectedStl
1586 toStl := to.stl.Properties.SelectedStl
1587 if fromStl == "" || toStl == "" {
1588 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001589 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001590 // We can be permissive with the system "STL" since it is only the C++
1591 // ABI layer, but in the future we should make sure that everyone is
1592 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001593 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001594 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1595 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1596 to.stl.Properties.SelectedStl)
1597 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001598}
1599
Jiyong Park5fb8c102018-04-09 12:03:06 +09001600// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001601// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1602// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001603// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001604func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
Inseob Kim9516ee92019-05-09 10:56:13 +09001605 llndkLibraries := llndkLibraries(ctx.Config())
Jooyung Hana70f0672019-01-18 15:20:43 +09001606 check := func(child, parent android.Module) bool {
1607 to, ok := child.(*Module)
1608 if !ok {
1609 // follow thru cc.Defaults, etc.
1610 return true
1611 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001612
Jooyung Hana70f0672019-01-18 15:20:43 +09001613 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1614 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001615 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001616
1617 // if target lib has no vendor variant, keep checking dependency graph
1618 if !to.hasVendorVariant() {
1619 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001620 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001621
Inseob Kim9516ee92019-05-09 10:56:13 +09001622 if to.isVndkSp() || inList(child.Name(), *llndkLibraries) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001623 return false
1624 }
1625
1626 var stringPath []string
1627 for _, m := range ctx.GetWalkPath() {
1628 stringPath = append(stringPath, m.Name())
1629 }
1630 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1631 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1632 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1633 return false
1634 }
1635 if module, ok := ctx.Module().(*Module); ok {
1636 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Inseob Kim9516ee92019-05-09 10:56:13 +09001637 if inList(ctx.ModuleName(), *llndkLibraries) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001638 ctx.WalkDeps(check)
1639 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001640 }
1641 }
1642}
1643
Colin Crossc99deeb2016-04-11 15:06:20 -07001644// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001645func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001646 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001647
Jeff Gaston294356f2017-09-27 17:05:30 -07001648 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001649 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001650
Inseob Kim9516ee92019-05-09 10:56:13 +09001651 llndkLibraries := llndkLibraries(ctx.Config())
1652 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
1653
Inseob Kim69378442019-06-03 19:10:47 +09001654 reexportExporter := func(exporter exportedFlagsProducer) {
1655 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
1656 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
1657 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
1658 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
1659 }
1660
Colin Crossd11fcda2017-10-23 17:59:01 -07001661 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001662 depName := ctx.OtherModuleName(dep)
1663 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001664
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001665 ccDep, _ := dep.(*Module)
1666 if ccDep == nil {
1667 // handling for a few module types that aren't cc Module but that are also supported
1668 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001669 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001670 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001671 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1672 genRule.GeneratedSourceFiles()...)
1673 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001674 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001675 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001676 // Support exported headers from a generated_sources dependency
1677 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001678 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001679 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001680 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001681 genRule.GeneratedDeps()...)
Inseob Kim69378442019-06-03 19:10:47 +09001682 dirs := genRule.GeneratedHeaderDirs().Strings()
1683 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001684 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09001685 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
1686 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001687 // 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 +09001688 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001689
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001690 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001691 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001692 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001693 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001694 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001695 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001696 files := genRule.GeneratedSourceFiles()
1697 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001698 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001699 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001700 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 -07001701 }
1702 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001703 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001704 }
Colin Crossca860ac2016-01-04 14:34:37 -08001705 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001706 return
1707 }
1708
Colin Crossfe17f6f2019-03-28 19:30:56 -07001709 if depTag == android.ProtoPluginDepTag {
1710 return
1711 }
1712
Colin Crossd11fcda2017-10-23 17:59:01 -07001713 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001714 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1715 return
1716 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001717 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001718 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001719 return
1720 }
1721
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001722 // re-exporting flags
1723 if depTag == reuseObjTag {
1724 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001725 c.staticVariant = ccDep
Inseob Kim69378442019-06-03 19:10:47 +09001726 objs, exporter := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001727 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09001728 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08001729 return
1730 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001731 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001732
Jiyong Parke4bb9862019-02-01 00:31:10 +09001733 if depTag == staticVariantTag {
1734 if _, ok := ccDep.compiler.(libraryInterface); ok {
1735 c.staticVariant = ccDep
1736 return
1737 }
1738 }
1739
Jiyong Park25fc6a92018-11-18 18:02:45 +09001740 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1741 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1742 // won't be matched to sharedDepTag and lateSharedDepTag.
1743 explicitlyVersioned := false
1744 if t, ok := depTag.(dependencyTag); ok {
1745 explicitlyVersioned = t.explicitlyVersioned
1746 t.explicitlyVersioned = false
1747 depTag = t
1748 }
1749
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001750 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001751 depIsStatic := false
1752 switch depTag {
1753 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1754 depIsStatic = true
1755 }
1756 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001757 depIsStubs := dependentLibrary.buildStubs()
1758 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001759 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001760 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001761
1762 var useThisDep bool
1763 if depIsStubs && explicitlyVersioned {
1764 // Always respect dependency to the versioned stubs (i.e. libX#10)
1765 useThisDep = true
1766 } else if !depHasStubs {
1767 // Use non-stub variant if that is the only choice
1768 // (i.e. depending on a lib without stubs.version property)
1769 useThisDep = true
1770 } else if c.IsForPlatform() {
1771 // If not building for APEX, use stubs only when it is from
1772 // an APEX (and not from platform)
1773 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001774 if c.inRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001775 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001776 // always link to non-stub variant
1777 useThisDep = !depIsStubs
1778 }
1779 } else {
1780 // If building for APEX, use stubs only when it is not from
1781 // the same APEX
1782 useThisDep = (depInSameApex != depIsStubs)
1783 }
1784
1785 if !useThisDep {
1786 return // stop processing this dep
1787 }
1788 }
1789
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001790 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Inseob Kim69378442019-06-03 19:10:47 +09001791 depPaths.IncludeDirs = append(depPaths.IncludeDirs, i.exportedDirs()...)
1792 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
1793 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedDeps()...)
1794 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001795
1796 if t.reexportFlags {
Inseob Kim69378442019-06-03 19:10:47 +09001797 reexportExporter(i)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001798 // 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 -07001799 // Re-exported shared library headers must be included as well since they can help us with type information
1800 // about template instantiations (instantiated from their headers).
Inseob Kim69378442019-06-03 19:10:47 +09001801 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
1802 // scripts.
1803 c.sabi.Properties.ReexportedIncludes = append(
1804 c.sabi.Properties.ReexportedIncludes, i.exportedDirs()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001805 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001806 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001807
Logan Chienf3511742017-10-31 18:04:35 +08001808 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001809 }
1810
Colin Cross26c34ed2016-09-30 17:10:16 -07001811 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001812 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001813
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001814 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001815 depFile := android.OptionalPath{}
1816
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001817 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001818 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001819 ptr = &depPaths.SharedLibs
1820 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001821 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001822 directSharedDeps = append(directSharedDeps, ccDep)
Jiyong Park64a44f22019-01-18 14:37:08 +09001823 case earlySharedDepTag:
1824 ptr = &depPaths.EarlySharedLibs
1825 depPtr = &depPaths.EarlySharedLibsDeps
1826 depFile = ccDep.linker.(libraryInterface).toc()
1827 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001828 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001829 ptr = &depPaths.LateSharedLibs
1830 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001831 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001832 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001833 ptr = nil
1834 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001835 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001836 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001837 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001838 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001839 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001840 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001841 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001842 return
1843 }
1844
1845 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001846 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001847 for i := range missingDeps {
1848 missingDeps[i] += postfix
1849 }
1850 ctx.AddMissingDependencies(missingDeps)
1851 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001852 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001853 case headerDepTag:
1854 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001855 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001856 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001857 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001858 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001859 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001860 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001861 case dynamicLinkerDepTag:
1862 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001863 }
1864
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001865 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001866 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001867 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001868 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001869 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001870 return
1871 }
1872
1873 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001874 // in static libraries act as if they were whole static libraries. The same goes for
1875 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001876 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1877 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001878 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1879 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001880
Dan Willemsen581341d2017-02-09 16:16:31 -08001881 }
1882
Colin Cross26c34ed2016-09-30 17:10:16 -07001883 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001884 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001885 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001886 return
1887 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001888 *ptr = append(*ptr, linkFile.Path())
1889 }
1890
Colin Crossc99deeb2016-04-11 15:06:20 -07001891 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001892 dep := depFile
1893 if !dep.Valid() {
1894 dep = linkFile
1895 }
1896 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001897 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001898
Logan Chien43d34c32017-12-20 01:17:32 +08001899 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001900 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001901 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001902 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kim9516ee92019-05-09 10:56:13 +09001903 isLLndk := inList(libName, *llndkLibraries)
1904 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001905 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08001906
yidong.zhangd06ecc82019-08-02 15:49:24 +08001907 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.isVndk() && !ccDep.mustUseVendorVariant() && !c.inRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08001908 // The vendor module is a no-vendor-variant VNDK library. Depend on the
1909 // core module instead.
1910 return libName
1911 } else if c.useVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001912 // The vendor module in Make will have been renamed to not conflict with the core
1913 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001914 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001915 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001916 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001917 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1918 return libName + recoverySuffix
dimitry1f33e402019-03-26 12:39:31 +01001919 } else if ccDep.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02001920 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001921 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001922 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001923 }
Logan Chien43d34c32017-12-20 01:17:32 +08001924 }
1925
1926 // Export the shared libs to Make.
1927 switch depTag {
Jiyong Park64a44f22019-01-18 14:37:08 +09001928 case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001929 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001930 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08001931 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09001932 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001933 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001934 c.Properties.ApexesProvidingSharedLibs = append(
1935 c.Properties.ApexesProvidingSharedLibs, an)
1936 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09001937 }
1938 }
1939
Jiyong Park27b188b2017-07-18 13:23:39 +09001940 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001941 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001942 c.Properties.AndroidMkSharedLibs = append(
1943 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08001944 case ndkStubDepTag, ndkLateStubDepTag:
1945 ndkStub := ccDep.linker.(*stubDecorator)
1946 c.Properties.AndroidMkSharedLibs = append(
1947 c.Properties.AndroidMkSharedLibs,
1948 depName+"."+ndkStub.properties.ApiLevel)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001949 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1950 c.Properties.AndroidMkStaticLibs = append(
1951 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001952 case runtimeDepTag:
1953 c.Properties.AndroidMkRuntimeLibs = append(
1954 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001955 case wholeStaticDepTag:
1956 c.Properties.AndroidMkWholeStaticLibs = append(
1957 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001958 }
Colin Crossca860ac2016-01-04 14:34:37 -08001959 })
1960
Jeff Gaston294356f2017-09-27 17:05:30 -07001961 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001962 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001963
Colin Crossdd84e052017-05-17 13:44:16 -07001964 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001965 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Inseob Kim69378442019-06-03 19:10:47 +09001966 depPaths.IncludeDirs = android.FirstUniqueStrings(depPaths.IncludeDirs)
1967 depPaths.SystemIncludeDirs = android.FirstUniqueStrings(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001968 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kim69378442019-06-03 19:10:47 +09001969 depPaths.ReexportedDirs = android.FirstUniqueStrings(depPaths.ReexportedDirs)
1970 depPaths.ReexportedSystemDirs = android.FirstUniqueStrings(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07001971 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09001972 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001973
1974 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09001975 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001976 }
Colin Crossdd84e052017-05-17 13:44:16 -07001977
Colin Crossca860ac2016-01-04 14:34:37 -08001978 return depPaths
1979}
1980
1981func (c *Module) InstallInData() bool {
1982 if c.installer == nil {
1983 return false
1984 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001985 return c.installer.inData()
1986}
1987
1988func (c *Module) InstallInSanitizerDir() bool {
1989 if c.installer == nil {
1990 return false
1991 }
1992 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001993 return true
1994 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001995 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001996}
1997
Jiyong Parkf9332f12018-02-01 00:54:12 +09001998func (c *Module) InstallInRecovery() bool {
1999 return c.inRecovery()
2000}
2001
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002002func (c *Module) HostToolPath() android.OptionalPath {
2003 if c.installer == nil {
2004 return android.OptionalPath{}
2005 }
2006 return c.installer.hostToolPath()
2007}
2008
Nan Zhangd4e641b2017-07-12 12:55:28 -07002009func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2010 return c.outputFile
2011}
2012
Colin Cross41955e82019-05-29 14:40:35 -07002013func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2014 switch tag {
2015 case "":
2016 if c.outputFile.Valid() {
2017 return android.Paths{c.outputFile.Path()}, nil
2018 }
2019 return android.Paths{}, nil
2020 default:
2021 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002022 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002023}
2024
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002025func (c *Module) static() bool {
2026 if static, ok := c.linker.(interface {
2027 static() bool
2028 }); ok {
2029 return static.static()
2030 }
2031 return false
2032}
2033
Jiyong Park379de2f2018-12-19 02:47:14 +09002034func (c *Module) staticBinary() bool {
2035 if static, ok := c.linker.(interface {
2036 staticBinary() bool
2037 }); ok {
2038 return static.staticBinary()
2039 }
2040 return false
2041}
2042
Jiyong Park1d1119f2019-07-29 21:27:18 +09002043func (c *Module) header() bool {
2044 if h, ok := c.linker.(interface {
2045 header() bool
2046 }); ok {
2047 return h.header()
2048 }
2049 return false
2050}
2051
Jooyung Han38002912019-05-16 04:01:54 +09002052func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
2053 name := actx.ModuleName()
Colin Crossb60190a2018-09-04 16:28:17 -07002054 if c.useVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002055 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2056 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002057 return "native:vndk"
2058 }
Jooyung Han38002912019-05-16 04:01:54 +09002059 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002060 }
Jooyung Han38002912019-05-16 04:01:54 +09002061 if c.isVndk() && !c.isVndkExt() {
2062 if Bool(c.VendorProperties.Vendor_available) {
2063 return "native:vndk"
2064 }
2065 return "native:vndk_private"
2066 }
2067 return "native:vendor"
Colin Crossb60190a2018-09-04 16:28:17 -07002068 } else if c.inRecovery() {
2069 return "native:recovery"
2070 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2071 return "native:ndk:none:none"
2072 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2073 //family, link := getNdkStlFamilyAndLinkType(c)
2074 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Jooyung Han38002912019-05-16 04:01:54 +09002075 } else if inList(name, *vndkUsingCoreVariantLibraries(actx.Config())) {
Vic Yangefd249e2018-11-12 20:19:56 -08002076 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002077 } else {
2078 return "native:platform"
2079 }
2080}
2081
Jiyong Park9d452992018-10-03 00:38:19 +09002082// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002083// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002084func (c *Module) IsInstallableToApex() bool {
2085 if shared, ok := c.linker.(interface {
2086 shared() bool
2087 }); ok {
2088 return shared.shared()
Roland Levillainf89cd092019-07-29 16:22:59 +01002089 } else if _, ok := c.linker.(testPerSrc); ok {
2090 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002091 }
2092 return false
2093}
2094
Inseob Kim1f086e22019-05-09 13:29:15 +09002095func (c *Module) installable() bool {
2096 return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
2097}
2098
Jiyong Park3b1746a2019-01-29 11:15:04 +09002099func (c *Module) imageVariation() string {
2100 variation := "core"
2101 if c.useVndk() {
2102 variation = "vendor"
2103 } else if c.inRecovery() {
2104 variation = "recovery"
2105 }
2106 return variation
2107}
2108
bralee3f49f4d2019-03-04 06:58:15 +08002109func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
Colin Cross41955e82019-05-29 14:40:35 -07002110 outputFiles, err := c.OutputFiles("")
2111 if err != nil {
2112 panic(err)
2113 }
2114 dpInfo.Srcs = append(dpInfo.Srcs, outputFiles.Strings()...)
bralee3f49f4d2019-03-04 06:58:15 +08002115}
2116
Logan Chien41eabe62019-04-10 13:33:58 +08002117func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2118 if c.linker != nil {
2119 if library, ok := c.linker.(*libraryDecorator); ok {
2120 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2121 }
2122 }
2123}
2124
Colin Cross2ba19d92015-05-07 15:44:20 -07002125//
Colin Crosscfad1192015-11-02 16:43:11 -08002126// Defaults
2127//
Colin Crossca860ac2016-01-04 14:34:37 -08002128type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002129 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002130 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002131 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002132}
2133
Patrice Arrudac249c712019-03-19 17:00:29 -07002134// cc_defaults provides a set of properties that can be inherited by other cc
2135// modules. A module can use the properties from a cc_defaults using
2136// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2137// merged (when possible) by prepending the default module's values to the
2138// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002139func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002140 return DefaultsFactory()
2141}
2142
Colin Cross36242852017-06-23 15:06:31 -07002143func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002144 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002145
Colin Cross36242852017-06-23 15:06:31 -07002146 module.AddProperties(props...)
2147 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002148 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002149 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002150 &BaseCompilerProperties{},
2151 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002152 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002153 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002154 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002155 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002156 &TestProperties{},
2157 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002158 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002159 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002160 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002161 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002162 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002163 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002164 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002165 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002166 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002167 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002168 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002169 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002170 )
Colin Crosscfad1192015-11-02 16:43:11 -08002171
Colin Cross1f44a3a2017-07-07 14:33:33 -07002172 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09002173 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002174
2175 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002176}
2177
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002178const (
2179 // coreMode is the variant used for framework-private libraries, or
2180 // SDK libraries. (which framework-private libraries can use)
2181 coreMode = "core"
2182
2183 // vendorMode is the variant used for /vendor code that compiles
2184 // against the VNDK.
2185 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09002186
2187 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002188)
2189
Jiyong Park6a43f042017-10-12 23:05:00 +09002190func squashVendorSrcs(m *Module) {
2191 if lib, ok := m.compiler.(*libraryDecorator); ok {
2192 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2193 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2194
2195 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2196 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2197 }
2198}
2199
Jiyong Parkf9332f12018-02-01 00:54:12 +09002200func squashRecoverySrcs(m *Module) {
2201 if lib, ok := m.compiler.(*libraryDecorator); ok {
2202 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2203 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2204
2205 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2206 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2207 }
2208}
2209
Jiyong Parkda6eb592018-12-19 17:12:36 +09002210func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002211 if mctx.Os() != android.Android {
2212 return
2213 }
2214
Jiyong Park7ed9de32018-10-15 22:25:07 +09002215 if g, ok := mctx.Module().(*genrule.Module); ok {
2216 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09002217 var coreVariantNeeded bool = false
2218 var vendorVariantNeeded bool = false
2219 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09002220 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09002221 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002222 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09002223 coreVariantNeeded = true
2224 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09002225 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09002226 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002227 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09002228 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002229 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002230 if Bool(props.Recovery_available) {
2231 recoveryVariantNeeded = true
2232 }
2233
Jiyong Park413cc742018-06-19 01:46:06 +09002234 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002235 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09002236 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09002237 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002238 recoveryVariantNeeded = false
2239 }
2240 }
2241
Jiyong Park3f736c92018-05-24 13:36:56 +09002242 var variants []string
2243 if coreVariantNeeded {
2244 variants = append(variants, coreMode)
2245 }
2246 if vendorVariantNeeded {
2247 variants = append(variants, vendorMode)
2248 }
2249 if recoveryVariantNeeded {
2250 variants = append(variants, recoveryMode)
2251 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002252 mod := mctx.CreateVariations(variants...)
2253 for i, v := range variants {
2254 if v == recoveryMode {
2255 m := mod[i].(*genrule.Module)
2256 m.Extra.(*GenruleExtraProperties).InRecovery = true
2257 }
2258 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002259 }
2260 }
2261
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002262 m, ok := mctx.Module().(*Module)
2263 if !ok {
2264 return
2265 }
2266
2267 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002268 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002269 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002270
2271 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002272 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002273 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002274 return
2275 }
Logan Chienf3511742017-10-31 18:04:35 +08002276
2277 if vndkdep := m.vndkdep; vndkdep != nil {
2278 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002279 if productSpecific {
2280 mctx.PropertyErrorf("product_specific",
2281 "product_specific must not be true when `vndk: {enabled: true}`")
2282 return
2283 }
Logan Chienf3511742017-10-31 18:04:35 +08002284 if vendorSpecific {
2285 if !vndkdep.isVndkExt() {
2286 mctx.PropertyErrorf("vndk",
2287 "must set `extends: \"...\"` to vndk extension")
2288 return
2289 }
2290 } else {
2291 if vndkdep.isVndkExt() {
2292 mctx.PropertyErrorf("vndk",
2293 "must set `vendor: true` to set `extends: %q`",
2294 m.getVndkExtendsModuleName())
2295 return
2296 }
2297 if m.VendorProperties.Vendor_available == nil {
2298 mctx.PropertyErrorf("vndk",
2299 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2300 return
2301 }
2302 }
2303 } else {
2304 if vndkdep.isVndkSp() {
2305 mctx.PropertyErrorf("vndk",
2306 "must set `enabled: true` to set `support_system_process: true`")
2307 return
2308 }
2309 if vndkdep.isVndkExt() {
2310 mctx.PropertyErrorf("vndk",
2311 "must set `enabled: true` to set `extends: %q`",
2312 m.getVndkExtendsModuleName())
2313 return
2314 }
Justin Yun8effde42017-06-23 19:24:43 +09002315 }
2316 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002317
Jiyong Parkf9332f12018-02-01 00:54:12 +09002318 var coreVariantNeeded bool = false
2319 var vendorVariantNeeded bool = false
2320 var recoveryVariantNeeded bool = false
2321
Justin Yun71549282017-11-17 12:10:28 +09002322 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002323 // If the device isn't compiling against the VNDK, we always
2324 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002325 coreVariantNeeded = true
Justin Yun1282f422019-09-09 14:42:44 +09002326 } else if m.Target().NativeBridge == android.NativeBridgeEnabled {
2327 // Skip creating vendor variants for natvie bridge modules
2328 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002329 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2330 // LL-NDK stubs only exist in the vendor variant, since the
2331 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002332 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09002333 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2334 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09002335 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09002336 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002337 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2338 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002339 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002340 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002341 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002342 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002343 coreVariantNeeded = true
2344 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002345 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002346 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09002347 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002348 } else {
2349 // This is either in /system (or similar: /data), or is a
2350 // modules built with the NDK. Modules built with the NDK
2351 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002352 coreVariantNeeded = true
2353 }
2354
2355 if Bool(m.Properties.Recovery_available) {
2356 recoveryVariantNeeded = true
2357 }
2358
2359 if m.ModuleBase.InstallInRecovery() {
2360 recoveryVariantNeeded = true
2361 coreVariantNeeded = false
2362 }
2363
Jiyong Park413cc742018-06-19 01:46:06 +09002364 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002365 primaryArch := mctx.Config().DevicePrimaryArchType()
2366 moduleArch := m.Target().Arch.ArchType
2367 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002368 recoveryVariantNeeded = false
2369 }
2370 }
2371
Jiyong Parkf9332f12018-02-01 00:54:12 +09002372 var variants []string
2373 if coreVariantNeeded {
2374 variants = append(variants, coreMode)
2375 }
2376 if vendorVariantNeeded {
2377 variants = append(variants, vendorMode)
2378 }
2379 if recoveryVariantNeeded {
2380 variants = append(variants, recoveryMode)
2381 }
2382 mod := mctx.CreateVariations(variants...)
2383 for i, v := range variants {
2384 if v == vendorMode {
2385 m := mod[i].(*Module)
2386 m.Properties.UseVndk = true
2387 squashVendorSrcs(m)
2388 } else if v == recoveryMode {
2389 m := mod[i].(*Module)
2390 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002391 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002392 squashRecoverySrcs(m)
2393 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002394 }
2395}
2396
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002397func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002398 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002399 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2400 }
Colin Cross6510f912017-11-29 00:27:14 -08002401 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002402}
2403
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002404func kytheExtractAllFactory() android.Singleton {
2405 return &kytheExtractAllSingleton{}
2406}
2407
2408type kytheExtractAllSingleton struct {
2409}
2410
2411func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2412 var xrefTargets android.Paths
2413 ctx.VisitAllModules(func(module android.Module) {
2414 if ccModule, ok := module.(xref); ok {
2415 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
2416 }
2417 })
2418 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
2419 if len(xrefTargets) > 0 {
2420 ctx.Build(pctx, android.BuildParams{
2421 Rule: blueprint.Phony,
2422 Output: android.PathForPhony(ctx, "xref_cxx"),
2423 Inputs: xrefTargets,
2424 //Default: true,
2425 })
2426 }
2427}
2428
Colin Cross06a931b2015-10-28 17:23:31 -07002429var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002430var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002431var BoolPtr = proptools.BoolPtr
2432var String = proptools.String
2433var StringPtr = proptools.StringPtr