blob: baee70a975d55c2e50cd3dd5303f51aa924a13d4 [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 (
Dan Albert9e10cd42016-08-03 14:12:14 -070022 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080023 "strings"
24
Colin Cross97ba0732015-03-23 17:50:24 -070025 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070026 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070027
Colin Cross635c3b02016-05-18 15:37:25 -070028 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070029 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070030 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080031)
32
Colin Cross463a90e2015-06-17 14:20:06 -070033func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070034 android.RegisterModuleType("cc_defaults", defaultsFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070035
Colin Cross1e676be2016-10-12 14:38:15 -070036 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +090037 ctx.BottomUp("image", ImageMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070038 ctx.BottomUp("link", LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +090039 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070040 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
41 ctx.BottomUp("test_per_src", testPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090042 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070043 ctx.BottomUp("begin", BeginMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070044 })
Colin Cross16b23492016-01-06 14:41:07 -080045
Colin Cross1e676be2016-10-12 14:38:15 -070046 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
47 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
48 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080049
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070050 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
51 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
52
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000053 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
54 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
55
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080056 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
57 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
58
Colin Cross1e676be2016-10-12 14:38:15 -070059 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
60 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080061
Colin Cross6b753602018-06-21 13:03:07 -070062 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator)
Jiyong Park379de2f2018-12-19 02:47:14 +090063 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080064
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +000065 ctx.BottomUp("coverage", coverageLinkingMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080066 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070067
68 ctx.TopDown("lto_deps", ltoDepsMutator)
69 ctx.BottomUp("lto", ltoMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070070 })
Colin Crossb98c8b02016-07-29 13:44:28 -070071
72 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070073}
74
Colin Crossca860ac2016-01-04 14:34:37 -080075type Deps struct {
76 SharedLibs, LateSharedLibs []string
77 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080078 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080079 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070080
Colin Cross5950f382016-12-13 12:50:57 -080081 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070082
Colin Cross81413472016-04-11 14:37:39 -070083 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070084
Dan Willemsenb40aab62016-04-20 14:21:14 -070085 GeneratedSources []string
86 GeneratedHeaders []string
87
Dan Willemsenb3454ab2016-09-28 17:34:58 -070088 ReexportGeneratedHeaders []string
89
Colin Cross97ba0732015-03-23 17:50:24 -070090 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -070091
92 // Used for host bionic
93 LinkerFlagsFile string
94 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -070095}
96
Colin Crossca860ac2016-01-04 14:34:37 -080097type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -070098 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +090099 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700100 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900101 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700102 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700103 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700104
Colin Cross26c34ed2016-09-30 17:10:16 -0700105 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700106 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800107 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700108 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700109
Colin Cross26c34ed2016-09-30 17:10:16 -0700110 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700111 GeneratedSources android.Paths
112 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700113
Dan Willemsen76f08272016-07-09 00:14:08 -0700114 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700115 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700116
Colin Cross26c34ed2016-09-30 17:10:16 -0700117 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700118 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700119
120 // Path to the file container flags to use with the linker
121 LinkerFlagsFile android.OptionalPath
122
123 // Path to the dynamic linker binary
124 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700125}
126
Colin Crossca860ac2016-01-04 14:34:37 -0800127type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700128 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
129 ArFlags []string // Flags that apply to ar
130 AsFlags []string // Flags that apply to assembly source files
131 CFlags []string // Flags that apply to C and C++ source files
132 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
133 ConlyFlags []string // Flags that apply to C source files
134 CppFlags []string // Flags that apply to C++ source files
135 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
136 YaccFlags []string // Flags that apply to Yacc source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700137 aidlFlags []string // Flags that apply to aidl source files
138 rsFlags []string // Flags that apply to renderscript source files
139 LdFlags []string // Flags that apply to linker command lines
140 libFlags []string // Flags to add libraries early to the link order
141 TidyFlags []string // Flags that apply to clang-tidy
142 SAbiFlags []string // Flags that apply to header-abi-dumper
143 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700144
Colin Crossc3199482017-03-30 15:03:04 -0700145 // Global include flags that apply to C, C++, and assembly source files
146 // These must be after any module include flags, which will be in GlobalFlags.
147 SystemIncludeFlags []string
148
Colin Crossb98c8b02016-07-29 13:44:28 -0700149 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700150 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800151 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800152 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800153
154 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800155 DynamicLinker string
156
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700157 CFlagsDeps android.Paths // Files depended on by compiler flags
158 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800159
160 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800161
162 protoDeps android.Paths
163 protoFlags []string // Flags that apply to proto source files
164 protoOutTypeFlag string // The output type, --cpp_out for example
165 protoOutParams []string // Flags that modify the output of proto generated files
166 protoC bool // Whether to use C instead of C++
167 protoOptionsFile bool // Whether to look for a .options file next to the .proto
168 ProtoRoot bool
Colin Crossc472d572015-03-17 15:06:21 -0700169}
170
Colin Cross81413472016-04-11 14:37:39 -0700171type ObjectLinkerProperties struct {
172 // names of other cc_object modules to link into this module using partial linking
173 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700174
175 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800176 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700177}
178
Colin Crossca860ac2016-01-04 14:34:37 -0800179// Properties used to compile all C or C++ modules
180type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700181 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800182 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700183
184 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800185 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700186
Jiyong Parkde866cb2018-12-07 23:08:36 +0900187 AndroidMkSharedLibs []string `blueprint:"mutated"`
188 AndroidMkStaticLibs []string `blueprint:"mutated"`
189 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
190 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
191 HideFromMake bool `blueprint:"mutated"`
192 PreventInstall bool `blueprint:"mutated"`
193 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700194
195 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800196
197 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
198 // file
199 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900200
201 // Make this module available when building for recovery
202 Recovery_available *bool
203
204 InRecovery bool `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900205
206 // Allows this module to use non-APEX version of libraries. Useful
207 // for building binaries that are started before APEXes are activated.
208 Bootstrap *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700209}
210
211type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900212 // whether this module should be allowed to be directly depended by other
213 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
214 // If set to true, two variants will be built separately, one like
215 // normal, and the other limited to the set of libraries and headers
216 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700217 //
218 // The vendor variant may be used with a different (newer) /system,
219 // so it shouldn't have any unversioned runtime dependencies, or
220 // make assumptions about the system that may not be true in the
221 // future.
222 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900223 // If set to false, this module becomes inaccessible from /vendor modules.
224 //
225 // Default value is true when vndk: {enabled: true} or vendor: true.
226 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700227 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
228 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900229
230 // whether this module is capable of being loaded with other instance
231 // (possibly an older version) of the same module in the same process.
232 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
233 // can be double loaded in a vendor process if the library is also a
234 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
235 // explicitly marked as `double_loadable: true` by the owner, or the dependency
236 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
237 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800238}
239
Colin Crossca860ac2016-01-04 14:34:37 -0800240type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800241 static() bool
242 staticBinary() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700243 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700244 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800245 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700246 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800247 isNdk() bool
248 isLlndk() bool
249 isLlndkPublic() bool
250 isVndkPrivate() bool
Justin Yun8effde42017-06-23 19:24:43 +0900251 isVndk() bool
252 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800253 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900254 inRecovery() bool
Logan Chien2f2b8902018-07-10 15:01:19 +0800255 shouldCreateVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700256 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700257 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800258 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800259 isPgoCompile() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800260 useClangLld(actx ModuleContext) bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900261 isApex() bool
Jiyong Parkb0788572018-12-20 22:10:17 +0900262 hasStubsVariants() bool
263 isStubs() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800264}
265
266type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700267 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800268 ModuleContextIntf
269}
270
271type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700272 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800273 ModuleContextIntf
274}
275
Colin Cross37047f12016-12-13 17:06:13 -0800276type DepsContext interface {
277 android.BottomUpMutatorContext
278 ModuleContextIntf
279}
280
Colin Crossca860ac2016-01-04 14:34:37 -0800281type feature interface {
282 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800283 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800284 flags(ctx ModuleContext, flags Flags) Flags
285 props() []interface{}
286}
287
288type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700289 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800290 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800291 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700292 compilerProps() []interface{}
293
Colin Cross76fada02016-07-27 10:31:13 -0700294 appendCflags([]string)
295 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700296 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800297}
298
299type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700300 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800301 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700302 linkerFlags(ctx ModuleContext, flags Flags) Flags
303 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800304 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700305
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700306 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700307 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800308}
309
310type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700311 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700312 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800313 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700314 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700315 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800316}
317
Colin Crossc99deeb2016-04-11 15:06:20 -0700318type dependencyTag struct {
319 blueprint.BaseDependencyTag
320 name string
321 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700322
323 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900324
325 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700326}
327
328var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700329 sharedDepTag = dependencyTag{name: "shared", library: true}
330 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
Jiyong Park64a44f22019-01-18 14:37:08 +0900331 earlySharedDepTag = dependencyTag{name: "early_shared", library: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700332 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
333 staticDepTag = dependencyTag{name: "static", library: true}
334 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
335 lateStaticDepTag = dependencyTag{name: "late static", library: true}
336 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800337 headerDepTag = dependencyTag{name: "header", library: true}
338 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700339 genSourceDepTag = dependencyTag{name: "gen source"}
340 genHeaderDepTag = dependencyTag{name: "gen header"}
341 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
342 objDepTag = dependencyTag{name: "obj"}
343 crtBeginDepTag = dependencyTag{name: "crtbegin"}
344 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700345 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
346 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700347 reuseObjTag = dependencyTag{name: "reuse objects"}
348 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
349 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800350 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800351 runtimeDepTag = dependencyTag{name: "runtime lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700352)
353
Colin Crossca860ac2016-01-04 14:34:37 -0800354// Module contains the properties and members used by all C/C++ module types, and implements
355// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
356// to construct the output file. Behavior can be customized with a Customizer interface
357type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700358 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700359 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900360 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700361
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700362 Properties BaseProperties
363 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700364
Colin Crossca860ac2016-01-04 14:34:37 -0800365 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700366 hod android.HostOrDeviceSupported
367 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700368
Colin Crossca860ac2016-01-04 14:34:37 -0800369 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700370 features []feature
371 compiler compiler
372 linker linker
373 installer installer
374 stl *stl
375 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800376 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800377 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900378 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700379 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700380 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800381 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800382
383 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700384
Colin Cross635c3b02016-05-18 15:37:25 -0700385 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800386
Colin Crossb98c8b02016-07-29 13:44:28 -0700387 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700388
389 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800390
391 // Flags used to compile this module
392 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700393
394 // 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 -0800395 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700396 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800397 depsInLinkOrder android.Paths
398
399 // only non-nil when this is a shared library that reuses the objects of a static library
400 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700401}
402
Jiyong Parkc20eee32018-09-05 22:36:17 +0900403func (c *Module) OutputFile() android.OptionalPath {
404 return c.outputFile
405}
406
Colin Cross36242852017-06-23 15:06:31 -0700407func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700408 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800409 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700410 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800411 }
412 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700413 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800414 }
415 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700416 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800417 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700418 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700419 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700420 }
Colin Cross16b23492016-01-06 14:41:07 -0800421 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700422 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800423 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800424 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700425 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800426 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800427 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700428 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800429 }
Justin Yun8effde42017-06-23 19:24:43 +0900430 if c.vndkdep != nil {
431 c.AddProperties(c.vndkdep.props()...)
432 }
Stephen Craneba090d12017-05-09 15:44:35 -0700433 if c.lto != nil {
434 c.AddProperties(c.lto.props()...)
435 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700436 if c.pgo != nil {
437 c.AddProperties(c.pgo.props()...)
438 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800439 if c.xom != nil {
440 c.AddProperties(c.xom.props()...)
441 }
Colin Crossca860ac2016-01-04 14:34:37 -0800442 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700443 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800444 }
Colin Crossc472d572015-03-17 15:06:21 -0700445
Colin Crossa9d8bee2018-10-02 13:59:46 -0700446 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
447 switch class {
448 case android.Device:
449 return ctx.Config().DevicePrefer32BitExecutables()
450 case android.HostCross:
451 // Windows builds always prefer 32-bit
452 return true
453 default:
454 return false
455 }
456 })
Colin Cross36242852017-06-23 15:06:31 -0700457 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700458
Colin Cross1f44a3a2017-07-07 14:33:33 -0700459 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700460
Jiyong Park9d452992018-10-03 00:38:19 +0900461 android.InitApexModule(c)
462
Colin Cross36242852017-06-23 15:06:31 -0700463 return c
Colin Crossc472d572015-03-17 15:06:21 -0700464}
465
Colin Crossb916a382016-07-29 17:28:03 -0700466// Returns true for dependency roots (binaries)
467// TODO(ccross): also handle dlopenable libraries
468func (c *Module) isDependencyRoot() bool {
469 if root, ok := c.linker.(interface {
470 isDependencyRoot() bool
471 }); ok {
472 return root.isDependencyRoot()
473 }
474 return false
475}
476
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700477func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700478 return c.Properties.UseVndk
479}
480
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800481func (c *Module) isNdk() bool {
482 return inList(c.Name(), ndkMigratedLibs)
483}
484
485func (c *Module) isLlndk() bool {
486 // Returns true for both LLNDK (public) and LLNDK-private libs.
487 return inList(c.Name(), llndkLibraries)
488}
489
490func (c *Module) isLlndkPublic() bool {
491 // Returns true only for LLNDK (public) libs.
492 return c.isLlndk() && !c.isVndkPrivate()
493}
494
495func (c *Module) isVndkPrivate() bool {
496 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
497 return inList(c.Name(), vndkPrivateLibraries)
498}
499
Justin Yun8effde42017-06-23 19:24:43 +0900500func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800501 if vndkdep := c.vndkdep; vndkdep != nil {
502 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900503 }
504 return false
505}
506
Yi Kong7e53c572018-02-14 18:16:12 +0800507func (c *Module) isPgoCompile() bool {
508 if pgo := c.pgo; pgo != nil {
509 return pgo.Properties.PgoCompile
510 }
511 return false
512}
513
Logan Chienf3511742017-10-31 18:04:35 +0800514func (c *Module) isVndkSp() bool {
515 if vndkdep := c.vndkdep; vndkdep != nil {
516 return vndkdep.isVndkSp()
517 }
518 return false
519}
520
521func (c *Module) isVndkExt() bool {
522 if vndkdep := c.vndkdep; vndkdep != nil {
523 return vndkdep.isVndkExt()
524 }
525 return false
526}
527
528func (c *Module) getVndkExtendsModuleName() string {
529 if vndkdep := c.vndkdep; vndkdep != nil {
530 return vndkdep.getVndkExtendsModuleName()
531 }
532 return ""
533}
534
Jiyong Park82e2bf32017-08-16 14:05:54 +0900535// Returns true only when this module is configured to have core and vendor
536// variants.
537func (c *Module) hasVendorVariant() bool {
538 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
539}
540
Jiyong Parkf9332f12018-02-01 00:54:12 +0900541func (c *Module) inRecovery() bool {
542 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
543}
544
545func (c *Module) onlyInRecovery() bool {
546 return c.ModuleBase.InstallInRecovery()
547}
548
Jiyong Park25fc6a92018-11-18 18:02:45 +0900549func (c *Module) IsStubs() bool {
550 if library, ok := c.linker.(*libraryDecorator); ok {
551 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900552 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
553 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900554 }
555 return false
556}
557
558func (c *Module) HasStubsVariants() bool {
559 if library, ok := c.linker.(*libraryDecorator); ok {
560 return len(library.Properties.Stubs.Versions) > 0
561 }
562 return false
563}
564
Colin Crossca860ac2016-01-04 14:34:37 -0800565type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700566 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800567 moduleContextImpl
568}
569
Colin Cross37047f12016-12-13 17:06:13 -0800570type depsContext struct {
571 android.BottomUpMutatorContext
572 moduleContextImpl
573}
574
Colin Crossca860ac2016-01-04 14:34:37 -0800575type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700576 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800577 moduleContextImpl
578}
579
Jiyong Park2db76922017-11-08 16:03:48 +0900580func (ctx *moduleContext) SocSpecific() bool {
581 return ctx.ModuleContext.SocSpecific() ||
582 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700583}
584
Colin Crossca860ac2016-01-04 14:34:37 -0800585type moduleContextImpl struct {
586 mod *Module
587 ctx BaseModuleContext
588}
589
Colin Crossb98c8b02016-07-29 13:44:28 -0700590func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800591 return ctx.mod.toolchain(ctx.ctx)
592}
593
594func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000595 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800596}
597
598func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900599 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800600}
601
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700602func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800603 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800604 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700605 }
606 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800607}
608
609func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700610 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700611 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900612 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700613 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900614 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
615 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
616 return "current"
617 }
618 return platform_vndk_ver
619 }
620 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800621 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900622 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700623 }
624 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800625}
626
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700627func (ctx *moduleContextImpl) useVndk() bool {
628 return ctx.mod.useVndk()
629}
Justin Yun8effde42017-06-23 19:24:43 +0900630
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800631func (ctx *moduleContextImpl) isNdk() bool {
632 return ctx.mod.isNdk()
633}
634
635func (ctx *moduleContextImpl) isLlndk() bool {
636 return ctx.mod.isLlndk()
637}
638
639func (ctx *moduleContextImpl) isLlndkPublic() bool {
640 return ctx.mod.isLlndkPublic()
641}
642
643func (ctx *moduleContextImpl) isVndkPrivate() bool {
644 return ctx.mod.isVndkPrivate()
645}
646
Logan Chienf3511742017-10-31 18:04:35 +0800647func (ctx *moduleContextImpl) isVndk() bool {
648 return ctx.mod.isVndk()
649}
650
Yi Kong7e53c572018-02-14 18:16:12 +0800651func (ctx *moduleContextImpl) isPgoCompile() bool {
652 return ctx.mod.isPgoCompile()
653}
654
Justin Yun8effde42017-06-23 19:24:43 +0900655func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800656 return ctx.mod.isVndkSp()
657}
658
659func (ctx *moduleContextImpl) isVndkExt() bool {
660 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900661}
662
Jiyong Parkf9332f12018-02-01 00:54:12 +0900663func (ctx *moduleContextImpl) inRecovery() bool {
664 return ctx.mod.inRecovery()
665}
666
Logan Chien2f2b8902018-07-10 15:01:19 +0800667// Check whether ABI dumps should be created for this module.
668func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump() bool {
669 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
670 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800671 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800672
673 if ctx.ctx.Fuchsia() {
674 return false
675 }
676
Logan Chien2f2b8902018-07-10 15:01:19 +0800677 if sanitize := ctx.mod.sanitize; sanitize != nil {
678 if !sanitize.isVariantOnProductionDevice() {
679 return false
680 }
681 }
682 if !ctx.ctx.Device() {
683 // Host modules do not need ABI dumps.
684 return false
685 }
Logan Chienfa478c02018-12-28 16:25:39 +0800686 if !ctx.mod.IsForPlatform() {
687 // APEX variants do not need ABI dumps.
688 return false
689 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800690 if ctx.isNdk() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800691 return true
692 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800693 if ctx.isLlndkPublic() {
Logan Chienf4b79c62018-08-02 02:27:02 +0800694 return true
695 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800696 if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800697 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
698 // VNDK-private.
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800699 return true
Logan Chien2f2b8902018-07-10 15:01:19 +0800700 }
701 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800702}
703
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700704func (ctx *moduleContextImpl) selectedStl() string {
705 if stl := ctx.mod.stl; stl != nil {
706 return stl.Properties.SelectedStl
707 }
708 return ""
709}
710
Ivan Lozanobd721262018-11-27 14:33:03 -0800711func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
712 return ctx.mod.linker.useClangLld(actx)
713}
714
Colin Crossce75d2c2016-10-06 16:12:58 -0700715func (ctx *moduleContextImpl) baseModuleName() string {
716 return ctx.mod.ModuleBase.BaseModuleName()
717}
718
Logan Chienf3511742017-10-31 18:04:35 +0800719func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
720 return ctx.mod.getVndkExtendsModuleName()
721}
722
Jiyong Park25fc6a92018-11-18 18:02:45 +0900723// Tests if this module is built for APEX
724func (ctx *moduleContextImpl) isApex() bool {
725 return ctx.mod.ApexName() != ""
726}
727
Jiyong Parkb0788572018-12-20 22:10:17 +0900728func (ctx *moduleContextImpl) hasStubsVariants() bool {
729 return ctx.mod.HasStubsVariants()
730}
731
732func (ctx *moduleContextImpl) isStubs() bool {
733 return ctx.mod.IsStubs()
734}
735
Colin Cross635c3b02016-05-18 15:37:25 -0700736func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800737 return &Module{
738 hod: hod,
739 multilib: multilib,
740 }
741}
742
Colin Cross635c3b02016-05-18 15:37:25 -0700743func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800744 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700745 module.features = []feature{
746 &tidyFeature{},
747 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700748 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800749 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800750 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800751 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900752 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700753 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700754 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800755 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800756 return module
757}
758
Colin Crossce75d2c2016-10-06 16:12:58 -0700759func (c *Module) Prebuilt() *android.Prebuilt {
760 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
761 return p.prebuilt()
762 }
763 return nil
764}
765
766func (c *Module) Name() string {
767 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700768 if p, ok := c.linker.(interface {
769 Name(string) string
770 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700771 name = p.Name(name)
772 }
773 return name
774}
775
Jeff Gaston294356f2017-09-27 17:05:30 -0700776// orderDeps reorders dependencies into a list such that if module A depends on B, then
777// A will precede B in the resultant list.
778// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800779// Note that directSharedDeps should be the analogous static library for each shared lib dep
780func 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 -0700781 // If A depends on B, then
782 // Every list containing A will also contain B later in the list
783 // So, after concatenating all lists, the final instance of B will have come from the same
784 // original list as the final instance of A
785 // So, the final instance of B will be later in the concatenation than the final A
786 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
787 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800788 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700789 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800790 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
791 }
792 for _, dep := range directSharedDeps {
793 orderedAllDeps = append(orderedAllDeps, dep)
794 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700795 }
796
Colin Crossb6715442017-10-24 11:13:31 -0700797 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700798
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800799 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700800 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800801 // resultant list to only what the caller has chosen to include in directStaticDeps
802 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700803
804 return orderedAllDeps, orderedDeclaredDeps
805}
806
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800807func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
808 // convert Module to Path
809 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
810 staticDepFiles := []android.Path{}
811 for _, dep := range staticDeps {
812 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
813 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700814 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800815 sharedDepFiles := []android.Path{}
816 for _, sharedDep := range sharedDeps {
817 staticAnalogue := sharedDep.staticVariant
818 if staticAnalogue != nil {
819 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
820 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
821 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700822 }
823
824 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800825 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700826
827 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700828}
829
Colin Cross635c3b02016-05-18 15:37:25 -0700830func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800831 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700832 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800833 moduleContextImpl: moduleContextImpl{
834 mod: c,
835 },
836 }
837 ctx.ctx = ctx
838
Colin Crossf18e1102017-11-16 14:33:08 -0800839 deps := c.depsToPaths(ctx)
840 if ctx.Failed() {
841 return
842 }
843
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700844 if c.Properties.Clang != nil && *c.Properties.Clang == false {
845 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
846 }
847
Colin Crossca860ac2016-01-04 14:34:37 -0800848 flags := Flags{
849 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800850 }
Colin Crossca860ac2016-01-04 14:34:37 -0800851 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800852 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800853 }
854 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700855 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800856 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700857 if c.stl != nil {
858 flags = c.stl.flags(ctx, flags)
859 }
Colin Cross16b23492016-01-06 14:41:07 -0800860 if c.sanitize != nil {
861 flags = c.sanitize.flags(ctx, flags)
862 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800863 if c.coverage != nil {
864 flags = c.coverage.flags(ctx, flags)
865 }
Stephen Craneba090d12017-05-09 15:44:35 -0700866 if c.lto != nil {
867 flags = c.lto.flags(ctx, flags)
868 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700869 if c.pgo != nil {
870 flags = c.pgo.flags(ctx, flags)
871 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800872 if c.xom != nil {
873 flags = c.xom.flags(ctx, flags)
874 }
Colin Crossca860ac2016-01-04 14:34:37 -0800875 for _, feature := range c.features {
876 flags = feature.flags(ctx, flags)
877 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800878 if ctx.Failed() {
879 return
880 }
881
Colin Crossb98c8b02016-07-29 13:44:28 -0700882 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
883 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
884 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800885
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800886 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
887 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700888 // We need access to all the flags seen by a source file.
889 if c.sabi != nil {
890 flags = c.sabi.flags(ctx, flags)
891 }
Colin Crossca860ac2016-01-04 14:34:37 -0800892 // Optimization to reduce size of build.ninja
893 // Replace the long list of flags for each file with a module-local variable
894 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
895 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
896 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
897 flags.CFlags = []string{"$cflags"}
898 flags.CppFlags = []string{"$cppflags"}
899 flags.AsFlags = []string{"$asflags"}
900
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700901 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800902 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700903 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800904 if ctx.Failed() {
905 return
906 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800907 }
908
Colin Crossca860ac2016-01-04 14:34:37 -0800909 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700910 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800911 if ctx.Failed() {
912 return
913 }
Colin Cross635c3b02016-05-18 15:37:25 -0700914 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +0900915
916 // If a lib is directly included in any of the APEXes, unhide the stubs
917 // variant having the latest version gets visible to make. In addition,
918 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
919 // force anything in the make world to link against the stubs library.
920 // (unless it is explicitly referenced via .bootstrap suffix or the
921 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +0000922 if c.HasStubsVariants() &&
923 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Jiyong Parkb0788572018-12-20 22:10:17 +0900924 !c.inRecovery() && !c.useVndk() && !c.static() && c.IsStubs() {
925 c.Properties.HideFromMake = false // unhide
926 // Note: this is still non-installable
927 }
Colin Crossce75d2c2016-10-06 16:12:58 -0700928 }
Colin Cross5049f022015-03-18 13:28:46 -0700929
Jiyong Park9d452992018-10-03 00:38:19 +0900930 if c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() {
Colin Crossce75d2c2016-10-06 16:12:58 -0700931 c.installer.install(ctx, c.outputFile.Path())
932 if ctx.Failed() {
933 return
Colin Crossca860ac2016-01-04 14:34:37 -0800934 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700935 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800936}
937
Jiyong Park379de2f2018-12-19 02:47:14 +0900938func (c *Module) toolchain(ctx android.BaseContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800939 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700940 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800941 }
Colin Crossca860ac2016-01-04 14:34:37 -0800942 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800943}
944
Colin Crossca860ac2016-01-04 14:34:37 -0800945func (c *Module) begin(ctx BaseModuleContext) {
946 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700947 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700948 }
Colin Crossca860ac2016-01-04 14:34:37 -0800949 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700950 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800951 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700952 if c.stl != nil {
953 c.stl.begin(ctx)
954 }
Colin Cross16b23492016-01-06 14:41:07 -0800955 if c.sanitize != nil {
956 c.sanitize.begin(ctx)
957 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800958 if c.coverage != nil {
959 c.coverage.begin(ctx)
960 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800961 if c.sabi != nil {
962 c.sabi.begin(ctx)
963 }
Justin Yun8effde42017-06-23 19:24:43 +0900964 if c.vndkdep != nil {
965 c.vndkdep.begin(ctx)
966 }
Stephen Craneba090d12017-05-09 15:44:35 -0700967 if c.lto != nil {
968 c.lto.begin(ctx)
969 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700970 if c.pgo != nil {
971 c.pgo.begin(ctx)
972 }
Colin Crossca860ac2016-01-04 14:34:37 -0800973 for _, feature := range c.features {
974 feature.begin(ctx)
975 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700976 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700977 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700978 if err != nil {
979 ctx.PropertyErrorf("sdk_version", err.Error())
980 }
Nan Zhang0007d812017-11-07 10:57:05 -0800981 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700982 }
Colin Crossca860ac2016-01-04 14:34:37 -0800983}
984
Colin Cross37047f12016-12-13 17:06:13 -0800985func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700986 deps := Deps{}
987
988 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700989 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700990 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +0000991 // Add the PGO dependency (the clang_rt.profile runtime library), which
992 // sometimes depends on symbols from libgcc, before libgcc gets added
993 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700994 if c.pgo != nil {
995 deps = c.pgo.deps(ctx, deps)
996 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700997 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700998 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700999 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001000 if c.stl != nil {
1001 deps = c.stl.deps(ctx, deps)
1002 }
Colin Cross16b23492016-01-06 14:41:07 -08001003 if c.sanitize != nil {
1004 deps = c.sanitize.deps(ctx, deps)
1005 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001006 if c.coverage != nil {
1007 deps = c.coverage.deps(ctx, deps)
1008 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001009 if c.sabi != nil {
1010 deps = c.sabi.deps(ctx, deps)
1011 }
Justin Yun8effde42017-06-23 19:24:43 +09001012 if c.vndkdep != nil {
1013 deps = c.vndkdep.deps(ctx, deps)
1014 }
Stephen Craneba090d12017-05-09 15:44:35 -07001015 if c.lto != nil {
1016 deps = c.lto.deps(ctx, deps)
1017 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001018 for _, feature := range c.features {
1019 deps = feature.deps(ctx, deps)
1020 }
1021
Colin Crossb6715442017-10-24 11:13:31 -07001022 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1023 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1024 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1025 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1026 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1027 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001028 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001029
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001030 for _, lib := range deps.ReexportSharedLibHeaders {
1031 if !inList(lib, deps.SharedLibs) {
1032 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1033 }
1034 }
1035
1036 for _, lib := range deps.ReexportStaticLibHeaders {
1037 if !inList(lib, deps.StaticLibs) {
1038 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1039 }
1040 }
1041
Colin Cross5950f382016-12-13 12:50:57 -08001042 for _, lib := range deps.ReexportHeaderLibHeaders {
1043 if !inList(lib, deps.HeaderLibs) {
1044 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1045 }
1046 }
1047
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001048 for _, gen := range deps.ReexportGeneratedHeaders {
1049 if !inList(gen, deps.GeneratedHeaders) {
1050 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1051 }
1052 }
1053
Colin Crossc99deeb2016-04-11 15:06:20 -07001054 return deps
1055}
1056
Dan Albert7e9d2952016-08-04 13:02:36 -07001057func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001058 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001059 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001060 moduleContextImpl: moduleContextImpl{
1061 mod: c,
1062 },
1063 }
1064 ctx.ctx = ctx
1065
Colin Crossca860ac2016-01-04 14:34:37 -08001066 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001067}
1068
Jiyong Park7ed9de32018-10-15 22:25:07 +09001069// Split name#version into name and version
1070func stubsLibNameAndVersion(name string) (string, string) {
1071 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1072 version := name[sharp+1:]
1073 libname := name[:sharp]
1074 return libname, version
1075 }
1076 return name, ""
1077}
1078
Colin Cross1e676be2016-10-12 14:38:15 -07001079func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001080 ctx := &depsContext{
1081 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001082 moduleContextImpl: moduleContextImpl{
1083 mod: c,
1084 },
1085 }
1086 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001087
Colin Crossc99deeb2016-04-11 15:06:20 -07001088 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001089
Dan Albert914449f2016-06-17 16:45:24 -07001090 variantNdkLibs := []string{}
1091 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001092 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001093 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001094
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001095 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1096 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001097 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001098 // 1. Name of an NDK library that refers to a prebuilt module.
1099 // For each of these, it adds the name of the prebuilt module (which will be in
1100 // prebuilts/ndk) to the list of nonvariant libs.
1101 // 2. Name of an NDK library that refers to an ndk_library module.
1102 // For each of these, it adds the name of the ndk_library module to the list of
1103 // variant libs.
1104 // 3. Anything else (so anything that isn't an NDK library).
1105 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001106 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001107 // The caller can then know to add the variantLibs dependencies differently from the
1108 // nonvariantLibs
1109 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1110 variantLibs = []string{}
1111 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001112 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001113 // strip #version suffix out
1114 name, _ := stubsLibNameAndVersion(entry)
1115 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1116 if !inList(name, ndkMigratedLibs) {
1117 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001118 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001119 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001120 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001121 } else if ctx.useVndk() && inList(name, llndkLibraries) {
1122 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
1123 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, vendorPublicLibraries) {
1124 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001125 if actx.OtherModuleExists(vendorPublicLib) {
1126 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1127 } else {
1128 // This can happen if vendor_public_library module is defined in a
1129 // namespace that isn't visible to the current module. In that case,
1130 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001131 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001132 }
Dan Albert914449f2016-06-17 16:45:24 -07001133 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001134 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001135 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001136 }
1137 }
Dan Albert914449f2016-06-17 16:45:24 -07001138 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001139 }
1140
Dan Albert914449f2016-06-17 16:45:24 -07001141 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1142 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001143 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001144 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001145
Jiyong Park7ed9de32018-10-15 22:25:07 +09001146 if c.linker != nil {
1147 if library, ok := c.linker.(*libraryDecorator); ok {
1148 if library.buildStubs() {
1149 // Stubs lib does not have dependency to other libraries. Don't proceed.
1150 return
1151 }
1152 }
1153 }
1154
Colin Cross32ec36c2016-12-15 07:39:51 -08001155 for _, lib := range deps.HeaderLibs {
1156 depTag := headerDepTag
1157 if inList(lib, deps.ReexportHeaderLibHeaders) {
1158 depTag = headerExportDepTag
1159 }
1160 actx.AddVariationDependencies(nil, depTag, lib)
1161 }
Colin Cross5950f382016-12-13 12:50:57 -08001162
Dan Willemsen59339a22018-07-22 21:18:45 -07001163 actx.AddVariationDependencies([]blueprint.Variation{
1164 {Mutator: "link", Variation: "static"},
1165 }, wholeStaticDepTag, deps.WholeStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001166
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001167 for _, lib := range deps.StaticLibs {
1168 depTag := staticDepTag
1169 if inList(lib, deps.ReexportStaticLibHeaders) {
1170 depTag = staticExportDepTag
1171 }
Dan Willemsen59339a22018-07-22 21:18:45 -07001172 actx.AddVariationDependencies([]blueprint.Variation{
1173 {Mutator: "link", Variation: "static"},
1174 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001175 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001176
Dan Willemsen59339a22018-07-22 21:18:45 -07001177 actx.AddVariationDependencies([]blueprint.Variation{
1178 {Mutator: "link", Variation: "static"},
1179 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001180
Jiyong Park25fc6a92018-11-18 18:02:45 +09001181 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1182 var variations []blueprint.Variation
1183 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001184 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001185 if version != "" && versionVariantAvail {
1186 // Version is explicitly specified. i.e. libFoo#30
1187 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1188 depTag.explicitlyVersioned = true
1189 }
1190 actx.AddVariationDependencies(variations, depTag, name)
1191
1192 // If the version is not specified, add dependency to the latest stubs library.
1193 // The stubs library will be used when the depending module is built for APEX and
1194 // the dependent module is not in the same APEX.
1195 latestVersion := latestStubsVersionFor(actx.Config(), name)
1196 if version == "" && latestVersion != "" && versionVariantAvail {
1197 actx.AddVariationDependencies([]blueprint.Variation{
1198 {Mutator: "link", Variation: "shared"},
1199 {Mutator: "version", Variation: latestVersion},
1200 }, depTag, name)
1201 // Note that depTag.explicitlyVersioned is false in this case.
1202 }
1203 }
1204
Jiyong Park7ed9de32018-10-15 22:25:07 +09001205 // shared lib names without the #version suffix
1206 var sharedLibNames []string
1207
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001208 for _, lib := range deps.SharedLibs {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001209 name, version := stubsLibNameAndVersion(lib)
1210 sharedLibNames = append(sharedLibNames, name)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001211 depTag := sharedDepTag
1212 if inList(lib, deps.ReexportSharedLibHeaders) {
1213 depTag = sharedExportDepTag
1214 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001215 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001216 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001217
Jiyong Park7ed9de32018-10-15 22:25:07 +09001218 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001219 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001220 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1221 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1222 // linking against both the stubs lib and the non-stubs lib at the same time.
1223 continue
1224 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001225 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001226 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001227
Dan Willemsen59339a22018-07-22 21:18:45 -07001228 actx.AddVariationDependencies([]blueprint.Variation{
1229 {Mutator: "link", Variation: "shared"},
1230 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001231
Colin Cross68861832016-07-08 10:41:41 -07001232 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001233
1234 for _, gen := range deps.GeneratedHeaders {
1235 depTag := genHeaderDepTag
1236 if inList(gen, deps.ReexportGeneratedHeaders) {
1237 depTag = genHeaderExportDepTag
1238 }
1239 actx.AddDependency(c, depTag, gen)
1240 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001241
Colin Cross42d48b72018-08-29 14:10:52 -07001242 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001243
1244 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001245 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001246 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001247 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001248 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001249 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001250 if deps.LinkerFlagsFile != "" {
1251 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1252 }
1253 if deps.DynamicLinker != "" {
1254 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001255 }
Dan Albert914449f2016-06-17 16:45:24 -07001256
1257 version := ctx.sdkVersion()
1258 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001259 {Mutator: "ndk_api", Variation: version},
1260 {Mutator: "link", Variation: "shared"},
1261 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001262 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001263 {Mutator: "ndk_api", Variation: version},
1264 {Mutator: "link", Variation: "shared"},
1265 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001266
1267 if vndkdep := c.vndkdep; vndkdep != nil {
1268 if vndkdep.isVndkExt() {
1269 baseModuleMode := vendorMode
1270 if actx.DeviceConfig().VndkVersion() == "" {
1271 baseModuleMode = coreMode
1272 }
1273 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001274 {Mutator: "image", Variation: baseModuleMode},
1275 {Mutator: "link", Variation: "shared"},
1276 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001277 }
1278 }
Colin Cross6362e272015-10-29 15:25:03 -07001279}
Colin Cross21b9a242015-03-24 14:15:58 -07001280
Colin Crosse40b4ea2018-10-02 22:25:58 -07001281func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001282 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1283 c.beginMutator(ctx)
1284 }
1285}
1286
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001287// Whether a module can link to another module, taking into
1288// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001289func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001290 if from.Target().Os != android.Android {
1291 // Host code is not restricted
1292 return
1293 }
1294 if from.Properties.UseVndk {
1295 // Though vendor code is limited by the vendor mutator,
1296 // each vendor-available module needs to check
1297 // link-type for VNDK.
1298 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001299 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001300 }
1301 return
1302 }
Nan Zhang0007d812017-11-07 10:57:05 -08001303 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001304 // Platform code can link to anything
1305 return
1306 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001307 if from.inRecovery() {
1308 // Recovery code is not NDK
1309 return
1310 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001311 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1312 // These are always allowed
1313 return
1314 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001315 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1316 // These are allowed, but they don't set sdk_version
1317 return
1318 }
1319 if _, ok := to.linker.(*stubDecorator); ok {
1320 // These aren't real libraries, but are the stub shared libraries that are included in
1321 // the NDK.
1322 return
1323 }
Logan Chien834b9a62019-01-14 15:39:03 +08001324
1325 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" {
1326 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1327 // to link to libc++ (non-NDK and without sdk_version).
1328 return
1329 }
1330
Nan Zhang0007d812017-11-07 10:57:05 -08001331 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001332 // NDK code linking to platform code is never okay.
1333 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1334 ctx.OtherModuleName(to))
1335 }
1336
1337 // At this point we know we have two NDK libraries, but we need to
1338 // check that we're not linking against anything built against a higher
1339 // API level, as it is only valid to link against older or equivalent
1340 // APIs.
1341
Inseob Kim01a28722018-04-11 09:48:45 +09001342 // Current can link against anything.
1343 if String(from.Properties.Sdk_version) != "current" {
1344 // Otherwise we need to check.
1345 if String(to.Properties.Sdk_version) == "current" {
1346 // Current can't be linked against by anything else.
1347 ctx.ModuleErrorf("links %q built against newer API version %q",
1348 ctx.OtherModuleName(to), "current")
1349 } else {
1350 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1351 if err != nil {
1352 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001353 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001354 String(from.Properties.Sdk_version))
1355 }
1356 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1357 if err != nil {
1358 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001359 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001360 String(to.Properties.Sdk_version))
1361 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001362
Inseob Kim01a28722018-04-11 09:48:45 +09001363 if toApi > fromApi {
1364 ctx.ModuleErrorf("links %q built against newer API version %q",
1365 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1366 }
1367 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001368 }
Dan Albert202fe492017-12-15 13:56:59 -08001369
1370 // Also check that the two STL choices are compatible.
1371 fromStl := from.stl.Properties.SelectedStl
1372 toStl := to.stl.Properties.SelectedStl
1373 if fromStl == "" || toStl == "" {
1374 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001375 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001376 // We can be permissive with the system "STL" since it is only the C++
1377 // ABI layer, but in the future we should make sure that everyone is
1378 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001379 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001380 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1381 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1382 to.stl.Properties.SelectedStl)
1383 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001384}
1385
Jiyong Park5fb8c102018-04-09 12:03:06 +09001386// Tests whether the dependent library is okay to be double loaded inside a single process.
1387// If a library is a member of VNDK and at the same time dependencies of an LLNDK library,
1388// it is subject to be double loaded. Such lib should be explicitly marked as double_loaded: true
1389// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
1390func checkDoubleLoadableLibries(ctx android.ModuleContext, from *Module, to *Module) {
1391 if _, ok := from.linker.(*libraryDecorator); !ok {
1392 return
1393 }
1394
1395 if inList(ctx.ModuleName(), llndkLibraries) ||
1396 (from.useVndk() && Bool(from.VendorProperties.Double_loadable)) {
1397 _, depIsLlndk := to.linker.(*llndkStubDecorator)
1398 depIsVndkSp := false
1399 if to.vndkdep != nil && to.vndkdep.isVndkSp() {
1400 depIsVndkSp = true
1401 }
1402 depIsVndk := false
1403 if to.vndkdep != nil && to.vndkdep.isVndk() {
1404 depIsVndk = true
1405 }
1406 depIsDoubleLoadable := Bool(to.VendorProperties.Double_loadable)
1407 if !depIsLlndk && !depIsVndkSp && !depIsDoubleLoadable && depIsVndk {
Steven Moreland742989e2018-11-26 12:41:04 -08001408 ctx.ModuleErrorf("links VNDK library %q that isn't double loadable (not also LL-NDK, "+
1409 "VNDK-SP, or explicitly marked as 'double_loadable').",
Jiyong Park5fb8c102018-04-09 12:03:06 +09001410 ctx.OtherModuleName(to))
1411 }
1412 }
1413}
1414
Colin Crossc99deeb2016-04-11 15:06:20 -07001415// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001416func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001417 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001418
Jeff Gaston294356f2017-09-27 17:05:30 -07001419 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001420 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001421
Colin Crossd11fcda2017-10-23 17:59:01 -07001422 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001423 depName := ctx.OtherModuleName(dep)
1424 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001425
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001426 ccDep, _ := dep.(*Module)
1427 if ccDep == nil {
1428 // handling for a few module types that aren't cc Module but that are also supported
1429 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001430 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001431 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001432 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1433 genRule.GeneratedSourceFiles()...)
1434 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001435 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001436 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001437 // Support exported headers from a generated_sources dependency
1438 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001439 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001440 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001441 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001442 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001443 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001444 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001445 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001446 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001447 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001448 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001449 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1450 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1451
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001452 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001453 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001454 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001455 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001456 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001457 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001458 files := genRule.GeneratedSourceFiles()
1459 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001460 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001461 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001462 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 -07001463 }
1464 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001465 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001466 }
Colin Crossca860ac2016-01-04 14:34:37 -08001467 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001468 return
1469 }
1470
Colin Crossd11fcda2017-10-23 17:59:01 -07001471 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001472 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1473 return
1474 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001475 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001476 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001477 return
1478 }
1479
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001480 // re-exporting flags
1481 if depTag == reuseObjTag {
1482 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001483 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001484 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001485 depPaths.Objs = depPaths.Objs.Append(objs)
1486 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001487 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001488 return
1489 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001490 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001491
1492 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1493 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1494 // won't be matched to sharedDepTag and lateSharedDepTag.
1495 explicitlyVersioned := false
1496 if t, ok := depTag.(dependencyTag); ok {
1497 explicitlyVersioned = t.explicitlyVersioned
1498 t.explicitlyVersioned = false
1499 depTag = t
1500 }
1501
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001502 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001503 depIsStatic := false
1504 switch depTag {
1505 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1506 depIsStatic = true
1507 }
1508 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001509 depIsStubs := dependentLibrary.buildStubs()
1510 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001511 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001512 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001513
1514 var useThisDep bool
1515 if depIsStubs && explicitlyVersioned {
1516 // Always respect dependency to the versioned stubs (i.e. libX#10)
1517 useThisDep = true
1518 } else if !depHasStubs {
1519 // Use non-stub variant if that is the only choice
1520 // (i.e. depending on a lib without stubs.version property)
1521 useThisDep = true
1522 } else if c.IsForPlatform() {
1523 // If not building for APEX, use stubs only when it is from
1524 // an APEX (and not from platform)
1525 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parkb0788572018-12-20 22:10:17 +09001526 if c.inRecovery() || Bool(c.Properties.Bootstrap) {
1527 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001528 // always link to non-stub variant
1529 useThisDep = !depIsStubs
1530 }
1531 } else {
1532 // If building for APEX, use stubs only when it is not from
1533 // the same APEX
1534 useThisDep = (depInSameApex != depIsStubs)
1535 }
1536
1537 if !useThisDep {
1538 return // stop processing this dep
1539 }
1540 }
1541
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001542 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001543 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001544 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001545 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001546 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001547
1548 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001549 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001550 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001551 // 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 -07001552 // Re-exported shared library headers must be included as well since they can help us with type information
1553 // about template instantiations (instantiated from their headers).
1554 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001555 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001556 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001557
Logan Chienf3511742017-10-31 18:04:35 +08001558 checkLinkType(ctx, c, ccDep, t)
Jiyong Park5fb8c102018-04-09 12:03:06 +09001559 checkDoubleLoadableLibries(ctx, c, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001560 }
1561
Colin Cross26c34ed2016-09-30 17:10:16 -07001562 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001563 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001564
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001565 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001566 depFile := android.OptionalPath{}
1567
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001568 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001569 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001570 ptr = &depPaths.SharedLibs
1571 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001572 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001573 directSharedDeps = append(directSharedDeps, ccDep)
Jiyong Park64a44f22019-01-18 14:37:08 +09001574 case earlySharedDepTag:
1575 ptr = &depPaths.EarlySharedLibs
1576 depPtr = &depPaths.EarlySharedLibsDeps
1577 depFile = ccDep.linker.(libraryInterface).toc()
1578 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001579 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001580 ptr = &depPaths.LateSharedLibs
1581 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001582 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001583 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001584 ptr = nil
1585 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001586 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001587 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001588 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001589 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001590 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001591 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001592 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001593 return
1594 }
1595
1596 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001597 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001598 for i := range missingDeps {
1599 missingDeps[i] += postfix
1600 }
1601 ctx.AddMissingDependencies(missingDeps)
1602 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001603 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001604 case headerDepTag:
1605 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001606 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001607 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001608 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001609 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001610 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001611 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001612 case dynamicLinkerDepTag:
1613 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001614 }
1615
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001616 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001617 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001618 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001619 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001620 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001621 return
1622 }
1623
1624 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001625 // in static libraries act as if they were whole static libraries. The same goes for
1626 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001627 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1628 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001629 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1630 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001631
Dan Willemsen581341d2017-02-09 16:16:31 -08001632 }
1633
Colin Cross26c34ed2016-09-30 17:10:16 -07001634 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001635 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001636 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001637 return
1638 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001639 *ptr = append(*ptr, linkFile.Path())
1640 }
1641
Colin Crossc99deeb2016-04-11 15:06:20 -07001642 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001643 dep := depFile
1644 if !dep.Valid() {
1645 dep = linkFile
1646 }
1647 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001648 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001649
Logan Chien43d34c32017-12-20 01:17:32 +08001650 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001651 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001652 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001653 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001654 isLLndk := inList(libName, llndkLibraries)
Jiyong Park374510b2018-03-19 18:23:01 +09001655 isVendorPublicLib := inList(libName, vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001656 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1657 if c.useVndk() && bothVendorAndCoreVariantsExist {
1658 // The vendor module in Make will have been renamed to not conflict with the core
1659 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001660 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001661 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001662 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001663 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1664 return libName + recoverySuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001665 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001666 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001667 }
Logan Chien43d34c32017-12-20 01:17:32 +08001668 }
1669
1670 // Export the shared libs to Make.
1671 switch depTag {
Jiyong Park64a44f22019-01-18 14:37:08 +09001672 case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001673 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001674 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08001675 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09001676 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001677 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001678 c.Properties.ApexesProvidingSharedLibs = append(
1679 c.Properties.ApexesProvidingSharedLibs, an)
1680 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09001681 }
1682 }
1683
Jiyong Park27b188b2017-07-18 13:23:39 +09001684 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001685 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001686 c.Properties.AndroidMkSharedLibs = append(
1687 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08001688 case ndkStubDepTag, ndkLateStubDepTag:
1689 ndkStub := ccDep.linker.(*stubDecorator)
1690 c.Properties.AndroidMkSharedLibs = append(
1691 c.Properties.AndroidMkSharedLibs,
1692 depName+"."+ndkStub.properties.ApiLevel)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001693 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1694 c.Properties.AndroidMkStaticLibs = append(
1695 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001696 case runtimeDepTag:
1697 c.Properties.AndroidMkRuntimeLibs = append(
1698 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001699 case wholeStaticDepTag:
1700 c.Properties.AndroidMkWholeStaticLibs = append(
1701 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001702 }
Colin Crossca860ac2016-01-04 14:34:37 -08001703 })
1704
Jeff Gaston294356f2017-09-27 17:05:30 -07001705 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001706 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001707
Colin Crossdd84e052017-05-17 13:44:16 -07001708 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001709 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001710 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001711 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001712 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1713
1714 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001715 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001716 }
Colin Crossdd84e052017-05-17 13:44:16 -07001717
Colin Crossca860ac2016-01-04 14:34:37 -08001718 return depPaths
1719}
1720
1721func (c *Module) InstallInData() bool {
1722 if c.installer == nil {
1723 return false
1724 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001725 return c.installer.inData()
1726}
1727
1728func (c *Module) InstallInSanitizerDir() bool {
1729 if c.installer == nil {
1730 return false
1731 }
1732 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001733 return true
1734 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001735 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001736}
1737
Jiyong Parkf9332f12018-02-01 00:54:12 +09001738func (c *Module) InstallInRecovery() bool {
1739 return c.inRecovery()
1740}
1741
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001742func (c *Module) HostToolPath() android.OptionalPath {
1743 if c.installer == nil {
1744 return android.OptionalPath{}
1745 }
1746 return c.installer.hostToolPath()
1747}
1748
Nan Zhangd4e641b2017-07-12 12:55:28 -07001749func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1750 return c.outputFile
1751}
1752
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001753func (c *Module) Srcs() android.Paths {
1754 if c.outputFile.Valid() {
1755 return android.Paths{c.outputFile.Path()}
1756 }
1757 return android.Paths{}
1758}
1759
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001760func (c *Module) static() bool {
1761 if static, ok := c.linker.(interface {
1762 static() bool
1763 }); ok {
1764 return static.static()
1765 }
1766 return false
1767}
1768
Jiyong Park379de2f2018-12-19 02:47:14 +09001769func (c *Module) staticBinary() bool {
1770 if static, ok := c.linker.(interface {
1771 staticBinary() bool
1772 }); ok {
1773 return static.staticBinary()
1774 }
1775 return false
1776}
1777
Colin Crossb60190a2018-09-04 16:28:17 -07001778func (c *Module) getMakeLinkType() string {
1779 if c.useVndk() {
1780 if inList(c.Name(), vndkCoreLibraries) || inList(c.Name(), vndkSpLibraries) || inList(c.Name(), llndkLibraries) {
1781 if inList(c.Name(), vndkPrivateLibraries) {
1782 return "native:vndk_private"
1783 } else {
1784 return "native:vndk"
1785 }
1786 } else {
1787 return "native:vendor"
1788 }
1789 } else if c.inRecovery() {
1790 return "native:recovery"
1791 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
1792 return "native:ndk:none:none"
1793 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
1794 //family, link := getNdkStlFamilyAndLinkType(c)
1795 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
1796 } else {
1797 return "native:platform"
1798 }
1799}
1800
Jiyong Park9d452992018-10-03 00:38:19 +09001801// Overrides ApexModule.IsInstallabeToApex()
1802// Only shared libraries are installable to APEX.
1803func (c *Module) IsInstallableToApex() bool {
1804 if shared, ok := c.linker.(interface {
1805 shared() bool
1806 }); ok {
1807 return shared.shared()
1808 }
1809 return false
1810}
1811
Colin Cross2ba19d92015-05-07 15:44:20 -07001812//
Colin Crosscfad1192015-11-02 16:43:11 -08001813// Defaults
1814//
Colin Crossca860ac2016-01-04 14:34:37 -08001815type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001816 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001817 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09001818 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001819}
1820
Colin Cross635c3b02016-05-18 15:37:25 -07001821func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001822}
1823
Colin Cross1e676be2016-10-12 14:38:15 -07001824func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1825}
1826
Colin Cross36242852017-06-23 15:06:31 -07001827func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001828 return DefaultsFactory()
1829}
1830
Colin Cross36242852017-06-23 15:06:31 -07001831func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001832 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001833
Colin Cross36242852017-06-23 15:06:31 -07001834 module.AddProperties(props...)
1835 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001836 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001837 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001838 &BaseCompilerProperties{},
1839 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001840 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001841 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001842 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001843 &TestProperties{},
1844 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001845 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001846 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001847 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001848 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001849 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001850 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001851 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001852 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001853 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001854 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08001855 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001856 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001857 )
Colin Crosscfad1192015-11-02 16:43:11 -08001858
Colin Cross1f44a3a2017-07-07 14:33:33 -07001859 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09001860 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001861
1862 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001863}
1864
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001865const (
1866 // coreMode is the variant used for framework-private libraries, or
1867 // SDK libraries. (which framework-private libraries can use)
1868 coreMode = "core"
1869
1870 // vendorMode is the variant used for /vendor code that compiles
1871 // against the VNDK.
1872 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09001873
1874 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001875)
1876
Jiyong Park6a43f042017-10-12 23:05:00 +09001877func squashVendorSrcs(m *Module) {
1878 if lib, ok := m.compiler.(*libraryDecorator); ok {
1879 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1880 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1881
1882 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1883 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1884 }
1885}
1886
Jiyong Parkf9332f12018-02-01 00:54:12 +09001887func squashRecoverySrcs(m *Module) {
1888 if lib, ok := m.compiler.(*libraryDecorator); ok {
1889 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1890 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
1891
1892 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1893 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
1894 }
1895}
1896
Jiyong Parkda6eb592018-12-19 17:12:36 +09001897func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001898 if mctx.Os() != android.Android {
1899 return
1900 }
1901
Jiyong Park7ed9de32018-10-15 22:25:07 +09001902 if g, ok := mctx.Module().(*genrule.Module); ok {
1903 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09001904 var coreVariantNeeded bool = false
1905 var vendorVariantNeeded bool = false
1906 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09001907 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09001908 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001909 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09001910 coreVariantNeeded = true
1911 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09001912 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09001913 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001914 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09001915 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001916 }
Jiyong Park3f736c92018-05-24 13:36:56 +09001917 if Bool(props.Recovery_available) {
1918 recoveryVariantNeeded = true
1919 }
1920
Jiyong Park413cc742018-06-19 01:46:06 +09001921 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09001922 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09001923 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09001924 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09001925 recoveryVariantNeeded = false
1926 }
1927 }
1928
Jiyong Park3f736c92018-05-24 13:36:56 +09001929 var variants []string
1930 if coreVariantNeeded {
1931 variants = append(variants, coreMode)
1932 }
1933 if vendorVariantNeeded {
1934 variants = append(variants, vendorMode)
1935 }
1936 if recoveryVariantNeeded {
1937 variants = append(variants, recoveryMode)
1938 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001939 mod := mctx.CreateVariations(variants...)
1940 for i, v := range variants {
1941 if v == recoveryMode {
1942 m := mod[i].(*genrule.Module)
1943 m.Extra.(*GenruleExtraProperties).InRecovery = true
1944 }
1945 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001946 }
1947 }
1948
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001949 m, ok := mctx.Module().(*Module)
1950 if !ok {
1951 return
1952 }
1953
1954 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08001955 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09001956 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08001957
1958 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001959 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09001960 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001961 return
1962 }
Logan Chienf3511742017-10-31 18:04:35 +08001963
1964 if vndkdep := m.vndkdep; vndkdep != nil {
1965 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09001966 if productSpecific {
1967 mctx.PropertyErrorf("product_specific",
1968 "product_specific must not be true when `vndk: {enabled: true}`")
1969 return
1970 }
Logan Chienf3511742017-10-31 18:04:35 +08001971 if vendorSpecific {
1972 if !vndkdep.isVndkExt() {
1973 mctx.PropertyErrorf("vndk",
1974 "must set `extends: \"...\"` to vndk extension")
1975 return
1976 }
1977 } else {
1978 if vndkdep.isVndkExt() {
1979 mctx.PropertyErrorf("vndk",
1980 "must set `vendor: true` to set `extends: %q`",
1981 m.getVndkExtendsModuleName())
1982 return
1983 }
1984 if m.VendorProperties.Vendor_available == nil {
1985 mctx.PropertyErrorf("vndk",
1986 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
1987 return
1988 }
1989 }
1990 } else {
1991 if vndkdep.isVndkSp() {
1992 mctx.PropertyErrorf("vndk",
1993 "must set `enabled: true` to set `support_system_process: true`")
1994 return
1995 }
1996 if vndkdep.isVndkExt() {
1997 mctx.PropertyErrorf("vndk",
1998 "must set `enabled: true` to set `extends: %q`",
1999 m.getVndkExtendsModuleName())
2000 return
2001 }
Justin Yun8effde42017-06-23 19:24:43 +09002002 }
2003 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002004
Jiyong Parkf9332f12018-02-01 00:54:12 +09002005 var coreVariantNeeded bool = false
2006 var vendorVariantNeeded bool = false
2007 var recoveryVariantNeeded bool = false
2008
Justin Yun71549282017-11-17 12:10:28 +09002009 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002010 // If the device isn't compiling against the VNDK, we always
2011 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002012 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002013 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2014 // LL-NDK stubs only exist in the vendor variant, since the
2015 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002016 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09002017 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2018 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09002019 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09002020 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002021 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2022 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002023 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002024 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002025 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002026 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002027 coreVariantNeeded = true
2028 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002029 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002030 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09002031 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002032 } else {
2033 // This is either in /system (or similar: /data), or is a
2034 // modules built with the NDK. Modules built with the NDK
2035 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002036 coreVariantNeeded = true
2037 }
2038
2039 if Bool(m.Properties.Recovery_available) {
2040 recoveryVariantNeeded = true
2041 }
2042
2043 if m.ModuleBase.InstallInRecovery() {
2044 recoveryVariantNeeded = true
2045 coreVariantNeeded = false
2046 }
2047
Jiyong Park413cc742018-06-19 01:46:06 +09002048 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002049 primaryArch := mctx.Config().DevicePrimaryArchType()
2050 moduleArch := m.Target().Arch.ArchType
2051 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002052 recoveryVariantNeeded = false
2053 }
2054 }
2055
Jiyong Parkf9332f12018-02-01 00:54:12 +09002056 var variants []string
2057 if coreVariantNeeded {
2058 variants = append(variants, coreMode)
2059 }
2060 if vendorVariantNeeded {
2061 variants = append(variants, vendorMode)
2062 }
2063 if recoveryVariantNeeded {
2064 variants = append(variants, recoveryMode)
2065 }
2066 mod := mctx.CreateVariations(variants...)
2067 for i, v := range variants {
2068 if v == vendorMode {
2069 m := mod[i].(*Module)
2070 m.Properties.UseVndk = true
2071 squashVendorSrcs(m)
2072 } else if v == recoveryMode {
2073 m := mod[i].(*Module)
2074 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002075 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002076 squashRecoverySrcs(m)
2077 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002078 }
2079}
2080
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002081func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002082 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002083 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2084 }
Colin Cross6510f912017-11-29 00:27:14 -08002085 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002086}
2087
Colin Cross06a931b2015-10-28 17:23:31 -07002088var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002089var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002090var BoolPtr = proptools.BoolPtr
2091var String = proptools.String
2092var StringPtr = proptools.StringPtr