blob: c0bd11e7c2341346dd88e6f767b363c977e48df8 [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
99 SharedLibs, LateSharedLibs android.Paths
100 // Paths to the dependencies to use for .so files (.so.toc files)
101 SharedLibsDeps, LateSharedLibsDeps android.Paths
102 // 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}
331 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
332 staticDepTag = dependencyTag{name: "static", library: true}
333 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
334 lateStaticDepTag = dependencyTag{name: "late static", library: true}
335 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800336 headerDepTag = dependencyTag{name: "header", library: true}
337 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700338 genSourceDepTag = dependencyTag{name: "gen source"}
339 genHeaderDepTag = dependencyTag{name: "gen header"}
340 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
341 objDepTag = dependencyTag{name: "obj"}
342 crtBeginDepTag = dependencyTag{name: "crtbegin"}
343 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700344 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
345 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700346 reuseObjTag = dependencyTag{name: "reuse objects"}
347 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
348 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800349 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800350 runtimeDepTag = dependencyTag{name: "runtime lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700351)
352
Colin Crossca860ac2016-01-04 14:34:37 -0800353// Module contains the properties and members used by all C/C++ module types, and implements
354// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
355// to construct the output file. Behavior can be customized with a Customizer interface
356type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700357 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700358 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900359 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700360
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700361 Properties BaseProperties
362 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700363
Colin Crossca860ac2016-01-04 14:34:37 -0800364 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700365 hod android.HostOrDeviceSupported
366 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700367
Colin Crossca860ac2016-01-04 14:34:37 -0800368 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700369 features []feature
370 compiler compiler
371 linker linker
372 installer installer
373 stl *stl
374 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800375 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800376 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900377 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700378 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700379 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800380 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800381
382 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700383
Colin Cross635c3b02016-05-18 15:37:25 -0700384 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800385
Colin Crossb98c8b02016-07-29 13:44:28 -0700386 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700387
388 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800389
390 // Flags used to compile this module
391 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700392
393 // 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 -0800394 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700395 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800396 depsInLinkOrder android.Paths
397
398 // only non-nil when this is a shared library that reuses the objects of a static library
399 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700400}
401
Jiyong Parkc20eee32018-09-05 22:36:17 +0900402func (c *Module) OutputFile() android.OptionalPath {
403 return c.outputFile
404}
405
Colin Cross36242852017-06-23 15:06:31 -0700406func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700407 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800408 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700409 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800410 }
411 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700412 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800413 }
414 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700415 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800416 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700417 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700418 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700419 }
Colin Cross16b23492016-01-06 14:41:07 -0800420 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700421 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800422 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800423 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700424 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800425 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800426 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700427 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800428 }
Justin Yun8effde42017-06-23 19:24:43 +0900429 if c.vndkdep != nil {
430 c.AddProperties(c.vndkdep.props()...)
431 }
Stephen Craneba090d12017-05-09 15:44:35 -0700432 if c.lto != nil {
433 c.AddProperties(c.lto.props()...)
434 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700435 if c.pgo != nil {
436 c.AddProperties(c.pgo.props()...)
437 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800438 if c.xom != nil {
439 c.AddProperties(c.xom.props()...)
440 }
Colin Crossca860ac2016-01-04 14:34:37 -0800441 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700442 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800443 }
Colin Crossc472d572015-03-17 15:06:21 -0700444
Colin Crossa9d8bee2018-10-02 13:59:46 -0700445 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
446 switch class {
447 case android.Device:
448 return ctx.Config().DevicePrefer32BitExecutables()
449 case android.HostCross:
450 // Windows builds always prefer 32-bit
451 return true
452 default:
453 return false
454 }
455 })
Colin Cross36242852017-06-23 15:06:31 -0700456 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700457
Colin Cross1f44a3a2017-07-07 14:33:33 -0700458 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700459
Jiyong Park9d452992018-10-03 00:38:19 +0900460 android.InitApexModule(c)
461
Colin Cross36242852017-06-23 15:06:31 -0700462 return c
Colin Crossc472d572015-03-17 15:06:21 -0700463}
464
Colin Crossb916a382016-07-29 17:28:03 -0700465// Returns true for dependency roots (binaries)
466// TODO(ccross): also handle dlopenable libraries
467func (c *Module) isDependencyRoot() bool {
468 if root, ok := c.linker.(interface {
469 isDependencyRoot() bool
470 }); ok {
471 return root.isDependencyRoot()
472 }
473 return false
474}
475
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700476func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700477 return c.Properties.UseVndk
478}
479
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800480func (c *Module) isNdk() bool {
481 return inList(c.Name(), ndkMigratedLibs)
482}
483
484func (c *Module) isLlndk() bool {
485 // Returns true for both LLNDK (public) and LLNDK-private libs.
486 return inList(c.Name(), llndkLibraries)
487}
488
489func (c *Module) isLlndkPublic() bool {
490 // Returns true only for LLNDK (public) libs.
491 return c.isLlndk() && !c.isVndkPrivate()
492}
493
494func (c *Module) isVndkPrivate() bool {
495 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
496 return inList(c.Name(), vndkPrivateLibraries)
497}
498
Justin Yun8effde42017-06-23 19:24:43 +0900499func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800500 if vndkdep := c.vndkdep; vndkdep != nil {
501 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900502 }
503 return false
504}
505
Yi Kong7e53c572018-02-14 18:16:12 +0800506func (c *Module) isPgoCompile() bool {
507 if pgo := c.pgo; pgo != nil {
508 return pgo.Properties.PgoCompile
509 }
510 return false
511}
512
Logan Chienf3511742017-10-31 18:04:35 +0800513func (c *Module) isVndkSp() bool {
514 if vndkdep := c.vndkdep; vndkdep != nil {
515 return vndkdep.isVndkSp()
516 }
517 return false
518}
519
520func (c *Module) isVndkExt() bool {
521 if vndkdep := c.vndkdep; vndkdep != nil {
522 return vndkdep.isVndkExt()
523 }
524 return false
525}
526
527func (c *Module) getVndkExtendsModuleName() string {
528 if vndkdep := c.vndkdep; vndkdep != nil {
529 return vndkdep.getVndkExtendsModuleName()
530 }
531 return ""
532}
533
Jiyong Park82e2bf32017-08-16 14:05:54 +0900534// Returns true only when this module is configured to have core and vendor
535// variants.
536func (c *Module) hasVendorVariant() bool {
537 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
538}
539
Jiyong Parkf9332f12018-02-01 00:54:12 +0900540func (c *Module) inRecovery() bool {
541 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
542}
543
544func (c *Module) onlyInRecovery() bool {
545 return c.ModuleBase.InstallInRecovery()
546}
547
Jiyong Park25fc6a92018-11-18 18:02:45 +0900548func (c *Module) IsStubs() bool {
549 if library, ok := c.linker.(*libraryDecorator); ok {
550 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900551 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
552 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900553 }
554 return false
555}
556
557func (c *Module) HasStubsVariants() bool {
558 if library, ok := c.linker.(*libraryDecorator); ok {
559 return len(library.Properties.Stubs.Versions) > 0
560 }
561 return false
562}
563
Colin Crossca860ac2016-01-04 14:34:37 -0800564type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700565 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800566 moduleContextImpl
567}
568
Colin Cross37047f12016-12-13 17:06:13 -0800569type depsContext struct {
570 android.BottomUpMutatorContext
571 moduleContextImpl
572}
573
Colin Crossca860ac2016-01-04 14:34:37 -0800574type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700575 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800576 moduleContextImpl
577}
578
Jiyong Park2db76922017-11-08 16:03:48 +0900579func (ctx *moduleContext) SocSpecific() bool {
580 return ctx.ModuleContext.SocSpecific() ||
581 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700582}
583
Colin Crossca860ac2016-01-04 14:34:37 -0800584type moduleContextImpl struct {
585 mod *Module
586 ctx BaseModuleContext
587}
588
Colin Crossb98c8b02016-07-29 13:44:28 -0700589func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800590 return ctx.mod.toolchain(ctx.ctx)
591}
592
593func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000594 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800595}
596
597func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900598 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800599}
600
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700601func (ctx *moduleContextImpl) useSdk() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900602 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() {
Nan Zhang0007d812017-11-07 10:57:05 -0800603 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700604 }
605 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800606}
607
608func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700609 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700610 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900611 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700612 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900613 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
614 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
615 return "current"
616 }
617 return platform_vndk_ver
618 }
619 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800620 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900621 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700622 }
623 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800624}
625
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700626func (ctx *moduleContextImpl) useVndk() bool {
627 return ctx.mod.useVndk()
628}
Justin Yun8effde42017-06-23 19:24:43 +0900629
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800630func (ctx *moduleContextImpl) isNdk() bool {
631 return ctx.mod.isNdk()
632}
633
634func (ctx *moduleContextImpl) isLlndk() bool {
635 return ctx.mod.isLlndk()
636}
637
638func (ctx *moduleContextImpl) isLlndkPublic() bool {
639 return ctx.mod.isLlndkPublic()
640}
641
642func (ctx *moduleContextImpl) isVndkPrivate() bool {
643 return ctx.mod.isVndkPrivate()
644}
645
Logan Chienf3511742017-10-31 18:04:35 +0800646func (ctx *moduleContextImpl) isVndk() bool {
647 return ctx.mod.isVndk()
648}
649
Yi Kong7e53c572018-02-14 18:16:12 +0800650func (ctx *moduleContextImpl) isPgoCompile() bool {
651 return ctx.mod.isPgoCompile()
652}
653
Justin Yun8effde42017-06-23 19:24:43 +0900654func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800655 return ctx.mod.isVndkSp()
656}
657
658func (ctx *moduleContextImpl) isVndkExt() bool {
659 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900660}
661
Jiyong Parkf9332f12018-02-01 00:54:12 +0900662func (ctx *moduleContextImpl) inRecovery() bool {
663 return ctx.mod.inRecovery()
664}
665
Logan Chien2f2b8902018-07-10 15:01:19 +0800666// Check whether ABI dumps should be created for this module.
667func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump() bool {
668 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
669 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800670 }
Logan Chien2f2b8902018-07-10 15:01:19 +0800671 if sanitize := ctx.mod.sanitize; sanitize != nil {
672 if !sanitize.isVariantOnProductionDevice() {
673 return false
674 }
675 }
676 if !ctx.ctx.Device() {
677 // Host modules do not need ABI dumps.
678 return false
679 }
Logan Chienfa478c02018-12-28 16:25:39 +0800680 if !ctx.mod.IsForPlatform() {
681 // APEX variants do not need ABI dumps.
682 return false
683 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800684 if ctx.isNdk() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800685 return true
686 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800687 if ctx.isLlndkPublic() {
Logan Chienf4b79c62018-08-02 02:27:02 +0800688 return true
689 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800690 if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800691 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
692 // VNDK-private.
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800693 return true
Logan Chien2f2b8902018-07-10 15:01:19 +0800694 }
695 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800696}
697
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700698func (ctx *moduleContextImpl) selectedStl() string {
699 if stl := ctx.mod.stl; stl != nil {
700 return stl.Properties.SelectedStl
701 }
702 return ""
703}
704
Ivan Lozanobd721262018-11-27 14:33:03 -0800705func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
706 return ctx.mod.linker.useClangLld(actx)
707}
708
Colin Crossce75d2c2016-10-06 16:12:58 -0700709func (ctx *moduleContextImpl) baseModuleName() string {
710 return ctx.mod.ModuleBase.BaseModuleName()
711}
712
Logan Chienf3511742017-10-31 18:04:35 +0800713func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
714 return ctx.mod.getVndkExtendsModuleName()
715}
716
Jiyong Park25fc6a92018-11-18 18:02:45 +0900717// Tests if this module is built for APEX
718func (ctx *moduleContextImpl) isApex() bool {
719 return ctx.mod.ApexName() != ""
720}
721
Jiyong Parkb0788572018-12-20 22:10:17 +0900722func (ctx *moduleContextImpl) hasStubsVariants() bool {
723 return ctx.mod.HasStubsVariants()
724}
725
726func (ctx *moduleContextImpl) isStubs() bool {
727 return ctx.mod.IsStubs()
728}
729
Colin Cross635c3b02016-05-18 15:37:25 -0700730func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800731 return &Module{
732 hod: hod,
733 multilib: multilib,
734 }
735}
736
Colin Cross635c3b02016-05-18 15:37:25 -0700737func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800738 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700739 module.features = []feature{
740 &tidyFeature{},
741 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700742 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800743 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800744 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800745 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900746 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700747 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700748 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800749 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800750 return module
751}
752
Colin Crossce75d2c2016-10-06 16:12:58 -0700753func (c *Module) Prebuilt() *android.Prebuilt {
754 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
755 return p.prebuilt()
756 }
757 return nil
758}
759
760func (c *Module) Name() string {
761 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700762 if p, ok := c.linker.(interface {
763 Name(string) string
764 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700765 name = p.Name(name)
766 }
767 return name
768}
769
Jeff Gaston294356f2017-09-27 17:05:30 -0700770// orderDeps reorders dependencies into a list such that if module A depends on B, then
771// A will precede B in the resultant list.
772// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800773// Note that directSharedDeps should be the analogous static library for each shared lib dep
774func 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 -0700775 // If A depends on B, then
776 // Every list containing A will also contain B later in the list
777 // So, after concatenating all lists, the final instance of B will have come from the same
778 // original list as the final instance of A
779 // So, the final instance of B will be later in the concatenation than the final A
780 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
781 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800782 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700783 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800784 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
785 }
786 for _, dep := range directSharedDeps {
787 orderedAllDeps = append(orderedAllDeps, dep)
788 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700789 }
790
Colin Crossb6715442017-10-24 11:13:31 -0700791 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700792
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800793 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700794 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800795 // resultant list to only what the caller has chosen to include in directStaticDeps
796 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700797
798 return orderedAllDeps, orderedDeclaredDeps
799}
800
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800801func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
802 // convert Module to Path
803 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
804 staticDepFiles := []android.Path{}
805 for _, dep := range staticDeps {
806 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
807 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700808 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800809 sharedDepFiles := []android.Path{}
810 for _, sharedDep := range sharedDeps {
811 staticAnalogue := sharedDep.staticVariant
812 if staticAnalogue != nil {
813 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
814 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
815 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700816 }
817
818 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800819 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700820
821 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700822}
823
Colin Cross635c3b02016-05-18 15:37:25 -0700824func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800825 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700826 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800827 moduleContextImpl: moduleContextImpl{
828 mod: c,
829 },
830 }
831 ctx.ctx = ctx
832
Colin Crossf18e1102017-11-16 14:33:08 -0800833 deps := c.depsToPaths(ctx)
834 if ctx.Failed() {
835 return
836 }
837
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700838 if c.Properties.Clang != nil && *c.Properties.Clang == false {
839 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
840 }
841
Colin Crossca860ac2016-01-04 14:34:37 -0800842 flags := Flags{
843 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800844 }
Colin Crossca860ac2016-01-04 14:34:37 -0800845 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800846 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800847 }
848 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700849 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800850 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700851 if c.stl != nil {
852 flags = c.stl.flags(ctx, flags)
853 }
Colin Cross16b23492016-01-06 14:41:07 -0800854 if c.sanitize != nil {
855 flags = c.sanitize.flags(ctx, flags)
856 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800857 if c.coverage != nil {
858 flags = c.coverage.flags(ctx, flags)
859 }
Stephen Craneba090d12017-05-09 15:44:35 -0700860 if c.lto != nil {
861 flags = c.lto.flags(ctx, flags)
862 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700863 if c.pgo != nil {
864 flags = c.pgo.flags(ctx, flags)
865 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800866 if c.xom != nil {
867 flags = c.xom.flags(ctx, flags)
868 }
Colin Crossca860ac2016-01-04 14:34:37 -0800869 for _, feature := range c.features {
870 flags = feature.flags(ctx, flags)
871 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800872 if ctx.Failed() {
873 return
874 }
875
Colin Crossb98c8b02016-07-29 13:44:28 -0700876 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
877 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
878 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800879
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800880 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
881 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700882 // We need access to all the flags seen by a source file.
883 if c.sabi != nil {
884 flags = c.sabi.flags(ctx, flags)
885 }
Colin Crossca860ac2016-01-04 14:34:37 -0800886 // Optimization to reduce size of build.ninja
887 // Replace the long list of flags for each file with a module-local variable
888 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
889 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
890 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
891 flags.CFlags = []string{"$cflags"}
892 flags.CppFlags = []string{"$cppflags"}
893 flags.AsFlags = []string{"$asflags"}
894
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700895 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800896 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700897 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800898 if ctx.Failed() {
899 return
900 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800901 }
902
Colin Crossca860ac2016-01-04 14:34:37 -0800903 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700904 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800905 if ctx.Failed() {
906 return
907 }
Colin Cross635c3b02016-05-18 15:37:25 -0700908 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +0900909
910 // If a lib is directly included in any of the APEXes, unhide the stubs
911 // variant having the latest version gets visible to make. In addition,
912 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
913 // force anything in the make world to link against the stubs library.
914 // (unless it is explicitly referenced via .bootstrap suffix or the
915 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +0000916 if c.HasStubsVariants() &&
917 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Jiyong Parkb0788572018-12-20 22:10:17 +0900918 !c.inRecovery() && !c.useVndk() && !c.static() && c.IsStubs() {
919 c.Properties.HideFromMake = false // unhide
920 // Note: this is still non-installable
921 }
Colin Crossce75d2c2016-10-06 16:12:58 -0700922 }
Colin Cross5049f022015-03-18 13:28:46 -0700923
Jiyong Park9d452992018-10-03 00:38:19 +0900924 if c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() {
Colin Crossce75d2c2016-10-06 16:12:58 -0700925 c.installer.install(ctx, c.outputFile.Path())
926 if ctx.Failed() {
927 return
Colin Crossca860ac2016-01-04 14:34:37 -0800928 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700929 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800930}
931
Jiyong Park379de2f2018-12-19 02:47:14 +0900932func (c *Module) toolchain(ctx android.BaseContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800933 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700934 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800935 }
Colin Crossca860ac2016-01-04 14:34:37 -0800936 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800937}
938
Colin Crossca860ac2016-01-04 14:34:37 -0800939func (c *Module) begin(ctx BaseModuleContext) {
940 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700941 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700942 }
Colin Crossca860ac2016-01-04 14:34:37 -0800943 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700944 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800945 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700946 if c.stl != nil {
947 c.stl.begin(ctx)
948 }
Colin Cross16b23492016-01-06 14:41:07 -0800949 if c.sanitize != nil {
950 c.sanitize.begin(ctx)
951 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800952 if c.coverage != nil {
953 c.coverage.begin(ctx)
954 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800955 if c.sabi != nil {
956 c.sabi.begin(ctx)
957 }
Justin Yun8effde42017-06-23 19:24:43 +0900958 if c.vndkdep != nil {
959 c.vndkdep.begin(ctx)
960 }
Stephen Craneba090d12017-05-09 15:44:35 -0700961 if c.lto != nil {
962 c.lto.begin(ctx)
963 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700964 if c.pgo != nil {
965 c.pgo.begin(ctx)
966 }
Colin Crossca860ac2016-01-04 14:34:37 -0800967 for _, feature := range c.features {
968 feature.begin(ctx)
969 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700970 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700971 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700972 if err != nil {
973 ctx.PropertyErrorf("sdk_version", err.Error())
974 }
Nan Zhang0007d812017-11-07 10:57:05 -0800975 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700976 }
Colin Crossca860ac2016-01-04 14:34:37 -0800977}
978
Colin Cross37047f12016-12-13 17:06:13 -0800979func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700980 deps := Deps{}
981
982 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700983 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700984 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +0000985 // Add the PGO dependency (the clang_rt.profile runtime library), which
986 // sometimes depends on symbols from libgcc, before libgcc gets added
987 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700988 if c.pgo != nil {
989 deps = c.pgo.deps(ctx, deps)
990 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700991 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700992 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700993 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700994 if c.stl != nil {
995 deps = c.stl.deps(ctx, deps)
996 }
Colin Cross16b23492016-01-06 14:41:07 -0800997 if c.sanitize != nil {
998 deps = c.sanitize.deps(ctx, deps)
999 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001000 if c.coverage != nil {
1001 deps = c.coverage.deps(ctx, deps)
1002 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001003 if c.sabi != nil {
1004 deps = c.sabi.deps(ctx, deps)
1005 }
Justin Yun8effde42017-06-23 19:24:43 +09001006 if c.vndkdep != nil {
1007 deps = c.vndkdep.deps(ctx, deps)
1008 }
Stephen Craneba090d12017-05-09 15:44:35 -07001009 if c.lto != nil {
1010 deps = c.lto.deps(ctx, deps)
1011 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001012 for _, feature := range c.features {
1013 deps = feature.deps(ctx, deps)
1014 }
1015
Colin Crossb6715442017-10-24 11:13:31 -07001016 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1017 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1018 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1019 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1020 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1021 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001022 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001023
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001024 for _, lib := range deps.ReexportSharedLibHeaders {
1025 if !inList(lib, deps.SharedLibs) {
1026 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1027 }
1028 }
1029
1030 for _, lib := range deps.ReexportStaticLibHeaders {
1031 if !inList(lib, deps.StaticLibs) {
1032 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1033 }
1034 }
1035
Colin Cross5950f382016-12-13 12:50:57 -08001036 for _, lib := range deps.ReexportHeaderLibHeaders {
1037 if !inList(lib, deps.HeaderLibs) {
1038 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1039 }
1040 }
1041
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001042 for _, gen := range deps.ReexportGeneratedHeaders {
1043 if !inList(gen, deps.GeneratedHeaders) {
1044 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1045 }
1046 }
1047
Colin Crossc99deeb2016-04-11 15:06:20 -07001048 return deps
1049}
1050
Dan Albert7e9d2952016-08-04 13:02:36 -07001051func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001052 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001053 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001054 moduleContextImpl: moduleContextImpl{
1055 mod: c,
1056 },
1057 }
1058 ctx.ctx = ctx
1059
Colin Crossca860ac2016-01-04 14:34:37 -08001060 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001061}
1062
Jiyong Park7ed9de32018-10-15 22:25:07 +09001063// Split name#version into name and version
1064func stubsLibNameAndVersion(name string) (string, string) {
1065 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1066 version := name[sharp+1:]
1067 libname := name[:sharp]
1068 return libname, version
1069 }
1070 return name, ""
1071}
1072
Colin Cross1e676be2016-10-12 14:38:15 -07001073func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001074 ctx := &depsContext{
1075 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001076 moduleContextImpl: moduleContextImpl{
1077 mod: c,
1078 },
1079 }
1080 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001081
Colin Crossc99deeb2016-04-11 15:06:20 -07001082 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001083
Dan Albert914449f2016-06-17 16:45:24 -07001084 variantNdkLibs := []string{}
1085 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001086 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001087 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001088
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001089 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1090 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001091 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001092 // 1. Name of an NDK library that refers to a prebuilt module.
1093 // For each of these, it adds the name of the prebuilt module (which will be in
1094 // prebuilts/ndk) to the list of nonvariant libs.
1095 // 2. Name of an NDK library that refers to an ndk_library module.
1096 // For each of these, it adds the name of the ndk_library module to the list of
1097 // variant libs.
1098 // 3. Anything else (so anything that isn't an NDK library).
1099 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001100 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001101 // The caller can then know to add the variantLibs dependencies differently from the
1102 // nonvariantLibs
1103 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1104 variantLibs = []string{}
1105 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001106 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001107 // strip #version suffix out
1108 name, _ := stubsLibNameAndVersion(entry)
1109 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1110 if !inList(name, ndkMigratedLibs) {
1111 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001112 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001113 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001114 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001115 } else if ctx.useVndk() && inList(name, llndkLibraries) {
1116 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
1117 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, vendorPublicLibraries) {
1118 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001119 if actx.OtherModuleExists(vendorPublicLib) {
1120 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1121 } else {
1122 // This can happen if vendor_public_library module is defined in a
1123 // namespace that isn't visible to the current module. In that case,
1124 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001125 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001126 }
Dan Albert914449f2016-06-17 16:45:24 -07001127 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001128 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001129 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001130 }
1131 }
Dan Albert914449f2016-06-17 16:45:24 -07001132 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001133 }
1134
Dan Albert914449f2016-06-17 16:45:24 -07001135 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1136 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001137 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001138 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001139
Jiyong Park7ed9de32018-10-15 22:25:07 +09001140 if c.linker != nil {
1141 if library, ok := c.linker.(*libraryDecorator); ok {
1142 if library.buildStubs() {
1143 // Stubs lib does not have dependency to other libraries. Don't proceed.
1144 return
1145 }
1146 }
1147 }
1148
Colin Cross32ec36c2016-12-15 07:39:51 -08001149 for _, lib := range deps.HeaderLibs {
1150 depTag := headerDepTag
1151 if inList(lib, deps.ReexportHeaderLibHeaders) {
1152 depTag = headerExportDepTag
1153 }
1154 actx.AddVariationDependencies(nil, depTag, lib)
1155 }
Colin Cross5950f382016-12-13 12:50:57 -08001156
Dan Willemsen59339a22018-07-22 21:18:45 -07001157 actx.AddVariationDependencies([]blueprint.Variation{
1158 {Mutator: "link", Variation: "static"},
1159 }, wholeStaticDepTag, deps.WholeStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001160
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001161 for _, lib := range deps.StaticLibs {
1162 depTag := staticDepTag
1163 if inList(lib, deps.ReexportStaticLibHeaders) {
1164 depTag = staticExportDepTag
1165 }
Dan Willemsen59339a22018-07-22 21:18:45 -07001166 actx.AddVariationDependencies([]blueprint.Variation{
1167 {Mutator: "link", Variation: "static"},
1168 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001169 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001170
Dan Willemsen59339a22018-07-22 21:18:45 -07001171 actx.AddVariationDependencies([]blueprint.Variation{
1172 {Mutator: "link", Variation: "static"},
1173 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001174
Jiyong Park25fc6a92018-11-18 18:02:45 +09001175 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1176 var variations []blueprint.Variation
1177 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001178 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001179 if version != "" && versionVariantAvail {
1180 // Version is explicitly specified. i.e. libFoo#30
1181 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1182 depTag.explicitlyVersioned = true
1183 }
1184 actx.AddVariationDependencies(variations, depTag, name)
1185
1186 // If the version is not specified, add dependency to the latest stubs library.
1187 // The stubs library will be used when the depending module is built for APEX and
1188 // the dependent module is not in the same APEX.
1189 latestVersion := latestStubsVersionFor(actx.Config(), name)
1190 if version == "" && latestVersion != "" && versionVariantAvail {
1191 actx.AddVariationDependencies([]blueprint.Variation{
1192 {Mutator: "link", Variation: "shared"},
1193 {Mutator: "version", Variation: latestVersion},
1194 }, depTag, name)
1195 // Note that depTag.explicitlyVersioned is false in this case.
1196 }
1197 }
1198
Jiyong Park7ed9de32018-10-15 22:25:07 +09001199 // shared lib names without the #version suffix
1200 var sharedLibNames []string
1201
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001202 for _, lib := range deps.SharedLibs {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001203 name, version := stubsLibNameAndVersion(lib)
1204 sharedLibNames = append(sharedLibNames, name)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001205 depTag := sharedDepTag
1206 if inList(lib, deps.ReexportSharedLibHeaders) {
1207 depTag = sharedExportDepTag
1208 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001209 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001210 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001211
Jiyong Park7ed9de32018-10-15 22:25:07 +09001212 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001213 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001214 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1215 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1216 // linking against both the stubs lib and the non-stubs lib at the same time.
1217 continue
1218 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001219 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001220 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001221
Dan Willemsen59339a22018-07-22 21:18:45 -07001222 actx.AddVariationDependencies([]blueprint.Variation{
1223 {Mutator: "link", Variation: "shared"},
1224 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001225
Colin Cross68861832016-07-08 10:41:41 -07001226 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001227
1228 for _, gen := range deps.GeneratedHeaders {
1229 depTag := genHeaderDepTag
1230 if inList(gen, deps.ReexportGeneratedHeaders) {
1231 depTag = genHeaderExportDepTag
1232 }
1233 actx.AddDependency(c, depTag, gen)
1234 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001235
Colin Cross42d48b72018-08-29 14:10:52 -07001236 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001237
1238 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001239 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001240 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001241 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001242 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001243 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001244 if deps.LinkerFlagsFile != "" {
1245 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1246 }
1247 if deps.DynamicLinker != "" {
1248 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001249 }
Dan Albert914449f2016-06-17 16:45:24 -07001250
1251 version := ctx.sdkVersion()
1252 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001253 {Mutator: "ndk_api", Variation: version},
1254 {Mutator: "link", Variation: "shared"},
1255 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001256 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001257 {Mutator: "ndk_api", Variation: version},
1258 {Mutator: "link", Variation: "shared"},
1259 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001260
1261 if vndkdep := c.vndkdep; vndkdep != nil {
1262 if vndkdep.isVndkExt() {
1263 baseModuleMode := vendorMode
1264 if actx.DeviceConfig().VndkVersion() == "" {
1265 baseModuleMode = coreMode
1266 }
1267 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001268 {Mutator: "image", Variation: baseModuleMode},
1269 {Mutator: "link", Variation: "shared"},
1270 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001271 }
1272 }
Colin Cross6362e272015-10-29 15:25:03 -07001273}
Colin Cross21b9a242015-03-24 14:15:58 -07001274
Colin Crosse40b4ea2018-10-02 22:25:58 -07001275func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001276 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1277 c.beginMutator(ctx)
1278 }
1279}
1280
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001281// Whether a module can link to another module, taking into
1282// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001283func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001284 if from.Target().Os != android.Android {
1285 // Host code is not restricted
1286 return
1287 }
1288 if from.Properties.UseVndk {
1289 // Though vendor code is limited by the vendor mutator,
1290 // each vendor-available module needs to check
1291 // link-type for VNDK.
1292 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001293 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001294 }
1295 return
1296 }
Nan Zhang0007d812017-11-07 10:57:05 -08001297 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001298 // Platform code can link to anything
1299 return
1300 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001301 if from.inRecovery() {
1302 // Recovery code is not NDK
1303 return
1304 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001305 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1306 // These are always allowed
1307 return
1308 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001309 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1310 // These are allowed, but they don't set sdk_version
1311 return
1312 }
1313 if _, ok := to.linker.(*stubDecorator); ok {
1314 // These aren't real libraries, but are the stub shared libraries that are included in
1315 // the NDK.
1316 return
1317 }
Nan Zhang0007d812017-11-07 10:57:05 -08001318 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001319 // NDK code linking to platform code is never okay.
1320 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1321 ctx.OtherModuleName(to))
1322 }
1323
1324 // At this point we know we have two NDK libraries, but we need to
1325 // check that we're not linking against anything built against a higher
1326 // API level, as it is only valid to link against older or equivalent
1327 // APIs.
1328
Inseob Kim01a28722018-04-11 09:48:45 +09001329 // Current can link against anything.
1330 if String(from.Properties.Sdk_version) != "current" {
1331 // Otherwise we need to check.
1332 if String(to.Properties.Sdk_version) == "current" {
1333 // Current can't be linked against by anything else.
1334 ctx.ModuleErrorf("links %q built against newer API version %q",
1335 ctx.OtherModuleName(to), "current")
1336 } else {
1337 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1338 if err != nil {
1339 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001340 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001341 String(from.Properties.Sdk_version))
1342 }
1343 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1344 if err != nil {
1345 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001346 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001347 String(to.Properties.Sdk_version))
1348 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001349
Inseob Kim01a28722018-04-11 09:48:45 +09001350 if toApi > fromApi {
1351 ctx.ModuleErrorf("links %q built against newer API version %q",
1352 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1353 }
1354 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001355 }
Dan Albert202fe492017-12-15 13:56:59 -08001356
1357 // Also check that the two STL choices are compatible.
1358 fromStl := from.stl.Properties.SelectedStl
1359 toStl := to.stl.Properties.SelectedStl
1360 if fromStl == "" || toStl == "" {
1361 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001362 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001363 // We can be permissive with the system "STL" since it is only the C++
1364 // ABI layer, but in the future we should make sure that everyone is
1365 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001366 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001367 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1368 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1369 to.stl.Properties.SelectedStl)
1370 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001371}
1372
Jiyong Park5fb8c102018-04-09 12:03:06 +09001373// Tests whether the dependent library is okay to be double loaded inside a single process.
1374// If a library is a member of VNDK and at the same time dependencies of an LLNDK library,
1375// it is subject to be double loaded. Such lib should be explicitly marked as double_loaded: true
1376// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
1377func checkDoubleLoadableLibries(ctx android.ModuleContext, from *Module, to *Module) {
1378 if _, ok := from.linker.(*libraryDecorator); !ok {
1379 return
1380 }
1381
1382 if inList(ctx.ModuleName(), llndkLibraries) ||
1383 (from.useVndk() && Bool(from.VendorProperties.Double_loadable)) {
1384 _, depIsLlndk := to.linker.(*llndkStubDecorator)
1385 depIsVndkSp := false
1386 if to.vndkdep != nil && to.vndkdep.isVndkSp() {
1387 depIsVndkSp = true
1388 }
1389 depIsVndk := false
1390 if to.vndkdep != nil && to.vndkdep.isVndk() {
1391 depIsVndk = true
1392 }
1393 depIsDoubleLoadable := Bool(to.VendorProperties.Double_loadable)
1394 if !depIsLlndk && !depIsVndkSp && !depIsDoubleLoadable && depIsVndk {
Steven Moreland742989e2018-11-26 12:41:04 -08001395 ctx.ModuleErrorf("links VNDK library %q that isn't double loadable (not also LL-NDK, "+
1396 "VNDK-SP, or explicitly marked as 'double_loadable').",
Jiyong Park5fb8c102018-04-09 12:03:06 +09001397 ctx.OtherModuleName(to))
1398 }
1399 }
1400}
1401
Colin Crossc99deeb2016-04-11 15:06:20 -07001402// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001403func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001404 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001405
Jeff Gaston294356f2017-09-27 17:05:30 -07001406 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001407 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001408
Colin Crossd11fcda2017-10-23 17:59:01 -07001409 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001410 depName := ctx.OtherModuleName(dep)
1411 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001412
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001413 ccDep, _ := dep.(*Module)
1414 if ccDep == nil {
1415 // handling for a few module types that aren't cc Module but that are also supported
1416 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001417 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001418 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001419 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1420 genRule.GeneratedSourceFiles()...)
1421 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001422 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001423 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001424 // Support exported headers from a generated_sources dependency
1425 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001426 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001427 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001428 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001429 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001430 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001431 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001432 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001433 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001434 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001435 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001436 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1437 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1438
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001439 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001440 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001441 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001442 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001443 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001444 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001445 files := genRule.GeneratedSourceFiles()
1446 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001447 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001448 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001449 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 -07001450 }
1451 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001452 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001453 }
Colin Crossca860ac2016-01-04 14:34:37 -08001454 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001455 return
1456 }
1457
Colin Crossd11fcda2017-10-23 17:59:01 -07001458 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001459 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1460 return
1461 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001462 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001463 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001464 return
1465 }
1466
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001467 // re-exporting flags
1468 if depTag == reuseObjTag {
1469 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001470 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001471 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001472 depPaths.Objs = depPaths.Objs.Append(objs)
1473 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001474 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001475 return
1476 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001477 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001478
1479 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1480 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1481 // won't be matched to sharedDepTag and lateSharedDepTag.
1482 explicitlyVersioned := false
1483 if t, ok := depTag.(dependencyTag); ok {
1484 explicitlyVersioned = t.explicitlyVersioned
1485 t.explicitlyVersioned = false
1486 depTag = t
1487 }
1488
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001489 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001490 depIsStatic := false
1491 switch depTag {
1492 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1493 depIsStatic = true
1494 }
1495 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001496 depIsStubs := dependentLibrary.buildStubs()
1497 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001498 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001499 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001500
1501 var useThisDep bool
1502 if depIsStubs && explicitlyVersioned {
1503 // Always respect dependency to the versioned stubs (i.e. libX#10)
1504 useThisDep = true
1505 } else if !depHasStubs {
1506 // Use non-stub variant if that is the only choice
1507 // (i.e. depending on a lib without stubs.version property)
1508 useThisDep = true
1509 } else if c.IsForPlatform() {
1510 // If not building for APEX, use stubs only when it is from
1511 // an APEX (and not from platform)
1512 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parkb0788572018-12-20 22:10:17 +09001513 if c.inRecovery() || Bool(c.Properties.Bootstrap) {
1514 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001515 // always link to non-stub variant
1516 useThisDep = !depIsStubs
1517 }
1518 } else {
1519 // If building for APEX, use stubs only when it is not from
1520 // the same APEX
1521 useThisDep = (depInSameApex != depIsStubs)
1522 }
1523
1524 if !useThisDep {
1525 return // stop processing this dep
1526 }
1527 }
1528
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001529 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001530 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001531 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001532 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001533 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001534
1535 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001536 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001537 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001538 // 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 -07001539 // Re-exported shared library headers must be included as well since they can help us with type information
1540 // about template instantiations (instantiated from their headers).
1541 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001542 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001543 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001544
Logan Chienf3511742017-10-31 18:04:35 +08001545 checkLinkType(ctx, c, ccDep, t)
Jiyong Park5fb8c102018-04-09 12:03:06 +09001546 checkDoubleLoadableLibries(ctx, c, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001547 }
1548
Colin Cross26c34ed2016-09-30 17:10:16 -07001549 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001550 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001551
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001552 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001553 depFile := android.OptionalPath{}
1554
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001555 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001556 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001557 ptr = &depPaths.SharedLibs
1558 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001559 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001560 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001561 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001562 ptr = &depPaths.LateSharedLibs
1563 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001564 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001565 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001566 ptr = nil
1567 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001568 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001569 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001570 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001571 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001572 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001573 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001574 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001575 return
1576 }
1577
1578 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001579 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001580 for i := range missingDeps {
1581 missingDeps[i] += postfix
1582 }
1583 ctx.AddMissingDependencies(missingDeps)
1584 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001585 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001586 case headerDepTag:
1587 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001588 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001589 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001590 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001591 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001592 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001593 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001594 case dynamicLinkerDepTag:
1595 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001596 }
1597
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001598 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001599 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001600 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001601 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001602 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001603 return
1604 }
1605
1606 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001607 // in static libraries act as if they were whole static libraries. The same goes for
1608 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001609 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1610 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001611 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1612 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001613
Dan Willemsen581341d2017-02-09 16:16:31 -08001614 }
1615
Colin Cross26c34ed2016-09-30 17:10:16 -07001616 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001617 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001618 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001619 return
1620 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001621 *ptr = append(*ptr, linkFile.Path())
1622 }
1623
Colin Crossc99deeb2016-04-11 15:06:20 -07001624 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001625 dep := depFile
1626 if !dep.Valid() {
1627 dep = linkFile
1628 }
1629 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001630 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001631
Logan Chien43d34c32017-12-20 01:17:32 +08001632 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001633 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001634 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001635 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001636 isLLndk := inList(libName, llndkLibraries)
Jiyong Park374510b2018-03-19 18:23:01 +09001637 isVendorPublicLib := inList(libName, vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001638 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1639 if c.useVndk() && bothVendorAndCoreVariantsExist {
1640 // The vendor module in Make will have been renamed to not conflict with the core
1641 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001642 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001643 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001644 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001645 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1646 return libName + recoverySuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001647 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001648 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001649 }
Logan Chien43d34c32017-12-20 01:17:32 +08001650 }
1651
1652 // Export the shared libs to Make.
1653 switch depTag {
1654 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001655 // Dependency to the stubs lib which is already included in an APEX
1656 // is not added to the androidmk dependency
1657 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001658 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001659 // Also add the dependency to the APEX(es) providing the library so that
1660 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001661 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001662 c.Properties.ApexesProvidingSharedLibs = append(
1663 c.Properties.ApexesProvidingSharedLibs, an)
1664 }
1665 break
1666 }
1667 }
1668
Jiyong Park27b188b2017-07-18 13:23:39 +09001669 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001670 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001671 c.Properties.AndroidMkSharedLibs = append(
1672 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001673 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1674 c.Properties.AndroidMkStaticLibs = append(
1675 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001676 case runtimeDepTag:
1677 c.Properties.AndroidMkRuntimeLibs = append(
1678 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001679 case wholeStaticDepTag:
1680 c.Properties.AndroidMkWholeStaticLibs = append(
1681 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001682 }
Colin Crossca860ac2016-01-04 14:34:37 -08001683 })
1684
Jeff Gaston294356f2017-09-27 17:05:30 -07001685 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001686 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001687
Colin Crossdd84e052017-05-17 13:44:16 -07001688 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001689 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001690 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001691 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001692 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1693
1694 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001695 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001696 }
Colin Crossdd84e052017-05-17 13:44:16 -07001697
Colin Crossca860ac2016-01-04 14:34:37 -08001698 return depPaths
1699}
1700
1701func (c *Module) InstallInData() bool {
1702 if c.installer == nil {
1703 return false
1704 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001705 return c.installer.inData()
1706}
1707
1708func (c *Module) InstallInSanitizerDir() bool {
1709 if c.installer == nil {
1710 return false
1711 }
1712 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001713 return true
1714 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001715 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001716}
1717
Jiyong Parkf9332f12018-02-01 00:54:12 +09001718func (c *Module) InstallInRecovery() bool {
1719 return c.inRecovery()
1720}
1721
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001722func (c *Module) HostToolPath() android.OptionalPath {
1723 if c.installer == nil {
1724 return android.OptionalPath{}
1725 }
1726 return c.installer.hostToolPath()
1727}
1728
Nan Zhangd4e641b2017-07-12 12:55:28 -07001729func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1730 return c.outputFile
1731}
1732
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001733func (c *Module) Srcs() android.Paths {
1734 if c.outputFile.Valid() {
1735 return android.Paths{c.outputFile.Path()}
1736 }
1737 return android.Paths{}
1738}
1739
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001740func (c *Module) static() bool {
1741 if static, ok := c.linker.(interface {
1742 static() bool
1743 }); ok {
1744 return static.static()
1745 }
1746 return false
1747}
1748
Jiyong Park379de2f2018-12-19 02:47:14 +09001749func (c *Module) staticBinary() bool {
1750 if static, ok := c.linker.(interface {
1751 staticBinary() bool
1752 }); ok {
1753 return static.staticBinary()
1754 }
1755 return false
1756}
1757
Colin Crossb60190a2018-09-04 16:28:17 -07001758func (c *Module) getMakeLinkType() string {
1759 if c.useVndk() {
1760 if inList(c.Name(), vndkCoreLibraries) || inList(c.Name(), vndkSpLibraries) || inList(c.Name(), llndkLibraries) {
1761 if inList(c.Name(), vndkPrivateLibraries) {
1762 return "native:vndk_private"
1763 } else {
1764 return "native:vndk"
1765 }
1766 } else {
1767 return "native:vendor"
1768 }
1769 } else if c.inRecovery() {
1770 return "native:recovery"
1771 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
1772 return "native:ndk:none:none"
1773 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
1774 //family, link := getNdkStlFamilyAndLinkType(c)
1775 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
1776 } else {
1777 return "native:platform"
1778 }
1779}
1780
Jiyong Park9d452992018-10-03 00:38:19 +09001781// Overrides ApexModule.IsInstallabeToApex()
1782// Only shared libraries are installable to APEX.
1783func (c *Module) IsInstallableToApex() bool {
1784 if shared, ok := c.linker.(interface {
1785 shared() bool
1786 }); ok {
1787 return shared.shared()
1788 }
1789 return false
1790}
1791
Colin Cross2ba19d92015-05-07 15:44:20 -07001792//
Colin Crosscfad1192015-11-02 16:43:11 -08001793// Defaults
1794//
Colin Crossca860ac2016-01-04 14:34:37 -08001795type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001796 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001797 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09001798 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001799}
1800
Colin Cross635c3b02016-05-18 15:37:25 -07001801func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001802}
1803
Colin Cross1e676be2016-10-12 14:38:15 -07001804func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1805}
1806
Colin Cross36242852017-06-23 15:06:31 -07001807func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001808 return DefaultsFactory()
1809}
1810
Colin Cross36242852017-06-23 15:06:31 -07001811func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001812 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001813
Colin Cross36242852017-06-23 15:06:31 -07001814 module.AddProperties(props...)
1815 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001816 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001817 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001818 &BaseCompilerProperties{},
1819 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001820 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001821 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001822 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001823 &TestProperties{},
1824 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001825 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001826 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001827 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001828 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001829 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001830 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001831 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001832 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001833 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001834 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08001835 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001836 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001837 )
Colin Crosscfad1192015-11-02 16:43:11 -08001838
Colin Cross1f44a3a2017-07-07 14:33:33 -07001839 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09001840 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001841
1842 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001843}
1844
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001845const (
1846 // coreMode is the variant used for framework-private libraries, or
1847 // SDK libraries. (which framework-private libraries can use)
1848 coreMode = "core"
1849
1850 // vendorMode is the variant used for /vendor code that compiles
1851 // against the VNDK.
1852 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09001853
1854 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001855)
1856
Jiyong Park6a43f042017-10-12 23:05:00 +09001857func squashVendorSrcs(m *Module) {
1858 if lib, ok := m.compiler.(*libraryDecorator); ok {
1859 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1860 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1861
1862 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1863 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1864 }
1865}
1866
Jiyong Parkf9332f12018-02-01 00:54:12 +09001867func squashRecoverySrcs(m *Module) {
1868 if lib, ok := m.compiler.(*libraryDecorator); ok {
1869 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1870 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
1871
1872 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1873 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
1874 }
1875}
1876
Jiyong Parkda6eb592018-12-19 17:12:36 +09001877func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001878 if mctx.Os() != android.Android {
1879 return
1880 }
1881
Jiyong Park7ed9de32018-10-15 22:25:07 +09001882 if g, ok := mctx.Module().(*genrule.Module); ok {
1883 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09001884 var coreVariantNeeded bool = false
1885 var vendorVariantNeeded bool = false
1886 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09001887 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09001888 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001889 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09001890 coreVariantNeeded = true
1891 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09001892 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09001893 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001894 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09001895 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001896 }
Jiyong Park3f736c92018-05-24 13:36:56 +09001897 if Bool(props.Recovery_available) {
1898 recoveryVariantNeeded = true
1899 }
1900
Jiyong Park413cc742018-06-19 01:46:06 +09001901 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09001902 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09001903 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09001904 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09001905 recoveryVariantNeeded = false
1906 }
1907 }
1908
Jiyong Park3f736c92018-05-24 13:36:56 +09001909 var variants []string
1910 if coreVariantNeeded {
1911 variants = append(variants, coreMode)
1912 }
1913 if vendorVariantNeeded {
1914 variants = append(variants, vendorMode)
1915 }
1916 if recoveryVariantNeeded {
1917 variants = append(variants, recoveryMode)
1918 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001919 mod := mctx.CreateVariations(variants...)
1920 for i, v := range variants {
1921 if v == recoveryMode {
1922 m := mod[i].(*genrule.Module)
1923 m.Extra.(*GenruleExtraProperties).InRecovery = true
1924 }
1925 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001926 }
1927 }
1928
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001929 m, ok := mctx.Module().(*Module)
1930 if !ok {
1931 return
1932 }
1933
1934 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08001935 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09001936 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08001937
1938 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001939 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09001940 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001941 return
1942 }
Logan Chienf3511742017-10-31 18:04:35 +08001943
1944 if vndkdep := m.vndkdep; vndkdep != nil {
1945 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09001946 if productSpecific {
1947 mctx.PropertyErrorf("product_specific",
1948 "product_specific must not be true when `vndk: {enabled: true}`")
1949 return
1950 }
Logan Chienf3511742017-10-31 18:04:35 +08001951 if vendorSpecific {
1952 if !vndkdep.isVndkExt() {
1953 mctx.PropertyErrorf("vndk",
1954 "must set `extends: \"...\"` to vndk extension")
1955 return
1956 }
1957 } else {
1958 if vndkdep.isVndkExt() {
1959 mctx.PropertyErrorf("vndk",
1960 "must set `vendor: true` to set `extends: %q`",
1961 m.getVndkExtendsModuleName())
1962 return
1963 }
1964 if m.VendorProperties.Vendor_available == nil {
1965 mctx.PropertyErrorf("vndk",
1966 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
1967 return
1968 }
1969 }
1970 } else {
1971 if vndkdep.isVndkSp() {
1972 mctx.PropertyErrorf("vndk",
1973 "must set `enabled: true` to set `support_system_process: true`")
1974 return
1975 }
1976 if vndkdep.isVndkExt() {
1977 mctx.PropertyErrorf("vndk",
1978 "must set `enabled: true` to set `extends: %q`",
1979 m.getVndkExtendsModuleName())
1980 return
1981 }
Justin Yun8effde42017-06-23 19:24:43 +09001982 }
1983 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001984
Jiyong Parkf9332f12018-02-01 00:54:12 +09001985 var coreVariantNeeded bool = false
1986 var vendorVariantNeeded bool = false
1987 var recoveryVariantNeeded bool = false
1988
Justin Yun71549282017-11-17 12:10:28 +09001989 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001990 // If the device isn't compiling against the VNDK, we always
1991 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001992 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001993 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1994 // LL-NDK stubs only exist in the vendor variant, since the
1995 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001996 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09001997 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1998 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09001999 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09002000 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002001 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2002 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002003 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002004 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002005 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002006 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002007 coreVariantNeeded = true
2008 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002009 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002010 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09002011 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002012 } else {
2013 // This is either in /system (or similar: /data), or is a
2014 // modules built with the NDK. Modules built with the NDK
2015 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002016 coreVariantNeeded = true
2017 }
2018
2019 if Bool(m.Properties.Recovery_available) {
2020 recoveryVariantNeeded = true
2021 }
2022
2023 if m.ModuleBase.InstallInRecovery() {
2024 recoveryVariantNeeded = true
2025 coreVariantNeeded = false
2026 }
2027
Jiyong Park413cc742018-06-19 01:46:06 +09002028 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002029 primaryArch := mctx.Config().DevicePrimaryArchType()
2030 moduleArch := m.Target().Arch.ArchType
2031 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002032 recoveryVariantNeeded = false
2033 }
2034 }
2035
Jiyong Parkf9332f12018-02-01 00:54:12 +09002036 var variants []string
2037 if coreVariantNeeded {
2038 variants = append(variants, coreMode)
2039 }
2040 if vendorVariantNeeded {
2041 variants = append(variants, vendorMode)
2042 }
2043 if recoveryVariantNeeded {
2044 variants = append(variants, recoveryMode)
2045 }
2046 mod := mctx.CreateVariations(variants...)
2047 for i, v := range variants {
2048 if v == vendorMode {
2049 m := mod[i].(*Module)
2050 m.Properties.UseVndk = true
2051 squashVendorSrcs(m)
2052 } else if v == recoveryMode {
2053 m := mod[i].(*Module)
2054 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002055 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002056 squashRecoverySrcs(m)
2057 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002058 }
2059}
2060
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002061func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002062 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002063 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2064 }
Colin Cross6510f912017-11-29 00:27:14 -08002065 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002066}
2067
Colin Cross06a931b2015-10-28 17:23:31 -07002068var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002069var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002070var BoolPtr = proptools.BoolPtr
2071var String = proptools.String
2072var StringPtr = proptools.StringPtr