blob: cda37e8c175ab09aa291484e6d660f49dca48466 [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -07001// Copyright 2015 Google Inc. All rights reserved.
Colin Cross3f40fa42015-01-30 17:27:36 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17// This file contains the module types for compiling C/C++ for Android, and converts the properties
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
Colin Cross41955e82019-05-29 14:40:35 -070022 "fmt"
Logan Chien41eabe62019-04-10 13:33:58 +080023 "io"
Dan Albert9e10cd42016-08-03 14:12:14 -070024 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080025 "strings"
26
Colin Cross97ba0732015-03-23 17:50:24 -070027 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070028 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070029
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070031 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070032 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080033)
34
Colin Cross463a90e2015-06-17 14:20:06 -070035func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070036 android.RegisterModuleType("cc_defaults", defaultsFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070037
Colin Cross1e676be2016-10-12 14:38:15 -070038 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Inseob Kim64c43952019-08-26 16:52:35 +090039 ctx.BottomUp("vndk", VndkMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +090040 ctx.BottomUp("image", ImageMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070041 ctx.BottomUp("link", LinkageMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070042 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +010043 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090044 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070045 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimc0907f12019-02-08 21:00:45 +090046 ctx.BottomUp("sysprop", SyspropMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070047 })
Colin Cross16b23492016-01-06 14:41:07 -080048
Colin Cross1e676be2016-10-12 14:38:15 -070049 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
50 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
51 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080052
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070053 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
54 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
55
Mitch Phillipsbfeade62019-05-01 14:42:05 -070056 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
57 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
58
Jiyong Park1d1119f2019-07-29 21:27:18 +090059 // cfi mutator shouldn't run before sanitizers that return true for
60 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000061 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
62 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
63
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080064 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
65 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
66
Colin Cross1e676be2016-10-12 14:38:15 -070067 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
68 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080069
Colin Cross0b908332019-06-19 23:00:20 -070070 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090071 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080072
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080073 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080074 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070075
76 ctx.TopDown("lto_deps", ltoDepsMutator)
77 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090078
79 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070080 })
Colin Crossb98c8b02016-07-29 13:44:28 -070081
Sasha Smundak2a4549e2018-11-05 16:49:08 -080082 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Crossb98c8b02016-07-29 13:44:28 -070083 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070084}
85
Colin Crossca860ac2016-01-04 14:34:37 -080086type Deps struct {
87 SharedLibs, LateSharedLibs []string
88 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080089 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080090 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070091
Colin Cross5950f382016-12-13 12:50:57 -080092 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070093
Colin Cross81413472016-04-11 14:37:39 -070094 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070095
Dan Willemsenb40aab62016-04-20 14:21:14 -070096 GeneratedSources []string
97 GeneratedHeaders []string
98
Dan Willemsenb3454ab2016-09-28 17:34:58 -070099 ReexportGeneratedHeaders []string
100
Colin Cross97ba0732015-03-23 17:50:24 -0700101 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700102
103 // Used for host bionic
104 LinkerFlagsFile string
105 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700106}
107
Colin Crossca860ac2016-01-04 14:34:37 -0800108type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700109 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900110 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700111 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900112 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700113 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700114 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700115
Colin Cross26c34ed2016-09-30 17:10:16 -0700116 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700117 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800118 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700119 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700120
Colin Cross26c34ed2016-09-30 17:10:16 -0700121 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700122 GeneratedSources android.Paths
123 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700124
Inseob Kim69378442019-06-03 19:10:47 +0900125 Flags []string
126 IncludeDirs []string
127 SystemIncludeDirs []string
128 ReexportedDirs []string
129 ReexportedSystemDirs []string
130 ReexportedFlags []string
131 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700132
Colin Cross26c34ed2016-09-30 17:10:16 -0700133 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700134 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700135
136 // Path to the file container flags to use with the linker
137 LinkerFlagsFile android.OptionalPath
138
139 // Path to the dynamic linker binary
140 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700141}
142
Colin Crossca860ac2016-01-04 14:34:37 -0800143type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700144 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
145 ArFlags []string // Flags that apply to ar
146 AsFlags []string // Flags that apply to assembly source files
147 CFlags []string // Flags that apply to C and C++ source files
148 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
149 ConlyFlags []string // Flags that apply to C source files
150 CppFlags []string // Flags that apply to C++ source files
151 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700152 aidlFlags []string // Flags that apply to aidl source files
153 rsFlags []string // Flags that apply to renderscript source files
154 LdFlags []string // Flags that apply to linker command lines
155 libFlags []string // Flags to add libraries early to the link order
Pete Bentley99f2fc22019-08-02 14:02:20 +0100156 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700157 TidyFlags []string // Flags that apply to clang-tidy
158 SAbiFlags []string // Flags that apply to header-abi-dumper
159 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700160
Colin Crossc3199482017-03-30 15:03:04 -0700161 // Global include flags that apply to C, C++, and assembly source files
162 // These must be after any module include flags, which will be in GlobalFlags.
163 SystemIncludeFlags []string
164
Colin Crossb98c8b02016-07-29 13:44:28 -0700165 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700166 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800167 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800168 SAbiDump bool
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800169 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800170
171 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800172 DynamicLinker string
173
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700174 CFlagsDeps android.Paths // Files depended on by compiler flags
175 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800176
Dan Willemsen98ab3112019-08-27 21:20:40 -0700177 AssemblerWithCpp bool
178 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800179
Colin Cross19878da2019-03-28 14:45:07 -0700180 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700181 protoC bool // Whether to use C instead of C++
182 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700183
184 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700185}
186
Colin Crossca860ac2016-01-04 14:34:37 -0800187// Properties used to compile all C or C++ modules
188type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700189 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800190 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700191
192 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800193 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700194
Jiyong Parkde866cb2018-12-07 23:08:36 +0900195 AndroidMkSharedLibs []string `blueprint:"mutated"`
196 AndroidMkStaticLibs []string `blueprint:"mutated"`
197 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
198 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
199 HideFromMake bool `blueprint:"mutated"`
200 PreventInstall bool `blueprint:"mutated"`
201 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700202
Inseob Kim64c43952019-08-26 16:52:35 +0900203 VndkVersion string `blueprint:"mutated"`
204 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800205
206 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
207 // file
208 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900209
210 // Make this module available when building for recovery
211 Recovery_available *bool
212
213 InRecovery bool `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900214
215 // Allows this module to use non-APEX version of libraries. Useful
216 // for building binaries that are started before APEXes are activated.
217 Bootstrap *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700218}
219
220type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900221 // whether this module should be allowed to be directly depended by other
222 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
223 // If set to true, two variants will be built separately, one like
224 // normal, and the other limited to the set of libraries and headers
225 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700226 //
227 // The vendor variant may be used with a different (newer) /system,
228 // so it shouldn't have any unversioned runtime dependencies, or
229 // make assumptions about the system that may not be true in the
230 // future.
231 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900232 // If set to false, this module becomes inaccessible from /vendor modules.
233 //
234 // Default value is true when vndk: {enabled: true} or vendor: true.
235 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700236 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
237 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900238
239 // whether this module is capable of being loaded with other instance
240 // (possibly an older version) of the same module in the same process.
241 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
242 // can be double loaded in a vendor process if the library is also a
243 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
244 // explicitly marked as `double_loadable: true` by the owner, or the dependency
245 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
246 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800247}
248
Colin Crossca860ac2016-01-04 14:34:37 -0800249type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800250 static() bool
251 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900252 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700253 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700254 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800255 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700256 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800257 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900258 isLlndk(config android.Config) bool
259 isLlndkPublic(config android.Config) bool
260 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900261 isVndk() bool
262 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800263 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900264 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800265 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700266 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700267 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800268 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800269 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800270 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800271 useClangLld(actx ModuleContext) bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900272 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900273 hasStubsVariants() bool
274 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900275 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800276 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700277 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800278}
279
280type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700281 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800282 ModuleContextIntf
283}
284
285type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700286 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800287 ModuleContextIntf
288}
289
Colin Cross37047f12016-12-13 17:06:13 -0800290type DepsContext interface {
291 android.BottomUpMutatorContext
292 ModuleContextIntf
293}
294
Colin Crossca860ac2016-01-04 14:34:37 -0800295type feature interface {
296 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800297 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800298 flags(ctx ModuleContext, flags Flags) Flags
299 props() []interface{}
300}
301
302type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700303 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800304 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800305 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700306 compilerProps() []interface{}
307
Colin Cross76fada02016-07-27 10:31:13 -0700308 appendCflags([]string)
309 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700310 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800311}
312
313type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700314 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800315 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700316 linkerFlags(ctx ModuleContext, flags Flags) Flags
317 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800318 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700319
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700320 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700321 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900322 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700323
324 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900325 coverageOutputFilePath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800326}
327
328type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700329 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700330 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800331 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700332 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700333 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900334 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800335}
336
Colin Crossc99deeb2016-04-11 15:06:20 -0700337type dependencyTag struct {
338 blueprint.BaseDependencyTag
339 name string
340 library bool
Roland Levillainf89cd092019-07-29 16:22:59 +0100341 shared bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700342
343 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900344
345 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700346}
347
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800348type xref interface {
349 XrefCcFiles() android.Paths
350}
351
Colin Crossc99deeb2016-04-11 15:06:20 -0700352var (
Roland Levillainf89cd092019-07-29 16:22:59 +0100353 sharedDepTag = dependencyTag{name: "shared", library: true, shared: true}
354 sharedExportDepTag = dependencyTag{name: "shared", library: true, shared: true, reexportFlags: true}
355 earlySharedDepTag = dependencyTag{name: "early_shared", library: true, shared: true}
356 lateSharedDepTag = dependencyTag{name: "late shared", library: true, shared: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700357 staticDepTag = dependencyTag{name: "static", library: true}
358 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
359 lateStaticDepTag = dependencyTag{name: "late static", library: true}
360 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800361 headerDepTag = dependencyTag{name: "header", library: true}
362 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700363 genSourceDepTag = dependencyTag{name: "gen source"}
364 genHeaderDepTag = dependencyTag{name: "gen header"}
365 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
366 objDepTag = dependencyTag{name: "obj"}
367 crtBeginDepTag = dependencyTag{name: "crtbegin"}
368 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700369 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
370 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700371 reuseObjTag = dependencyTag{name: "reuse objects"}
Jiyong Parke4bb9862019-02-01 00:31:10 +0900372 staticVariantTag = dependencyTag{name: "static variant"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700373 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
374 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800375 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800376 runtimeDepTag = dependencyTag{name: "runtime lib"}
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -0700377 coverageDepTag = dependencyTag{name: "coverage"}
Roland Levillainf2fad972019-06-28 15:41:19 +0100378 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700379)
380
Roland Levillainf89cd092019-07-29 16:22:59 +0100381func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
382 ccDepTag, ok := depTag.(dependencyTag)
383 return ok && ccDepTag.shared
384}
385
386func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
387 ccDepTag, ok := depTag.(dependencyTag)
388 return ok && ccDepTag == runtimeDepTag
389}
390
391func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
392 ccDepTag, ok := depTag.(dependencyTag)
393 return ok && ccDepTag == testPerSrcDepTag
394}
395
Ivan Lozanoffee3342019-08-27 12:03:00 -0700396func SharedDepTag() dependencyTag {
397 return sharedDepTag
398}
399
400func StaticDepTag() dependencyTag {
401 return staticDepTag
402}
403
Colin Crossca860ac2016-01-04 14:34:37 -0800404// Module contains the properties and members used by all C/C++ module types, and implements
405// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
406// to construct the output file. Behavior can be customized with a Customizer interface
407type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700408 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700409 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900410 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700411
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700412 Properties BaseProperties
413 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700414
Colin Crossca860ac2016-01-04 14:34:37 -0800415 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700416 hod android.HostOrDeviceSupported
417 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700418
Colin Crossca860ac2016-01-04 14:34:37 -0800419 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700420 features []feature
421 compiler compiler
422 linker linker
423 installer installer
424 stl *stl
425 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800426 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800427 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900428 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700429 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700430 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800431 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800432
433 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700434
Colin Cross635c3b02016-05-18 15:37:25 -0700435 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800436
Colin Crossb98c8b02016-07-29 13:44:28 -0700437 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700438
439 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800440
441 // Flags used to compile this module
442 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700443
444 // 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 -0800445 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700446 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800447 depsInLinkOrder android.Paths
448
449 // only non-nil when this is a shared library that reuses the objects of a static library
450 staticVariant *Module
Inseob Kim9516ee92019-05-09 10:56:13 +0900451
452 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800453 // Kythe (source file indexer) paths for this compilation module
454 kytheFiles android.Paths
Colin Crossc472d572015-03-17 15:06:21 -0700455}
456
Jiyong Parkc20eee32018-09-05 22:36:17 +0900457func (c *Module) OutputFile() android.OptionalPath {
458 return c.outputFile
459}
460
Jiyong Park719b4462019-01-13 00:39:51 +0900461func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900462 if c.linker != nil {
463 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900464 }
465 return nil
466}
467
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900468func (c *Module) CoverageOutputFile() android.OptionalPath {
469 if c.linker != nil {
470 return c.linker.coverageOutputFilePath()
471 }
472 return android.OptionalPath{}
473}
474
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900475func (c *Module) RelativeInstallPath() string {
476 if c.installer != nil {
477 return c.installer.relativeInstallPath()
478 }
479 return ""
480}
481
Jooyung Han344d5432019-08-23 11:17:39 +0900482// IsVndkOnSystem returns true if a module is supposed to be a vndk library provided by system to vendor
483func (c *Module) IsVndkOnSystem() bool {
484 if linker, ok := c.linker.(libraryInterface); ok {
485 return linker.shared() && c.isVndk() && c.useVndk() && !c.isVndkExt()
486 }
487
488 return false
489}
490
491func (c *Module) VndkVersion() string {
492 return c.vndkVersion()
493}
494
Colin Cross36242852017-06-23 15:06:31 -0700495func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700496 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800497 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700498 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800499 }
500 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700501 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800502 }
503 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700504 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800505 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700506 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700507 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700508 }
Colin Cross16b23492016-01-06 14:41:07 -0800509 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700510 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800511 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800512 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700513 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800514 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800515 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700516 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800517 }
Justin Yun8effde42017-06-23 19:24:43 +0900518 if c.vndkdep != nil {
519 c.AddProperties(c.vndkdep.props()...)
520 }
Stephen Craneba090d12017-05-09 15:44:35 -0700521 if c.lto != nil {
522 c.AddProperties(c.lto.props()...)
523 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700524 if c.pgo != nil {
525 c.AddProperties(c.pgo.props()...)
526 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800527 if c.xom != nil {
528 c.AddProperties(c.xom.props()...)
529 }
Colin Crossca860ac2016-01-04 14:34:37 -0800530 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700531 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800532 }
Colin Crossc472d572015-03-17 15:06:21 -0700533
Colin Crossa9d8bee2018-10-02 13:59:46 -0700534 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
535 switch class {
536 case android.Device:
537 return ctx.Config().DevicePrefer32BitExecutables()
538 case android.HostCross:
539 // Windows builds always prefer 32-bit
540 return true
541 default:
542 return false
543 }
544 })
Colin Cross36242852017-06-23 15:06:31 -0700545 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700546
Colin Cross1f44a3a2017-07-07 14:33:33 -0700547 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700548
Jiyong Park9d452992018-10-03 00:38:19 +0900549 android.InitApexModule(c)
550
Colin Cross36242852017-06-23 15:06:31 -0700551 return c
Colin Crossc472d572015-03-17 15:06:21 -0700552}
553
Colin Crossb916a382016-07-29 17:28:03 -0700554// Returns true for dependency roots (binaries)
555// TODO(ccross): also handle dlopenable libraries
556func (c *Module) isDependencyRoot() bool {
557 if root, ok := c.linker.(interface {
558 isDependencyRoot() bool
559 }); ok {
560 return root.isDependencyRoot()
561 }
562 return false
563}
564
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700565func (c *Module) useVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900566 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700567}
568
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800569func (c *Module) isCoverageVariant() bool {
570 return c.coverage.Properties.IsCoverageVariant
571}
572
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800573func (c *Module) isNdk() bool {
574 return inList(c.Name(), ndkMigratedLibs)
575}
576
Inseob Kim9516ee92019-05-09 10:56:13 +0900577func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800578 // Returns true for both LLNDK (public) and LLNDK-private libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900579 return inList(c.Name(), *llndkLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800580}
581
Inseob Kim9516ee92019-05-09 10:56:13 +0900582func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800583 // Returns true only for LLNDK (public) libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900584 return c.isLlndk(config) && !c.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800585}
586
Inseob Kim9516ee92019-05-09 10:56:13 +0900587func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800588 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Inseob Kim9516ee92019-05-09 10:56:13 +0900589 return inList(c.Name(), *vndkPrivateLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800590}
591
Justin Yun8effde42017-06-23 19:24:43 +0900592func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800593 if vndkdep := c.vndkdep; vndkdep != nil {
594 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900595 }
596 return false
597}
598
Jooyung Han76106d92019-05-20 18:49:10 +0900599func (c *Module) vndkVersion() string {
Inseob Kim64c43952019-08-26 16:52:35 +0900600 return c.Properties.VndkVersion
Jooyung Han76106d92019-05-20 18:49:10 +0900601}
602
Yi Kong7e53c572018-02-14 18:16:12 +0800603func (c *Module) isPgoCompile() bool {
604 if pgo := c.pgo; pgo != nil {
605 return pgo.Properties.PgoCompile
606 }
607 return false
608}
609
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800610func (c *Module) isNDKStubLibrary() bool {
611 if _, ok := c.compiler.(*stubDecorator); ok {
612 return true
613 }
614 return false
615}
616
Logan Chienf3511742017-10-31 18:04:35 +0800617func (c *Module) isVndkSp() bool {
618 if vndkdep := c.vndkdep; vndkdep != nil {
619 return vndkdep.isVndkSp()
620 }
621 return false
622}
623
624func (c *Module) isVndkExt() bool {
625 if vndkdep := c.vndkdep; vndkdep != nil {
626 return vndkdep.isVndkExt()
627 }
628 return false
629}
630
Vic Yangefd249e2018-11-12 20:19:56 -0800631func (c *Module) mustUseVendorVariant() bool {
632 return c.isVndkSp() || inList(c.Name(), config.VndkMustUseVendorVariantList)
633}
634
Logan Chienf3511742017-10-31 18:04:35 +0800635func (c *Module) getVndkExtendsModuleName() string {
636 if vndkdep := c.vndkdep; vndkdep != nil {
637 return vndkdep.getVndkExtendsModuleName()
638 }
639 return ""
640}
641
Jiyong Park82e2bf32017-08-16 14:05:54 +0900642// Returns true only when this module is configured to have core and vendor
643// variants.
644func (c *Module) hasVendorVariant() bool {
645 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
646}
647
Jiyong Parkf9332f12018-02-01 00:54:12 +0900648func (c *Module) inRecovery() bool {
649 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
650}
651
652func (c *Module) onlyInRecovery() bool {
653 return c.ModuleBase.InstallInRecovery()
654}
655
Jiyong Park25fc6a92018-11-18 18:02:45 +0900656func (c *Module) IsStubs() bool {
657 if library, ok := c.linker.(*libraryDecorator); ok {
658 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900659 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
660 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900661 }
662 return false
663}
664
665func (c *Module) HasStubsVariants() bool {
666 if library, ok := c.linker.(*libraryDecorator); ok {
667 return len(library.Properties.Stubs.Versions) > 0
668 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700669 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
670 return len(library.Properties.Stubs.Versions) > 0
671 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900672 return false
673}
674
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900675func (c *Module) bootstrap() bool {
676 return Bool(c.Properties.Bootstrap)
677}
678
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700679func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700680 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
681 if c.Target().NativeBridge == android.NativeBridgeEnabled {
682 return false
683 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700684 return c.linker != nil && c.linker.nativeCoverage()
685}
686
Jiyong Parkf1194352019-02-25 11:05:47 +0900687func isBionic(name string) bool {
688 switch name {
689 case "libc", "libm", "libdl", "linker":
690 return true
691 }
692 return false
693}
694
Martin Stjernholm279de572019-09-10 23:18:20 +0100695func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700696 if name == "libclang_rt.hwasan-aarch64-android" {
697 return inList("hwaddress", config.SanitizeDevice())
698 }
699 return isBionic(name)
700}
701
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800702func (c *Module) XrefCcFiles() android.Paths {
703 return c.kytheFiles
704}
705
Colin Crossca860ac2016-01-04 14:34:37 -0800706type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700707 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800708 moduleContextImpl
709}
710
Colin Cross37047f12016-12-13 17:06:13 -0800711type depsContext struct {
712 android.BottomUpMutatorContext
713 moduleContextImpl
714}
715
Colin Crossca860ac2016-01-04 14:34:37 -0800716type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700717 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800718 moduleContextImpl
719}
720
Jiyong Park2db76922017-11-08 16:03:48 +0900721func (ctx *moduleContext) SocSpecific() bool {
722 return ctx.ModuleContext.SocSpecific() ||
723 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700724}
725
Colin Crossca860ac2016-01-04 14:34:37 -0800726type moduleContextImpl struct {
727 mod *Module
728 ctx BaseModuleContext
729}
730
Colin Crossb98c8b02016-07-29 13:44:28 -0700731func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800732 return ctx.mod.toolchain(ctx.ctx)
733}
734
735func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000736 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800737}
738
739func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900740 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800741}
742
Jiyong Park1d1119f2019-07-29 21:27:18 +0900743func (ctx *moduleContextImpl) header() bool {
744 return ctx.mod.header()
745}
746
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700747func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800748 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800749 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700750 }
751 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800752}
753
754func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700755 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700756 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900757 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700758 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900759 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
760 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
761 return "current"
762 }
763 return platform_vndk_ver
764 }
765 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800766 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900767 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700768 }
769 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800770}
771
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700772func (ctx *moduleContextImpl) useVndk() bool {
773 return ctx.mod.useVndk()
774}
Justin Yun8effde42017-06-23 19:24:43 +0900775
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800776func (ctx *moduleContextImpl) isNdk() bool {
777 return ctx.mod.isNdk()
778}
779
Inseob Kim9516ee92019-05-09 10:56:13 +0900780func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
781 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800782}
783
Inseob Kim9516ee92019-05-09 10:56:13 +0900784func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
785 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800786}
787
Inseob Kim9516ee92019-05-09 10:56:13 +0900788func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
789 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800790}
791
Logan Chienf3511742017-10-31 18:04:35 +0800792func (ctx *moduleContextImpl) isVndk() bool {
793 return ctx.mod.isVndk()
794}
795
Yi Kong7e53c572018-02-14 18:16:12 +0800796func (ctx *moduleContextImpl) isPgoCompile() bool {
797 return ctx.mod.isPgoCompile()
798}
799
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800800func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
801 return ctx.mod.isNDKStubLibrary()
802}
803
Justin Yun8effde42017-06-23 19:24:43 +0900804func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800805 return ctx.mod.isVndkSp()
806}
807
808func (ctx *moduleContextImpl) isVndkExt() bool {
809 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900810}
811
Vic Yangefd249e2018-11-12 20:19:56 -0800812func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
813 return ctx.mod.mustUseVendorVariant()
814}
815
Jiyong Parkf9332f12018-02-01 00:54:12 +0900816func (ctx *moduleContextImpl) inRecovery() bool {
817 return ctx.mod.inRecovery()
818}
819
Logan Chien2f2b8902018-07-10 15:01:19 +0800820// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800821func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +0800822 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
823 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800824 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800825
826 if ctx.ctx.Fuchsia() {
827 return false
828 }
829
Logan Chien2f2b8902018-07-10 15:01:19 +0800830 if sanitize := ctx.mod.sanitize; sanitize != nil {
831 if !sanitize.isVariantOnProductionDevice() {
832 return false
833 }
834 }
835 if !ctx.ctx.Device() {
836 // Host modules do not need ABI dumps.
837 return false
838 }
Logan Chienfa478c02018-12-28 16:25:39 +0800839 if !ctx.mod.IsForPlatform() {
840 // APEX variants do not need ABI dumps.
841 return false
842 }
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +0800843 if ctx.isStubs() {
844 // Stubs do not need ABI dumps.
845 return false
846 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800847 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800848}
849
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700850func (ctx *moduleContextImpl) selectedStl() string {
851 if stl := ctx.mod.stl; stl != nil {
852 return stl.Properties.SelectedStl
853 }
854 return ""
855}
856
Ivan Lozanobd721262018-11-27 14:33:03 -0800857func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
858 return ctx.mod.linker.useClangLld(actx)
859}
860
Colin Crossce75d2c2016-10-06 16:12:58 -0700861func (ctx *moduleContextImpl) baseModuleName() string {
862 return ctx.mod.ModuleBase.BaseModuleName()
863}
864
Logan Chienf3511742017-10-31 18:04:35 +0800865func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
866 return ctx.mod.getVndkExtendsModuleName()
867}
868
Jiyong Park58e364a2019-01-19 19:24:06 +0900869func (ctx *moduleContextImpl) apexName() string {
870 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900871}
872
Jiyong Parkb0788572018-12-20 22:10:17 +0900873func (ctx *moduleContextImpl) hasStubsVariants() bool {
874 return ctx.mod.HasStubsVariants()
875}
876
877func (ctx *moduleContextImpl) isStubs() bool {
878 return ctx.mod.IsStubs()
879}
880
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900881func (ctx *moduleContextImpl) bootstrap() bool {
882 return ctx.mod.bootstrap()
883}
884
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700885func (ctx *moduleContextImpl) nativeCoverage() bool {
886 return ctx.mod.nativeCoverage()
887}
888
Colin Cross635c3b02016-05-18 15:37:25 -0700889func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800890 return &Module{
891 hod: hod,
892 multilib: multilib,
893 }
894}
895
Colin Cross635c3b02016-05-18 15:37:25 -0700896func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800897 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700898 module.features = []feature{
899 &tidyFeature{},
900 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700901 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800902 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800903 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800904 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900905 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700906 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700907 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800908 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800909 return module
910}
911
Colin Crossce75d2c2016-10-06 16:12:58 -0700912func (c *Module) Prebuilt() *android.Prebuilt {
913 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
914 return p.prebuilt()
915 }
916 return nil
917}
918
919func (c *Module) Name() string {
920 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700921 if p, ok := c.linker.(interface {
922 Name(string) string
923 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700924 name = p.Name(name)
925 }
926 return name
927}
928
Alex Light3d673592019-01-18 14:37:31 -0800929func (c *Module) Symlinks() []string {
930 if p, ok := c.installer.(interface {
931 symlinkList() []string
932 }); ok {
933 return p.symlinkList()
934 }
935 return nil
936}
937
Jeff Gaston294356f2017-09-27 17:05:30 -0700938// orderDeps reorders dependencies into a list such that if module A depends on B, then
939// A will precede B in the resultant list.
940// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800941// Note that directSharedDeps should be the analogous static library for each shared lib dep
942func 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 -0700943 // If A depends on B, then
944 // Every list containing A will also contain B later in the list
945 // So, after concatenating all lists, the final instance of B will have come from the same
946 // original list as the final instance of A
947 // So, the final instance of B will be later in the concatenation than the final A
948 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
949 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800950 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700951 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800952 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
953 }
954 for _, dep := range directSharedDeps {
955 orderedAllDeps = append(orderedAllDeps, dep)
956 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700957 }
958
Colin Crossb6715442017-10-24 11:13:31 -0700959 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700960
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800961 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700962 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800963 // resultant list to only what the caller has chosen to include in directStaticDeps
964 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700965
966 return orderedAllDeps, orderedDeclaredDeps
967}
968
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800969func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
970 // convert Module to Path
971 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
972 staticDepFiles := []android.Path{}
973 for _, dep := range staticDeps {
974 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
975 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700976 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800977 sharedDepFiles := []android.Path{}
978 for _, sharedDep := range sharedDeps {
979 staticAnalogue := sharedDep.staticVariant
980 if staticAnalogue != nil {
981 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
982 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
983 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700984 }
985
986 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800987 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700988
989 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700990}
991
Roland Levillainf89cd092019-07-29 16:22:59 +0100992func (c *Module) IsTestPerSrcAllTestsVariation() bool {
993 test, ok := c.linker.(testPerSrc)
994 return ok && test.isAllTestsVariation()
995}
996
Colin Cross635c3b02016-05-18 15:37:25 -0700997func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +0100998 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +0100999 //
1000 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1001 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1002 // module and return early, as this module does not produce an output file per se.
1003 if c.IsTestPerSrcAllTestsVariation() {
1004 c.outputFile = android.OptionalPath{}
1005 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001006 }
1007
Jooyung Han38002912019-05-16 04:01:54 +09001008 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001009
Inseob Kim64c43952019-08-26 16:52:35 +09001010 c.Properties.SubName = ""
1011
1012 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1013 c.Properties.SubName += nativeBridgeSuffix
1014 }
1015
1016 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
1017 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1018 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1019 c.Properties.SubName += vendorSuffix
1020 } else if _, ok := c.linker.(*llndkStubDecorator); ok || (c.useVndk() && c.hasVendorVariant()) {
1021 // .vendor.{version} suffix is added only when we will have two variants: core and vendor.
1022 // The suffix is not added for vendor-only module.
1023 c.Properties.SubName += vendorSuffix
1024 vendorVersion := actx.DeviceConfig().VndkVersion()
1025 if vendorVersion == "current" {
1026 vendorVersion = actx.DeviceConfig().PlatformVndkVersion()
1027 }
1028 if c.Properties.VndkVersion != vendorVersion {
1029 c.Properties.SubName += "." + c.Properties.VndkVersion
1030 }
1031 } else if c.inRecovery() && !c.onlyInRecovery() {
1032 c.Properties.SubName += recoverySuffix
1033 }
1034
Colin Crossca860ac2016-01-04 14:34:37 -08001035 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001036 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001037 moduleContextImpl: moduleContextImpl{
1038 mod: c,
1039 },
1040 }
1041 ctx.ctx = ctx
1042
Colin Crossf18e1102017-11-16 14:33:08 -08001043 deps := c.depsToPaths(ctx)
1044 if ctx.Failed() {
1045 return
1046 }
1047
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001048 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1049 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1050 }
1051
Colin Crossca860ac2016-01-04 14:34:37 -08001052 flags := Flags{
1053 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001054 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001055 }
Colin Crossca860ac2016-01-04 14:34:37 -08001056 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001057 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001058 }
1059 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001060 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001061 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001062 if c.stl != nil {
1063 flags = c.stl.flags(ctx, flags)
1064 }
Colin Cross16b23492016-01-06 14:41:07 -08001065 if c.sanitize != nil {
1066 flags = c.sanitize.flags(ctx, flags)
1067 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001068 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001069 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001070 }
Stephen Craneba090d12017-05-09 15:44:35 -07001071 if c.lto != nil {
1072 flags = c.lto.flags(ctx, flags)
1073 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001074 if c.pgo != nil {
1075 flags = c.pgo.flags(ctx, flags)
1076 }
Ivan Lozano074ec482018-11-21 08:59:37 -08001077 if c.xom != nil {
1078 flags = c.xom.flags(ctx, flags)
1079 }
Colin Crossca860ac2016-01-04 14:34:37 -08001080 for _, feature := range c.features {
1081 flags = feature.flags(ctx, flags)
1082 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001083 if ctx.Failed() {
1084 return
1085 }
1086
Colin Crossb98c8b02016-07-29 13:44:28 -07001087 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
1088 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
1089 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001090
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001091 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001092
1093 for _, dir := range deps.IncludeDirs {
1094 flags.GlobalFlags = append(flags.GlobalFlags, "-I"+dir)
1095 }
1096 for _, dir := range deps.SystemIncludeDirs {
1097 flags.GlobalFlags = append(flags.GlobalFlags, "-isystem "+dir)
1098 }
1099
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001100 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001101 // We need access to all the flags seen by a source file.
1102 if c.sabi != nil {
1103 flags = c.sabi.flags(ctx, flags)
1104 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001105
1106 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.AsFlags)
1107
Colin Crossca860ac2016-01-04 14:34:37 -08001108 // Optimization to reduce size of build.ninja
1109 // Replace the long list of flags for each file with a module-local variable
1110 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
1111 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
1112 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
1113 flags.CFlags = []string{"$cflags"}
1114 flags.CppFlags = []string{"$cppflags"}
1115 flags.AsFlags = []string{"$asflags"}
1116
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001117 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001118 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001119 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001120 if ctx.Failed() {
1121 return
1122 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001123 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001124 }
1125
Colin Crossca860ac2016-01-04 14:34:37 -08001126 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001127 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001128 if ctx.Failed() {
1129 return
1130 }
Colin Cross635c3b02016-05-18 15:37:25 -07001131 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001132
1133 // If a lib is directly included in any of the APEXes, unhide the stubs
1134 // variant having the latest version gets visible to make. In addition,
1135 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1136 // force anything in the make world to link against the stubs library.
1137 // (unless it is explicitly referenced via .bootstrap suffix or the
1138 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001139 if c.HasStubsVariants() &&
1140 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001141 !c.inRecovery() && !c.useVndk() && !c.static() && !c.isCoverageVariant() &&
1142 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001143 c.Properties.HideFromMake = false // unhide
1144 // Note: this is still non-installable
1145 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001146 }
Colin Cross5049f022015-03-18 13:28:46 -07001147
Inseob Kim1f086e22019-05-09 13:29:15 +09001148 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001149 c.installer.install(ctx, c.outputFile.Path())
1150 if ctx.Failed() {
1151 return
Colin Crossca860ac2016-01-04 14:34:37 -08001152 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001153 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001154}
1155
Colin Cross0ea8ba82019-06-06 14:33:29 -07001156func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001157 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001158 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001159 }
Colin Crossca860ac2016-01-04 14:34:37 -08001160 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001161}
1162
Colin Crossca860ac2016-01-04 14:34:37 -08001163func (c *Module) begin(ctx BaseModuleContext) {
1164 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001165 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001166 }
Colin Crossca860ac2016-01-04 14:34:37 -08001167 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001168 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001169 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001170 if c.stl != nil {
1171 c.stl.begin(ctx)
1172 }
Colin Cross16b23492016-01-06 14:41:07 -08001173 if c.sanitize != nil {
1174 c.sanitize.begin(ctx)
1175 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001176 if c.coverage != nil {
1177 c.coverage.begin(ctx)
1178 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001179 if c.sabi != nil {
1180 c.sabi.begin(ctx)
1181 }
Justin Yun8effde42017-06-23 19:24:43 +09001182 if c.vndkdep != nil {
1183 c.vndkdep.begin(ctx)
1184 }
Stephen Craneba090d12017-05-09 15:44:35 -07001185 if c.lto != nil {
1186 c.lto.begin(ctx)
1187 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001188 if c.pgo != nil {
1189 c.pgo.begin(ctx)
1190 }
Colin Crossca860ac2016-01-04 14:34:37 -08001191 for _, feature := range c.features {
1192 feature.begin(ctx)
1193 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001194 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001195 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001196 if err != nil {
1197 ctx.PropertyErrorf("sdk_version", err.Error())
1198 }
Nan Zhang0007d812017-11-07 10:57:05 -08001199 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001200 }
Colin Crossca860ac2016-01-04 14:34:37 -08001201}
1202
Colin Cross37047f12016-12-13 17:06:13 -08001203func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001204 deps := Deps{}
1205
1206 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001207 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001208 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001209 // Add the PGO dependency (the clang_rt.profile runtime library), which
1210 // sometimes depends on symbols from libgcc, before libgcc gets added
1211 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001212 if c.pgo != nil {
1213 deps = c.pgo.deps(ctx, deps)
1214 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001215 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001216 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001217 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001218 if c.stl != nil {
1219 deps = c.stl.deps(ctx, deps)
1220 }
Colin Cross16b23492016-01-06 14:41:07 -08001221 if c.sanitize != nil {
1222 deps = c.sanitize.deps(ctx, deps)
1223 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001224 if c.coverage != nil {
1225 deps = c.coverage.deps(ctx, deps)
1226 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001227 if c.sabi != nil {
1228 deps = c.sabi.deps(ctx, deps)
1229 }
Justin Yun8effde42017-06-23 19:24:43 +09001230 if c.vndkdep != nil {
1231 deps = c.vndkdep.deps(ctx, deps)
1232 }
Stephen Craneba090d12017-05-09 15:44:35 -07001233 if c.lto != nil {
1234 deps = c.lto.deps(ctx, deps)
1235 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001236 for _, feature := range c.features {
1237 deps = feature.deps(ctx, deps)
1238 }
1239
Colin Crossb6715442017-10-24 11:13:31 -07001240 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1241 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1242 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1243 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1244 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1245 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001246 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001247
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001248 for _, lib := range deps.ReexportSharedLibHeaders {
1249 if !inList(lib, deps.SharedLibs) {
1250 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1251 }
1252 }
1253
1254 for _, lib := range deps.ReexportStaticLibHeaders {
1255 if !inList(lib, deps.StaticLibs) {
1256 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1257 }
1258 }
1259
Colin Cross5950f382016-12-13 12:50:57 -08001260 for _, lib := range deps.ReexportHeaderLibHeaders {
1261 if !inList(lib, deps.HeaderLibs) {
1262 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1263 }
1264 }
1265
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001266 for _, gen := range deps.ReexportGeneratedHeaders {
1267 if !inList(gen, deps.GeneratedHeaders) {
1268 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1269 }
1270 }
1271
Colin Crossc99deeb2016-04-11 15:06:20 -07001272 return deps
1273}
1274
Dan Albert7e9d2952016-08-04 13:02:36 -07001275func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001276 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001277 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001278 moduleContextImpl: moduleContextImpl{
1279 mod: c,
1280 },
1281 }
1282 ctx.ctx = ctx
1283
Colin Crossca860ac2016-01-04 14:34:37 -08001284 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001285}
1286
Jiyong Park7ed9de32018-10-15 22:25:07 +09001287// Split name#version into name and version
1288func stubsLibNameAndVersion(name string) (string, string) {
1289 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1290 version := name[sharp+1:]
1291 libname := name[:sharp]
1292 return libname, version
1293 }
1294 return name, ""
1295}
1296
Colin Cross1e676be2016-10-12 14:38:15 -07001297func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001298 ctx := &depsContext{
1299 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001300 moduleContextImpl: moduleContextImpl{
1301 mod: c,
1302 },
1303 }
1304 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001305
Colin Crossc99deeb2016-04-11 15:06:20 -07001306 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001307
Dan Albert914449f2016-06-17 16:45:24 -07001308 variantNdkLibs := []string{}
1309 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001310 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001311 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001312
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001313 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1314 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001315 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001316 // 1. Name of an NDK library that refers to a prebuilt module.
1317 // For each of these, it adds the name of the prebuilt module (which will be in
1318 // prebuilts/ndk) to the list of nonvariant libs.
1319 // 2. Name of an NDK library that refers to an ndk_library module.
1320 // For each of these, it adds the name of the ndk_library module to the list of
1321 // variant libs.
1322 // 3. Anything else (so anything that isn't an NDK library).
1323 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001324 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001325 // The caller can then know to add the variantLibs dependencies differently from the
1326 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001327
1328 llndkLibraries := llndkLibraries(actx.Config())
1329 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001330 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1331 variantLibs = []string{}
1332 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001333 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001334 // strip #version suffix out
1335 name, _ := stubsLibNameAndVersion(entry)
1336 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1337 if !inList(name, ndkMigratedLibs) {
1338 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001339 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001340 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001341 }
Inseob Kim9516ee92019-05-09 10:56:13 +09001342 } else if ctx.useVndk() && inList(name, *llndkLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001343 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001344 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001345 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001346 if actx.OtherModuleExists(vendorPublicLib) {
1347 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1348 } else {
1349 // This can happen if vendor_public_library module is defined in a
1350 // namespace that isn't visible to the current module. In that case,
1351 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001352 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001353 }
Dan Albert914449f2016-06-17 16:45:24 -07001354 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001355 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001356 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001357 }
1358 }
Dan Albert914449f2016-06-17 16:45:24 -07001359 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001360 }
1361
Dan Albert914449f2016-06-17 16:45:24 -07001362 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1363 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001364 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001365 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001366
Jiyong Park7e636d02019-01-28 16:16:54 +09001367 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001368 if c.linker != nil {
1369 if library, ok := c.linker.(*libraryDecorator); ok {
1370 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001371 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001372 }
1373 }
1374 }
1375
Colin Cross32ec36c2016-12-15 07:39:51 -08001376 for _, lib := range deps.HeaderLibs {
1377 depTag := headerDepTag
1378 if inList(lib, deps.ReexportHeaderLibHeaders) {
1379 depTag = headerExportDepTag
1380 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001381 if buildStubs {
Jiyong Park7e636d02019-01-28 16:16:54 +09001382 actx.AddFarVariationDependencies([]blueprint.Variation{
1383 {Mutator: "arch", Variation: ctx.Target().String()},
Jiyong Park3b1746a2019-01-29 11:15:04 +09001384 {Mutator: "image", Variation: c.imageVariation()},
Jiyong Park7e636d02019-01-28 16:16:54 +09001385 }, depTag, lib)
1386 } else {
1387 actx.AddVariationDependencies(nil, depTag, lib)
1388 }
1389 }
1390
1391 if buildStubs {
1392 // Stubs lib does not have dependency to other static/shared libraries.
1393 // Don't proceed.
1394 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001395 }
Colin Cross5950f382016-12-13 12:50:57 -08001396
Inseob Kimc0907f12019-02-08 21:00:45 +09001397 syspropImplLibraries := syspropImplLibraries(actx.Config())
1398
Jiyong Park5d1598f2019-02-25 22:14:17 +09001399 for _, lib := range deps.WholeStaticLibs {
1400 depTag := wholeStaticDepTag
1401 if impl, ok := syspropImplLibraries[lib]; ok {
1402 lib = impl
1403 }
1404 actx.AddVariationDependencies([]blueprint.Variation{
1405 {Mutator: "link", Variation: "static"},
1406 }, depTag, lib)
1407 }
1408
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001409 for _, lib := range deps.StaticLibs {
1410 depTag := staticDepTag
1411 if inList(lib, deps.ReexportStaticLibHeaders) {
1412 depTag = staticExportDepTag
1413 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001414
1415 if impl, ok := syspropImplLibraries[lib]; ok {
1416 lib = impl
1417 }
1418
Dan Willemsen59339a22018-07-22 21:18:45 -07001419 actx.AddVariationDependencies([]blueprint.Variation{
1420 {Mutator: "link", Variation: "static"},
1421 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001422 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001423
Dan Willemsen59339a22018-07-22 21:18:45 -07001424 actx.AddVariationDependencies([]blueprint.Variation{
1425 {Mutator: "link", Variation: "static"},
1426 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001427
Jiyong Park25fc6a92018-11-18 18:02:45 +09001428 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1429 var variations []blueprint.Variation
1430 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001431 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001432 if version != "" && versionVariantAvail {
1433 // Version is explicitly specified. i.e. libFoo#30
1434 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1435 depTag.explicitlyVersioned = true
1436 }
1437 actx.AddVariationDependencies(variations, depTag, name)
1438
1439 // If the version is not specified, add dependency to the latest stubs library.
1440 // The stubs library will be used when the depending module is built for APEX and
1441 // the dependent module is not in the same APEX.
1442 latestVersion := latestStubsVersionFor(actx.Config(), name)
1443 if version == "" && latestVersion != "" && versionVariantAvail {
1444 actx.AddVariationDependencies([]blueprint.Variation{
1445 {Mutator: "link", Variation: "shared"},
1446 {Mutator: "version", Variation: latestVersion},
1447 }, depTag, name)
1448 // Note that depTag.explicitlyVersioned is false in this case.
1449 }
1450 }
1451
Jiyong Park7ed9de32018-10-15 22:25:07 +09001452 // shared lib names without the #version suffix
1453 var sharedLibNames []string
1454
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001455 for _, lib := range deps.SharedLibs {
1456 depTag := sharedDepTag
1457 if inList(lib, deps.ReexportSharedLibHeaders) {
1458 depTag = sharedExportDepTag
1459 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001460
1461 if impl, ok := syspropImplLibraries[lib]; ok {
1462 lib = impl
1463 }
1464
1465 name, version := stubsLibNameAndVersion(lib)
1466 sharedLibNames = append(sharedLibNames, name)
1467
Jiyong Park25fc6a92018-11-18 18:02:45 +09001468 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001469 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001470
Jiyong Park7ed9de32018-10-15 22:25:07 +09001471 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001472 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001473 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1474 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1475 // linking against both the stubs lib and the non-stubs lib at the same time.
1476 continue
1477 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001478 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001479 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001480
Dan Willemsen59339a22018-07-22 21:18:45 -07001481 actx.AddVariationDependencies([]blueprint.Variation{
1482 {Mutator: "link", Variation: "shared"},
1483 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001484
Colin Cross68861832016-07-08 10:41:41 -07001485 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001486
1487 for _, gen := range deps.GeneratedHeaders {
1488 depTag := genHeaderDepTag
1489 if inList(gen, deps.ReexportGeneratedHeaders) {
1490 depTag = genHeaderExportDepTag
1491 }
1492 actx.AddDependency(c, depTag, gen)
1493 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001494
Colin Cross42d48b72018-08-29 14:10:52 -07001495 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001496
1497 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001498 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001499 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001500 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001501 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001502 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001503 if deps.LinkerFlagsFile != "" {
1504 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1505 }
1506 if deps.DynamicLinker != "" {
1507 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001508 }
Dan Albert914449f2016-06-17 16:45:24 -07001509
1510 version := ctx.sdkVersion()
1511 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001512 {Mutator: "ndk_api", Variation: version},
1513 {Mutator: "link", Variation: "shared"},
1514 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001515 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001516 {Mutator: "ndk_api", Variation: version},
1517 {Mutator: "link", Variation: "shared"},
1518 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001519
1520 if vndkdep := c.vndkdep; vndkdep != nil {
1521 if vndkdep.isVndkExt() {
Inseob Kim64c43952019-08-26 16:52:35 +09001522 var baseModuleMode string
Logan Chienf3511742017-10-31 18:04:35 +08001523 if actx.DeviceConfig().VndkVersion() == "" {
1524 baseModuleMode = coreMode
Inseob Kim64c43952019-08-26 16:52:35 +09001525 } else {
1526 baseModuleMode = c.imageVariation()
Logan Chienf3511742017-10-31 18:04:35 +08001527 }
1528 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001529 {Mutator: "image", Variation: baseModuleMode},
1530 {Mutator: "link", Variation: "shared"},
1531 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001532 }
1533 }
Colin Cross6362e272015-10-29 15:25:03 -07001534}
Colin Cross21b9a242015-03-24 14:15:58 -07001535
Colin Crosse40b4ea2018-10-02 22:25:58 -07001536func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001537 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1538 c.beginMutator(ctx)
1539 }
1540}
1541
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001542// Whether a module can link to another module, taking into
1543// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001544func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001545 if from.Target().Os != android.Android {
1546 // Host code is not restricted
1547 return
1548 }
Inseob Kim64c43952019-08-26 16:52:35 +09001549 if from.useVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001550 // Though vendor code is limited by the vendor mutator,
1551 // each vendor-available module needs to check
1552 // link-type for VNDK.
1553 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001554 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001555 }
1556 return
1557 }
Nan Zhang0007d812017-11-07 10:57:05 -08001558 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001559 // Platform code can link to anything
1560 return
1561 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001562 if from.inRecovery() {
1563 // Recovery code is not NDK
1564 return
1565 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001566 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1567 // These are always allowed
1568 return
1569 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001570 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1571 // These are allowed, but they don't set sdk_version
1572 return
1573 }
1574 if _, ok := to.linker.(*stubDecorator); ok {
1575 // These aren't real libraries, but are the stub shared libraries that are included in
1576 // the NDK.
1577 return
1578 }
Logan Chien834b9a62019-01-14 15:39:03 +08001579
1580 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" {
1581 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1582 // to link to libc++ (non-NDK and without sdk_version).
1583 return
1584 }
1585
Nan Zhang0007d812017-11-07 10:57:05 -08001586 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001587 // NDK code linking to platform code is never okay.
1588 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1589 ctx.OtherModuleName(to))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001590 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001591 }
1592
1593 // At this point we know we have two NDK libraries, but we need to
1594 // check that we're not linking against anything built against a higher
1595 // API level, as it is only valid to link against older or equivalent
1596 // APIs.
1597
Inseob Kim01a28722018-04-11 09:48:45 +09001598 // Current can link against anything.
1599 if String(from.Properties.Sdk_version) != "current" {
1600 // Otherwise we need to check.
1601 if String(to.Properties.Sdk_version) == "current" {
1602 // Current can't be linked against by anything else.
1603 ctx.ModuleErrorf("links %q built against newer API version %q",
1604 ctx.OtherModuleName(to), "current")
1605 } else {
1606 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1607 if err != nil {
1608 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001609 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001610 String(from.Properties.Sdk_version))
1611 }
1612 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1613 if err != nil {
1614 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001615 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001616 String(to.Properties.Sdk_version))
1617 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001618
Inseob Kim01a28722018-04-11 09:48:45 +09001619 if toApi > fromApi {
1620 ctx.ModuleErrorf("links %q built against newer API version %q",
1621 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1622 }
1623 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001624 }
Dan Albert202fe492017-12-15 13:56:59 -08001625
1626 // Also check that the two STL choices are compatible.
1627 fromStl := from.stl.Properties.SelectedStl
1628 toStl := to.stl.Properties.SelectedStl
1629 if fromStl == "" || toStl == "" {
1630 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001631 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001632 // We can be permissive with the system "STL" since it is only the C++
1633 // ABI layer, but in the future we should make sure that everyone is
1634 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001635 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001636 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1637 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1638 to.stl.Properties.SelectedStl)
1639 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001640}
1641
Jiyong Park5fb8c102018-04-09 12:03:06 +09001642// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001643// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1644// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001645// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001646func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
Inseob Kim9516ee92019-05-09 10:56:13 +09001647 llndkLibraries := llndkLibraries(ctx.Config())
Jooyung Hana70f0672019-01-18 15:20:43 +09001648 check := func(child, parent android.Module) bool {
1649 to, ok := child.(*Module)
1650 if !ok {
1651 // follow thru cc.Defaults, etc.
1652 return true
1653 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001654
Jooyung Hana70f0672019-01-18 15:20:43 +09001655 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1656 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001657 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001658
1659 // if target lib has no vendor variant, keep checking dependency graph
1660 if !to.hasVendorVariant() {
1661 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001662 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001663
Inseob Kim9516ee92019-05-09 10:56:13 +09001664 if to.isVndkSp() || inList(child.Name(), *llndkLibraries) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001665 return false
1666 }
1667
1668 var stringPath []string
1669 for _, m := range ctx.GetWalkPath() {
1670 stringPath = append(stringPath, m.Name())
1671 }
1672 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1673 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1674 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1675 return false
1676 }
1677 if module, ok := ctx.Module().(*Module); ok {
1678 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Inseob Kim9516ee92019-05-09 10:56:13 +09001679 if inList(ctx.ModuleName(), *llndkLibraries) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001680 ctx.WalkDeps(check)
1681 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001682 }
1683 }
1684}
1685
Colin Crossc99deeb2016-04-11 15:06:20 -07001686// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001687func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001688 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001689
Jeff Gaston294356f2017-09-27 17:05:30 -07001690 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001691 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001692
Inseob Kim9516ee92019-05-09 10:56:13 +09001693 llndkLibraries := llndkLibraries(ctx.Config())
1694 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
1695
Inseob Kim69378442019-06-03 19:10:47 +09001696 reexportExporter := func(exporter exportedFlagsProducer) {
1697 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
1698 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
1699 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
1700 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
1701 }
1702
Colin Crossd11fcda2017-10-23 17:59:01 -07001703 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001704 depName := ctx.OtherModuleName(dep)
1705 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001706
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001707 ccDep, _ := dep.(*Module)
1708 if ccDep == nil {
1709 // handling for a few module types that aren't cc Module but that are also supported
1710 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001711 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001712 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001713 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1714 genRule.GeneratedSourceFiles()...)
1715 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001716 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001717 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001718 // Support exported headers from a generated_sources dependency
1719 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001720 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001721 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001722 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001723 genRule.GeneratedDeps()...)
Inseob Kim69378442019-06-03 19:10:47 +09001724 dirs := genRule.GeneratedHeaderDirs().Strings()
1725 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001726 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09001727 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
1728 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001729 // 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 +09001730 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001731
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001732 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001733 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001734 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001735 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001736 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001737 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001738 files := genRule.GeneratedSourceFiles()
1739 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001740 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001741 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001742 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 -07001743 }
1744 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001745 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001746 }
Colin Crossca860ac2016-01-04 14:34:37 -08001747 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001748 return
1749 }
1750
Colin Crossfe17f6f2019-03-28 19:30:56 -07001751 if depTag == android.ProtoPluginDepTag {
1752 return
1753 }
1754
Colin Crossd11fcda2017-10-23 17:59:01 -07001755 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001756 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1757 return
1758 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001759 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001760 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001761 return
1762 }
1763
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001764 // re-exporting flags
1765 if depTag == reuseObjTag {
1766 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001767 c.staticVariant = ccDep
Inseob Kim69378442019-06-03 19:10:47 +09001768 objs, exporter := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001769 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09001770 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08001771 return
1772 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001773 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001774
Jiyong Parke4bb9862019-02-01 00:31:10 +09001775 if depTag == staticVariantTag {
1776 if _, ok := ccDep.compiler.(libraryInterface); ok {
1777 c.staticVariant = ccDep
1778 return
1779 }
1780 }
1781
Jiyong Park25fc6a92018-11-18 18:02:45 +09001782 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1783 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1784 // won't be matched to sharedDepTag and lateSharedDepTag.
1785 explicitlyVersioned := false
1786 if t, ok := depTag.(dependencyTag); ok {
1787 explicitlyVersioned = t.explicitlyVersioned
1788 t.explicitlyVersioned = false
1789 depTag = t
1790 }
1791
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001792 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001793 depIsStatic := false
1794 switch depTag {
1795 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1796 depIsStatic = true
1797 }
1798 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001799 depIsStubs := dependentLibrary.buildStubs()
1800 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001801 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001802 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001803
1804 var useThisDep bool
1805 if depIsStubs && explicitlyVersioned {
1806 // Always respect dependency to the versioned stubs (i.e. libX#10)
1807 useThisDep = true
1808 } else if !depHasStubs {
1809 // Use non-stub variant if that is the only choice
1810 // (i.e. depending on a lib without stubs.version property)
1811 useThisDep = true
1812 } else if c.IsForPlatform() {
1813 // If not building for APEX, use stubs only when it is from
1814 // an APEX (and not from platform)
1815 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001816 if c.inRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001817 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001818 // always link to non-stub variant
1819 useThisDep = !depIsStubs
1820 }
1821 } else {
1822 // If building for APEX, use stubs only when it is not from
1823 // the same APEX
1824 useThisDep = (depInSameApex != depIsStubs)
1825 }
1826
1827 if !useThisDep {
1828 return // stop processing this dep
1829 }
1830 }
1831
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001832 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Inseob Kim69378442019-06-03 19:10:47 +09001833 depPaths.IncludeDirs = append(depPaths.IncludeDirs, i.exportedDirs()...)
1834 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
1835 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedDeps()...)
1836 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001837
1838 if t.reexportFlags {
Inseob Kim69378442019-06-03 19:10:47 +09001839 reexportExporter(i)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001840 // 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 -07001841 // Re-exported shared library headers must be included as well since they can help us with type information
1842 // about template instantiations (instantiated from their headers).
Inseob Kim69378442019-06-03 19:10:47 +09001843 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
1844 // scripts.
1845 c.sabi.Properties.ReexportedIncludes = append(
1846 c.sabi.Properties.ReexportedIncludes, i.exportedDirs()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001847 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001848 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001849
Logan Chienf3511742017-10-31 18:04:35 +08001850 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001851 }
1852
Colin Cross26c34ed2016-09-30 17:10:16 -07001853 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001854 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001855
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001856 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001857 depFile := android.OptionalPath{}
1858
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001859 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001860 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001861 ptr = &depPaths.SharedLibs
1862 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001863 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001864 directSharedDeps = append(directSharedDeps, ccDep)
Jiyong Park64a44f22019-01-18 14:37:08 +09001865 case earlySharedDepTag:
1866 ptr = &depPaths.EarlySharedLibs
1867 depPtr = &depPaths.EarlySharedLibsDeps
1868 depFile = ccDep.linker.(libraryInterface).toc()
1869 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001870 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001871 ptr = &depPaths.LateSharedLibs
1872 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001873 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001874 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001875 ptr = nil
1876 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001877 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001878 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001879 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001880 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001881 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001882 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001883 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001884 return
1885 }
1886
1887 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001888 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001889 for i := range missingDeps {
1890 missingDeps[i] += postfix
1891 }
1892 ctx.AddMissingDependencies(missingDeps)
1893 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001894 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001895 case headerDepTag:
1896 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001897 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001898 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001899 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001900 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001901 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001902 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001903 case dynamicLinkerDepTag:
1904 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001905 }
1906
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001907 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001908 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001909 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001910 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001911 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001912 return
1913 }
1914
1915 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001916 // in static libraries act as if they were whole static libraries. The same goes for
1917 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001918 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1919 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001920 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1921 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001922
Dan Willemsen581341d2017-02-09 16:16:31 -08001923 }
1924
Colin Cross26c34ed2016-09-30 17:10:16 -07001925 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001926 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001927 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001928 return
1929 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001930 *ptr = append(*ptr, linkFile.Path())
1931 }
1932
Colin Crossc99deeb2016-04-11 15:06:20 -07001933 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001934 dep := depFile
1935 if !dep.Valid() {
1936 dep = linkFile
1937 }
1938 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001939 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001940
Logan Chien43d34c32017-12-20 01:17:32 +08001941 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001942 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001943 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001944 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kim9516ee92019-05-09 10:56:13 +09001945 isLLndk := inList(libName, *llndkLibraries)
1946 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001947 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08001948
yidong.zhangd06ecc82019-08-02 15:49:24 +08001949 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.isVndk() && !ccDep.mustUseVendorVariant() && !c.inRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08001950 // The vendor module is a no-vendor-variant VNDK library. Depend on the
1951 // core module instead.
1952 return libName
1953 } else if c.useVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001954 // The vendor module in Make will have been renamed to not conflict with the core
1955 // module, so update the dependency name here accordingly.
Inseob Kim64c43952019-08-26 16:52:35 +09001956 ret := libName + vendorSuffix
1957 vendorVersion := ctx.DeviceConfig().VndkVersion()
1958 if vendorVersion == "current" {
1959 vendorVersion = ctx.DeviceConfig().PlatformVndkVersion()
1960 }
1961 if c.Properties.VndkVersion != vendorVersion {
1962 ret += "." + c.Properties.VndkVersion
1963 }
1964 return ret
Jiyong Park374510b2018-03-19 18:23:01 +09001965 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001966 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001967 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1968 return libName + recoverySuffix
dimitry1f33e402019-03-26 12:39:31 +01001969 } else if ccDep.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02001970 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001971 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001972 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001973 }
Logan Chien43d34c32017-12-20 01:17:32 +08001974 }
1975
1976 // Export the shared libs to Make.
1977 switch depTag {
Jiyong Park64a44f22019-01-18 14:37:08 +09001978 case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001979 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001980 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08001981 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09001982 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001983 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001984 c.Properties.ApexesProvidingSharedLibs = append(
1985 c.Properties.ApexesProvidingSharedLibs, an)
1986 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09001987 }
1988 }
1989
Jiyong Park27b188b2017-07-18 13:23:39 +09001990 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001991 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001992 c.Properties.AndroidMkSharedLibs = append(
1993 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08001994 case ndkStubDepTag, ndkLateStubDepTag:
1995 ndkStub := ccDep.linker.(*stubDecorator)
1996 c.Properties.AndroidMkSharedLibs = append(
1997 c.Properties.AndroidMkSharedLibs,
1998 depName+"."+ndkStub.properties.ApiLevel)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001999 case staticDepTag, staticExportDepTag, lateStaticDepTag:
2000 c.Properties.AndroidMkStaticLibs = append(
2001 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002002 case runtimeDepTag:
2003 c.Properties.AndroidMkRuntimeLibs = append(
2004 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002005 case wholeStaticDepTag:
2006 c.Properties.AndroidMkWholeStaticLibs = append(
2007 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002008 }
Colin Crossca860ac2016-01-04 14:34:37 -08002009 })
2010
Jeff Gaston294356f2017-09-27 17:05:30 -07002011 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002012 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002013
Colin Crossdd84e052017-05-17 13:44:16 -07002014 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002015 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Inseob Kim69378442019-06-03 19:10:47 +09002016 depPaths.IncludeDirs = android.FirstUniqueStrings(depPaths.IncludeDirs)
2017 depPaths.SystemIncludeDirs = android.FirstUniqueStrings(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002018 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kim69378442019-06-03 19:10:47 +09002019 depPaths.ReexportedDirs = android.FirstUniqueStrings(depPaths.ReexportedDirs)
2020 depPaths.ReexportedSystemDirs = android.FirstUniqueStrings(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002021 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002022 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002023
2024 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002025 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002026 }
Colin Crossdd84e052017-05-17 13:44:16 -07002027
Colin Crossca860ac2016-01-04 14:34:37 -08002028 return depPaths
2029}
2030
2031func (c *Module) InstallInData() bool {
2032 if c.installer == nil {
2033 return false
2034 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002035 return c.installer.inData()
2036}
2037
2038func (c *Module) InstallInSanitizerDir() bool {
2039 if c.installer == nil {
2040 return false
2041 }
2042 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002043 return true
2044 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002045 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002046}
2047
Jiyong Parkf9332f12018-02-01 00:54:12 +09002048func (c *Module) InstallInRecovery() bool {
2049 return c.inRecovery()
2050}
2051
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002052func (c *Module) HostToolPath() android.OptionalPath {
2053 if c.installer == nil {
2054 return android.OptionalPath{}
2055 }
2056 return c.installer.hostToolPath()
2057}
2058
Nan Zhangd4e641b2017-07-12 12:55:28 -07002059func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2060 return c.outputFile
2061}
2062
Colin Cross41955e82019-05-29 14:40:35 -07002063func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2064 switch tag {
2065 case "":
2066 if c.outputFile.Valid() {
2067 return android.Paths{c.outputFile.Path()}, nil
2068 }
2069 return android.Paths{}, nil
2070 default:
2071 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002072 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002073}
2074
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002075func (c *Module) static() bool {
2076 if static, ok := c.linker.(interface {
2077 static() bool
2078 }); ok {
2079 return static.static()
2080 }
2081 return false
2082}
2083
Jiyong Park379de2f2018-12-19 02:47:14 +09002084func (c *Module) staticBinary() bool {
2085 if static, ok := c.linker.(interface {
2086 staticBinary() bool
2087 }); ok {
2088 return static.staticBinary()
2089 }
2090 return false
2091}
2092
Jiyong Park1d1119f2019-07-29 21:27:18 +09002093func (c *Module) header() bool {
2094 if h, ok := c.linker.(interface {
2095 header() bool
2096 }); ok {
2097 return h.header()
2098 }
2099 return false
2100}
2101
Jooyung Han38002912019-05-16 04:01:54 +09002102func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
2103 name := actx.ModuleName()
Colin Crossb60190a2018-09-04 16:28:17 -07002104 if c.useVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002105 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2106 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002107 return "native:vndk"
2108 }
Jooyung Han38002912019-05-16 04:01:54 +09002109 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002110 }
Jooyung Han38002912019-05-16 04:01:54 +09002111 if c.isVndk() && !c.isVndkExt() {
2112 if Bool(c.VendorProperties.Vendor_available) {
2113 return "native:vndk"
2114 }
2115 return "native:vndk_private"
2116 }
2117 return "native:vendor"
Colin Crossb60190a2018-09-04 16:28:17 -07002118 } else if c.inRecovery() {
2119 return "native:recovery"
2120 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2121 return "native:ndk:none:none"
2122 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2123 //family, link := getNdkStlFamilyAndLinkType(c)
2124 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Jooyung Han38002912019-05-16 04:01:54 +09002125 } else if inList(name, *vndkUsingCoreVariantLibraries(actx.Config())) {
Vic Yangefd249e2018-11-12 20:19:56 -08002126 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002127 } else {
2128 return "native:platform"
2129 }
2130}
2131
Jiyong Park9d452992018-10-03 00:38:19 +09002132// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002133// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002134func (c *Module) IsInstallableToApex() bool {
2135 if shared, ok := c.linker.(interface {
2136 shared() bool
2137 }); ok {
2138 return shared.shared()
Roland Levillainf89cd092019-07-29 16:22:59 +01002139 } else if _, ok := c.linker.(testPerSrc); ok {
2140 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002141 }
2142 return false
2143}
2144
Inseob Kim1f086e22019-05-09 13:29:15 +09002145func (c *Module) installable() bool {
2146 return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
2147}
2148
Jiyong Park3b1746a2019-01-29 11:15:04 +09002149func (c *Module) imageVariation() string {
Jiyong Park3b1746a2019-01-29 11:15:04 +09002150 if c.useVndk() {
Inseob Kim64c43952019-08-26 16:52:35 +09002151 return vendorMode + "." + c.Properties.VndkVersion
Jiyong Park3b1746a2019-01-29 11:15:04 +09002152 } else if c.inRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09002153 return recoveryMode
Jiyong Park3b1746a2019-01-29 11:15:04 +09002154 }
Inseob Kim64c43952019-08-26 16:52:35 +09002155 return coreMode
Jiyong Park3b1746a2019-01-29 11:15:04 +09002156}
2157
bralee3f49f4d2019-03-04 06:58:15 +08002158func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
Colin Cross41955e82019-05-29 14:40:35 -07002159 outputFiles, err := c.OutputFiles("")
2160 if err != nil {
2161 panic(err)
2162 }
2163 dpInfo.Srcs = append(dpInfo.Srcs, outputFiles.Strings()...)
bralee3f49f4d2019-03-04 06:58:15 +08002164}
2165
Logan Chien41eabe62019-04-10 13:33:58 +08002166func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2167 if c.linker != nil {
2168 if library, ok := c.linker.(*libraryDecorator); ok {
2169 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2170 }
2171 }
2172}
2173
Colin Cross2ba19d92015-05-07 15:44:20 -07002174//
Colin Crosscfad1192015-11-02 16:43:11 -08002175// Defaults
2176//
Colin Crossca860ac2016-01-04 14:34:37 -08002177type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002178 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002179 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002180 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002181}
2182
Patrice Arrudac249c712019-03-19 17:00:29 -07002183// cc_defaults provides a set of properties that can be inherited by other cc
2184// modules. A module can use the properties from a cc_defaults using
2185// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2186// merged (when possible) by prepending the default module's values to the
2187// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002188func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002189 return DefaultsFactory()
2190}
2191
Colin Cross36242852017-06-23 15:06:31 -07002192func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002193 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002194
Colin Cross36242852017-06-23 15:06:31 -07002195 module.AddProperties(props...)
2196 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002197 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002198 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002199 &BaseCompilerProperties{},
2200 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002201 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002202 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002203 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002204 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002205 &TestProperties{},
2206 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002207 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002208 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002209 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002210 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002211 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002212 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002213 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002214 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002215 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002216 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002217 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002218 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002219 )
Colin Crosscfad1192015-11-02 16:43:11 -08002220
Colin Cross1f44a3a2017-07-07 14:33:33 -07002221 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09002222 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002223
2224 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002225}
2226
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002227const (
2228 // coreMode is the variant used for framework-private libraries, or
2229 // SDK libraries. (which framework-private libraries can use)
2230 coreMode = "core"
2231
Inseob Kim64c43952019-08-26 16:52:35 +09002232 // vendorMode is the variant prefix used for /vendor code that compiles
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002233 // against the VNDK.
2234 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09002235
2236 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002237)
2238
Jiyong Park6a43f042017-10-12 23:05:00 +09002239func squashVendorSrcs(m *Module) {
2240 if lib, ok := m.compiler.(*libraryDecorator); ok {
2241 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2242 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2243
2244 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2245 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2246 }
2247}
2248
Jiyong Parkf9332f12018-02-01 00:54:12 +09002249func squashRecoverySrcs(m *Module) {
2250 if lib, ok := m.compiler.(*libraryDecorator); ok {
2251 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2252 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2253
2254 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2255 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2256 }
2257}
2258
Jiyong Parkda6eb592018-12-19 17:12:36 +09002259func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002260 if mctx.Os() != android.Android {
2261 return
2262 }
2263
Jiyong Park7ed9de32018-10-15 22:25:07 +09002264 if g, ok := mctx.Module().(*genrule.Module); ok {
2265 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09002266 var coreVariantNeeded bool = false
2267 var vendorVariantNeeded bool = false
2268 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09002269 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09002270 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002271 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09002272 coreVariantNeeded = true
2273 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09002274 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09002275 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002276 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09002277 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002278 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002279 if Bool(props.Recovery_available) {
2280 recoveryVariantNeeded = true
2281 }
2282
Jiyong Park413cc742018-06-19 01:46:06 +09002283 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002284 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09002285 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09002286 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002287 recoveryVariantNeeded = false
2288 }
2289 }
2290
Jiyong Park3f736c92018-05-24 13:36:56 +09002291 var variants []string
2292 if coreVariantNeeded {
2293 variants = append(variants, coreMode)
2294 }
2295 if vendorVariantNeeded {
Inseob Kim64c43952019-08-26 16:52:35 +09002296 variants = append(variants, vendorMode+"."+mctx.DeviceConfig().PlatformVndkVersion())
2297 if vndkVersion := mctx.DeviceConfig().VndkVersion(); vndkVersion != "current" {
2298 variants = append(variants, vendorMode+"."+vndkVersion)
2299 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002300 }
2301 if recoveryVariantNeeded {
2302 variants = append(variants, recoveryMode)
2303 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002304 mod := mctx.CreateVariations(variants...)
2305 for i, v := range variants {
2306 if v == recoveryMode {
2307 m := mod[i].(*genrule.Module)
2308 m.Extra.(*GenruleExtraProperties).InRecovery = true
2309 }
2310 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002311 }
2312 }
2313
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002314 m, ok := mctx.Module().(*Module)
2315 if !ok {
2316 return
2317 }
2318
2319 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002320 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002321 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002322
2323 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002324 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002325 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002326 return
2327 }
Logan Chienf3511742017-10-31 18:04:35 +08002328
2329 if vndkdep := m.vndkdep; vndkdep != nil {
2330 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002331 if productSpecific {
2332 mctx.PropertyErrorf("product_specific",
2333 "product_specific must not be true when `vndk: {enabled: true}`")
2334 return
2335 }
Logan Chienf3511742017-10-31 18:04:35 +08002336 if vendorSpecific {
2337 if !vndkdep.isVndkExt() {
2338 mctx.PropertyErrorf("vndk",
2339 "must set `extends: \"...\"` to vndk extension")
2340 return
2341 }
2342 } else {
2343 if vndkdep.isVndkExt() {
2344 mctx.PropertyErrorf("vndk",
2345 "must set `vendor: true` to set `extends: %q`",
2346 m.getVndkExtendsModuleName())
2347 return
2348 }
2349 if m.VendorProperties.Vendor_available == nil {
2350 mctx.PropertyErrorf("vndk",
2351 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2352 return
2353 }
2354 }
2355 } else {
2356 if vndkdep.isVndkSp() {
2357 mctx.PropertyErrorf("vndk",
2358 "must set `enabled: true` to set `support_system_process: true`")
2359 return
2360 }
2361 if vndkdep.isVndkExt() {
2362 mctx.PropertyErrorf("vndk",
2363 "must set `enabled: true` to set `extends: %q`",
2364 m.getVndkExtendsModuleName())
2365 return
2366 }
Justin Yun8effde42017-06-23 19:24:43 +09002367 }
2368 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002369
Jiyong Parkf9332f12018-02-01 00:54:12 +09002370 var coreVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002371 var recoveryVariantNeeded bool = false
2372
Inseob Kim64c43952019-08-26 16:52:35 +09002373 var vendorVariants []string
2374
2375 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
2376 deviceVndkVersion := mctx.DeviceConfig().VndkVersion()
2377 if deviceVndkVersion == "current" {
2378 deviceVndkVersion = platformVndkVersion
2379 }
2380
Justin Yun71549282017-11-17 12:10:28 +09002381 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002382 // If the device isn't compiling against the VNDK, we always
2383 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002384 coreVariantNeeded = true
Justin Yun1282f422019-09-09 14:42:44 +09002385 } else if m.Target().NativeBridge == android.NativeBridgeEnabled {
2386 // Skip creating vendor variants for natvie bridge modules
2387 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002388 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2389 // LL-NDK stubs only exist in the vendor variant, since the
2390 // real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002391 vendorVariants = append(vendorVariants,
2392 platformVndkVersion,
2393 deviceVndkVersion,
2394 )
Jiyong Park2a454122017-10-19 15:59:33 +09002395 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2396 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002397 vendorVariants = append(vendorVariants,
2398 platformVndkVersion,
2399 deviceVndkVersion,
2400 )
2401 } else if lib, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002402 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2403 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kim64c43952019-08-26 16:52:35 +09002404 vendorVariants = append(vendorVariants, lib.version())
Logan Chienf3511742017-10-31 18:04:35 +08002405 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002406 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002407 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002408 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002409 vendorVariants = append(vendorVariants, platformVndkVersion)
2410 if m.isVndk() {
2411 vendorVariants = append(vendorVariants, deviceVndkVersion)
2412 }
Logan Chienf3511742017-10-31 18:04:35 +08002413 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002414 // This will be available in /vendor (or /odm) only
Inseob Kim64c43952019-08-26 16:52:35 +09002415 vendorVariants = append(vendorVariants, deviceVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002416 } else {
2417 // This is either in /system (or similar: /data), or is a
2418 // modules built with the NDK. Modules built with the NDK
2419 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002420 coreVariantNeeded = true
2421 }
2422
2423 if Bool(m.Properties.Recovery_available) {
2424 recoveryVariantNeeded = true
2425 }
2426
2427 if m.ModuleBase.InstallInRecovery() {
2428 recoveryVariantNeeded = true
2429 coreVariantNeeded = false
2430 }
2431
Jiyong Park413cc742018-06-19 01:46:06 +09002432 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002433 primaryArch := mctx.Config().DevicePrimaryArchType()
2434 moduleArch := m.Target().Arch.ArchType
2435 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002436 recoveryVariantNeeded = false
2437 }
2438 }
2439
Jiyong Parkf9332f12018-02-01 00:54:12 +09002440 var variants []string
2441 if coreVariantNeeded {
2442 variants = append(variants, coreMode)
2443 }
Inseob Kim64c43952019-08-26 16:52:35 +09002444 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
2445 variants = append(variants, vendorMode+"."+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09002446 }
2447 if recoveryVariantNeeded {
2448 variants = append(variants, recoveryMode)
2449 }
2450 mod := mctx.CreateVariations(variants...)
2451 for i, v := range variants {
Inseob Kim64c43952019-08-26 16:52:35 +09002452 if strings.HasPrefix(v, vendorMode+".") {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002453 m := mod[i].(*Module)
Inseob Kim64c43952019-08-26 16:52:35 +09002454 m.Properties.VndkVersion = strings.TrimPrefix(v, vendorMode+".")
Jiyong Parkf9332f12018-02-01 00:54:12 +09002455 squashVendorSrcs(m)
2456 } else if v == recoveryMode {
2457 m := mod[i].(*Module)
2458 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002459 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002460 squashRecoverySrcs(m)
2461 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002462 }
2463}
2464
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002465func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002466 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002467 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2468 }
Colin Cross6510f912017-11-29 00:27:14 -08002469 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002470}
2471
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002472func kytheExtractAllFactory() android.Singleton {
2473 return &kytheExtractAllSingleton{}
2474}
2475
2476type kytheExtractAllSingleton struct {
2477}
2478
2479func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2480 var xrefTargets android.Paths
2481 ctx.VisitAllModules(func(module android.Module) {
2482 if ccModule, ok := module.(xref); ok {
2483 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
2484 }
2485 })
2486 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
2487 if len(xrefTargets) > 0 {
2488 ctx.Build(pctx, android.BuildParams{
2489 Rule: blueprint.Phony,
2490 Output: android.PathForPhony(ctx, "xref_cxx"),
2491 Inputs: xrefTargets,
2492 //Default: true,
2493 })
2494 }
2495}
2496
Colin Cross06a931b2015-10-28 17:23:31 -07002497var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002498var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002499var BoolPtr = proptools.BoolPtr
2500var String = proptools.String
2501var StringPtr = proptools.StringPtr