blob: 26cec900842c82e1700992aeb03dded03089d77b [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
Ivan Lozanoffee3342019-08-27 12:03:00 -0700394func SharedDepTag() dependencyTag {
395 return sharedDepTag
396}
397
398func StaticDepTag() dependencyTag {
399 return staticDepTag
400}
401
Colin Crossca860ac2016-01-04 14:34:37 -0800402// Module contains the properties and members used by all C/C++ module types, and implements
403// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
404// to construct the output file. Behavior can be customized with a Customizer interface
405type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700406 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700407 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900408 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700409
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700410 Properties BaseProperties
411 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700412
Colin Crossca860ac2016-01-04 14:34:37 -0800413 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700414 hod android.HostOrDeviceSupported
415 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700416
Colin Crossca860ac2016-01-04 14:34:37 -0800417 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700418 features []feature
419 compiler compiler
420 linker linker
421 installer installer
422 stl *stl
423 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800424 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800425 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900426 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700427 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700428 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800429 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800430
431 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700432
Colin Cross635c3b02016-05-18 15:37:25 -0700433 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800434
Colin Crossb98c8b02016-07-29 13:44:28 -0700435 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700436
437 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800438
439 // Flags used to compile this module
440 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700441
442 // 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 -0800443 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700444 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800445 depsInLinkOrder android.Paths
446
447 // only non-nil when this is a shared library that reuses the objects of a static library
448 staticVariant *Module
Inseob Kim9516ee92019-05-09 10:56:13 +0900449
450 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800451 // Kythe (source file indexer) paths for this compilation module
452 kytheFiles android.Paths
Colin Crossc472d572015-03-17 15:06:21 -0700453}
454
Jiyong Parkc20eee32018-09-05 22:36:17 +0900455func (c *Module) OutputFile() android.OptionalPath {
456 return c.outputFile
457}
458
Jiyong Park719b4462019-01-13 00:39:51 +0900459func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900460 if c.linker != nil {
461 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900462 }
463 return nil
464}
465
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900466func (c *Module) CoverageOutputFile() android.OptionalPath {
467 if c.linker != nil {
468 return c.linker.coverageOutputFilePath()
469 }
470 return android.OptionalPath{}
471}
472
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900473func (c *Module) RelativeInstallPath() string {
474 if c.installer != nil {
475 return c.installer.relativeInstallPath()
476 }
477 return ""
478}
479
Colin Cross36242852017-06-23 15:06:31 -0700480func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700481 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800482 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700483 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800484 }
485 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700486 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800487 }
488 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700489 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800490 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700491 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700492 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700493 }
Colin Cross16b23492016-01-06 14:41:07 -0800494 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700495 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800496 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800497 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700498 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800499 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800500 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700501 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800502 }
Justin Yun8effde42017-06-23 19:24:43 +0900503 if c.vndkdep != nil {
504 c.AddProperties(c.vndkdep.props()...)
505 }
Stephen Craneba090d12017-05-09 15:44:35 -0700506 if c.lto != nil {
507 c.AddProperties(c.lto.props()...)
508 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700509 if c.pgo != nil {
510 c.AddProperties(c.pgo.props()...)
511 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800512 if c.xom != nil {
513 c.AddProperties(c.xom.props()...)
514 }
Colin Crossca860ac2016-01-04 14:34:37 -0800515 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700516 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800517 }
Colin Crossc472d572015-03-17 15:06:21 -0700518
Colin Crossa9d8bee2018-10-02 13:59:46 -0700519 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
520 switch class {
521 case android.Device:
522 return ctx.Config().DevicePrefer32BitExecutables()
523 case android.HostCross:
524 // Windows builds always prefer 32-bit
525 return true
526 default:
527 return false
528 }
529 })
Colin Cross36242852017-06-23 15:06:31 -0700530 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700531
Colin Cross1f44a3a2017-07-07 14:33:33 -0700532 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700533
Jiyong Park9d452992018-10-03 00:38:19 +0900534 android.InitApexModule(c)
535
Colin Cross36242852017-06-23 15:06:31 -0700536 return c
Colin Crossc472d572015-03-17 15:06:21 -0700537}
538
Colin Crossb916a382016-07-29 17:28:03 -0700539// Returns true for dependency roots (binaries)
540// TODO(ccross): also handle dlopenable libraries
541func (c *Module) isDependencyRoot() bool {
542 if root, ok := c.linker.(interface {
543 isDependencyRoot() bool
544 }); ok {
545 return root.isDependencyRoot()
546 }
547 return false
548}
549
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700550func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700551 return c.Properties.UseVndk
552}
553
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800554func (c *Module) isCoverageVariant() bool {
555 return c.coverage.Properties.IsCoverageVariant
556}
557
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800558func (c *Module) isNdk() bool {
559 return inList(c.Name(), ndkMigratedLibs)
560}
561
Inseob Kim9516ee92019-05-09 10:56:13 +0900562func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800563 // Returns true for both LLNDK (public) and LLNDK-private libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900564 return inList(c.Name(), *llndkLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800565}
566
Inseob Kim9516ee92019-05-09 10:56:13 +0900567func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800568 // Returns true only for LLNDK (public) libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900569 return c.isLlndk(config) && !c.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800570}
571
Inseob Kim9516ee92019-05-09 10:56:13 +0900572func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800573 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Inseob Kim9516ee92019-05-09 10:56:13 +0900574 return inList(c.Name(), *vndkPrivateLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800575}
576
Justin Yun8effde42017-06-23 19:24:43 +0900577func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800578 if vndkdep := c.vndkdep; vndkdep != nil {
579 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900580 }
581 return false
582}
583
Jooyung Han76106d92019-05-20 18:49:10 +0900584func (c *Module) vndkVersion() string {
585 if vndkdep := c.vndkdep; vndkdep != nil {
586 return vndkdep.Properties.Vndk.Version
587 }
588 return ""
589}
590
Yi Kong7e53c572018-02-14 18:16:12 +0800591func (c *Module) isPgoCompile() bool {
592 if pgo := c.pgo; pgo != nil {
593 return pgo.Properties.PgoCompile
594 }
595 return false
596}
597
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800598func (c *Module) isNDKStubLibrary() bool {
599 if _, ok := c.compiler.(*stubDecorator); ok {
600 return true
601 }
602 return false
603}
604
Logan Chienf3511742017-10-31 18:04:35 +0800605func (c *Module) isVndkSp() bool {
606 if vndkdep := c.vndkdep; vndkdep != nil {
607 return vndkdep.isVndkSp()
608 }
609 return false
610}
611
612func (c *Module) isVndkExt() bool {
613 if vndkdep := c.vndkdep; vndkdep != nil {
614 return vndkdep.isVndkExt()
615 }
616 return false
617}
618
Vic Yangefd249e2018-11-12 20:19:56 -0800619func (c *Module) mustUseVendorVariant() bool {
620 return c.isVndkSp() || inList(c.Name(), config.VndkMustUseVendorVariantList)
621}
622
Logan Chienf3511742017-10-31 18:04:35 +0800623func (c *Module) getVndkExtendsModuleName() string {
624 if vndkdep := c.vndkdep; vndkdep != nil {
625 return vndkdep.getVndkExtendsModuleName()
626 }
627 return ""
628}
629
Jiyong Park82e2bf32017-08-16 14:05:54 +0900630// Returns true only when this module is configured to have core and vendor
631// variants.
632func (c *Module) hasVendorVariant() bool {
633 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
634}
635
Jiyong Parkf9332f12018-02-01 00:54:12 +0900636func (c *Module) inRecovery() bool {
637 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
638}
639
640func (c *Module) onlyInRecovery() bool {
641 return c.ModuleBase.InstallInRecovery()
642}
643
Jiyong Park25fc6a92018-11-18 18:02:45 +0900644func (c *Module) IsStubs() bool {
645 if library, ok := c.linker.(*libraryDecorator); ok {
646 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900647 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
648 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900649 }
650 return false
651}
652
653func (c *Module) HasStubsVariants() bool {
654 if library, ok := c.linker.(*libraryDecorator); ok {
655 return len(library.Properties.Stubs.Versions) > 0
656 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700657 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
658 return len(library.Properties.Stubs.Versions) > 0
659 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900660 return false
661}
662
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900663func (c *Module) bootstrap() bool {
664 return Bool(c.Properties.Bootstrap)
665}
666
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700667func (c *Module) nativeCoverage() bool {
668 return c.linker != nil && c.linker.nativeCoverage()
669}
670
Jiyong Parkf1194352019-02-25 11:05:47 +0900671func isBionic(name string) bool {
672 switch name {
673 case "libc", "libm", "libdl", "linker":
674 return true
675 }
676 return false
677}
678
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700679func installToBootstrap(name string, config android.Config) bool {
680 if name == "libclang_rt.hwasan-aarch64-android" {
681 return inList("hwaddress", config.SanitizeDevice())
682 }
683 return isBionic(name)
684}
685
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800686func (c *Module) XrefCcFiles() android.Paths {
687 return c.kytheFiles
688}
689
Colin Crossca860ac2016-01-04 14:34:37 -0800690type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700691 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800692 moduleContextImpl
693}
694
Colin Cross37047f12016-12-13 17:06:13 -0800695type depsContext struct {
696 android.BottomUpMutatorContext
697 moduleContextImpl
698}
699
Colin Crossca860ac2016-01-04 14:34:37 -0800700type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700701 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800702 moduleContextImpl
703}
704
Jiyong Park2db76922017-11-08 16:03:48 +0900705func (ctx *moduleContext) SocSpecific() bool {
706 return ctx.ModuleContext.SocSpecific() ||
707 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700708}
709
Colin Crossca860ac2016-01-04 14:34:37 -0800710type moduleContextImpl struct {
711 mod *Module
712 ctx BaseModuleContext
713}
714
Colin Crossb98c8b02016-07-29 13:44:28 -0700715func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800716 return ctx.mod.toolchain(ctx.ctx)
717}
718
719func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000720 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800721}
722
723func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900724 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800725}
726
Jiyong Park1d1119f2019-07-29 21:27:18 +0900727func (ctx *moduleContextImpl) header() bool {
728 return ctx.mod.header()
729}
730
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700731func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800732 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800733 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700734 }
735 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800736}
737
738func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700739 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700740 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900741 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700742 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900743 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
744 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
745 return "current"
746 }
747 return platform_vndk_ver
748 }
749 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800750 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900751 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700752 }
753 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800754}
755
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700756func (ctx *moduleContextImpl) useVndk() bool {
757 return ctx.mod.useVndk()
758}
Justin Yun8effde42017-06-23 19:24:43 +0900759
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800760func (ctx *moduleContextImpl) isNdk() bool {
761 return ctx.mod.isNdk()
762}
763
Inseob Kim9516ee92019-05-09 10:56:13 +0900764func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
765 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800766}
767
Inseob Kim9516ee92019-05-09 10:56:13 +0900768func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
769 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800770}
771
Inseob Kim9516ee92019-05-09 10:56:13 +0900772func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
773 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800774}
775
Logan Chienf3511742017-10-31 18:04:35 +0800776func (ctx *moduleContextImpl) isVndk() bool {
777 return ctx.mod.isVndk()
778}
779
Yi Kong7e53c572018-02-14 18:16:12 +0800780func (ctx *moduleContextImpl) isPgoCompile() bool {
781 return ctx.mod.isPgoCompile()
782}
783
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800784func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
785 return ctx.mod.isNDKStubLibrary()
786}
787
Justin Yun8effde42017-06-23 19:24:43 +0900788func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800789 return ctx.mod.isVndkSp()
790}
791
792func (ctx *moduleContextImpl) isVndkExt() bool {
793 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900794}
795
Vic Yangefd249e2018-11-12 20:19:56 -0800796func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
797 return ctx.mod.mustUseVendorVariant()
798}
799
Jiyong Parkf9332f12018-02-01 00:54:12 +0900800func (ctx *moduleContextImpl) inRecovery() bool {
801 return ctx.mod.inRecovery()
802}
803
Logan Chien2f2b8902018-07-10 15:01:19 +0800804// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800805func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +0800806 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
807 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800808 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800809
810 if ctx.ctx.Fuchsia() {
811 return false
812 }
813
Logan Chien2f2b8902018-07-10 15:01:19 +0800814 if sanitize := ctx.mod.sanitize; sanitize != nil {
815 if !sanitize.isVariantOnProductionDevice() {
816 return false
817 }
818 }
819 if !ctx.ctx.Device() {
820 // Host modules do not need ABI dumps.
821 return false
822 }
Logan Chienfa478c02018-12-28 16:25:39 +0800823 if !ctx.mod.IsForPlatform() {
824 // APEX variants do not need ABI dumps.
825 return false
826 }
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +0800827 if ctx.isStubs() {
828 // Stubs do not need ABI dumps.
829 return false
830 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800831 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800832}
833
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700834func (ctx *moduleContextImpl) selectedStl() string {
835 if stl := ctx.mod.stl; stl != nil {
836 return stl.Properties.SelectedStl
837 }
838 return ""
839}
840
Ivan Lozanobd721262018-11-27 14:33:03 -0800841func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
842 return ctx.mod.linker.useClangLld(actx)
843}
844
Colin Crossce75d2c2016-10-06 16:12:58 -0700845func (ctx *moduleContextImpl) baseModuleName() string {
846 return ctx.mod.ModuleBase.BaseModuleName()
847}
848
Logan Chienf3511742017-10-31 18:04:35 +0800849func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
850 return ctx.mod.getVndkExtendsModuleName()
851}
852
Jiyong Park58e364a2019-01-19 19:24:06 +0900853func (ctx *moduleContextImpl) apexName() string {
854 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900855}
856
Jiyong Parkb0788572018-12-20 22:10:17 +0900857func (ctx *moduleContextImpl) hasStubsVariants() bool {
858 return ctx.mod.HasStubsVariants()
859}
860
861func (ctx *moduleContextImpl) isStubs() bool {
862 return ctx.mod.IsStubs()
863}
864
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900865func (ctx *moduleContextImpl) bootstrap() bool {
866 return ctx.mod.bootstrap()
867}
868
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700869func (ctx *moduleContextImpl) nativeCoverage() bool {
870 return ctx.mod.nativeCoverage()
871}
872
Colin Cross635c3b02016-05-18 15:37:25 -0700873func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800874 return &Module{
875 hod: hod,
876 multilib: multilib,
877 }
878}
879
Colin Cross635c3b02016-05-18 15:37:25 -0700880func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800881 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700882 module.features = []feature{
883 &tidyFeature{},
884 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700885 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800886 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800887 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800888 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900889 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700890 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700891 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800892 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800893 return module
894}
895
Colin Crossce75d2c2016-10-06 16:12:58 -0700896func (c *Module) Prebuilt() *android.Prebuilt {
897 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
898 return p.prebuilt()
899 }
900 return nil
901}
902
903func (c *Module) Name() string {
904 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700905 if p, ok := c.linker.(interface {
906 Name(string) string
907 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700908 name = p.Name(name)
909 }
910 return name
911}
912
Alex Light3d673592019-01-18 14:37:31 -0800913func (c *Module) Symlinks() []string {
914 if p, ok := c.installer.(interface {
915 symlinkList() []string
916 }); ok {
917 return p.symlinkList()
918 }
919 return nil
920}
921
Jeff Gaston294356f2017-09-27 17:05:30 -0700922// orderDeps reorders dependencies into a list such that if module A depends on B, then
923// A will precede B in the resultant list.
924// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800925// Note that directSharedDeps should be the analogous static library for each shared lib dep
926func 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 -0700927 // If A depends on B, then
928 // Every list containing A will also contain B later in the list
929 // So, after concatenating all lists, the final instance of B will have come from the same
930 // original list as the final instance of A
931 // So, the final instance of B will be later in the concatenation than the final A
932 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
933 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800934 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700935 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800936 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
937 }
938 for _, dep := range directSharedDeps {
939 orderedAllDeps = append(orderedAllDeps, dep)
940 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700941 }
942
Colin Crossb6715442017-10-24 11:13:31 -0700943 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700944
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800945 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700946 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800947 // resultant list to only what the caller has chosen to include in directStaticDeps
948 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700949
950 return orderedAllDeps, orderedDeclaredDeps
951}
952
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800953func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
954 // convert Module to Path
955 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
956 staticDepFiles := []android.Path{}
957 for _, dep := range staticDeps {
958 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
959 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700960 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800961 sharedDepFiles := []android.Path{}
962 for _, sharedDep := range sharedDeps {
963 staticAnalogue := sharedDep.staticVariant
964 if staticAnalogue != nil {
965 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
966 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
967 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700968 }
969
970 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800971 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700972
973 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700974}
975
Roland Levillainf89cd092019-07-29 16:22:59 +0100976func (c *Module) IsTestPerSrcAllTestsVariation() bool {
977 test, ok := c.linker.(testPerSrc)
978 return ok && test.isAllTestsVariation()
979}
980
Colin Cross635c3b02016-05-18 15:37:25 -0700981func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +0100982 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +0100983 //
984 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
985 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
986 // module and return early, as this module does not produce an output file per se.
987 if c.IsTestPerSrcAllTestsVariation() {
988 c.outputFile = android.OptionalPath{}
989 return
Roland Levillainf2fad972019-06-28 15:41:19 +0100990 }
991
Jooyung Han38002912019-05-16 04:01:54 +0900992 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +0900993
Colin Crossca860ac2016-01-04 14:34:37 -0800994 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700995 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800996 moduleContextImpl: moduleContextImpl{
997 mod: c,
998 },
999 }
1000 ctx.ctx = ctx
1001
Colin Crossf18e1102017-11-16 14:33:08 -08001002 deps := c.depsToPaths(ctx)
1003 if ctx.Failed() {
1004 return
1005 }
1006
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001007 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1008 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1009 }
1010
Colin Crossca860ac2016-01-04 14:34:37 -08001011 flags := Flags{
1012 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001013 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001014 }
Colin Crossca860ac2016-01-04 14:34:37 -08001015 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001016 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001017 }
1018 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001019 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001020 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001021 if c.stl != nil {
1022 flags = c.stl.flags(ctx, flags)
1023 }
Colin Cross16b23492016-01-06 14:41:07 -08001024 if c.sanitize != nil {
1025 flags = c.sanitize.flags(ctx, flags)
1026 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001027 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001028 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001029 }
Stephen Craneba090d12017-05-09 15:44:35 -07001030 if c.lto != nil {
1031 flags = c.lto.flags(ctx, flags)
1032 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001033 if c.pgo != nil {
1034 flags = c.pgo.flags(ctx, flags)
1035 }
Ivan Lozano074ec482018-11-21 08:59:37 -08001036 if c.xom != nil {
1037 flags = c.xom.flags(ctx, flags)
1038 }
Colin Crossca860ac2016-01-04 14:34:37 -08001039 for _, feature := range c.features {
1040 flags = feature.flags(ctx, flags)
1041 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001042 if ctx.Failed() {
1043 return
1044 }
1045
Colin Crossb98c8b02016-07-29 13:44:28 -07001046 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
1047 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
1048 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001049
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001050 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001051
1052 for _, dir := range deps.IncludeDirs {
1053 flags.GlobalFlags = append(flags.GlobalFlags, "-I"+dir)
1054 }
1055 for _, dir := range deps.SystemIncludeDirs {
1056 flags.GlobalFlags = append(flags.GlobalFlags, "-isystem "+dir)
1057 }
1058
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001059 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001060 // We need access to all the flags seen by a source file.
1061 if c.sabi != nil {
1062 flags = c.sabi.flags(ctx, flags)
1063 }
Colin Crossca860ac2016-01-04 14:34:37 -08001064 // Optimization to reduce size of build.ninja
1065 // Replace the long list of flags for each file with a module-local variable
1066 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
1067 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
1068 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
1069 flags.CFlags = []string{"$cflags"}
1070 flags.CppFlags = []string{"$cppflags"}
1071 flags.AsFlags = []string{"$asflags"}
1072
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001073 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001074 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001075 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001076 if ctx.Failed() {
1077 return
1078 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001079 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001080 }
1081
Colin Crossca860ac2016-01-04 14:34:37 -08001082 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001083 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001084 if ctx.Failed() {
1085 return
1086 }
Colin Cross635c3b02016-05-18 15:37:25 -07001087 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001088
1089 // If a lib is directly included in any of the APEXes, unhide the stubs
1090 // variant having the latest version gets visible to make. In addition,
1091 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1092 // force anything in the make world to link against the stubs library.
1093 // (unless it is explicitly referenced via .bootstrap suffix or the
1094 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001095 if c.HasStubsVariants() &&
1096 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001097 !c.inRecovery() && !c.useVndk() && !c.static() && !c.isCoverageVariant() &&
1098 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001099 c.Properties.HideFromMake = false // unhide
1100 // Note: this is still non-installable
1101 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001102 }
Colin Cross5049f022015-03-18 13:28:46 -07001103
Inseob Kim1f086e22019-05-09 13:29:15 +09001104 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001105 c.installer.install(ctx, c.outputFile.Path())
1106 if ctx.Failed() {
1107 return
Colin Crossca860ac2016-01-04 14:34:37 -08001108 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001109 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001110}
1111
Colin Cross0ea8ba82019-06-06 14:33:29 -07001112func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001113 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001114 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001115 }
Colin Crossca860ac2016-01-04 14:34:37 -08001116 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001117}
1118
Colin Crossca860ac2016-01-04 14:34:37 -08001119func (c *Module) begin(ctx BaseModuleContext) {
1120 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001121 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001122 }
Colin Crossca860ac2016-01-04 14:34:37 -08001123 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001124 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001125 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001126 if c.stl != nil {
1127 c.stl.begin(ctx)
1128 }
Colin Cross16b23492016-01-06 14:41:07 -08001129 if c.sanitize != nil {
1130 c.sanitize.begin(ctx)
1131 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001132 if c.coverage != nil {
1133 c.coverage.begin(ctx)
1134 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001135 if c.sabi != nil {
1136 c.sabi.begin(ctx)
1137 }
Justin Yun8effde42017-06-23 19:24:43 +09001138 if c.vndkdep != nil {
1139 c.vndkdep.begin(ctx)
1140 }
Stephen Craneba090d12017-05-09 15:44:35 -07001141 if c.lto != nil {
1142 c.lto.begin(ctx)
1143 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001144 if c.pgo != nil {
1145 c.pgo.begin(ctx)
1146 }
Colin Crossca860ac2016-01-04 14:34:37 -08001147 for _, feature := range c.features {
1148 feature.begin(ctx)
1149 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001150 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001151 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001152 if err != nil {
1153 ctx.PropertyErrorf("sdk_version", err.Error())
1154 }
Nan Zhang0007d812017-11-07 10:57:05 -08001155 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001156 }
Colin Crossca860ac2016-01-04 14:34:37 -08001157}
1158
Colin Cross37047f12016-12-13 17:06:13 -08001159func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001160 deps := Deps{}
1161
1162 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001163 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001164 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001165 // Add the PGO dependency (the clang_rt.profile runtime library), which
1166 // sometimes depends on symbols from libgcc, before libgcc gets added
1167 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001168 if c.pgo != nil {
1169 deps = c.pgo.deps(ctx, deps)
1170 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001171 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001172 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001173 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001174 if c.stl != nil {
1175 deps = c.stl.deps(ctx, deps)
1176 }
Colin Cross16b23492016-01-06 14:41:07 -08001177 if c.sanitize != nil {
1178 deps = c.sanitize.deps(ctx, deps)
1179 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001180 if c.coverage != nil {
1181 deps = c.coverage.deps(ctx, deps)
1182 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001183 if c.sabi != nil {
1184 deps = c.sabi.deps(ctx, deps)
1185 }
Justin Yun8effde42017-06-23 19:24:43 +09001186 if c.vndkdep != nil {
1187 deps = c.vndkdep.deps(ctx, deps)
1188 }
Stephen Craneba090d12017-05-09 15:44:35 -07001189 if c.lto != nil {
1190 deps = c.lto.deps(ctx, deps)
1191 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001192 for _, feature := range c.features {
1193 deps = feature.deps(ctx, deps)
1194 }
1195
Colin Crossb6715442017-10-24 11:13:31 -07001196 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1197 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1198 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1199 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1200 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1201 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001202 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001203
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001204 for _, lib := range deps.ReexportSharedLibHeaders {
1205 if !inList(lib, deps.SharedLibs) {
1206 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1207 }
1208 }
1209
1210 for _, lib := range deps.ReexportStaticLibHeaders {
1211 if !inList(lib, deps.StaticLibs) {
1212 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1213 }
1214 }
1215
Colin Cross5950f382016-12-13 12:50:57 -08001216 for _, lib := range deps.ReexportHeaderLibHeaders {
1217 if !inList(lib, deps.HeaderLibs) {
1218 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1219 }
1220 }
1221
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001222 for _, gen := range deps.ReexportGeneratedHeaders {
1223 if !inList(gen, deps.GeneratedHeaders) {
1224 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1225 }
1226 }
1227
Colin Crossc99deeb2016-04-11 15:06:20 -07001228 return deps
1229}
1230
Dan Albert7e9d2952016-08-04 13:02:36 -07001231func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001232 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001233 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001234 moduleContextImpl: moduleContextImpl{
1235 mod: c,
1236 },
1237 }
1238 ctx.ctx = ctx
1239
Colin Crossca860ac2016-01-04 14:34:37 -08001240 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001241}
1242
Jiyong Park7ed9de32018-10-15 22:25:07 +09001243// Split name#version into name and version
1244func stubsLibNameAndVersion(name string) (string, string) {
1245 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1246 version := name[sharp+1:]
1247 libname := name[:sharp]
1248 return libname, version
1249 }
1250 return name, ""
1251}
1252
Colin Cross1e676be2016-10-12 14:38:15 -07001253func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001254 ctx := &depsContext{
1255 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001256 moduleContextImpl: moduleContextImpl{
1257 mod: c,
1258 },
1259 }
1260 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001261
Colin Crossc99deeb2016-04-11 15:06:20 -07001262 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001263
Dan Albert914449f2016-06-17 16:45:24 -07001264 variantNdkLibs := []string{}
1265 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001266 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001267 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001268
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001269 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1270 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001271 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001272 // 1. Name of an NDK library that refers to a prebuilt module.
1273 // For each of these, it adds the name of the prebuilt module (which will be in
1274 // prebuilts/ndk) to the list of nonvariant libs.
1275 // 2. Name of an NDK library that refers to an ndk_library module.
1276 // For each of these, it adds the name of the ndk_library module to the list of
1277 // variant libs.
1278 // 3. Anything else (so anything that isn't an NDK library).
1279 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001280 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001281 // The caller can then know to add the variantLibs dependencies differently from the
1282 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001283
1284 llndkLibraries := llndkLibraries(actx.Config())
1285 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001286 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1287 variantLibs = []string{}
1288 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001289 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001290 // strip #version suffix out
1291 name, _ := stubsLibNameAndVersion(entry)
1292 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1293 if !inList(name, ndkMigratedLibs) {
1294 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001295 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001296 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001297 }
Inseob Kim9516ee92019-05-09 10:56:13 +09001298 } else if ctx.useVndk() && inList(name, *llndkLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001299 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001300 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001301 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001302 if actx.OtherModuleExists(vendorPublicLib) {
1303 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1304 } else {
1305 // This can happen if vendor_public_library module is defined in a
1306 // namespace that isn't visible to the current module. In that case,
1307 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001308 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001309 }
Dan Albert914449f2016-06-17 16:45:24 -07001310 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001311 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001312 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001313 }
1314 }
Dan Albert914449f2016-06-17 16:45:24 -07001315 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001316 }
1317
Dan Albert914449f2016-06-17 16:45:24 -07001318 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1319 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001320 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001321 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001322
Jiyong Park7e636d02019-01-28 16:16:54 +09001323 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001324 if c.linker != nil {
1325 if library, ok := c.linker.(*libraryDecorator); ok {
1326 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001327 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001328 }
1329 }
1330 }
1331
Colin Cross32ec36c2016-12-15 07:39:51 -08001332 for _, lib := range deps.HeaderLibs {
1333 depTag := headerDepTag
1334 if inList(lib, deps.ReexportHeaderLibHeaders) {
1335 depTag = headerExportDepTag
1336 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001337 if buildStubs {
Jiyong Park7e636d02019-01-28 16:16:54 +09001338 actx.AddFarVariationDependencies([]blueprint.Variation{
1339 {Mutator: "arch", Variation: ctx.Target().String()},
Jiyong Park3b1746a2019-01-29 11:15:04 +09001340 {Mutator: "image", Variation: c.imageVariation()},
Jiyong Park7e636d02019-01-28 16:16:54 +09001341 }, depTag, lib)
1342 } else {
1343 actx.AddVariationDependencies(nil, depTag, lib)
1344 }
1345 }
1346
1347 if buildStubs {
1348 // Stubs lib does not have dependency to other static/shared libraries.
1349 // Don't proceed.
1350 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001351 }
Colin Cross5950f382016-12-13 12:50:57 -08001352
Inseob Kimc0907f12019-02-08 21:00:45 +09001353 syspropImplLibraries := syspropImplLibraries(actx.Config())
1354
Jiyong Park5d1598f2019-02-25 22:14:17 +09001355 for _, lib := range deps.WholeStaticLibs {
1356 depTag := wholeStaticDepTag
1357 if impl, ok := syspropImplLibraries[lib]; ok {
1358 lib = impl
1359 }
1360 actx.AddVariationDependencies([]blueprint.Variation{
1361 {Mutator: "link", Variation: "static"},
1362 }, depTag, lib)
1363 }
1364
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001365 for _, lib := range deps.StaticLibs {
1366 depTag := staticDepTag
1367 if inList(lib, deps.ReexportStaticLibHeaders) {
1368 depTag = staticExportDepTag
1369 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001370
1371 if impl, ok := syspropImplLibraries[lib]; ok {
1372 lib = impl
1373 }
1374
Dan Willemsen59339a22018-07-22 21:18:45 -07001375 actx.AddVariationDependencies([]blueprint.Variation{
1376 {Mutator: "link", Variation: "static"},
1377 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001378 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001379
Dan Willemsen59339a22018-07-22 21:18:45 -07001380 actx.AddVariationDependencies([]blueprint.Variation{
1381 {Mutator: "link", Variation: "static"},
1382 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001383
Jiyong Park25fc6a92018-11-18 18:02:45 +09001384 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1385 var variations []blueprint.Variation
1386 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001387 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001388 if version != "" && versionVariantAvail {
1389 // Version is explicitly specified. i.e. libFoo#30
1390 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1391 depTag.explicitlyVersioned = true
1392 }
1393 actx.AddVariationDependencies(variations, depTag, name)
1394
1395 // If the version is not specified, add dependency to the latest stubs library.
1396 // The stubs library will be used when the depending module is built for APEX and
1397 // the dependent module is not in the same APEX.
1398 latestVersion := latestStubsVersionFor(actx.Config(), name)
1399 if version == "" && latestVersion != "" && versionVariantAvail {
1400 actx.AddVariationDependencies([]blueprint.Variation{
1401 {Mutator: "link", Variation: "shared"},
1402 {Mutator: "version", Variation: latestVersion},
1403 }, depTag, name)
1404 // Note that depTag.explicitlyVersioned is false in this case.
1405 }
1406 }
1407
Jiyong Park7ed9de32018-10-15 22:25:07 +09001408 // shared lib names without the #version suffix
1409 var sharedLibNames []string
1410
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001411 for _, lib := range deps.SharedLibs {
1412 depTag := sharedDepTag
1413 if inList(lib, deps.ReexportSharedLibHeaders) {
1414 depTag = sharedExportDepTag
1415 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001416
1417 if impl, ok := syspropImplLibraries[lib]; ok {
1418 lib = impl
1419 }
1420
1421 name, version := stubsLibNameAndVersion(lib)
1422 sharedLibNames = append(sharedLibNames, name)
1423
Jiyong Park25fc6a92018-11-18 18:02:45 +09001424 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001425 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001426
Jiyong Park7ed9de32018-10-15 22:25:07 +09001427 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001428 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001429 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1430 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1431 // linking against both the stubs lib and the non-stubs lib at the same time.
1432 continue
1433 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001434 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001435 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001436
Dan Willemsen59339a22018-07-22 21:18:45 -07001437 actx.AddVariationDependencies([]blueprint.Variation{
1438 {Mutator: "link", Variation: "shared"},
1439 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001440
Colin Cross68861832016-07-08 10:41:41 -07001441 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001442
1443 for _, gen := range deps.GeneratedHeaders {
1444 depTag := genHeaderDepTag
1445 if inList(gen, deps.ReexportGeneratedHeaders) {
1446 depTag = genHeaderExportDepTag
1447 }
1448 actx.AddDependency(c, depTag, gen)
1449 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001450
Colin Cross42d48b72018-08-29 14:10:52 -07001451 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001452
1453 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001454 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001455 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001456 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001457 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001458 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001459 if deps.LinkerFlagsFile != "" {
1460 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1461 }
1462 if deps.DynamicLinker != "" {
1463 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001464 }
Dan Albert914449f2016-06-17 16:45:24 -07001465
1466 version := ctx.sdkVersion()
1467 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001468 {Mutator: "ndk_api", Variation: version},
1469 {Mutator: "link", Variation: "shared"},
1470 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001471 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001472 {Mutator: "ndk_api", Variation: version},
1473 {Mutator: "link", Variation: "shared"},
1474 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001475
1476 if vndkdep := c.vndkdep; vndkdep != nil {
1477 if vndkdep.isVndkExt() {
1478 baseModuleMode := vendorMode
1479 if actx.DeviceConfig().VndkVersion() == "" {
1480 baseModuleMode = coreMode
1481 }
1482 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001483 {Mutator: "image", Variation: baseModuleMode},
1484 {Mutator: "link", Variation: "shared"},
1485 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001486 }
1487 }
Colin Cross6362e272015-10-29 15:25:03 -07001488}
Colin Cross21b9a242015-03-24 14:15:58 -07001489
Colin Crosse40b4ea2018-10-02 22:25:58 -07001490func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001491 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1492 c.beginMutator(ctx)
1493 }
1494}
1495
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001496// Whether a module can link to another module, taking into
1497// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001498func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001499 if from.Target().Os != android.Android {
1500 // Host code is not restricted
1501 return
1502 }
1503 if from.Properties.UseVndk {
1504 // Though vendor code is limited by the vendor mutator,
1505 // each vendor-available module needs to check
1506 // link-type for VNDK.
1507 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001508 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001509 }
1510 return
1511 }
Nan Zhang0007d812017-11-07 10:57:05 -08001512 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001513 // Platform code can link to anything
1514 return
1515 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001516 if from.inRecovery() {
1517 // Recovery code is not NDK
1518 return
1519 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001520 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1521 // These are always allowed
1522 return
1523 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001524 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1525 // These are allowed, but they don't set sdk_version
1526 return
1527 }
1528 if _, ok := to.linker.(*stubDecorator); ok {
1529 // These aren't real libraries, but are the stub shared libraries that are included in
1530 // the NDK.
1531 return
1532 }
Logan Chien834b9a62019-01-14 15:39:03 +08001533
1534 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" {
1535 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1536 // to link to libc++ (non-NDK and without sdk_version).
1537 return
1538 }
1539
Nan Zhang0007d812017-11-07 10:57:05 -08001540 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001541 // NDK code linking to platform code is never okay.
1542 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1543 ctx.OtherModuleName(to))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001544 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001545 }
1546
1547 // At this point we know we have two NDK libraries, but we need to
1548 // check that we're not linking against anything built against a higher
1549 // API level, as it is only valid to link against older or equivalent
1550 // APIs.
1551
Inseob Kim01a28722018-04-11 09:48:45 +09001552 // Current can link against anything.
1553 if String(from.Properties.Sdk_version) != "current" {
1554 // Otherwise we need to check.
1555 if String(to.Properties.Sdk_version) == "current" {
1556 // Current can't be linked against by anything else.
1557 ctx.ModuleErrorf("links %q built against newer API version %q",
1558 ctx.OtherModuleName(to), "current")
1559 } else {
1560 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1561 if err != nil {
1562 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001563 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001564 String(from.Properties.Sdk_version))
1565 }
1566 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1567 if err != nil {
1568 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001569 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001570 String(to.Properties.Sdk_version))
1571 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001572
Inseob Kim01a28722018-04-11 09:48:45 +09001573 if toApi > fromApi {
1574 ctx.ModuleErrorf("links %q built against newer API version %q",
1575 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1576 }
1577 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001578 }
Dan Albert202fe492017-12-15 13:56:59 -08001579
1580 // Also check that the two STL choices are compatible.
1581 fromStl := from.stl.Properties.SelectedStl
1582 toStl := to.stl.Properties.SelectedStl
1583 if fromStl == "" || toStl == "" {
1584 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001585 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001586 // We can be permissive with the system "STL" since it is only the C++
1587 // ABI layer, but in the future we should make sure that everyone is
1588 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001589 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001590 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1591 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1592 to.stl.Properties.SelectedStl)
1593 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001594}
1595
Jiyong Park5fb8c102018-04-09 12:03:06 +09001596// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001597// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1598// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001599// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001600func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
Inseob Kim9516ee92019-05-09 10:56:13 +09001601 llndkLibraries := llndkLibraries(ctx.Config())
Jooyung Hana70f0672019-01-18 15:20:43 +09001602 check := func(child, parent android.Module) bool {
1603 to, ok := child.(*Module)
1604 if !ok {
1605 // follow thru cc.Defaults, etc.
1606 return true
1607 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001608
Jooyung Hana70f0672019-01-18 15:20:43 +09001609 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1610 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001611 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001612
1613 // if target lib has no vendor variant, keep checking dependency graph
1614 if !to.hasVendorVariant() {
1615 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001616 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001617
Inseob Kim9516ee92019-05-09 10:56:13 +09001618 if to.isVndkSp() || inList(child.Name(), *llndkLibraries) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001619 return false
1620 }
1621
1622 var stringPath []string
1623 for _, m := range ctx.GetWalkPath() {
1624 stringPath = append(stringPath, m.Name())
1625 }
1626 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1627 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1628 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1629 return false
1630 }
1631 if module, ok := ctx.Module().(*Module); ok {
1632 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Inseob Kim9516ee92019-05-09 10:56:13 +09001633 if inList(ctx.ModuleName(), *llndkLibraries) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001634 ctx.WalkDeps(check)
1635 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001636 }
1637 }
1638}
1639
Colin Crossc99deeb2016-04-11 15:06:20 -07001640// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001641func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001642 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001643
Jeff Gaston294356f2017-09-27 17:05:30 -07001644 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001645 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001646
Inseob Kim9516ee92019-05-09 10:56:13 +09001647 llndkLibraries := llndkLibraries(ctx.Config())
1648 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
1649
Inseob Kim69378442019-06-03 19:10:47 +09001650 reexportExporter := func(exporter exportedFlagsProducer) {
1651 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
1652 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
1653 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
1654 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
1655 }
1656
Colin Crossd11fcda2017-10-23 17:59:01 -07001657 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001658 depName := ctx.OtherModuleName(dep)
1659 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001660
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001661 ccDep, _ := dep.(*Module)
1662 if ccDep == nil {
1663 // handling for a few module types that aren't cc Module but that are also supported
1664 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001665 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001666 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001667 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1668 genRule.GeneratedSourceFiles()...)
1669 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001670 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001671 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001672 // Support exported headers from a generated_sources dependency
1673 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001674 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001675 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001676 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001677 genRule.GeneratedDeps()...)
Inseob Kim69378442019-06-03 19:10:47 +09001678 dirs := genRule.GeneratedHeaderDirs().Strings()
1679 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001680 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09001681 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
1682 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001683 // 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 +09001684 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001685
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001686 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001687 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001688 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001689 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001690 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001691 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001692 files := genRule.GeneratedSourceFiles()
1693 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001694 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001695 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001696 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 -07001697 }
1698 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001699 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001700 }
Colin Crossca860ac2016-01-04 14:34:37 -08001701 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001702 return
1703 }
1704
Colin Crossfe17f6f2019-03-28 19:30:56 -07001705 if depTag == android.ProtoPluginDepTag {
1706 return
1707 }
1708
Colin Crossd11fcda2017-10-23 17:59:01 -07001709 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001710 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1711 return
1712 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001713 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001714 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001715 return
1716 }
1717
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001718 // re-exporting flags
1719 if depTag == reuseObjTag {
1720 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001721 c.staticVariant = ccDep
Inseob Kim69378442019-06-03 19:10:47 +09001722 objs, exporter := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001723 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09001724 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08001725 return
1726 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001727 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001728
Jiyong Parke4bb9862019-02-01 00:31:10 +09001729 if depTag == staticVariantTag {
1730 if _, ok := ccDep.compiler.(libraryInterface); ok {
1731 c.staticVariant = ccDep
1732 return
1733 }
1734 }
1735
Jiyong Park25fc6a92018-11-18 18:02:45 +09001736 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1737 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1738 // won't be matched to sharedDepTag and lateSharedDepTag.
1739 explicitlyVersioned := false
1740 if t, ok := depTag.(dependencyTag); ok {
1741 explicitlyVersioned = t.explicitlyVersioned
1742 t.explicitlyVersioned = false
1743 depTag = t
1744 }
1745
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001746 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001747 depIsStatic := false
1748 switch depTag {
1749 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1750 depIsStatic = true
1751 }
1752 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001753 depIsStubs := dependentLibrary.buildStubs()
1754 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001755 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001756 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001757
1758 var useThisDep bool
1759 if depIsStubs && explicitlyVersioned {
1760 // Always respect dependency to the versioned stubs (i.e. libX#10)
1761 useThisDep = true
1762 } else if !depHasStubs {
1763 // Use non-stub variant if that is the only choice
1764 // (i.e. depending on a lib without stubs.version property)
1765 useThisDep = true
1766 } else if c.IsForPlatform() {
1767 // If not building for APEX, use stubs only when it is from
1768 // an APEX (and not from platform)
1769 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001770 if c.inRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001771 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001772 // always link to non-stub variant
1773 useThisDep = !depIsStubs
1774 }
1775 } else {
1776 // If building for APEX, use stubs only when it is not from
1777 // the same APEX
1778 useThisDep = (depInSameApex != depIsStubs)
1779 }
1780
1781 if !useThisDep {
1782 return // stop processing this dep
1783 }
1784 }
1785
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001786 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Inseob Kim69378442019-06-03 19:10:47 +09001787 depPaths.IncludeDirs = append(depPaths.IncludeDirs, i.exportedDirs()...)
1788 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
1789 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedDeps()...)
1790 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001791
1792 if t.reexportFlags {
Inseob Kim69378442019-06-03 19:10:47 +09001793 reexportExporter(i)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001794 // 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 -07001795 // Re-exported shared library headers must be included as well since they can help us with type information
1796 // about template instantiations (instantiated from their headers).
Inseob Kim69378442019-06-03 19:10:47 +09001797 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
1798 // scripts.
1799 c.sabi.Properties.ReexportedIncludes = append(
1800 c.sabi.Properties.ReexportedIncludes, i.exportedDirs()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001801 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001802 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001803
Logan Chienf3511742017-10-31 18:04:35 +08001804 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001805 }
1806
Colin Cross26c34ed2016-09-30 17:10:16 -07001807 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001808 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001809
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001810 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001811 depFile := android.OptionalPath{}
1812
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001813 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001814 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001815 ptr = &depPaths.SharedLibs
1816 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001817 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001818 directSharedDeps = append(directSharedDeps, ccDep)
Jiyong Park64a44f22019-01-18 14:37:08 +09001819 case earlySharedDepTag:
1820 ptr = &depPaths.EarlySharedLibs
1821 depPtr = &depPaths.EarlySharedLibsDeps
1822 depFile = ccDep.linker.(libraryInterface).toc()
1823 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001824 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001825 ptr = &depPaths.LateSharedLibs
1826 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001827 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001828 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001829 ptr = nil
1830 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001831 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001832 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001833 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001834 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001835 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001836 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001837 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001838 return
1839 }
1840
1841 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001842 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001843 for i := range missingDeps {
1844 missingDeps[i] += postfix
1845 }
1846 ctx.AddMissingDependencies(missingDeps)
1847 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001848 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001849 case headerDepTag:
1850 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001851 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001852 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001853 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001854 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001855 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001856 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001857 case dynamicLinkerDepTag:
1858 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001859 }
1860
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001861 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001862 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001863 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001864 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001865 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001866 return
1867 }
1868
1869 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001870 // in static libraries act as if they were whole static libraries. The same goes for
1871 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001872 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1873 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001874 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1875 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001876
Dan Willemsen581341d2017-02-09 16:16:31 -08001877 }
1878
Colin Cross26c34ed2016-09-30 17:10:16 -07001879 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001880 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001881 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001882 return
1883 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001884 *ptr = append(*ptr, linkFile.Path())
1885 }
1886
Colin Crossc99deeb2016-04-11 15:06:20 -07001887 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001888 dep := depFile
1889 if !dep.Valid() {
1890 dep = linkFile
1891 }
1892 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001893 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001894
Logan Chien43d34c32017-12-20 01:17:32 +08001895 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001896 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001897 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001898 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kim9516ee92019-05-09 10:56:13 +09001899 isLLndk := inList(libName, *llndkLibraries)
1900 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001901 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08001902
yidong.zhangd06ecc82019-08-02 15:49:24 +08001903 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.isVndk() && !ccDep.mustUseVendorVariant() && !c.inRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08001904 // The vendor module is a no-vendor-variant VNDK library. Depend on the
1905 // core module instead.
1906 return libName
1907 } else if c.useVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001908 // The vendor module in Make will have been renamed to not conflict with the core
1909 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001910 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001911 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001912 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001913 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1914 return libName + recoverySuffix
dimitry1f33e402019-03-26 12:39:31 +01001915 } else if ccDep.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02001916 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001917 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001918 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001919 }
Logan Chien43d34c32017-12-20 01:17:32 +08001920 }
1921
1922 // Export the shared libs to Make.
1923 switch depTag {
Jiyong Park64a44f22019-01-18 14:37:08 +09001924 case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001925 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001926 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08001927 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09001928 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001929 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001930 c.Properties.ApexesProvidingSharedLibs = append(
1931 c.Properties.ApexesProvidingSharedLibs, an)
1932 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09001933 }
1934 }
1935
Jiyong Park27b188b2017-07-18 13:23:39 +09001936 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001937 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001938 c.Properties.AndroidMkSharedLibs = append(
1939 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08001940 case ndkStubDepTag, ndkLateStubDepTag:
1941 ndkStub := ccDep.linker.(*stubDecorator)
1942 c.Properties.AndroidMkSharedLibs = append(
1943 c.Properties.AndroidMkSharedLibs,
1944 depName+"."+ndkStub.properties.ApiLevel)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001945 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1946 c.Properties.AndroidMkStaticLibs = append(
1947 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001948 case runtimeDepTag:
1949 c.Properties.AndroidMkRuntimeLibs = append(
1950 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001951 case wholeStaticDepTag:
1952 c.Properties.AndroidMkWholeStaticLibs = append(
1953 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001954 }
Colin Crossca860ac2016-01-04 14:34:37 -08001955 })
1956
Jeff Gaston294356f2017-09-27 17:05:30 -07001957 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001958 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001959
Colin Crossdd84e052017-05-17 13:44:16 -07001960 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001961 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Inseob Kim69378442019-06-03 19:10:47 +09001962 depPaths.IncludeDirs = android.FirstUniqueStrings(depPaths.IncludeDirs)
1963 depPaths.SystemIncludeDirs = android.FirstUniqueStrings(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001964 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kim69378442019-06-03 19:10:47 +09001965 depPaths.ReexportedDirs = android.FirstUniqueStrings(depPaths.ReexportedDirs)
1966 depPaths.ReexportedSystemDirs = android.FirstUniqueStrings(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07001967 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09001968 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001969
1970 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09001971 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001972 }
Colin Crossdd84e052017-05-17 13:44:16 -07001973
Colin Crossca860ac2016-01-04 14:34:37 -08001974 return depPaths
1975}
1976
1977func (c *Module) InstallInData() bool {
1978 if c.installer == nil {
1979 return false
1980 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001981 return c.installer.inData()
1982}
1983
1984func (c *Module) InstallInSanitizerDir() bool {
1985 if c.installer == nil {
1986 return false
1987 }
1988 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001989 return true
1990 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001991 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001992}
1993
Jiyong Parkf9332f12018-02-01 00:54:12 +09001994func (c *Module) InstallInRecovery() bool {
1995 return c.inRecovery()
1996}
1997
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001998func (c *Module) HostToolPath() android.OptionalPath {
1999 if c.installer == nil {
2000 return android.OptionalPath{}
2001 }
2002 return c.installer.hostToolPath()
2003}
2004
Nan Zhangd4e641b2017-07-12 12:55:28 -07002005func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2006 return c.outputFile
2007}
2008
Colin Cross41955e82019-05-29 14:40:35 -07002009func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2010 switch tag {
2011 case "":
2012 if c.outputFile.Valid() {
2013 return android.Paths{c.outputFile.Path()}, nil
2014 }
2015 return android.Paths{}, nil
2016 default:
2017 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002018 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002019}
2020
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002021func (c *Module) static() bool {
2022 if static, ok := c.linker.(interface {
2023 static() bool
2024 }); ok {
2025 return static.static()
2026 }
2027 return false
2028}
2029
Jiyong Park379de2f2018-12-19 02:47:14 +09002030func (c *Module) staticBinary() bool {
2031 if static, ok := c.linker.(interface {
2032 staticBinary() bool
2033 }); ok {
2034 return static.staticBinary()
2035 }
2036 return false
2037}
2038
Jiyong Park1d1119f2019-07-29 21:27:18 +09002039func (c *Module) header() bool {
2040 if h, ok := c.linker.(interface {
2041 header() bool
2042 }); ok {
2043 return h.header()
2044 }
2045 return false
2046}
2047
Jooyung Han38002912019-05-16 04:01:54 +09002048func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
2049 name := actx.ModuleName()
Colin Crossb60190a2018-09-04 16:28:17 -07002050 if c.useVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002051 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2052 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002053 return "native:vndk"
2054 }
Jooyung Han38002912019-05-16 04:01:54 +09002055 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002056 }
Jooyung Han38002912019-05-16 04:01:54 +09002057 if c.isVndk() && !c.isVndkExt() {
2058 if Bool(c.VendorProperties.Vendor_available) {
2059 return "native:vndk"
2060 }
2061 return "native:vndk_private"
2062 }
2063 return "native:vendor"
Colin Crossb60190a2018-09-04 16:28:17 -07002064 } else if c.inRecovery() {
2065 return "native:recovery"
2066 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2067 return "native:ndk:none:none"
2068 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2069 //family, link := getNdkStlFamilyAndLinkType(c)
2070 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Jooyung Han38002912019-05-16 04:01:54 +09002071 } else if inList(name, *vndkUsingCoreVariantLibraries(actx.Config())) {
Vic Yangefd249e2018-11-12 20:19:56 -08002072 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002073 } else {
2074 return "native:platform"
2075 }
2076}
2077
Jiyong Park9d452992018-10-03 00:38:19 +09002078// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002079// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002080func (c *Module) IsInstallableToApex() bool {
2081 if shared, ok := c.linker.(interface {
2082 shared() bool
2083 }); ok {
2084 return shared.shared()
Roland Levillainf89cd092019-07-29 16:22:59 +01002085 } else if _, ok := c.linker.(testPerSrc); ok {
2086 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002087 }
2088 return false
2089}
2090
Inseob Kim1f086e22019-05-09 13:29:15 +09002091func (c *Module) installable() bool {
2092 return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
2093}
2094
Jiyong Park3b1746a2019-01-29 11:15:04 +09002095func (c *Module) imageVariation() string {
2096 variation := "core"
2097 if c.useVndk() {
2098 variation = "vendor"
2099 } else if c.inRecovery() {
2100 variation = "recovery"
2101 }
2102 return variation
2103}
2104
bralee3f49f4d2019-03-04 06:58:15 +08002105func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
Colin Cross41955e82019-05-29 14:40:35 -07002106 outputFiles, err := c.OutputFiles("")
2107 if err != nil {
2108 panic(err)
2109 }
2110 dpInfo.Srcs = append(dpInfo.Srcs, outputFiles.Strings()...)
bralee3f49f4d2019-03-04 06:58:15 +08002111}
2112
Logan Chien41eabe62019-04-10 13:33:58 +08002113func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2114 if c.linker != nil {
2115 if library, ok := c.linker.(*libraryDecorator); ok {
2116 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2117 }
2118 }
2119}
2120
Colin Cross2ba19d92015-05-07 15:44:20 -07002121//
Colin Crosscfad1192015-11-02 16:43:11 -08002122// Defaults
2123//
Colin Crossca860ac2016-01-04 14:34:37 -08002124type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002125 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002126 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002127 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002128}
2129
Patrice Arrudac249c712019-03-19 17:00:29 -07002130// cc_defaults provides a set of properties that can be inherited by other cc
2131// modules. A module can use the properties from a cc_defaults using
2132// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2133// merged (when possible) by prepending the default module's values to the
2134// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002135func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002136 return DefaultsFactory()
2137}
2138
Colin Cross36242852017-06-23 15:06:31 -07002139func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002140 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002141
Colin Cross36242852017-06-23 15:06:31 -07002142 module.AddProperties(props...)
2143 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002144 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002145 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002146 &BaseCompilerProperties{},
2147 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002148 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002149 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002150 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002151 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002152 &TestProperties{},
2153 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002154 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002155 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002156 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002157 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002158 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002159 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002160 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002161 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002162 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002163 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002164 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002165 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002166 )
Colin Crosscfad1192015-11-02 16:43:11 -08002167
Colin Cross1f44a3a2017-07-07 14:33:33 -07002168 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09002169 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002170
2171 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002172}
2173
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002174const (
2175 // coreMode is the variant used for framework-private libraries, or
2176 // SDK libraries. (which framework-private libraries can use)
2177 coreMode = "core"
2178
2179 // vendorMode is the variant used for /vendor code that compiles
2180 // against the VNDK.
2181 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09002182
2183 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002184)
2185
Jiyong Park6a43f042017-10-12 23:05:00 +09002186func squashVendorSrcs(m *Module) {
2187 if lib, ok := m.compiler.(*libraryDecorator); ok {
2188 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2189 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2190
2191 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2192 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2193 }
2194}
2195
Jiyong Parkf9332f12018-02-01 00:54:12 +09002196func squashRecoverySrcs(m *Module) {
2197 if lib, ok := m.compiler.(*libraryDecorator); ok {
2198 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2199 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2200
2201 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2202 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2203 }
2204}
2205
Jiyong Parkda6eb592018-12-19 17:12:36 +09002206func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002207 if mctx.Os() != android.Android {
2208 return
2209 }
2210
Jiyong Park7ed9de32018-10-15 22:25:07 +09002211 if g, ok := mctx.Module().(*genrule.Module); ok {
2212 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09002213 var coreVariantNeeded bool = false
2214 var vendorVariantNeeded bool = false
2215 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09002216 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09002217 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002218 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09002219 coreVariantNeeded = true
2220 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09002221 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09002222 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002223 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09002224 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002225 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002226 if Bool(props.Recovery_available) {
2227 recoveryVariantNeeded = true
2228 }
2229
Jiyong Park413cc742018-06-19 01:46:06 +09002230 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002231 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09002232 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09002233 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002234 recoveryVariantNeeded = false
2235 }
2236 }
2237
Jiyong Park3f736c92018-05-24 13:36:56 +09002238 var variants []string
2239 if coreVariantNeeded {
2240 variants = append(variants, coreMode)
2241 }
2242 if vendorVariantNeeded {
2243 variants = append(variants, vendorMode)
2244 }
2245 if recoveryVariantNeeded {
2246 variants = append(variants, recoveryMode)
2247 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002248 mod := mctx.CreateVariations(variants...)
2249 for i, v := range variants {
2250 if v == recoveryMode {
2251 m := mod[i].(*genrule.Module)
2252 m.Extra.(*GenruleExtraProperties).InRecovery = true
2253 }
2254 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002255 }
2256 }
2257
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002258 m, ok := mctx.Module().(*Module)
2259 if !ok {
2260 return
2261 }
2262
2263 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002264 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002265 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002266
2267 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002268 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002269 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002270 return
2271 }
Logan Chienf3511742017-10-31 18:04:35 +08002272
2273 if vndkdep := m.vndkdep; vndkdep != nil {
2274 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002275 if productSpecific {
2276 mctx.PropertyErrorf("product_specific",
2277 "product_specific must not be true when `vndk: {enabled: true}`")
2278 return
2279 }
Logan Chienf3511742017-10-31 18:04:35 +08002280 if vendorSpecific {
2281 if !vndkdep.isVndkExt() {
2282 mctx.PropertyErrorf("vndk",
2283 "must set `extends: \"...\"` to vndk extension")
2284 return
2285 }
2286 } else {
2287 if vndkdep.isVndkExt() {
2288 mctx.PropertyErrorf("vndk",
2289 "must set `vendor: true` to set `extends: %q`",
2290 m.getVndkExtendsModuleName())
2291 return
2292 }
2293 if m.VendorProperties.Vendor_available == nil {
2294 mctx.PropertyErrorf("vndk",
2295 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2296 return
2297 }
2298 }
2299 } else {
2300 if vndkdep.isVndkSp() {
2301 mctx.PropertyErrorf("vndk",
2302 "must set `enabled: true` to set `support_system_process: true`")
2303 return
2304 }
2305 if vndkdep.isVndkExt() {
2306 mctx.PropertyErrorf("vndk",
2307 "must set `enabled: true` to set `extends: %q`",
2308 m.getVndkExtendsModuleName())
2309 return
2310 }
Justin Yun8effde42017-06-23 19:24:43 +09002311 }
2312 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002313
Jiyong Parkf9332f12018-02-01 00:54:12 +09002314 var coreVariantNeeded bool = false
2315 var vendorVariantNeeded bool = false
2316 var recoveryVariantNeeded bool = false
2317
Justin Yun71549282017-11-17 12:10:28 +09002318 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002319 // If the device isn't compiling against the VNDK, we always
2320 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002321 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002322 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2323 // LL-NDK stubs only exist in the vendor variant, since the
2324 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002325 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09002326 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2327 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09002328 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09002329 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002330 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2331 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002332 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002333 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002334 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002335 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002336 coreVariantNeeded = true
2337 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002338 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002339 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09002340 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002341 } else {
2342 // This is either in /system (or similar: /data), or is a
2343 // modules built with the NDK. Modules built with the NDK
2344 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002345 coreVariantNeeded = true
2346 }
2347
2348 if Bool(m.Properties.Recovery_available) {
2349 recoveryVariantNeeded = true
2350 }
2351
2352 if m.ModuleBase.InstallInRecovery() {
2353 recoveryVariantNeeded = true
2354 coreVariantNeeded = false
2355 }
2356
Jiyong Park413cc742018-06-19 01:46:06 +09002357 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002358 primaryArch := mctx.Config().DevicePrimaryArchType()
2359 moduleArch := m.Target().Arch.ArchType
2360 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002361 recoveryVariantNeeded = false
2362 }
2363 }
2364
Jiyong Parkf9332f12018-02-01 00:54:12 +09002365 var variants []string
2366 if coreVariantNeeded {
2367 variants = append(variants, coreMode)
2368 }
2369 if vendorVariantNeeded {
2370 variants = append(variants, vendorMode)
2371 }
2372 if recoveryVariantNeeded {
2373 variants = append(variants, recoveryMode)
2374 }
2375 mod := mctx.CreateVariations(variants...)
2376 for i, v := range variants {
2377 if v == vendorMode {
2378 m := mod[i].(*Module)
2379 m.Properties.UseVndk = true
2380 squashVendorSrcs(m)
2381 } else if v == recoveryMode {
2382 m := mod[i].(*Module)
2383 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002384 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002385 squashRecoverySrcs(m)
2386 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002387 }
2388}
2389
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002390func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002391 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002392 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2393 }
Colin Cross6510f912017-11-29 00:27:14 -08002394 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002395}
2396
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002397func kytheExtractAllFactory() android.Singleton {
2398 return &kytheExtractAllSingleton{}
2399}
2400
2401type kytheExtractAllSingleton struct {
2402}
2403
2404func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2405 var xrefTargets android.Paths
2406 ctx.VisitAllModules(func(module android.Module) {
2407 if ccModule, ok := module.(xref); ok {
2408 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
2409 }
2410 })
2411 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
2412 if len(xrefTargets) > 0 {
2413 ctx.Build(pctx, android.BuildParams{
2414 Rule: blueprint.Phony,
2415 Output: android.PathForPhony(ctx, "xref_cxx"),
2416 Inputs: xrefTargets,
2417 //Default: true,
2418 })
2419 }
2420}
2421
Colin Cross06a931b2015-10-28 17:23:31 -07002422var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002423var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002424var BoolPtr = proptools.BoolPtr
2425var String = proptools.String
2426var StringPtr = proptools.StringPtr