blob: 0245c6a185fec5807a40567abca0e7ed43b4e681 [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -07001// Copyright 2015 Google Inc. All rights reserved.
Colin Cross3f40fa42015-01-30 17:27:36 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17// This file contains the module types for compiling C/C++ for Android, and converts the properties
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
Colin Cross41955e82019-05-29 14:40:35 -070022 "fmt"
Logan Chien41eabe62019-04-10 13:33:58 +080023 "io"
Dan Albert9e10cd42016-08-03 14:12:14 -070024 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080025 "strings"
26
Colin Cross97ba0732015-03-23 17:50:24 -070027 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070028 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070029
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070031 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070032 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080033)
34
Colin Cross463a90e2015-06-17 14:20:06 -070035func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070036 android.RegisterModuleType("cc_defaults", defaultsFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070037
Colin Cross1e676be2016-10-12 14:38:15 -070038 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +090039 ctx.BottomUp("image", ImageMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070040 ctx.BottomUp("link", LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +090041 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070042 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +010043 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090044 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070045 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimc0907f12019-02-08 21:00:45 +090046 ctx.BottomUp("sysprop", SyspropMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070047 })
Colin Cross16b23492016-01-06 14:41:07 -080048
Colin Cross1e676be2016-10-12 14:38:15 -070049 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
50 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
51 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080052
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070053 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
54 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
55
Mitch Phillipsbfeade62019-05-01 14:42:05 -070056 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
57 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
58
Jiyong Park1d1119f2019-07-29 21:27:18 +090059 // cfi mutator shouldn't run before sanitizers that return true for
60 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000061 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
62 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
63
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080064 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
65 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
66
Colin Cross1e676be2016-10-12 14:38:15 -070067 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
68 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080069
Colin Cross0b908332019-06-19 23:00:20 -070070 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090071 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080072
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080073 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080074 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070075
76 ctx.TopDown("lto_deps", ltoDepsMutator)
77 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090078
79 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070080 })
Colin Crossb98c8b02016-07-29 13:44:28 -070081
Sasha Smundak2a4549e2018-11-05 16:49:08 -080082 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Crossb98c8b02016-07-29 13:44:28 -070083 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070084}
85
Colin Crossca860ac2016-01-04 14:34:37 -080086type Deps struct {
87 SharedLibs, LateSharedLibs []string
88 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080089 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080090 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070091
Colin Cross5950f382016-12-13 12:50:57 -080092 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070093
Colin Cross81413472016-04-11 14:37:39 -070094 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070095
Dan Willemsenb40aab62016-04-20 14:21:14 -070096 GeneratedSources []string
97 GeneratedHeaders []string
98
Dan Willemsenb3454ab2016-09-28 17:34:58 -070099 ReexportGeneratedHeaders []string
100
Colin Cross97ba0732015-03-23 17:50:24 -0700101 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700102
103 // Used for host bionic
104 LinkerFlagsFile string
105 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700106}
107
Colin Crossca860ac2016-01-04 14:34:37 -0800108type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700109 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900110 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700111 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900112 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700113 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700114 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700115
Colin Cross26c34ed2016-09-30 17:10:16 -0700116 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700117 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800118 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700119 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700120
Colin Cross26c34ed2016-09-30 17:10:16 -0700121 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700122 GeneratedSources android.Paths
123 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700124
Inseob Kim69378442019-06-03 19:10:47 +0900125 Flags []string
126 IncludeDirs []string
127 SystemIncludeDirs []string
128 ReexportedDirs []string
129 ReexportedSystemDirs []string
130 ReexportedFlags []string
131 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700132
Colin Cross26c34ed2016-09-30 17:10:16 -0700133 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700134 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700135
136 // Path to the file container flags to use with the linker
137 LinkerFlagsFile android.OptionalPath
138
139 // Path to the dynamic linker binary
140 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700141}
142
Colin Crossca860ac2016-01-04 14:34:37 -0800143type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700144 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
145 ArFlags []string // Flags that apply to ar
146 AsFlags []string // Flags that apply to assembly source files
147 CFlags []string // Flags that apply to C and C++ source files
148 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
149 ConlyFlags []string // Flags that apply to C source files
150 CppFlags []string // Flags that apply to C++ source files
151 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700152 aidlFlags []string // Flags that apply to aidl source files
153 rsFlags []string // Flags that apply to renderscript source files
154 LdFlags []string // Flags that apply to linker command lines
155 libFlags []string // Flags to add libraries early to the link order
Pete Bentley99f2fc22019-08-02 14:02:20 +0100156 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700157 TidyFlags []string // Flags that apply to clang-tidy
158 SAbiFlags []string // Flags that apply to header-abi-dumper
159 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700160
Colin Crossc3199482017-03-30 15:03:04 -0700161 // Global include flags that apply to C, C++, and assembly source files
162 // These must be after any module include flags, which will be in GlobalFlags.
163 SystemIncludeFlags []string
164
Colin Crossb98c8b02016-07-29 13:44:28 -0700165 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700166 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800167 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800168 SAbiDump bool
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800169 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800170
171 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800172 DynamicLinker string
173
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700174 CFlagsDeps android.Paths // Files depended on by compiler flags
175 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800176
177 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800178
Colin Cross19878da2019-03-28 14:45:07 -0700179 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700180 protoC bool // Whether to use C instead of C++
181 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700182
183 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700184}
185
Colin Crossca860ac2016-01-04 14:34:37 -0800186// Properties used to compile all C or C++ modules
187type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700188 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800189 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700190
191 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800192 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700193
Jiyong Parkde866cb2018-12-07 23:08:36 +0900194 AndroidMkSharedLibs []string `blueprint:"mutated"`
195 AndroidMkStaticLibs []string `blueprint:"mutated"`
196 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
197 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
198 HideFromMake bool `blueprint:"mutated"`
199 PreventInstall bool `blueprint:"mutated"`
200 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700201
202 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800203
204 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
205 // file
206 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900207
208 // Make this module available when building for recovery
209 Recovery_available *bool
210
211 InRecovery bool `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900212
213 // Allows this module to use non-APEX version of libraries. Useful
214 // for building binaries that are started before APEXes are activated.
215 Bootstrap *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700216}
217
218type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900219 // whether this module should be allowed to be directly depended by other
220 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
221 // If set to true, two variants will be built separately, one like
222 // normal, and the other limited to the set of libraries and headers
223 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700224 //
225 // The vendor variant may be used with a different (newer) /system,
226 // so it shouldn't have any unversioned runtime dependencies, or
227 // make assumptions about the system that may not be true in the
228 // future.
229 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900230 // If set to false, this module becomes inaccessible from /vendor modules.
231 //
232 // Default value is true when vndk: {enabled: true} or vendor: true.
233 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700234 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
235 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900236
237 // whether this module is capable of being loaded with other instance
238 // (possibly an older version) of the same module in the same process.
239 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
240 // can be double loaded in a vendor process if the library is also a
241 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
242 // explicitly marked as `double_loadable: true` by the owner, or the dependency
243 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
244 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800245}
246
Colin Crossca860ac2016-01-04 14:34:37 -0800247type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800248 static() bool
249 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900250 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700251 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700252 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800253 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700254 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800255 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900256 isLlndk(config android.Config) bool
257 isLlndkPublic(config android.Config) bool
258 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900259 isVndk() bool
260 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800261 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900262 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800263 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700264 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700265 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800266 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800267 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800268 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800269 useClangLld(actx ModuleContext) bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900270 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900271 hasStubsVariants() bool
272 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900273 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800274 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700275 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800276}
277
278type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700279 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800280 ModuleContextIntf
281}
282
283type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700284 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800285 ModuleContextIntf
286}
287
Colin Cross37047f12016-12-13 17:06:13 -0800288type DepsContext interface {
289 android.BottomUpMutatorContext
290 ModuleContextIntf
291}
292
Colin Crossca860ac2016-01-04 14:34:37 -0800293type feature interface {
294 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800295 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800296 flags(ctx ModuleContext, flags Flags) Flags
297 props() []interface{}
298}
299
300type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700301 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800302 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800303 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700304 compilerProps() []interface{}
305
Colin Cross76fada02016-07-27 10:31:13 -0700306 appendCflags([]string)
307 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700308 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800309}
310
311type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700312 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800313 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700314 linkerFlags(ctx ModuleContext, flags Flags) Flags
315 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800316 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700317
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700318 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700319 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900320 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700321
322 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900323 coverageOutputFilePath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800324}
325
326type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700327 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700328 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800329 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700330 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700331 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900332 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800333}
334
Colin Crossc99deeb2016-04-11 15:06:20 -0700335type dependencyTag struct {
336 blueprint.BaseDependencyTag
337 name string
338 library bool
Roland Levillainf89cd092019-07-29 16:22:59 +0100339 shared bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700340
341 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900342
343 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700344}
345
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800346type xref interface {
347 XrefCcFiles() android.Paths
348}
349
Colin Crossc99deeb2016-04-11 15:06:20 -0700350var (
Roland Levillainf89cd092019-07-29 16:22:59 +0100351 sharedDepTag = dependencyTag{name: "shared", library: true, shared: true}
352 sharedExportDepTag = dependencyTag{name: "shared", library: true, shared: true, reexportFlags: true}
353 earlySharedDepTag = dependencyTag{name: "early_shared", library: true, shared: true}
354 lateSharedDepTag = dependencyTag{name: "late shared", library: true, shared: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700355 staticDepTag = dependencyTag{name: "static", library: true}
356 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
357 lateStaticDepTag = dependencyTag{name: "late static", library: true}
358 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800359 headerDepTag = dependencyTag{name: "header", library: true}
360 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700361 genSourceDepTag = dependencyTag{name: "gen source"}
362 genHeaderDepTag = dependencyTag{name: "gen header"}
363 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
364 objDepTag = dependencyTag{name: "obj"}
365 crtBeginDepTag = dependencyTag{name: "crtbegin"}
366 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700367 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
368 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700369 reuseObjTag = dependencyTag{name: "reuse objects"}
Jiyong Parke4bb9862019-02-01 00:31:10 +0900370 staticVariantTag = dependencyTag{name: "static variant"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700371 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
372 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800373 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800374 runtimeDepTag = dependencyTag{name: "runtime lib"}
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -0700375 coverageDepTag = dependencyTag{name: "coverage"}
Roland Levillainf2fad972019-06-28 15:41:19 +0100376 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700377)
378
Roland Levillainf89cd092019-07-29 16:22:59 +0100379func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
380 ccDepTag, ok := depTag.(dependencyTag)
381 return ok && ccDepTag.shared
382}
383
384func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
385 ccDepTag, ok := depTag.(dependencyTag)
386 return ok && ccDepTag == runtimeDepTag
387}
388
389func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
390 ccDepTag, ok := depTag.(dependencyTag)
391 return ok && ccDepTag == testPerSrcDepTag
392}
393
Colin Crossca860ac2016-01-04 14:34:37 -0800394// Module contains the properties and members used by all C/C++ module types, and implements
395// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
396// to construct the output file. Behavior can be customized with a Customizer interface
397type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700398 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700399 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900400 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700401
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700402 Properties BaseProperties
403 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700404
Colin Crossca860ac2016-01-04 14:34:37 -0800405 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700406 hod android.HostOrDeviceSupported
407 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700408
Colin Crossca860ac2016-01-04 14:34:37 -0800409 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700410 features []feature
411 compiler compiler
412 linker linker
413 installer installer
414 stl *stl
415 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800416 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800417 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900418 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700419 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700420 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800421 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800422
423 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700424
Colin Cross635c3b02016-05-18 15:37:25 -0700425 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800426
Colin Crossb98c8b02016-07-29 13:44:28 -0700427 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700428
429 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800430
431 // Flags used to compile this module
432 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700433
434 // 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 -0800435 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700436 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800437 depsInLinkOrder android.Paths
438
439 // only non-nil when this is a shared library that reuses the objects of a static library
440 staticVariant *Module
Inseob Kim9516ee92019-05-09 10:56:13 +0900441
442 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800443 // Kythe (source file indexer) paths for this compilation module
444 kytheFiles android.Paths
Colin Crossc472d572015-03-17 15:06:21 -0700445}
446
Jiyong Parkc20eee32018-09-05 22:36:17 +0900447func (c *Module) OutputFile() android.OptionalPath {
448 return c.outputFile
449}
450
Jiyong Park719b4462019-01-13 00:39:51 +0900451func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900452 if c.linker != nil {
453 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900454 }
455 return nil
456}
457
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900458func (c *Module) CoverageOutputFile() android.OptionalPath {
459 if c.linker != nil {
460 return c.linker.coverageOutputFilePath()
461 }
462 return android.OptionalPath{}
463}
464
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900465func (c *Module) RelativeInstallPath() string {
466 if c.installer != nil {
467 return c.installer.relativeInstallPath()
468 }
469 return ""
470}
471
Colin Cross36242852017-06-23 15:06:31 -0700472func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700473 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800474 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700475 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800476 }
477 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700478 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800479 }
480 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700481 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800482 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700483 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700484 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700485 }
Colin Cross16b23492016-01-06 14:41:07 -0800486 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700487 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800488 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800489 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700490 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800491 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800492 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700493 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800494 }
Justin Yun8effde42017-06-23 19:24:43 +0900495 if c.vndkdep != nil {
496 c.AddProperties(c.vndkdep.props()...)
497 }
Stephen Craneba090d12017-05-09 15:44:35 -0700498 if c.lto != nil {
499 c.AddProperties(c.lto.props()...)
500 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700501 if c.pgo != nil {
502 c.AddProperties(c.pgo.props()...)
503 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800504 if c.xom != nil {
505 c.AddProperties(c.xom.props()...)
506 }
Colin Crossca860ac2016-01-04 14:34:37 -0800507 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700508 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800509 }
Colin Crossc472d572015-03-17 15:06:21 -0700510
Colin Crossa9d8bee2018-10-02 13:59:46 -0700511 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
512 switch class {
513 case android.Device:
514 return ctx.Config().DevicePrefer32BitExecutables()
515 case android.HostCross:
516 // Windows builds always prefer 32-bit
517 return true
518 default:
519 return false
520 }
521 })
Colin Cross36242852017-06-23 15:06:31 -0700522 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700523
Colin Cross1f44a3a2017-07-07 14:33:33 -0700524 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700525
Jiyong Park9d452992018-10-03 00:38:19 +0900526 android.InitApexModule(c)
527
Colin Cross36242852017-06-23 15:06:31 -0700528 return c
Colin Crossc472d572015-03-17 15:06:21 -0700529}
530
Colin Crossb916a382016-07-29 17:28:03 -0700531// Returns true for dependency roots (binaries)
532// TODO(ccross): also handle dlopenable libraries
533func (c *Module) isDependencyRoot() bool {
534 if root, ok := c.linker.(interface {
535 isDependencyRoot() bool
536 }); ok {
537 return root.isDependencyRoot()
538 }
539 return false
540}
541
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700542func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700543 return c.Properties.UseVndk
544}
545
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800546func (c *Module) isCoverageVariant() bool {
547 return c.coverage.Properties.IsCoverageVariant
548}
549
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800550func (c *Module) isNdk() bool {
551 return inList(c.Name(), ndkMigratedLibs)
552}
553
Inseob Kim9516ee92019-05-09 10:56:13 +0900554func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800555 // Returns true for both LLNDK (public) and LLNDK-private libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900556 return inList(c.Name(), *llndkLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800557}
558
Inseob Kim9516ee92019-05-09 10:56:13 +0900559func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800560 // Returns true only for LLNDK (public) libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900561 return c.isLlndk(config) && !c.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800562}
563
Inseob Kim9516ee92019-05-09 10:56:13 +0900564func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800565 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Inseob Kim9516ee92019-05-09 10:56:13 +0900566 return inList(c.Name(), *vndkPrivateLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800567}
568
Justin Yun8effde42017-06-23 19:24:43 +0900569func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800570 if vndkdep := c.vndkdep; vndkdep != nil {
571 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900572 }
573 return false
574}
575
Jooyung Han76106d92019-05-20 18:49:10 +0900576func (c *Module) vndkVersion() string {
577 if vndkdep := c.vndkdep; vndkdep != nil {
578 return vndkdep.Properties.Vndk.Version
579 }
580 return ""
581}
582
Yi Kong7e53c572018-02-14 18:16:12 +0800583func (c *Module) isPgoCompile() bool {
584 if pgo := c.pgo; pgo != nil {
585 return pgo.Properties.PgoCompile
586 }
587 return false
588}
589
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800590func (c *Module) isNDKStubLibrary() bool {
591 if _, ok := c.compiler.(*stubDecorator); ok {
592 return true
593 }
594 return false
595}
596
Logan Chienf3511742017-10-31 18:04:35 +0800597func (c *Module) isVndkSp() bool {
598 if vndkdep := c.vndkdep; vndkdep != nil {
599 return vndkdep.isVndkSp()
600 }
601 return false
602}
603
604func (c *Module) isVndkExt() bool {
605 if vndkdep := c.vndkdep; vndkdep != nil {
606 return vndkdep.isVndkExt()
607 }
608 return false
609}
610
Vic Yangefd249e2018-11-12 20:19:56 -0800611func (c *Module) mustUseVendorVariant() bool {
612 return c.isVndkSp() || inList(c.Name(), config.VndkMustUseVendorVariantList)
613}
614
Logan Chienf3511742017-10-31 18:04:35 +0800615func (c *Module) getVndkExtendsModuleName() string {
616 if vndkdep := c.vndkdep; vndkdep != nil {
617 return vndkdep.getVndkExtendsModuleName()
618 }
619 return ""
620}
621
Jiyong Park82e2bf32017-08-16 14:05:54 +0900622// Returns true only when this module is configured to have core and vendor
623// variants.
624func (c *Module) hasVendorVariant() bool {
625 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
626}
627
Jiyong Parkf9332f12018-02-01 00:54:12 +0900628func (c *Module) inRecovery() bool {
629 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
630}
631
632func (c *Module) onlyInRecovery() bool {
633 return c.ModuleBase.InstallInRecovery()
634}
635
Jiyong Park25fc6a92018-11-18 18:02:45 +0900636func (c *Module) IsStubs() bool {
637 if library, ok := c.linker.(*libraryDecorator); ok {
638 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900639 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
640 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900641 }
642 return false
643}
644
645func (c *Module) HasStubsVariants() bool {
646 if library, ok := c.linker.(*libraryDecorator); ok {
647 return len(library.Properties.Stubs.Versions) > 0
648 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700649 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
650 return len(library.Properties.Stubs.Versions) > 0
651 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900652 return false
653}
654
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900655func (c *Module) bootstrap() bool {
656 return Bool(c.Properties.Bootstrap)
657}
658
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700659func (c *Module) nativeCoverage() bool {
660 return c.linker != nil && c.linker.nativeCoverage()
661}
662
Jiyong Parkf1194352019-02-25 11:05:47 +0900663func isBionic(name string) bool {
664 switch name {
665 case "libc", "libm", "libdl", "linker":
666 return true
667 }
668 return false
669}
670
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700671func installToBootstrap(name string, config android.Config) bool {
672 if name == "libclang_rt.hwasan-aarch64-android" {
673 return inList("hwaddress", config.SanitizeDevice())
674 }
675 return isBionic(name)
676}
677
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800678func (c *Module) XrefCcFiles() android.Paths {
679 return c.kytheFiles
680}
681
Colin Crossca860ac2016-01-04 14:34:37 -0800682type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700683 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800684 moduleContextImpl
685}
686
Colin Cross37047f12016-12-13 17:06:13 -0800687type depsContext struct {
688 android.BottomUpMutatorContext
689 moduleContextImpl
690}
691
Colin Crossca860ac2016-01-04 14:34:37 -0800692type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700693 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800694 moduleContextImpl
695}
696
Jiyong Park2db76922017-11-08 16:03:48 +0900697func (ctx *moduleContext) SocSpecific() bool {
698 return ctx.ModuleContext.SocSpecific() ||
699 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700700}
701
Colin Crossca860ac2016-01-04 14:34:37 -0800702type moduleContextImpl struct {
703 mod *Module
704 ctx BaseModuleContext
705}
706
Colin Crossb98c8b02016-07-29 13:44:28 -0700707func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800708 return ctx.mod.toolchain(ctx.ctx)
709}
710
711func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000712 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800713}
714
715func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900716 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800717}
718
Jiyong Park1d1119f2019-07-29 21:27:18 +0900719func (ctx *moduleContextImpl) header() bool {
720 return ctx.mod.header()
721}
722
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700723func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800724 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800725 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700726 }
727 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800728}
729
730func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700731 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700732 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900733 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700734 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900735 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
736 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
737 return "current"
738 }
739 return platform_vndk_ver
740 }
741 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800742 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900743 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700744 }
745 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800746}
747
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700748func (ctx *moduleContextImpl) useVndk() bool {
749 return ctx.mod.useVndk()
750}
Justin Yun8effde42017-06-23 19:24:43 +0900751
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800752func (ctx *moduleContextImpl) isNdk() bool {
753 return ctx.mod.isNdk()
754}
755
Inseob Kim9516ee92019-05-09 10:56:13 +0900756func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
757 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800758}
759
Inseob Kim9516ee92019-05-09 10:56:13 +0900760func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
761 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800762}
763
Inseob Kim9516ee92019-05-09 10:56:13 +0900764func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
765 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800766}
767
Logan Chienf3511742017-10-31 18:04:35 +0800768func (ctx *moduleContextImpl) isVndk() bool {
769 return ctx.mod.isVndk()
770}
771
Yi Kong7e53c572018-02-14 18:16:12 +0800772func (ctx *moduleContextImpl) isPgoCompile() bool {
773 return ctx.mod.isPgoCompile()
774}
775
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800776func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
777 return ctx.mod.isNDKStubLibrary()
778}
779
Justin Yun8effde42017-06-23 19:24:43 +0900780func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800781 return ctx.mod.isVndkSp()
782}
783
784func (ctx *moduleContextImpl) isVndkExt() bool {
785 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900786}
787
Vic Yangefd249e2018-11-12 20:19:56 -0800788func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
789 return ctx.mod.mustUseVendorVariant()
790}
791
Jiyong Parkf9332f12018-02-01 00:54:12 +0900792func (ctx *moduleContextImpl) inRecovery() bool {
793 return ctx.mod.inRecovery()
794}
795
Logan Chien2f2b8902018-07-10 15:01:19 +0800796// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800797func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +0800798 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
799 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800800 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800801
802 if ctx.ctx.Fuchsia() {
803 return false
804 }
805
Logan Chien2f2b8902018-07-10 15:01:19 +0800806 if sanitize := ctx.mod.sanitize; sanitize != nil {
807 if !sanitize.isVariantOnProductionDevice() {
808 return false
809 }
810 }
811 if !ctx.ctx.Device() {
812 // Host modules do not need ABI dumps.
813 return false
814 }
Logan Chienfa478c02018-12-28 16:25:39 +0800815 if !ctx.mod.IsForPlatform() {
816 // APEX variants do not need ABI dumps.
817 return false
818 }
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +0800819 if ctx.isStubs() {
820 // Stubs do not need ABI dumps.
821 return false
822 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800823 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800824}
825
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700826func (ctx *moduleContextImpl) selectedStl() string {
827 if stl := ctx.mod.stl; stl != nil {
828 return stl.Properties.SelectedStl
829 }
830 return ""
831}
832
Ivan Lozanobd721262018-11-27 14:33:03 -0800833func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
834 return ctx.mod.linker.useClangLld(actx)
835}
836
Colin Crossce75d2c2016-10-06 16:12:58 -0700837func (ctx *moduleContextImpl) baseModuleName() string {
838 return ctx.mod.ModuleBase.BaseModuleName()
839}
840
Logan Chienf3511742017-10-31 18:04:35 +0800841func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
842 return ctx.mod.getVndkExtendsModuleName()
843}
844
Jiyong Park58e364a2019-01-19 19:24:06 +0900845func (ctx *moduleContextImpl) apexName() string {
846 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900847}
848
Jiyong Parkb0788572018-12-20 22:10:17 +0900849func (ctx *moduleContextImpl) hasStubsVariants() bool {
850 return ctx.mod.HasStubsVariants()
851}
852
853func (ctx *moduleContextImpl) isStubs() bool {
854 return ctx.mod.IsStubs()
855}
856
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900857func (ctx *moduleContextImpl) bootstrap() bool {
858 return ctx.mod.bootstrap()
859}
860
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700861func (ctx *moduleContextImpl) nativeCoverage() bool {
862 return ctx.mod.nativeCoverage()
863}
864
Colin Cross635c3b02016-05-18 15:37:25 -0700865func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800866 return &Module{
867 hod: hod,
868 multilib: multilib,
869 }
870}
871
Colin Cross635c3b02016-05-18 15:37:25 -0700872func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800873 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700874 module.features = []feature{
875 &tidyFeature{},
876 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700877 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800878 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800879 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800880 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900881 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700882 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700883 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800884 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800885 return module
886}
887
Colin Crossce75d2c2016-10-06 16:12:58 -0700888func (c *Module) Prebuilt() *android.Prebuilt {
889 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
890 return p.prebuilt()
891 }
892 return nil
893}
894
895func (c *Module) Name() string {
896 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700897 if p, ok := c.linker.(interface {
898 Name(string) string
899 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700900 name = p.Name(name)
901 }
902 return name
903}
904
Alex Light3d673592019-01-18 14:37:31 -0800905func (c *Module) Symlinks() []string {
906 if p, ok := c.installer.(interface {
907 symlinkList() []string
908 }); ok {
909 return p.symlinkList()
910 }
911 return nil
912}
913
Jeff Gaston294356f2017-09-27 17:05:30 -0700914// orderDeps reorders dependencies into a list such that if module A depends on B, then
915// A will precede B in the resultant list.
916// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800917// Note that directSharedDeps should be the analogous static library for each shared lib dep
918func 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 -0700919 // If A depends on B, then
920 // Every list containing A will also contain B later in the list
921 // So, after concatenating all lists, the final instance of B will have come from the same
922 // original list as the final instance of A
923 // So, the final instance of B will be later in the concatenation than the final A
924 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
925 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800926 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700927 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800928 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
929 }
930 for _, dep := range directSharedDeps {
931 orderedAllDeps = append(orderedAllDeps, dep)
932 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700933 }
934
Colin Crossb6715442017-10-24 11:13:31 -0700935 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700936
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800937 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700938 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800939 // resultant list to only what the caller has chosen to include in directStaticDeps
940 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700941
942 return orderedAllDeps, orderedDeclaredDeps
943}
944
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800945func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
946 // convert Module to Path
947 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
948 staticDepFiles := []android.Path{}
949 for _, dep := range staticDeps {
950 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
951 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700952 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800953 sharedDepFiles := []android.Path{}
954 for _, sharedDep := range sharedDeps {
955 staticAnalogue := sharedDep.staticVariant
956 if staticAnalogue != nil {
957 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
958 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
959 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700960 }
961
962 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800963 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700964
965 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700966}
967
Roland Levillainf89cd092019-07-29 16:22:59 +0100968func (c *Module) IsTestPerSrcAllTestsVariation() bool {
969 test, ok := c.linker.(testPerSrc)
970 return ok && test.isAllTestsVariation()
971}
972
Colin Cross635c3b02016-05-18 15:37:25 -0700973func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +0100974 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +0100975 //
976 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
977 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
978 // module and return early, as this module does not produce an output file per se.
979 if c.IsTestPerSrcAllTestsVariation() {
980 c.outputFile = android.OptionalPath{}
981 return
Roland Levillainf2fad972019-06-28 15:41:19 +0100982 }
983
Jooyung Han38002912019-05-16 04:01:54 +0900984 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +0900985
Colin Crossca860ac2016-01-04 14:34:37 -0800986 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700987 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800988 moduleContextImpl: moduleContextImpl{
989 mod: c,
990 },
991 }
992 ctx.ctx = ctx
993
Colin Crossf18e1102017-11-16 14:33:08 -0800994 deps := c.depsToPaths(ctx)
995 if ctx.Failed() {
996 return
997 }
998
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700999 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1000 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1001 }
1002
Colin Crossca860ac2016-01-04 14:34:37 -08001003 flags := Flags{
1004 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001005 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001006 }
Colin Crossca860ac2016-01-04 14:34:37 -08001007 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001008 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001009 }
1010 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001011 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001012 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001013 if c.stl != nil {
1014 flags = c.stl.flags(ctx, flags)
1015 }
Colin Cross16b23492016-01-06 14:41:07 -08001016 if c.sanitize != nil {
1017 flags = c.sanitize.flags(ctx, flags)
1018 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001019 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001020 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001021 }
Stephen Craneba090d12017-05-09 15:44:35 -07001022 if c.lto != nil {
1023 flags = c.lto.flags(ctx, flags)
1024 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001025 if c.pgo != nil {
1026 flags = c.pgo.flags(ctx, flags)
1027 }
Ivan Lozano074ec482018-11-21 08:59:37 -08001028 if c.xom != nil {
1029 flags = c.xom.flags(ctx, flags)
1030 }
Colin Crossca860ac2016-01-04 14:34:37 -08001031 for _, feature := range c.features {
1032 flags = feature.flags(ctx, flags)
1033 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001034 if ctx.Failed() {
1035 return
1036 }
1037
Colin Crossb98c8b02016-07-29 13:44:28 -07001038 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
1039 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
1040 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001041
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001042 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001043
1044 for _, dir := range deps.IncludeDirs {
1045 flags.GlobalFlags = append(flags.GlobalFlags, "-I"+dir)
1046 }
1047 for _, dir := range deps.SystemIncludeDirs {
1048 flags.GlobalFlags = append(flags.GlobalFlags, "-isystem "+dir)
1049 }
1050
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001051 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001052 // We need access to all the flags seen by a source file.
1053 if c.sabi != nil {
1054 flags = c.sabi.flags(ctx, flags)
1055 }
Colin Crossca860ac2016-01-04 14:34:37 -08001056 // Optimization to reduce size of build.ninja
1057 // Replace the long list of flags for each file with a module-local variable
1058 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
1059 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
1060 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
1061 flags.CFlags = []string{"$cflags"}
1062 flags.CppFlags = []string{"$cppflags"}
1063 flags.AsFlags = []string{"$asflags"}
1064
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001065 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001066 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001067 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001068 if ctx.Failed() {
1069 return
1070 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001071 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001072 }
1073
Colin Crossca860ac2016-01-04 14:34:37 -08001074 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001075 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001076 if ctx.Failed() {
1077 return
1078 }
Colin Cross635c3b02016-05-18 15:37:25 -07001079 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001080
1081 // If a lib is directly included in any of the APEXes, unhide the stubs
1082 // variant having the latest version gets visible to make. In addition,
1083 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1084 // force anything in the make world to link against the stubs library.
1085 // (unless it is explicitly referenced via .bootstrap suffix or the
1086 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001087 if c.HasStubsVariants() &&
1088 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001089 !c.inRecovery() && !c.useVndk() && !c.static() && !c.isCoverageVariant() &&
1090 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001091 c.Properties.HideFromMake = false // unhide
1092 // Note: this is still non-installable
1093 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001094 }
Colin Cross5049f022015-03-18 13:28:46 -07001095
Inseob Kim1f086e22019-05-09 13:29:15 +09001096 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001097 c.installer.install(ctx, c.outputFile.Path())
1098 if ctx.Failed() {
1099 return
Colin Crossca860ac2016-01-04 14:34:37 -08001100 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001101 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001102}
1103
Colin Cross0ea8ba82019-06-06 14:33:29 -07001104func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001105 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001106 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001107 }
Colin Crossca860ac2016-01-04 14:34:37 -08001108 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001109}
1110
Colin Crossca860ac2016-01-04 14:34:37 -08001111func (c *Module) begin(ctx BaseModuleContext) {
1112 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001113 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001114 }
Colin Crossca860ac2016-01-04 14:34:37 -08001115 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001116 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001117 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001118 if c.stl != nil {
1119 c.stl.begin(ctx)
1120 }
Colin Cross16b23492016-01-06 14:41:07 -08001121 if c.sanitize != nil {
1122 c.sanitize.begin(ctx)
1123 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001124 if c.coverage != nil {
1125 c.coverage.begin(ctx)
1126 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001127 if c.sabi != nil {
1128 c.sabi.begin(ctx)
1129 }
Justin Yun8effde42017-06-23 19:24:43 +09001130 if c.vndkdep != nil {
1131 c.vndkdep.begin(ctx)
1132 }
Stephen Craneba090d12017-05-09 15:44:35 -07001133 if c.lto != nil {
1134 c.lto.begin(ctx)
1135 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001136 if c.pgo != nil {
1137 c.pgo.begin(ctx)
1138 }
Colin Crossca860ac2016-01-04 14:34:37 -08001139 for _, feature := range c.features {
1140 feature.begin(ctx)
1141 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001142 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001143 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001144 if err != nil {
1145 ctx.PropertyErrorf("sdk_version", err.Error())
1146 }
Nan Zhang0007d812017-11-07 10:57:05 -08001147 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001148 }
Colin Crossca860ac2016-01-04 14:34:37 -08001149}
1150
Colin Cross37047f12016-12-13 17:06:13 -08001151func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001152 deps := Deps{}
1153
1154 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001155 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001156 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001157 // Add the PGO dependency (the clang_rt.profile runtime library), which
1158 // sometimes depends on symbols from libgcc, before libgcc gets added
1159 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001160 if c.pgo != nil {
1161 deps = c.pgo.deps(ctx, deps)
1162 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001163 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001164 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001165 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001166 if c.stl != nil {
1167 deps = c.stl.deps(ctx, deps)
1168 }
Colin Cross16b23492016-01-06 14:41:07 -08001169 if c.sanitize != nil {
1170 deps = c.sanitize.deps(ctx, deps)
1171 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001172 if c.coverage != nil {
1173 deps = c.coverage.deps(ctx, deps)
1174 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001175 if c.sabi != nil {
1176 deps = c.sabi.deps(ctx, deps)
1177 }
Justin Yun8effde42017-06-23 19:24:43 +09001178 if c.vndkdep != nil {
1179 deps = c.vndkdep.deps(ctx, deps)
1180 }
Stephen Craneba090d12017-05-09 15:44:35 -07001181 if c.lto != nil {
1182 deps = c.lto.deps(ctx, deps)
1183 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001184 for _, feature := range c.features {
1185 deps = feature.deps(ctx, deps)
1186 }
1187
Colin Crossb6715442017-10-24 11:13:31 -07001188 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1189 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1190 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1191 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1192 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1193 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001194 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001195
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001196 for _, lib := range deps.ReexportSharedLibHeaders {
1197 if !inList(lib, deps.SharedLibs) {
1198 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1199 }
1200 }
1201
1202 for _, lib := range deps.ReexportStaticLibHeaders {
1203 if !inList(lib, deps.StaticLibs) {
1204 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1205 }
1206 }
1207
Colin Cross5950f382016-12-13 12:50:57 -08001208 for _, lib := range deps.ReexportHeaderLibHeaders {
1209 if !inList(lib, deps.HeaderLibs) {
1210 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1211 }
1212 }
1213
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001214 for _, gen := range deps.ReexportGeneratedHeaders {
1215 if !inList(gen, deps.GeneratedHeaders) {
1216 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1217 }
1218 }
1219
Colin Crossc99deeb2016-04-11 15:06:20 -07001220 return deps
1221}
1222
Dan Albert7e9d2952016-08-04 13:02:36 -07001223func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001224 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001225 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001226 moduleContextImpl: moduleContextImpl{
1227 mod: c,
1228 },
1229 }
1230 ctx.ctx = ctx
1231
Colin Crossca860ac2016-01-04 14:34:37 -08001232 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001233}
1234
Jiyong Park7ed9de32018-10-15 22:25:07 +09001235// Split name#version into name and version
1236func stubsLibNameAndVersion(name string) (string, string) {
1237 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1238 version := name[sharp+1:]
1239 libname := name[:sharp]
1240 return libname, version
1241 }
1242 return name, ""
1243}
1244
Colin Cross1e676be2016-10-12 14:38:15 -07001245func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001246 ctx := &depsContext{
1247 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001248 moduleContextImpl: moduleContextImpl{
1249 mod: c,
1250 },
1251 }
1252 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001253
Colin Crossc99deeb2016-04-11 15:06:20 -07001254 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001255
Dan Albert914449f2016-06-17 16:45:24 -07001256 variantNdkLibs := []string{}
1257 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001258 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001259 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001260
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001261 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1262 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001263 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001264 // 1. Name of an NDK library that refers to a prebuilt module.
1265 // For each of these, it adds the name of the prebuilt module (which will be in
1266 // prebuilts/ndk) to the list of nonvariant libs.
1267 // 2. Name of an NDK library that refers to an ndk_library module.
1268 // For each of these, it adds the name of the ndk_library module to the list of
1269 // variant libs.
1270 // 3. Anything else (so anything that isn't an NDK library).
1271 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001272 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001273 // The caller can then know to add the variantLibs dependencies differently from the
1274 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001275
1276 llndkLibraries := llndkLibraries(actx.Config())
1277 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001278 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1279 variantLibs = []string{}
1280 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001281 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001282 // strip #version suffix out
1283 name, _ := stubsLibNameAndVersion(entry)
1284 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1285 if !inList(name, ndkMigratedLibs) {
1286 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001287 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001288 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001289 }
Inseob Kim9516ee92019-05-09 10:56:13 +09001290 } else if ctx.useVndk() && inList(name, *llndkLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001291 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001292 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001293 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001294 if actx.OtherModuleExists(vendorPublicLib) {
1295 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1296 } else {
1297 // This can happen if vendor_public_library module is defined in a
1298 // namespace that isn't visible to the current module. In that case,
1299 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001300 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001301 }
Dan Albert914449f2016-06-17 16:45:24 -07001302 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001303 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001304 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001305 }
1306 }
Dan Albert914449f2016-06-17 16:45:24 -07001307 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001308 }
1309
Dan Albert914449f2016-06-17 16:45:24 -07001310 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1311 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001312 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001313 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001314
Jiyong Park7e636d02019-01-28 16:16:54 +09001315 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001316 if c.linker != nil {
1317 if library, ok := c.linker.(*libraryDecorator); ok {
1318 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001319 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001320 }
1321 }
1322 }
1323
Colin Cross32ec36c2016-12-15 07:39:51 -08001324 for _, lib := range deps.HeaderLibs {
1325 depTag := headerDepTag
1326 if inList(lib, deps.ReexportHeaderLibHeaders) {
1327 depTag = headerExportDepTag
1328 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001329 if buildStubs {
Jiyong Park7e636d02019-01-28 16:16:54 +09001330 actx.AddFarVariationDependencies([]blueprint.Variation{
1331 {Mutator: "arch", Variation: ctx.Target().String()},
Jiyong Park3b1746a2019-01-29 11:15:04 +09001332 {Mutator: "image", Variation: c.imageVariation()},
Jiyong Park7e636d02019-01-28 16:16:54 +09001333 }, depTag, lib)
1334 } else {
1335 actx.AddVariationDependencies(nil, depTag, lib)
1336 }
1337 }
1338
1339 if buildStubs {
1340 // Stubs lib does not have dependency to other static/shared libraries.
1341 // Don't proceed.
1342 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001343 }
Colin Cross5950f382016-12-13 12:50:57 -08001344
Inseob Kimc0907f12019-02-08 21:00:45 +09001345 syspropImplLibraries := syspropImplLibraries(actx.Config())
1346
Jiyong Park5d1598f2019-02-25 22:14:17 +09001347 for _, lib := range deps.WholeStaticLibs {
1348 depTag := wholeStaticDepTag
1349 if impl, ok := syspropImplLibraries[lib]; ok {
1350 lib = impl
1351 }
1352 actx.AddVariationDependencies([]blueprint.Variation{
1353 {Mutator: "link", Variation: "static"},
1354 }, depTag, lib)
1355 }
1356
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001357 for _, lib := range deps.StaticLibs {
1358 depTag := staticDepTag
1359 if inList(lib, deps.ReexportStaticLibHeaders) {
1360 depTag = staticExportDepTag
1361 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001362
1363 if impl, ok := syspropImplLibraries[lib]; ok {
1364 lib = impl
1365 }
1366
Dan Willemsen59339a22018-07-22 21:18:45 -07001367 actx.AddVariationDependencies([]blueprint.Variation{
1368 {Mutator: "link", Variation: "static"},
1369 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001370 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001371
Dan Willemsen59339a22018-07-22 21:18:45 -07001372 actx.AddVariationDependencies([]blueprint.Variation{
1373 {Mutator: "link", Variation: "static"},
1374 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001375
Jiyong Park25fc6a92018-11-18 18:02:45 +09001376 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1377 var variations []blueprint.Variation
1378 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001379 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001380 if version != "" && versionVariantAvail {
1381 // Version is explicitly specified. i.e. libFoo#30
1382 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1383 depTag.explicitlyVersioned = true
1384 }
1385 actx.AddVariationDependencies(variations, depTag, name)
1386
1387 // If the version is not specified, add dependency to the latest stubs library.
1388 // The stubs library will be used when the depending module is built for APEX and
1389 // the dependent module is not in the same APEX.
1390 latestVersion := latestStubsVersionFor(actx.Config(), name)
1391 if version == "" && latestVersion != "" && versionVariantAvail {
1392 actx.AddVariationDependencies([]blueprint.Variation{
1393 {Mutator: "link", Variation: "shared"},
1394 {Mutator: "version", Variation: latestVersion},
1395 }, depTag, name)
1396 // Note that depTag.explicitlyVersioned is false in this case.
1397 }
1398 }
1399
Jiyong Park7ed9de32018-10-15 22:25:07 +09001400 // shared lib names without the #version suffix
1401 var sharedLibNames []string
1402
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001403 for _, lib := range deps.SharedLibs {
1404 depTag := sharedDepTag
1405 if inList(lib, deps.ReexportSharedLibHeaders) {
1406 depTag = sharedExportDepTag
1407 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001408
1409 if impl, ok := syspropImplLibraries[lib]; ok {
1410 lib = impl
1411 }
1412
1413 name, version := stubsLibNameAndVersion(lib)
1414 sharedLibNames = append(sharedLibNames, name)
1415
Jiyong Park25fc6a92018-11-18 18:02:45 +09001416 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001417 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001418
Jiyong Park7ed9de32018-10-15 22:25:07 +09001419 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001420 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001421 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1422 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1423 // linking against both the stubs lib and the non-stubs lib at the same time.
1424 continue
1425 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001426 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001427 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001428
Dan Willemsen59339a22018-07-22 21:18:45 -07001429 actx.AddVariationDependencies([]blueprint.Variation{
1430 {Mutator: "link", Variation: "shared"},
1431 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001432
Colin Cross68861832016-07-08 10:41:41 -07001433 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001434
1435 for _, gen := range deps.GeneratedHeaders {
1436 depTag := genHeaderDepTag
1437 if inList(gen, deps.ReexportGeneratedHeaders) {
1438 depTag = genHeaderExportDepTag
1439 }
1440 actx.AddDependency(c, depTag, gen)
1441 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001442
Colin Cross42d48b72018-08-29 14:10:52 -07001443 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001444
1445 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001446 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001447 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001448 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001449 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001450 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001451 if deps.LinkerFlagsFile != "" {
1452 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1453 }
1454 if deps.DynamicLinker != "" {
1455 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001456 }
Dan Albert914449f2016-06-17 16:45:24 -07001457
1458 version := ctx.sdkVersion()
1459 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001460 {Mutator: "ndk_api", Variation: version},
1461 {Mutator: "link", Variation: "shared"},
1462 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001463 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001464 {Mutator: "ndk_api", Variation: version},
1465 {Mutator: "link", Variation: "shared"},
1466 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001467
1468 if vndkdep := c.vndkdep; vndkdep != nil {
1469 if vndkdep.isVndkExt() {
1470 baseModuleMode := vendorMode
1471 if actx.DeviceConfig().VndkVersion() == "" {
1472 baseModuleMode = coreMode
1473 }
1474 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001475 {Mutator: "image", Variation: baseModuleMode},
1476 {Mutator: "link", Variation: "shared"},
1477 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001478 }
1479 }
Colin Cross6362e272015-10-29 15:25:03 -07001480}
Colin Cross21b9a242015-03-24 14:15:58 -07001481
Colin Crosse40b4ea2018-10-02 22:25:58 -07001482func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001483 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1484 c.beginMutator(ctx)
1485 }
1486}
1487
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001488// Whether a module can link to another module, taking into
1489// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001490func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001491 if from.Target().Os != android.Android {
1492 // Host code is not restricted
1493 return
1494 }
1495 if from.Properties.UseVndk {
1496 // Though vendor code is limited by the vendor mutator,
1497 // each vendor-available module needs to check
1498 // link-type for VNDK.
1499 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001500 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001501 }
1502 return
1503 }
Nan Zhang0007d812017-11-07 10:57:05 -08001504 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001505 // Platform code can link to anything
1506 return
1507 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001508 if from.inRecovery() {
1509 // Recovery code is not NDK
1510 return
1511 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001512 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1513 // These are always allowed
1514 return
1515 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001516 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1517 // These are allowed, but they don't set sdk_version
1518 return
1519 }
1520 if _, ok := to.linker.(*stubDecorator); ok {
1521 // These aren't real libraries, but are the stub shared libraries that are included in
1522 // the NDK.
1523 return
1524 }
Logan Chien834b9a62019-01-14 15:39:03 +08001525
1526 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" {
1527 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1528 // to link to libc++ (non-NDK and without sdk_version).
1529 return
1530 }
1531
Nan Zhang0007d812017-11-07 10:57:05 -08001532 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001533 // NDK code linking to platform code is never okay.
1534 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1535 ctx.OtherModuleName(to))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001536 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001537 }
1538
1539 // At this point we know we have two NDK libraries, but we need to
1540 // check that we're not linking against anything built against a higher
1541 // API level, as it is only valid to link against older or equivalent
1542 // APIs.
1543
Inseob Kim01a28722018-04-11 09:48:45 +09001544 // Current can link against anything.
1545 if String(from.Properties.Sdk_version) != "current" {
1546 // Otherwise we need to check.
1547 if String(to.Properties.Sdk_version) == "current" {
1548 // Current can't be linked against by anything else.
1549 ctx.ModuleErrorf("links %q built against newer API version %q",
1550 ctx.OtherModuleName(to), "current")
1551 } else {
1552 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1553 if err != nil {
1554 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001555 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001556 String(from.Properties.Sdk_version))
1557 }
1558 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1559 if err != nil {
1560 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001561 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001562 String(to.Properties.Sdk_version))
1563 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001564
Inseob Kim01a28722018-04-11 09:48:45 +09001565 if toApi > fromApi {
1566 ctx.ModuleErrorf("links %q built against newer API version %q",
1567 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1568 }
1569 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001570 }
Dan Albert202fe492017-12-15 13:56:59 -08001571
1572 // Also check that the two STL choices are compatible.
1573 fromStl := from.stl.Properties.SelectedStl
1574 toStl := to.stl.Properties.SelectedStl
1575 if fromStl == "" || toStl == "" {
1576 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001577 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001578 // We can be permissive with the system "STL" since it is only the C++
1579 // ABI layer, but in the future we should make sure that everyone is
1580 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001581 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001582 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1583 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1584 to.stl.Properties.SelectedStl)
1585 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001586}
1587
Jiyong Park5fb8c102018-04-09 12:03:06 +09001588// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001589// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1590// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001591// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001592func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
Inseob Kim9516ee92019-05-09 10:56:13 +09001593 llndkLibraries := llndkLibraries(ctx.Config())
Jooyung Hana70f0672019-01-18 15:20:43 +09001594 check := func(child, parent android.Module) bool {
1595 to, ok := child.(*Module)
1596 if !ok {
1597 // follow thru cc.Defaults, etc.
1598 return true
1599 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001600
Jooyung Hana70f0672019-01-18 15:20:43 +09001601 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1602 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001603 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001604
1605 // if target lib has no vendor variant, keep checking dependency graph
1606 if !to.hasVendorVariant() {
1607 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001608 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001609
Inseob Kim9516ee92019-05-09 10:56:13 +09001610 if to.isVndkSp() || inList(child.Name(), *llndkLibraries) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001611 return false
1612 }
1613
1614 var stringPath []string
1615 for _, m := range ctx.GetWalkPath() {
1616 stringPath = append(stringPath, m.Name())
1617 }
1618 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1619 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1620 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1621 return false
1622 }
1623 if module, ok := ctx.Module().(*Module); ok {
1624 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Inseob Kim9516ee92019-05-09 10:56:13 +09001625 if inList(ctx.ModuleName(), *llndkLibraries) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001626 ctx.WalkDeps(check)
1627 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001628 }
1629 }
1630}
1631
Colin Crossc99deeb2016-04-11 15:06:20 -07001632// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001633func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001634 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001635
Jeff Gaston294356f2017-09-27 17:05:30 -07001636 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001637 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001638
Inseob Kim9516ee92019-05-09 10:56:13 +09001639 llndkLibraries := llndkLibraries(ctx.Config())
1640 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
1641
Inseob Kim69378442019-06-03 19:10:47 +09001642 reexportExporter := func(exporter exportedFlagsProducer) {
1643 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
1644 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
1645 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
1646 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
1647 }
1648
Colin Crossd11fcda2017-10-23 17:59:01 -07001649 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001650 depName := ctx.OtherModuleName(dep)
1651 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001652
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001653 ccDep, _ := dep.(*Module)
1654 if ccDep == nil {
1655 // handling for a few module types that aren't cc Module but that are also supported
1656 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001657 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001658 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001659 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1660 genRule.GeneratedSourceFiles()...)
1661 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001662 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001663 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001664 // Support exported headers from a generated_sources dependency
1665 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001666 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001667 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001668 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001669 genRule.GeneratedDeps()...)
Inseob Kim69378442019-06-03 19:10:47 +09001670 dirs := genRule.GeneratedHeaderDirs().Strings()
1671 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001672 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09001673 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
1674 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001675 // 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 +09001676 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001677
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001678 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001679 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001680 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001681 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001682 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001683 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001684 files := genRule.GeneratedSourceFiles()
1685 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001686 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001687 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001688 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 -07001689 }
1690 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001691 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001692 }
Colin Crossca860ac2016-01-04 14:34:37 -08001693 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001694 return
1695 }
1696
Colin Crossfe17f6f2019-03-28 19:30:56 -07001697 if depTag == android.ProtoPluginDepTag {
1698 return
1699 }
1700
Colin Crossd11fcda2017-10-23 17:59:01 -07001701 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001702 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1703 return
1704 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001705 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001706 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001707 return
1708 }
1709
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001710 // re-exporting flags
1711 if depTag == reuseObjTag {
1712 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001713 c.staticVariant = ccDep
Inseob Kim69378442019-06-03 19:10:47 +09001714 objs, exporter := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001715 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09001716 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08001717 return
1718 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001719 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001720
Jiyong Parke4bb9862019-02-01 00:31:10 +09001721 if depTag == staticVariantTag {
1722 if _, ok := ccDep.compiler.(libraryInterface); ok {
1723 c.staticVariant = ccDep
1724 return
1725 }
1726 }
1727
Jiyong Park25fc6a92018-11-18 18:02:45 +09001728 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1729 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1730 // won't be matched to sharedDepTag and lateSharedDepTag.
1731 explicitlyVersioned := false
1732 if t, ok := depTag.(dependencyTag); ok {
1733 explicitlyVersioned = t.explicitlyVersioned
1734 t.explicitlyVersioned = false
1735 depTag = t
1736 }
1737
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001738 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001739 depIsStatic := false
1740 switch depTag {
1741 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1742 depIsStatic = true
1743 }
1744 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001745 depIsStubs := dependentLibrary.buildStubs()
1746 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001747 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001748 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001749
1750 var useThisDep bool
1751 if depIsStubs && explicitlyVersioned {
1752 // Always respect dependency to the versioned stubs (i.e. libX#10)
1753 useThisDep = true
1754 } else if !depHasStubs {
1755 // Use non-stub variant if that is the only choice
1756 // (i.e. depending on a lib without stubs.version property)
1757 useThisDep = true
1758 } else if c.IsForPlatform() {
1759 // If not building for APEX, use stubs only when it is from
1760 // an APEX (and not from platform)
1761 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001762 if c.inRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001763 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001764 // always link to non-stub variant
1765 useThisDep = !depIsStubs
1766 }
1767 } else {
1768 // If building for APEX, use stubs only when it is not from
1769 // the same APEX
1770 useThisDep = (depInSameApex != depIsStubs)
1771 }
1772
1773 if !useThisDep {
1774 return // stop processing this dep
1775 }
1776 }
1777
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001778 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Inseob Kim69378442019-06-03 19:10:47 +09001779 depPaths.IncludeDirs = append(depPaths.IncludeDirs, i.exportedDirs()...)
1780 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
1781 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedDeps()...)
1782 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001783
1784 if t.reexportFlags {
Inseob Kim69378442019-06-03 19:10:47 +09001785 reexportExporter(i)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001786 // 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 -07001787 // Re-exported shared library headers must be included as well since they can help us with type information
1788 // about template instantiations (instantiated from their headers).
Inseob Kim69378442019-06-03 19:10:47 +09001789 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
1790 // scripts.
1791 c.sabi.Properties.ReexportedIncludes = append(
1792 c.sabi.Properties.ReexportedIncludes, i.exportedDirs()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001793 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001794 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001795
Logan Chienf3511742017-10-31 18:04:35 +08001796 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001797 }
1798
Colin Cross26c34ed2016-09-30 17:10:16 -07001799 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001800 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001801
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001802 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001803 depFile := android.OptionalPath{}
1804
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001805 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001806 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001807 ptr = &depPaths.SharedLibs
1808 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001809 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001810 directSharedDeps = append(directSharedDeps, ccDep)
Jiyong Park64a44f22019-01-18 14:37:08 +09001811 case earlySharedDepTag:
1812 ptr = &depPaths.EarlySharedLibs
1813 depPtr = &depPaths.EarlySharedLibsDeps
1814 depFile = ccDep.linker.(libraryInterface).toc()
1815 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001816 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001817 ptr = &depPaths.LateSharedLibs
1818 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001819 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001820 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001821 ptr = nil
1822 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001823 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001824 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001825 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001826 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001827 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001828 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001829 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001830 return
1831 }
1832
1833 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001834 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001835 for i := range missingDeps {
1836 missingDeps[i] += postfix
1837 }
1838 ctx.AddMissingDependencies(missingDeps)
1839 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001840 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001841 case headerDepTag:
1842 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001843 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001844 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001845 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001846 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001847 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001848 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001849 case dynamicLinkerDepTag:
1850 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001851 }
1852
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001853 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001854 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001855 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001856 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001857 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001858 return
1859 }
1860
1861 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001862 // in static libraries act as if they were whole static libraries. The same goes for
1863 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001864 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1865 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001866 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1867 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001868
Dan Willemsen581341d2017-02-09 16:16:31 -08001869 }
1870
Colin Cross26c34ed2016-09-30 17:10:16 -07001871 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001872 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001873 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001874 return
1875 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001876 *ptr = append(*ptr, linkFile.Path())
1877 }
1878
Colin Crossc99deeb2016-04-11 15:06:20 -07001879 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001880 dep := depFile
1881 if !dep.Valid() {
1882 dep = linkFile
1883 }
1884 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001885 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001886
Logan Chien43d34c32017-12-20 01:17:32 +08001887 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001888 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001889 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001890 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kim9516ee92019-05-09 10:56:13 +09001891 isLLndk := inList(libName, *llndkLibraries)
1892 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001893 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08001894
yidong.zhangd06ecc82019-08-02 15:49:24 +08001895 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.isVndk() && !ccDep.mustUseVendorVariant() && !c.inRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08001896 // The vendor module is a no-vendor-variant VNDK library. Depend on the
1897 // core module instead.
1898 return libName
1899 } else if c.useVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001900 // The vendor module in Make will have been renamed to not conflict with the core
1901 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001902 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001903 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001904 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001905 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1906 return libName + recoverySuffix
dimitry1f33e402019-03-26 12:39:31 +01001907 } else if ccDep.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02001908 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001909 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001910 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001911 }
Logan Chien43d34c32017-12-20 01:17:32 +08001912 }
1913
1914 // Export the shared libs to Make.
1915 switch depTag {
Jiyong Park64a44f22019-01-18 14:37:08 +09001916 case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001917 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001918 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08001919 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09001920 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001921 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001922 c.Properties.ApexesProvidingSharedLibs = append(
1923 c.Properties.ApexesProvidingSharedLibs, an)
1924 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09001925 }
1926 }
1927
Jiyong Park27b188b2017-07-18 13:23:39 +09001928 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001929 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001930 c.Properties.AndroidMkSharedLibs = append(
1931 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08001932 case ndkStubDepTag, ndkLateStubDepTag:
1933 ndkStub := ccDep.linker.(*stubDecorator)
1934 c.Properties.AndroidMkSharedLibs = append(
1935 c.Properties.AndroidMkSharedLibs,
1936 depName+"."+ndkStub.properties.ApiLevel)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001937 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1938 c.Properties.AndroidMkStaticLibs = append(
1939 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001940 case runtimeDepTag:
1941 c.Properties.AndroidMkRuntimeLibs = append(
1942 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001943 case wholeStaticDepTag:
1944 c.Properties.AndroidMkWholeStaticLibs = append(
1945 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001946 }
Colin Crossca860ac2016-01-04 14:34:37 -08001947 })
1948
Jeff Gaston294356f2017-09-27 17:05:30 -07001949 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001950 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001951
Colin Crossdd84e052017-05-17 13:44:16 -07001952 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001953 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Inseob Kim69378442019-06-03 19:10:47 +09001954 depPaths.IncludeDirs = android.FirstUniqueStrings(depPaths.IncludeDirs)
1955 depPaths.SystemIncludeDirs = android.FirstUniqueStrings(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001956 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kim69378442019-06-03 19:10:47 +09001957 depPaths.ReexportedDirs = android.FirstUniqueStrings(depPaths.ReexportedDirs)
1958 depPaths.ReexportedSystemDirs = android.FirstUniqueStrings(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07001959 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09001960 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001961
1962 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09001963 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001964 }
Colin Crossdd84e052017-05-17 13:44:16 -07001965
Colin Crossca860ac2016-01-04 14:34:37 -08001966 return depPaths
1967}
1968
1969func (c *Module) InstallInData() bool {
1970 if c.installer == nil {
1971 return false
1972 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001973 return c.installer.inData()
1974}
1975
1976func (c *Module) InstallInSanitizerDir() bool {
1977 if c.installer == nil {
1978 return false
1979 }
1980 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001981 return true
1982 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001983 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001984}
1985
Jiyong Parkf9332f12018-02-01 00:54:12 +09001986func (c *Module) InstallInRecovery() bool {
1987 return c.inRecovery()
1988}
1989
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001990func (c *Module) HostToolPath() android.OptionalPath {
1991 if c.installer == nil {
1992 return android.OptionalPath{}
1993 }
1994 return c.installer.hostToolPath()
1995}
1996
Nan Zhangd4e641b2017-07-12 12:55:28 -07001997func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1998 return c.outputFile
1999}
2000
Colin Cross41955e82019-05-29 14:40:35 -07002001func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2002 switch tag {
2003 case "":
2004 if c.outputFile.Valid() {
2005 return android.Paths{c.outputFile.Path()}, nil
2006 }
2007 return android.Paths{}, nil
2008 default:
2009 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002010 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002011}
2012
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002013func (c *Module) static() bool {
2014 if static, ok := c.linker.(interface {
2015 static() bool
2016 }); ok {
2017 return static.static()
2018 }
2019 return false
2020}
2021
Jiyong Park379de2f2018-12-19 02:47:14 +09002022func (c *Module) staticBinary() bool {
2023 if static, ok := c.linker.(interface {
2024 staticBinary() bool
2025 }); ok {
2026 return static.staticBinary()
2027 }
2028 return false
2029}
2030
Jiyong Park1d1119f2019-07-29 21:27:18 +09002031func (c *Module) header() bool {
2032 if h, ok := c.linker.(interface {
2033 header() bool
2034 }); ok {
2035 return h.header()
2036 }
2037 return false
2038}
2039
Jooyung Han38002912019-05-16 04:01:54 +09002040func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
2041 name := actx.ModuleName()
Colin Crossb60190a2018-09-04 16:28:17 -07002042 if c.useVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002043 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2044 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002045 return "native:vndk"
2046 }
Jooyung Han38002912019-05-16 04:01:54 +09002047 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002048 }
Jooyung Han38002912019-05-16 04:01:54 +09002049 if c.isVndk() && !c.isVndkExt() {
2050 if Bool(c.VendorProperties.Vendor_available) {
2051 return "native:vndk"
2052 }
2053 return "native:vndk_private"
2054 }
2055 return "native:vendor"
Colin Crossb60190a2018-09-04 16:28:17 -07002056 } else if c.inRecovery() {
2057 return "native:recovery"
2058 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2059 return "native:ndk:none:none"
2060 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2061 //family, link := getNdkStlFamilyAndLinkType(c)
2062 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Jooyung Han38002912019-05-16 04:01:54 +09002063 } else if inList(name, *vndkUsingCoreVariantLibraries(actx.Config())) {
Vic Yangefd249e2018-11-12 20:19:56 -08002064 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002065 } else {
2066 return "native:platform"
2067 }
2068}
2069
Jiyong Park9d452992018-10-03 00:38:19 +09002070// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002071// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002072func (c *Module) IsInstallableToApex() bool {
2073 if shared, ok := c.linker.(interface {
2074 shared() bool
2075 }); ok {
2076 return shared.shared()
Roland Levillainf89cd092019-07-29 16:22:59 +01002077 } else if _, ok := c.linker.(testPerSrc); ok {
2078 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002079 }
2080 return false
2081}
2082
Inseob Kim1f086e22019-05-09 13:29:15 +09002083func (c *Module) installable() bool {
2084 return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
2085}
2086
Jiyong Park3b1746a2019-01-29 11:15:04 +09002087func (c *Module) imageVariation() string {
2088 variation := "core"
2089 if c.useVndk() {
2090 variation = "vendor"
2091 } else if c.inRecovery() {
2092 variation = "recovery"
2093 }
2094 return variation
2095}
2096
bralee3f49f4d2019-03-04 06:58:15 +08002097func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
Colin Cross41955e82019-05-29 14:40:35 -07002098 outputFiles, err := c.OutputFiles("")
2099 if err != nil {
2100 panic(err)
2101 }
2102 dpInfo.Srcs = append(dpInfo.Srcs, outputFiles.Strings()...)
bralee3f49f4d2019-03-04 06:58:15 +08002103}
2104
Logan Chien41eabe62019-04-10 13:33:58 +08002105func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2106 if c.linker != nil {
2107 if library, ok := c.linker.(*libraryDecorator); ok {
2108 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2109 }
2110 }
2111}
2112
Colin Cross2ba19d92015-05-07 15:44:20 -07002113//
Colin Crosscfad1192015-11-02 16:43:11 -08002114// Defaults
2115//
Colin Crossca860ac2016-01-04 14:34:37 -08002116type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002117 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002118 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002119 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002120}
2121
Patrice Arrudac249c712019-03-19 17:00:29 -07002122// cc_defaults provides a set of properties that can be inherited by other cc
2123// modules. A module can use the properties from a cc_defaults using
2124// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2125// merged (when possible) by prepending the default module's values to the
2126// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002127func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002128 return DefaultsFactory()
2129}
2130
Colin Cross36242852017-06-23 15:06:31 -07002131func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002132 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002133
Colin Cross36242852017-06-23 15:06:31 -07002134 module.AddProperties(props...)
2135 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002136 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002137 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002138 &BaseCompilerProperties{},
2139 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002140 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002141 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002142 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002143 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002144 &TestProperties{},
2145 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002146 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002147 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002148 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002149 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002150 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002151 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002152 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002153 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002154 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002155 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002156 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002157 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002158 )
Colin Crosscfad1192015-11-02 16:43:11 -08002159
Colin Cross1f44a3a2017-07-07 14:33:33 -07002160 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09002161 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002162
2163 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002164}
2165
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002166const (
2167 // coreMode is the variant used for framework-private libraries, or
2168 // SDK libraries. (which framework-private libraries can use)
2169 coreMode = "core"
2170
2171 // vendorMode is the variant used for /vendor code that compiles
2172 // against the VNDK.
2173 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09002174
2175 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002176)
2177
Jiyong Park6a43f042017-10-12 23:05:00 +09002178func squashVendorSrcs(m *Module) {
2179 if lib, ok := m.compiler.(*libraryDecorator); ok {
2180 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2181 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2182
2183 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2184 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2185 }
2186}
2187
Jiyong Parkf9332f12018-02-01 00:54:12 +09002188func squashRecoverySrcs(m *Module) {
2189 if lib, ok := m.compiler.(*libraryDecorator); ok {
2190 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2191 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2192
2193 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2194 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2195 }
2196}
2197
Jiyong Parkda6eb592018-12-19 17:12:36 +09002198func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002199 if mctx.Os() != android.Android {
2200 return
2201 }
2202
Jiyong Park7ed9de32018-10-15 22:25:07 +09002203 if g, ok := mctx.Module().(*genrule.Module); ok {
2204 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09002205 var coreVariantNeeded bool = false
2206 var vendorVariantNeeded bool = false
2207 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09002208 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09002209 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002210 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09002211 coreVariantNeeded = true
2212 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09002213 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09002214 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002215 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09002216 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002217 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002218 if Bool(props.Recovery_available) {
2219 recoveryVariantNeeded = true
2220 }
2221
Jiyong Park413cc742018-06-19 01:46:06 +09002222 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002223 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09002224 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09002225 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002226 recoveryVariantNeeded = false
2227 }
2228 }
2229
Jiyong Park3f736c92018-05-24 13:36:56 +09002230 var variants []string
2231 if coreVariantNeeded {
2232 variants = append(variants, coreMode)
2233 }
2234 if vendorVariantNeeded {
2235 variants = append(variants, vendorMode)
2236 }
2237 if recoveryVariantNeeded {
2238 variants = append(variants, recoveryMode)
2239 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002240 mod := mctx.CreateVariations(variants...)
2241 for i, v := range variants {
2242 if v == recoveryMode {
2243 m := mod[i].(*genrule.Module)
2244 m.Extra.(*GenruleExtraProperties).InRecovery = true
2245 }
2246 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002247 }
2248 }
2249
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002250 m, ok := mctx.Module().(*Module)
2251 if !ok {
2252 return
2253 }
2254
2255 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002256 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002257 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002258
2259 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002260 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002261 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002262 return
2263 }
Logan Chienf3511742017-10-31 18:04:35 +08002264
2265 if vndkdep := m.vndkdep; vndkdep != nil {
2266 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002267 if productSpecific {
2268 mctx.PropertyErrorf("product_specific",
2269 "product_specific must not be true when `vndk: {enabled: true}`")
2270 return
2271 }
Logan Chienf3511742017-10-31 18:04:35 +08002272 if vendorSpecific {
2273 if !vndkdep.isVndkExt() {
2274 mctx.PropertyErrorf("vndk",
2275 "must set `extends: \"...\"` to vndk extension")
2276 return
2277 }
2278 } else {
2279 if vndkdep.isVndkExt() {
2280 mctx.PropertyErrorf("vndk",
2281 "must set `vendor: true` to set `extends: %q`",
2282 m.getVndkExtendsModuleName())
2283 return
2284 }
2285 if m.VendorProperties.Vendor_available == nil {
2286 mctx.PropertyErrorf("vndk",
2287 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2288 return
2289 }
2290 }
2291 } else {
2292 if vndkdep.isVndkSp() {
2293 mctx.PropertyErrorf("vndk",
2294 "must set `enabled: true` to set `support_system_process: true`")
2295 return
2296 }
2297 if vndkdep.isVndkExt() {
2298 mctx.PropertyErrorf("vndk",
2299 "must set `enabled: true` to set `extends: %q`",
2300 m.getVndkExtendsModuleName())
2301 return
2302 }
Justin Yun8effde42017-06-23 19:24:43 +09002303 }
2304 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002305
Jiyong Parkf9332f12018-02-01 00:54:12 +09002306 var coreVariantNeeded bool = false
2307 var vendorVariantNeeded bool = false
2308 var recoveryVariantNeeded bool = false
2309
Justin Yun71549282017-11-17 12:10:28 +09002310 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002311 // If the device isn't compiling against the VNDK, we always
2312 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002313 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002314 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2315 // LL-NDK stubs only exist in the vendor variant, since the
2316 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002317 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09002318 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2319 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09002320 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09002321 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002322 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2323 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002324 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002325 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002326 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002327 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002328 coreVariantNeeded = true
2329 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002330 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002331 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09002332 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002333 } else {
2334 // This is either in /system (or similar: /data), or is a
2335 // modules built with the NDK. Modules built with the NDK
2336 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002337 coreVariantNeeded = true
2338 }
2339
2340 if Bool(m.Properties.Recovery_available) {
2341 recoveryVariantNeeded = true
2342 }
2343
2344 if m.ModuleBase.InstallInRecovery() {
2345 recoveryVariantNeeded = true
2346 coreVariantNeeded = false
2347 }
2348
Jiyong Park413cc742018-06-19 01:46:06 +09002349 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002350 primaryArch := mctx.Config().DevicePrimaryArchType()
2351 moduleArch := m.Target().Arch.ArchType
2352 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002353 recoveryVariantNeeded = false
2354 }
2355 }
2356
Jiyong Parkf9332f12018-02-01 00:54:12 +09002357 var variants []string
2358 if coreVariantNeeded {
2359 variants = append(variants, coreMode)
2360 }
2361 if vendorVariantNeeded {
2362 variants = append(variants, vendorMode)
2363 }
2364 if recoveryVariantNeeded {
2365 variants = append(variants, recoveryMode)
2366 }
2367 mod := mctx.CreateVariations(variants...)
2368 for i, v := range variants {
2369 if v == vendorMode {
2370 m := mod[i].(*Module)
2371 m.Properties.UseVndk = true
2372 squashVendorSrcs(m)
2373 } else if v == recoveryMode {
2374 m := mod[i].(*Module)
2375 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002376 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002377 squashRecoverySrcs(m)
2378 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002379 }
2380}
2381
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002382func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002383 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002384 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2385 }
Colin Cross6510f912017-11-29 00:27:14 -08002386 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002387}
2388
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002389func kytheExtractAllFactory() android.Singleton {
2390 return &kytheExtractAllSingleton{}
2391}
2392
2393type kytheExtractAllSingleton struct {
2394}
2395
2396func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2397 var xrefTargets android.Paths
2398 ctx.VisitAllModules(func(module android.Module) {
2399 if ccModule, ok := module.(xref); ok {
2400 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
2401 }
2402 })
2403 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
2404 if len(xrefTargets) > 0 {
2405 ctx.Build(pctx, android.BuildParams{
2406 Rule: blueprint.Phony,
2407 Output: android.PathForPhony(ctx, "xref_cxx"),
2408 Inputs: xrefTargets,
2409 //Default: true,
2410 })
2411 }
2412}
2413
Colin Cross06a931b2015-10-28 17:23:31 -07002414var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002415var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002416var BoolPtr = proptools.BoolPtr
2417var String = proptools.String
2418var StringPtr = proptools.StringPtr