blob: c80d00c3c01f03578c12b578416d4c13c16560ee [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()
Inseob Kimc0907f12019-02-08 21:00:45 +090044 ctx.BottomUp("sysprop", SyspropMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070045 })
Colin Cross16b23492016-01-06 14:41:07 -080046
Colin Cross1e676be2016-10-12 14:38:15 -070047 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
48 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
49 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080050
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070051 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
52 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
53
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000054 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
55 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
56
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080057 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
58 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
59
Colin Cross1e676be2016-10-12 14:38:15 -070060 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
61 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080062
Colin Cross6b753602018-06-21 13:03:07 -070063 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator)
Jiyong Park379de2f2018-12-19 02:47:14 +090064 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080065
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080066 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080067 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070068
69 ctx.TopDown("lto_deps", ltoDepsMutator)
70 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090071
72 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070073 })
Colin Crossb98c8b02016-07-29 13:44:28 -070074
75 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070076}
77
Colin Crossca860ac2016-01-04 14:34:37 -080078type Deps struct {
79 SharedLibs, LateSharedLibs []string
80 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080081 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080082 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070083
Colin Cross5950f382016-12-13 12:50:57 -080084 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070085
Colin Cross81413472016-04-11 14:37:39 -070086 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070087
Dan Willemsenb40aab62016-04-20 14:21:14 -070088 GeneratedSources []string
89 GeneratedHeaders []string
90
Dan Willemsenb3454ab2016-09-28 17:34:58 -070091 ReexportGeneratedHeaders []string
92
Colin Cross97ba0732015-03-23 17:50:24 -070093 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -070094
95 // Used for host bionic
96 LinkerFlagsFile string
97 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -070098}
99
Colin Crossca860ac2016-01-04 14:34:37 -0800100type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700101 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900102 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700103 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900104 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700105 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700106 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700107
Colin Cross26c34ed2016-09-30 17:10:16 -0700108 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700109 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800110 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700111 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700112
Colin Cross26c34ed2016-09-30 17:10:16 -0700113 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700114 GeneratedSources android.Paths
115 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700116
Dan Willemsen76f08272016-07-09 00:14:08 -0700117 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700118 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700119
Colin Cross26c34ed2016-09-30 17:10:16 -0700120 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700121 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700122
123 // Path to the file container flags to use with the linker
124 LinkerFlagsFile android.OptionalPath
125
126 // Path to the dynamic linker binary
127 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700128}
129
Colin Crossca860ac2016-01-04 14:34:37 -0800130type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700131 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
132 ArFlags []string // Flags that apply to ar
133 AsFlags []string // Flags that apply to assembly source files
134 CFlags []string // Flags that apply to C and C++ source files
135 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
136 ConlyFlags []string // Flags that apply to C source files
137 CppFlags []string // Flags that apply to C++ source files
138 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
139 YaccFlags []string // Flags that apply to Yacc source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700140 aidlFlags []string // Flags that apply to aidl source files
141 rsFlags []string // Flags that apply to renderscript source files
142 LdFlags []string // Flags that apply to linker command lines
143 libFlags []string // Flags to add libraries early to the link order
144 TidyFlags []string // Flags that apply to clang-tidy
145 SAbiFlags []string // Flags that apply to header-abi-dumper
146 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700147
Colin Crossc3199482017-03-30 15:03:04 -0700148 // Global include flags that apply to C, C++, and assembly source files
149 // These must be after any module include flags, which will be in GlobalFlags.
150 SystemIncludeFlags []string
151
Colin Crossb98c8b02016-07-29 13:44:28 -0700152 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700153 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800154 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800155 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800156
157 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800158 DynamicLinker string
159
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700160 CFlagsDeps android.Paths // Files depended on by compiler flags
161 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800162
163 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800164
165 protoDeps android.Paths
166 protoFlags []string // Flags that apply to proto source files
167 protoOutTypeFlag string // The output type, --cpp_out for example
168 protoOutParams []string // Flags that modify the output of proto generated files
169 protoC bool // Whether to use C instead of C++
170 protoOptionsFile bool // Whether to look for a .options file next to the .proto
171 ProtoRoot bool
Colin Crossc472d572015-03-17 15:06:21 -0700172}
173
Colin Cross81413472016-04-11 14:37:39 -0700174type ObjectLinkerProperties struct {
175 // names of other cc_object modules to link into this module using partial linking
176 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700177
178 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800179 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700180}
181
Colin Crossca860ac2016-01-04 14:34:37 -0800182// Properties used to compile all C or C++ modules
183type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700184 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800185 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700186
187 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800188 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700189
Jiyong Parkde866cb2018-12-07 23:08:36 +0900190 AndroidMkSharedLibs []string `blueprint:"mutated"`
191 AndroidMkStaticLibs []string `blueprint:"mutated"`
192 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
193 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
194 HideFromMake bool `blueprint:"mutated"`
195 PreventInstall bool `blueprint:"mutated"`
196 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700197
198 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800199
200 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
201 // file
202 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900203
204 // Make this module available when building for recovery
205 Recovery_available *bool
206
207 InRecovery bool `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900208
209 // Allows this module to use non-APEX version of libraries. Useful
210 // for building binaries that are started before APEXes are activated.
211 Bootstrap *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700212}
213
214type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900215 // whether this module should be allowed to be directly depended by other
216 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
217 // If set to true, two variants will be built separately, one like
218 // normal, and the other limited to the set of libraries and headers
219 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700220 //
221 // The vendor variant may be used with a different (newer) /system,
222 // so it shouldn't have any unversioned runtime dependencies, or
223 // make assumptions about the system that may not be true in the
224 // future.
225 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900226 // If set to false, this module becomes inaccessible from /vendor modules.
227 //
228 // Default value is true when vndk: {enabled: true} or vendor: true.
229 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700230 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
231 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900232
233 // whether this module is capable of being loaded with other instance
234 // (possibly an older version) of the same module in the same process.
235 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
236 // can be double loaded in a vendor process if the library is also a
237 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
238 // explicitly marked as `double_loadable: true` by the owner, or the dependency
239 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
240 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800241}
242
Colin Crossca860ac2016-01-04 14:34:37 -0800243type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800244 static() bool
245 staticBinary() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700246 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700247 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800248 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700249 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800250 isNdk() bool
251 isLlndk() bool
252 isLlndkPublic() bool
253 isVndkPrivate() bool
Justin Yun8effde42017-06-23 19:24:43 +0900254 isVndk() bool
255 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800256 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900257 inRecovery() bool
Logan Chien2f2b8902018-07-10 15:01:19 +0800258 shouldCreateVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700259 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700260 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800261 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800262 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800263 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800264 useClangLld(actx ModuleContext) bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900265 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900266 hasStubsVariants() bool
267 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900268 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800269 mustUseVendorVariant() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800270}
271
272type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700273 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800274 ModuleContextIntf
275}
276
277type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700278 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800279 ModuleContextIntf
280}
281
Colin Cross37047f12016-12-13 17:06:13 -0800282type DepsContext interface {
283 android.BottomUpMutatorContext
284 ModuleContextIntf
285}
286
Colin Crossca860ac2016-01-04 14:34:37 -0800287type feature interface {
288 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800289 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800290 flags(ctx ModuleContext, flags Flags) Flags
291 props() []interface{}
292}
293
294type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700295 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800296 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800297 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700298 compilerProps() []interface{}
299
Colin Cross76fada02016-07-27 10:31:13 -0700300 appendCflags([]string)
301 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700302 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800303}
304
305type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700306 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800307 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700308 linkerFlags(ctx ModuleContext, flags Flags) Flags
309 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800310 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700311
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700312 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700313 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900314 unstrippedOutputFilePath() android.Path
Colin Crossca860ac2016-01-04 14:34:37 -0800315}
316
317type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700318 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700319 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800320 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700321 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700322 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900323 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800324}
325
Colin Crossc99deeb2016-04-11 15:06:20 -0700326type dependencyTag struct {
327 blueprint.BaseDependencyTag
328 name string
329 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700330
331 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900332
333 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700334}
335
336var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700337 sharedDepTag = dependencyTag{name: "shared", library: true}
338 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
Jiyong Park64a44f22019-01-18 14:37:08 +0900339 earlySharedDepTag = dependencyTag{name: "early_shared", library: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700340 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
341 staticDepTag = dependencyTag{name: "static", library: true}
342 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
343 lateStaticDepTag = dependencyTag{name: "late static", library: true}
344 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800345 headerDepTag = dependencyTag{name: "header", library: true}
346 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700347 genSourceDepTag = dependencyTag{name: "gen source"}
348 genHeaderDepTag = dependencyTag{name: "gen header"}
349 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
350 objDepTag = dependencyTag{name: "obj"}
351 crtBeginDepTag = dependencyTag{name: "crtbegin"}
352 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700353 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
354 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700355 reuseObjTag = dependencyTag{name: "reuse objects"}
Jiyong Parke4bb9862019-02-01 00:31:10 +0900356 staticVariantTag = dependencyTag{name: "static variant"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700357 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
358 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800359 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800360 runtimeDepTag = dependencyTag{name: "runtime lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700361)
362
Colin Crossca860ac2016-01-04 14:34:37 -0800363// Module contains the properties and members used by all C/C++ module types, and implements
364// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
365// to construct the output file. Behavior can be customized with a Customizer interface
366type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700367 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700368 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900369 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700370
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700371 Properties BaseProperties
372 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700373
Colin Crossca860ac2016-01-04 14:34:37 -0800374 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700375 hod android.HostOrDeviceSupported
376 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700377
Colin Crossca860ac2016-01-04 14:34:37 -0800378 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700379 features []feature
380 compiler compiler
381 linker linker
382 installer installer
383 stl *stl
384 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800385 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800386 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900387 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700388 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700389 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800390 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800391
392 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700393
Colin Cross635c3b02016-05-18 15:37:25 -0700394 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800395
Colin Crossb98c8b02016-07-29 13:44:28 -0700396 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700397
398 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800399
400 // Flags used to compile this module
401 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700402
403 // 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 -0800404 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700405 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800406 depsInLinkOrder android.Paths
407
408 // only non-nil when this is a shared library that reuses the objects of a static library
409 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700410}
411
Jiyong Parkc20eee32018-09-05 22:36:17 +0900412func (c *Module) OutputFile() android.OptionalPath {
413 return c.outputFile
414}
415
Jiyong Park719b4462019-01-13 00:39:51 +0900416func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900417 if c.linker != nil {
418 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900419 }
420 return nil
421}
422
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900423func (c *Module) RelativeInstallPath() string {
424 if c.installer != nil {
425 return c.installer.relativeInstallPath()
426 }
427 return ""
428}
429
Colin Cross36242852017-06-23 15:06:31 -0700430func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700431 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800432 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700433 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800434 }
435 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700436 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800437 }
438 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700439 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800440 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700441 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700442 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700443 }
Colin Cross16b23492016-01-06 14:41:07 -0800444 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700445 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800446 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800447 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700448 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800449 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800450 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700451 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800452 }
Justin Yun8effde42017-06-23 19:24:43 +0900453 if c.vndkdep != nil {
454 c.AddProperties(c.vndkdep.props()...)
455 }
Stephen Craneba090d12017-05-09 15:44:35 -0700456 if c.lto != nil {
457 c.AddProperties(c.lto.props()...)
458 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700459 if c.pgo != nil {
460 c.AddProperties(c.pgo.props()...)
461 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800462 if c.xom != nil {
463 c.AddProperties(c.xom.props()...)
464 }
Colin Crossca860ac2016-01-04 14:34:37 -0800465 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700466 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800467 }
Colin Crossc472d572015-03-17 15:06:21 -0700468
Colin Crossa9d8bee2018-10-02 13:59:46 -0700469 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
470 switch class {
471 case android.Device:
472 return ctx.Config().DevicePrefer32BitExecutables()
473 case android.HostCross:
474 // Windows builds always prefer 32-bit
475 return true
476 default:
477 return false
478 }
479 })
Colin Cross36242852017-06-23 15:06:31 -0700480 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700481
Colin Cross1f44a3a2017-07-07 14:33:33 -0700482 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700483
Jiyong Park9d452992018-10-03 00:38:19 +0900484 android.InitApexModule(c)
485
Colin Cross36242852017-06-23 15:06:31 -0700486 return c
Colin Crossc472d572015-03-17 15:06:21 -0700487}
488
Colin Crossb916a382016-07-29 17:28:03 -0700489// Returns true for dependency roots (binaries)
490// TODO(ccross): also handle dlopenable libraries
491func (c *Module) isDependencyRoot() bool {
492 if root, ok := c.linker.(interface {
493 isDependencyRoot() bool
494 }); ok {
495 return root.isDependencyRoot()
496 }
497 return false
498}
499
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700500func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700501 return c.Properties.UseVndk
502}
503
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800504func (c *Module) isCoverageVariant() bool {
505 return c.coverage.Properties.IsCoverageVariant
506}
507
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800508func (c *Module) isNdk() bool {
509 return inList(c.Name(), ndkMigratedLibs)
510}
511
512func (c *Module) isLlndk() bool {
513 // Returns true for both LLNDK (public) and LLNDK-private libs.
514 return inList(c.Name(), llndkLibraries)
515}
516
517func (c *Module) isLlndkPublic() bool {
518 // Returns true only for LLNDK (public) libs.
519 return c.isLlndk() && !c.isVndkPrivate()
520}
521
522func (c *Module) isVndkPrivate() bool {
523 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
524 return inList(c.Name(), vndkPrivateLibraries)
525}
526
Justin Yun8effde42017-06-23 19:24:43 +0900527func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800528 if vndkdep := c.vndkdep; vndkdep != nil {
529 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900530 }
531 return false
532}
533
Yi Kong7e53c572018-02-14 18:16:12 +0800534func (c *Module) isPgoCompile() bool {
535 if pgo := c.pgo; pgo != nil {
536 return pgo.Properties.PgoCompile
537 }
538 return false
539}
540
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800541func (c *Module) isNDKStubLibrary() bool {
542 if _, ok := c.compiler.(*stubDecorator); ok {
543 return true
544 }
545 return false
546}
547
Logan Chienf3511742017-10-31 18:04:35 +0800548func (c *Module) isVndkSp() bool {
549 if vndkdep := c.vndkdep; vndkdep != nil {
550 return vndkdep.isVndkSp()
551 }
552 return false
553}
554
555func (c *Module) isVndkExt() bool {
556 if vndkdep := c.vndkdep; vndkdep != nil {
557 return vndkdep.isVndkExt()
558 }
559 return false
560}
561
Vic Yangefd249e2018-11-12 20:19:56 -0800562func (c *Module) mustUseVendorVariant() bool {
563 return c.isVndkSp() || inList(c.Name(), config.VndkMustUseVendorVariantList)
564}
565
Logan Chienf3511742017-10-31 18:04:35 +0800566func (c *Module) getVndkExtendsModuleName() string {
567 if vndkdep := c.vndkdep; vndkdep != nil {
568 return vndkdep.getVndkExtendsModuleName()
569 }
570 return ""
571}
572
Jiyong Park82e2bf32017-08-16 14:05:54 +0900573// Returns true only when this module is configured to have core and vendor
574// variants.
575func (c *Module) hasVendorVariant() bool {
576 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
577}
578
Jiyong Parkf9332f12018-02-01 00:54:12 +0900579func (c *Module) inRecovery() bool {
580 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
581}
582
583func (c *Module) onlyInRecovery() bool {
584 return c.ModuleBase.InstallInRecovery()
585}
586
Jiyong Park25fc6a92018-11-18 18:02:45 +0900587func (c *Module) IsStubs() bool {
588 if library, ok := c.linker.(*libraryDecorator); ok {
589 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900590 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
591 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900592 }
593 return false
594}
595
596func (c *Module) HasStubsVariants() bool {
597 if library, ok := c.linker.(*libraryDecorator); ok {
598 return len(library.Properties.Stubs.Versions) > 0
599 }
600 return false
601}
602
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900603func (c *Module) bootstrap() bool {
604 return Bool(c.Properties.Bootstrap)
605}
606
Jiyong Parkf1194352019-02-25 11:05:47 +0900607func isBionic(name string) bool {
608 switch name {
609 case "libc", "libm", "libdl", "linker":
610 return true
611 }
612 return false
613}
614
Colin Crossca860ac2016-01-04 14:34:37 -0800615type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700616 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800617 moduleContextImpl
618}
619
Colin Cross37047f12016-12-13 17:06:13 -0800620type depsContext struct {
621 android.BottomUpMutatorContext
622 moduleContextImpl
623}
624
Colin Crossca860ac2016-01-04 14:34:37 -0800625type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700626 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800627 moduleContextImpl
628}
629
Jiyong Park2db76922017-11-08 16:03:48 +0900630func (ctx *moduleContext) SocSpecific() bool {
631 return ctx.ModuleContext.SocSpecific() ||
632 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700633}
634
Colin Crossca860ac2016-01-04 14:34:37 -0800635type moduleContextImpl struct {
636 mod *Module
637 ctx BaseModuleContext
638}
639
Colin Crossb98c8b02016-07-29 13:44:28 -0700640func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800641 return ctx.mod.toolchain(ctx.ctx)
642}
643
644func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000645 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800646}
647
648func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900649 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800650}
651
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700652func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800653 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800654 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700655 }
656 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800657}
658
659func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700660 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700661 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900662 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700663 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900664 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
665 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
666 return "current"
667 }
668 return platform_vndk_ver
669 }
670 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800671 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900672 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700673 }
674 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800675}
676
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700677func (ctx *moduleContextImpl) useVndk() bool {
678 return ctx.mod.useVndk()
679}
Justin Yun8effde42017-06-23 19:24:43 +0900680
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800681func (ctx *moduleContextImpl) isNdk() bool {
682 return ctx.mod.isNdk()
683}
684
685func (ctx *moduleContextImpl) isLlndk() bool {
686 return ctx.mod.isLlndk()
687}
688
689func (ctx *moduleContextImpl) isLlndkPublic() bool {
690 return ctx.mod.isLlndkPublic()
691}
692
693func (ctx *moduleContextImpl) isVndkPrivate() bool {
694 return ctx.mod.isVndkPrivate()
695}
696
Logan Chienf3511742017-10-31 18:04:35 +0800697func (ctx *moduleContextImpl) isVndk() bool {
698 return ctx.mod.isVndk()
699}
700
Yi Kong7e53c572018-02-14 18:16:12 +0800701func (ctx *moduleContextImpl) isPgoCompile() bool {
702 return ctx.mod.isPgoCompile()
703}
704
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800705func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
706 return ctx.mod.isNDKStubLibrary()
707}
708
Justin Yun8effde42017-06-23 19:24:43 +0900709func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800710 return ctx.mod.isVndkSp()
711}
712
713func (ctx *moduleContextImpl) isVndkExt() bool {
714 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900715}
716
Vic Yangefd249e2018-11-12 20:19:56 -0800717func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
718 return ctx.mod.mustUseVendorVariant()
719}
720
Jiyong Parkf9332f12018-02-01 00:54:12 +0900721func (ctx *moduleContextImpl) inRecovery() bool {
722 return ctx.mod.inRecovery()
723}
724
Logan Chien2f2b8902018-07-10 15:01:19 +0800725// Check whether ABI dumps should be created for this module.
726func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump() bool {
727 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
728 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800729 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800730
731 if ctx.ctx.Fuchsia() {
732 return false
733 }
734
Logan Chien2f2b8902018-07-10 15:01:19 +0800735 if sanitize := ctx.mod.sanitize; sanitize != nil {
736 if !sanitize.isVariantOnProductionDevice() {
737 return false
738 }
739 }
740 if !ctx.ctx.Device() {
741 // Host modules do not need ABI dumps.
742 return false
743 }
Logan Chienfa478c02018-12-28 16:25:39 +0800744 if !ctx.mod.IsForPlatform() {
745 // APEX variants do not need ABI dumps.
746 return false
747 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800748 if ctx.isNdk() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800749 return true
750 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800751 if ctx.isLlndkPublic() {
Logan Chienf4b79c62018-08-02 02:27:02 +0800752 return true
753 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800754 if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800755 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
756 // VNDK-private.
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800757 return true
Logan Chien2f2b8902018-07-10 15:01:19 +0800758 }
759 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800760}
761
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700762func (ctx *moduleContextImpl) selectedStl() string {
763 if stl := ctx.mod.stl; stl != nil {
764 return stl.Properties.SelectedStl
765 }
766 return ""
767}
768
Ivan Lozanobd721262018-11-27 14:33:03 -0800769func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
770 return ctx.mod.linker.useClangLld(actx)
771}
772
Colin Crossce75d2c2016-10-06 16:12:58 -0700773func (ctx *moduleContextImpl) baseModuleName() string {
774 return ctx.mod.ModuleBase.BaseModuleName()
775}
776
Logan Chienf3511742017-10-31 18:04:35 +0800777func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
778 return ctx.mod.getVndkExtendsModuleName()
779}
780
Jiyong Park58e364a2019-01-19 19:24:06 +0900781func (ctx *moduleContextImpl) apexName() string {
782 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900783}
784
Jiyong Parkb0788572018-12-20 22:10:17 +0900785func (ctx *moduleContextImpl) hasStubsVariants() bool {
786 return ctx.mod.HasStubsVariants()
787}
788
789func (ctx *moduleContextImpl) isStubs() bool {
790 return ctx.mod.IsStubs()
791}
792
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900793func (ctx *moduleContextImpl) bootstrap() bool {
794 return ctx.mod.bootstrap()
795}
796
Colin Cross635c3b02016-05-18 15:37:25 -0700797func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800798 return &Module{
799 hod: hod,
800 multilib: multilib,
801 }
802}
803
Colin Cross635c3b02016-05-18 15:37:25 -0700804func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800805 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700806 module.features = []feature{
807 &tidyFeature{},
808 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700809 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800810 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800811 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800812 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900813 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700814 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700815 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800816 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800817 return module
818}
819
Colin Crossce75d2c2016-10-06 16:12:58 -0700820func (c *Module) Prebuilt() *android.Prebuilt {
821 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
822 return p.prebuilt()
823 }
824 return nil
825}
826
827func (c *Module) Name() string {
828 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700829 if p, ok := c.linker.(interface {
830 Name(string) string
831 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700832 name = p.Name(name)
833 }
834 return name
835}
836
Alex Light3d673592019-01-18 14:37:31 -0800837func (c *Module) Symlinks() []string {
838 if p, ok := c.installer.(interface {
839 symlinkList() []string
840 }); ok {
841 return p.symlinkList()
842 }
843 return nil
844}
845
Jeff Gaston294356f2017-09-27 17:05:30 -0700846// orderDeps reorders dependencies into a list such that if module A depends on B, then
847// A will precede B in the resultant list.
848// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800849// Note that directSharedDeps should be the analogous static library for each shared lib dep
850func 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 -0700851 // If A depends on B, then
852 // Every list containing A will also contain B later in the list
853 // So, after concatenating all lists, the final instance of B will have come from the same
854 // original list as the final instance of A
855 // So, the final instance of B will be later in the concatenation than the final A
856 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
857 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800858 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700859 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800860 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
861 }
862 for _, dep := range directSharedDeps {
863 orderedAllDeps = append(orderedAllDeps, dep)
864 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700865 }
866
Colin Crossb6715442017-10-24 11:13:31 -0700867 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700868
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800869 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700870 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800871 // resultant list to only what the caller has chosen to include in directStaticDeps
872 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700873
874 return orderedAllDeps, orderedDeclaredDeps
875}
876
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800877func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
878 // convert Module to Path
879 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
880 staticDepFiles := []android.Path{}
881 for _, dep := range staticDeps {
882 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
883 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700884 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800885 sharedDepFiles := []android.Path{}
886 for _, sharedDep := range sharedDeps {
887 staticAnalogue := sharedDep.staticVariant
888 if staticAnalogue != nil {
889 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
890 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
891 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700892 }
893
894 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800895 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700896
897 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700898}
899
Colin Cross635c3b02016-05-18 15:37:25 -0700900func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800901 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700902 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800903 moduleContextImpl: moduleContextImpl{
904 mod: c,
905 },
906 }
907 ctx.ctx = ctx
908
Colin Crossf18e1102017-11-16 14:33:08 -0800909 deps := c.depsToPaths(ctx)
910 if ctx.Failed() {
911 return
912 }
913
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700914 if c.Properties.Clang != nil && *c.Properties.Clang == false {
915 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
916 }
917
Colin Crossca860ac2016-01-04 14:34:37 -0800918 flags := Flags{
919 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800920 }
Colin Crossca860ac2016-01-04 14:34:37 -0800921 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800922 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800923 }
924 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700925 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800926 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700927 if c.stl != nil {
928 flags = c.stl.flags(ctx, flags)
929 }
Colin Cross16b23492016-01-06 14:41:07 -0800930 if c.sanitize != nil {
931 flags = c.sanitize.flags(ctx, flags)
932 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800933 if c.coverage != nil {
934 flags = c.coverage.flags(ctx, flags)
935 }
Stephen Craneba090d12017-05-09 15:44:35 -0700936 if c.lto != nil {
937 flags = c.lto.flags(ctx, flags)
938 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700939 if c.pgo != nil {
940 flags = c.pgo.flags(ctx, flags)
941 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800942 if c.xom != nil {
943 flags = c.xom.flags(ctx, flags)
944 }
Colin Crossca860ac2016-01-04 14:34:37 -0800945 for _, feature := range c.features {
946 flags = feature.flags(ctx, flags)
947 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800948 if ctx.Failed() {
949 return
950 }
951
Colin Crossb98c8b02016-07-29 13:44:28 -0700952 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
953 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
954 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800955
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800956 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
957 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700958 // We need access to all the flags seen by a source file.
959 if c.sabi != nil {
960 flags = c.sabi.flags(ctx, flags)
961 }
Colin Crossca860ac2016-01-04 14:34:37 -0800962 // Optimization to reduce size of build.ninja
963 // Replace the long list of flags for each file with a module-local variable
964 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
965 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
966 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
967 flags.CFlags = []string{"$cflags"}
968 flags.CppFlags = []string{"$cppflags"}
969 flags.AsFlags = []string{"$asflags"}
970
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700971 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800972 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700973 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800974 if ctx.Failed() {
975 return
976 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800977 }
978
Colin Crossca860ac2016-01-04 14:34:37 -0800979 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700980 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800981 if ctx.Failed() {
982 return
983 }
Colin Cross635c3b02016-05-18 15:37:25 -0700984 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +0900985
986 // If a lib is directly included in any of the APEXes, unhide the stubs
987 // variant having the latest version gets visible to make. In addition,
988 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
989 // force anything in the make world to link against the stubs library.
990 // (unless it is explicitly referenced via .bootstrap suffix or the
991 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +0000992 if c.HasStubsVariants() &&
993 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800994 !c.inRecovery() && !c.useVndk() && !c.static() && !c.isCoverageVariant() &&
995 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +0900996 c.Properties.HideFromMake = false // unhide
997 // Note: this is still non-installable
998 }
Colin Crossce75d2c2016-10-06 16:12:58 -0700999 }
Colin Cross5049f022015-03-18 13:28:46 -07001000
Jiyong Park9d452992018-10-03 00:38:19 +09001001 if c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001002 c.installer.install(ctx, c.outputFile.Path())
1003 if ctx.Failed() {
1004 return
Colin Crossca860ac2016-01-04 14:34:37 -08001005 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001006 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001007}
1008
Jiyong Park379de2f2018-12-19 02:47:14 +09001009func (c *Module) toolchain(ctx android.BaseContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001010 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001011 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001012 }
Colin Crossca860ac2016-01-04 14:34:37 -08001013 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001014}
1015
Colin Crossca860ac2016-01-04 14:34:37 -08001016func (c *Module) begin(ctx BaseModuleContext) {
1017 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001018 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001019 }
Colin Crossca860ac2016-01-04 14:34:37 -08001020 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001021 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001022 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001023 if c.stl != nil {
1024 c.stl.begin(ctx)
1025 }
Colin Cross16b23492016-01-06 14:41:07 -08001026 if c.sanitize != nil {
1027 c.sanitize.begin(ctx)
1028 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001029 if c.coverage != nil {
1030 c.coverage.begin(ctx)
1031 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001032 if c.sabi != nil {
1033 c.sabi.begin(ctx)
1034 }
Justin Yun8effde42017-06-23 19:24:43 +09001035 if c.vndkdep != nil {
1036 c.vndkdep.begin(ctx)
1037 }
Stephen Craneba090d12017-05-09 15:44:35 -07001038 if c.lto != nil {
1039 c.lto.begin(ctx)
1040 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001041 if c.pgo != nil {
1042 c.pgo.begin(ctx)
1043 }
Colin Crossca860ac2016-01-04 14:34:37 -08001044 for _, feature := range c.features {
1045 feature.begin(ctx)
1046 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001047 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001048 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001049 if err != nil {
1050 ctx.PropertyErrorf("sdk_version", err.Error())
1051 }
Nan Zhang0007d812017-11-07 10:57:05 -08001052 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001053 }
Colin Crossca860ac2016-01-04 14:34:37 -08001054}
1055
Colin Cross37047f12016-12-13 17:06:13 -08001056func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001057 deps := Deps{}
1058
1059 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001060 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001061 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001062 // Add the PGO dependency (the clang_rt.profile runtime library), which
1063 // sometimes depends on symbols from libgcc, before libgcc gets added
1064 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001065 if c.pgo != nil {
1066 deps = c.pgo.deps(ctx, deps)
1067 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001068 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001069 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001070 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001071 if c.stl != nil {
1072 deps = c.stl.deps(ctx, deps)
1073 }
Colin Cross16b23492016-01-06 14:41:07 -08001074 if c.sanitize != nil {
1075 deps = c.sanitize.deps(ctx, deps)
1076 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001077 if c.coverage != nil {
1078 deps = c.coverage.deps(ctx, deps)
1079 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001080 if c.sabi != nil {
1081 deps = c.sabi.deps(ctx, deps)
1082 }
Justin Yun8effde42017-06-23 19:24:43 +09001083 if c.vndkdep != nil {
1084 deps = c.vndkdep.deps(ctx, deps)
1085 }
Stephen Craneba090d12017-05-09 15:44:35 -07001086 if c.lto != nil {
1087 deps = c.lto.deps(ctx, deps)
1088 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001089 for _, feature := range c.features {
1090 deps = feature.deps(ctx, deps)
1091 }
1092
Colin Crossb6715442017-10-24 11:13:31 -07001093 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1094 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1095 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1096 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1097 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1098 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001099 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001100
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001101 for _, lib := range deps.ReexportSharedLibHeaders {
1102 if !inList(lib, deps.SharedLibs) {
1103 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1104 }
1105 }
1106
1107 for _, lib := range deps.ReexportStaticLibHeaders {
1108 if !inList(lib, deps.StaticLibs) {
1109 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1110 }
1111 }
1112
Colin Cross5950f382016-12-13 12:50:57 -08001113 for _, lib := range deps.ReexportHeaderLibHeaders {
1114 if !inList(lib, deps.HeaderLibs) {
1115 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1116 }
1117 }
1118
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001119 for _, gen := range deps.ReexportGeneratedHeaders {
1120 if !inList(gen, deps.GeneratedHeaders) {
1121 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1122 }
1123 }
1124
Colin Crossc99deeb2016-04-11 15:06:20 -07001125 return deps
1126}
1127
Dan Albert7e9d2952016-08-04 13:02:36 -07001128func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001129 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001130 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001131 moduleContextImpl: moduleContextImpl{
1132 mod: c,
1133 },
1134 }
1135 ctx.ctx = ctx
1136
Colin Crossca860ac2016-01-04 14:34:37 -08001137 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001138}
1139
Jiyong Park7ed9de32018-10-15 22:25:07 +09001140// Split name#version into name and version
1141func stubsLibNameAndVersion(name string) (string, string) {
1142 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1143 version := name[sharp+1:]
1144 libname := name[:sharp]
1145 return libname, version
1146 }
1147 return name, ""
1148}
1149
Colin Cross1e676be2016-10-12 14:38:15 -07001150func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001151 ctx := &depsContext{
1152 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001153 moduleContextImpl: moduleContextImpl{
1154 mod: c,
1155 },
1156 }
1157 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001158
Colin Crossc99deeb2016-04-11 15:06:20 -07001159 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001160
Dan Albert914449f2016-06-17 16:45:24 -07001161 variantNdkLibs := []string{}
1162 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001163 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001164 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001165
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001166 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1167 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001168 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001169 // 1. Name of an NDK library that refers to a prebuilt module.
1170 // For each of these, it adds the name of the prebuilt module (which will be in
1171 // prebuilts/ndk) to the list of nonvariant libs.
1172 // 2. Name of an NDK library that refers to an ndk_library module.
1173 // For each of these, it adds the name of the ndk_library module to the list of
1174 // variant libs.
1175 // 3. Anything else (so anything that isn't an NDK library).
1176 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001177 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001178 // The caller can then know to add the variantLibs dependencies differently from the
1179 // nonvariantLibs
1180 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1181 variantLibs = []string{}
1182 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001183 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001184 // strip #version suffix out
1185 name, _ := stubsLibNameAndVersion(entry)
1186 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1187 if !inList(name, ndkMigratedLibs) {
1188 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001189 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001190 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001191 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001192 } else if ctx.useVndk() && inList(name, llndkLibraries) {
1193 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
1194 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, vendorPublicLibraries) {
1195 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001196 if actx.OtherModuleExists(vendorPublicLib) {
1197 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1198 } else {
1199 // This can happen if vendor_public_library module is defined in a
1200 // namespace that isn't visible to the current module. In that case,
1201 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001202 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001203 }
Dan Albert914449f2016-06-17 16:45:24 -07001204 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001205 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001206 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001207 }
1208 }
Dan Albert914449f2016-06-17 16:45:24 -07001209 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001210 }
1211
Dan Albert914449f2016-06-17 16:45:24 -07001212 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1213 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001214 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001215 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001216
Jiyong Park7e636d02019-01-28 16:16:54 +09001217 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001218 if c.linker != nil {
1219 if library, ok := c.linker.(*libraryDecorator); ok {
1220 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001221 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001222 }
1223 }
1224 }
1225
Colin Cross32ec36c2016-12-15 07:39:51 -08001226 for _, lib := range deps.HeaderLibs {
1227 depTag := headerDepTag
1228 if inList(lib, deps.ReexportHeaderLibHeaders) {
1229 depTag = headerExportDepTag
1230 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001231 if buildStubs {
Jiyong Park7e636d02019-01-28 16:16:54 +09001232 actx.AddFarVariationDependencies([]blueprint.Variation{
1233 {Mutator: "arch", Variation: ctx.Target().String()},
Jiyong Park3b1746a2019-01-29 11:15:04 +09001234 {Mutator: "image", Variation: c.imageVariation()},
Jiyong Park7e636d02019-01-28 16:16:54 +09001235 }, depTag, lib)
1236 } else {
1237 actx.AddVariationDependencies(nil, depTag, lib)
1238 }
1239 }
1240
1241 if buildStubs {
1242 // Stubs lib does not have dependency to other static/shared libraries.
1243 // Don't proceed.
1244 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001245 }
Colin Cross5950f382016-12-13 12:50:57 -08001246
Inseob Kimc0907f12019-02-08 21:00:45 +09001247 syspropImplLibraries := syspropImplLibraries(actx.Config())
1248
Jiyong Park5d1598f2019-02-25 22:14:17 +09001249 for _, lib := range deps.WholeStaticLibs {
1250 depTag := wholeStaticDepTag
1251 if impl, ok := syspropImplLibraries[lib]; ok {
1252 lib = impl
1253 }
1254 actx.AddVariationDependencies([]blueprint.Variation{
1255 {Mutator: "link", Variation: "static"},
1256 }, depTag, lib)
1257 }
1258
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001259 for _, lib := range deps.StaticLibs {
1260 depTag := staticDepTag
1261 if inList(lib, deps.ReexportStaticLibHeaders) {
1262 depTag = staticExportDepTag
1263 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001264
1265 if impl, ok := syspropImplLibraries[lib]; ok {
1266 lib = impl
1267 }
1268
Dan Willemsen59339a22018-07-22 21:18:45 -07001269 actx.AddVariationDependencies([]blueprint.Variation{
1270 {Mutator: "link", Variation: "static"},
1271 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001272 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001273
Dan Willemsen59339a22018-07-22 21:18:45 -07001274 actx.AddVariationDependencies([]blueprint.Variation{
1275 {Mutator: "link", Variation: "static"},
1276 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001277
Jiyong Park25fc6a92018-11-18 18:02:45 +09001278 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1279 var variations []blueprint.Variation
1280 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001281 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001282 if version != "" && versionVariantAvail {
1283 // Version is explicitly specified. i.e. libFoo#30
1284 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1285 depTag.explicitlyVersioned = true
1286 }
1287 actx.AddVariationDependencies(variations, depTag, name)
1288
1289 // If the version is not specified, add dependency to the latest stubs library.
1290 // The stubs library will be used when the depending module is built for APEX and
1291 // the dependent module is not in the same APEX.
1292 latestVersion := latestStubsVersionFor(actx.Config(), name)
1293 if version == "" && latestVersion != "" && versionVariantAvail {
1294 actx.AddVariationDependencies([]blueprint.Variation{
1295 {Mutator: "link", Variation: "shared"},
1296 {Mutator: "version", Variation: latestVersion},
1297 }, depTag, name)
1298 // Note that depTag.explicitlyVersioned is false in this case.
1299 }
1300 }
1301
Jiyong Park7ed9de32018-10-15 22:25:07 +09001302 // shared lib names without the #version suffix
1303 var sharedLibNames []string
1304
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001305 for _, lib := range deps.SharedLibs {
1306 depTag := sharedDepTag
1307 if inList(lib, deps.ReexportSharedLibHeaders) {
1308 depTag = sharedExportDepTag
1309 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001310
1311 if impl, ok := syspropImplLibraries[lib]; ok {
1312 lib = impl
1313 }
1314
1315 name, version := stubsLibNameAndVersion(lib)
1316 sharedLibNames = append(sharedLibNames, name)
1317
Jiyong Park25fc6a92018-11-18 18:02:45 +09001318 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001319 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001320
Jiyong Park7ed9de32018-10-15 22:25:07 +09001321 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001322 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001323 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1324 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1325 // linking against both the stubs lib and the non-stubs lib at the same time.
1326 continue
1327 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001328 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001329 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001330
Dan Willemsen59339a22018-07-22 21:18:45 -07001331 actx.AddVariationDependencies([]blueprint.Variation{
1332 {Mutator: "link", Variation: "shared"},
1333 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001334
Colin Cross68861832016-07-08 10:41:41 -07001335 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001336
1337 for _, gen := range deps.GeneratedHeaders {
1338 depTag := genHeaderDepTag
1339 if inList(gen, deps.ReexportGeneratedHeaders) {
1340 depTag = genHeaderExportDepTag
1341 }
1342 actx.AddDependency(c, depTag, gen)
1343 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001344
Colin Cross42d48b72018-08-29 14:10:52 -07001345 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001346
1347 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001348 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001349 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001350 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001351 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001352 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001353 if deps.LinkerFlagsFile != "" {
1354 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1355 }
1356 if deps.DynamicLinker != "" {
1357 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001358 }
Dan Albert914449f2016-06-17 16:45:24 -07001359
1360 version := ctx.sdkVersion()
1361 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001362 {Mutator: "ndk_api", Variation: version},
1363 {Mutator: "link", Variation: "shared"},
1364 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001365 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001366 {Mutator: "ndk_api", Variation: version},
1367 {Mutator: "link", Variation: "shared"},
1368 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001369
1370 if vndkdep := c.vndkdep; vndkdep != nil {
1371 if vndkdep.isVndkExt() {
1372 baseModuleMode := vendorMode
1373 if actx.DeviceConfig().VndkVersion() == "" {
1374 baseModuleMode = coreMode
1375 }
1376 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001377 {Mutator: "image", Variation: baseModuleMode},
1378 {Mutator: "link", Variation: "shared"},
1379 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001380 }
1381 }
Colin Cross6362e272015-10-29 15:25:03 -07001382}
Colin Cross21b9a242015-03-24 14:15:58 -07001383
Colin Crosse40b4ea2018-10-02 22:25:58 -07001384func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001385 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1386 c.beginMutator(ctx)
1387 }
1388}
1389
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001390// Whether a module can link to another module, taking into
1391// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001392func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001393 if from.Target().Os != android.Android {
1394 // Host code is not restricted
1395 return
1396 }
1397 if from.Properties.UseVndk {
1398 // Though vendor code is limited by the vendor mutator,
1399 // each vendor-available module needs to check
1400 // link-type for VNDK.
1401 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001402 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001403 }
1404 return
1405 }
Nan Zhang0007d812017-11-07 10:57:05 -08001406 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001407 // Platform code can link to anything
1408 return
1409 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001410 if from.inRecovery() {
1411 // Recovery code is not NDK
1412 return
1413 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001414 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1415 // These are always allowed
1416 return
1417 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001418 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1419 // These are allowed, but they don't set sdk_version
1420 return
1421 }
1422 if _, ok := to.linker.(*stubDecorator); ok {
1423 // These aren't real libraries, but are the stub shared libraries that are included in
1424 // the NDK.
1425 return
1426 }
Logan Chien834b9a62019-01-14 15:39:03 +08001427
1428 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" {
1429 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1430 // to link to libc++ (non-NDK and without sdk_version).
1431 return
1432 }
1433
Nan Zhang0007d812017-11-07 10:57:05 -08001434 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001435 // NDK code linking to platform code is never okay.
1436 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1437 ctx.OtherModuleName(to))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001438 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001439 }
1440
1441 // At this point we know we have two NDK libraries, but we need to
1442 // check that we're not linking against anything built against a higher
1443 // API level, as it is only valid to link against older or equivalent
1444 // APIs.
1445
Inseob Kim01a28722018-04-11 09:48:45 +09001446 // Current can link against anything.
1447 if String(from.Properties.Sdk_version) != "current" {
1448 // Otherwise we need to check.
1449 if String(to.Properties.Sdk_version) == "current" {
1450 // Current can't be linked against by anything else.
1451 ctx.ModuleErrorf("links %q built against newer API version %q",
1452 ctx.OtherModuleName(to), "current")
1453 } else {
1454 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1455 if err != nil {
1456 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001457 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001458 String(from.Properties.Sdk_version))
1459 }
1460 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1461 if err != nil {
1462 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001463 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001464 String(to.Properties.Sdk_version))
1465 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001466
Inseob Kim01a28722018-04-11 09:48:45 +09001467 if toApi > fromApi {
1468 ctx.ModuleErrorf("links %q built against newer API version %q",
1469 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1470 }
1471 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001472 }
Dan Albert202fe492017-12-15 13:56:59 -08001473
1474 // Also check that the two STL choices are compatible.
1475 fromStl := from.stl.Properties.SelectedStl
1476 toStl := to.stl.Properties.SelectedStl
1477 if fromStl == "" || toStl == "" {
1478 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001479 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001480 // We can be permissive with the system "STL" since it is only the C++
1481 // ABI layer, but in the future we should make sure that everyone is
1482 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001483 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001484 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1485 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1486 to.stl.Properties.SelectedStl)
1487 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001488}
1489
Jiyong Park5fb8c102018-04-09 12:03:06 +09001490// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001491// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1492// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001493// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001494func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
1495 check := func(child, parent android.Module) bool {
1496 to, ok := child.(*Module)
1497 if !ok {
1498 // follow thru cc.Defaults, etc.
1499 return true
1500 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001501
Jooyung Hana70f0672019-01-18 15:20:43 +09001502 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1503 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001504 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001505
1506 // if target lib has no vendor variant, keep checking dependency graph
1507 if !to.hasVendorVariant() {
1508 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001509 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001510
1511 if to.isVndkSp() || inList(child.Name(), llndkLibraries) || Bool(to.VendorProperties.Double_loadable) {
1512 return false
1513 }
1514
1515 var stringPath []string
1516 for _, m := range ctx.GetWalkPath() {
1517 stringPath = append(stringPath, m.Name())
1518 }
1519 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1520 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1521 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1522 return false
1523 }
1524 if module, ok := ctx.Module().(*Module); ok {
1525 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
1526 if inList(ctx.ModuleName(), llndkLibraries) || Bool(module.VendorProperties.Double_loadable) {
1527 ctx.WalkDeps(check)
1528 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001529 }
1530 }
1531}
1532
Colin Crossc99deeb2016-04-11 15:06:20 -07001533// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001534func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001535 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001536
Jeff Gaston294356f2017-09-27 17:05:30 -07001537 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001538 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001539
Colin Crossd11fcda2017-10-23 17:59:01 -07001540 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001541 depName := ctx.OtherModuleName(dep)
1542 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001543
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001544 ccDep, _ := dep.(*Module)
1545 if ccDep == nil {
1546 // handling for a few module types that aren't cc Module but that are also supported
1547 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001548 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001549 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001550 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1551 genRule.GeneratedSourceFiles()...)
1552 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001553 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001554 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001555 // Support exported headers from a generated_sources dependency
1556 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001557 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001558 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001559 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001560 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001561 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001562 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001563 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001564 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001565 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001566 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001567 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1568 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1569
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001570 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001571 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001572 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001573 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001574 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001575 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001576 files := genRule.GeneratedSourceFiles()
1577 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001578 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001579 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001580 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 -07001581 }
1582 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001583 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001584 }
Colin Crossca860ac2016-01-04 14:34:37 -08001585 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001586 return
1587 }
1588
Colin Crossd11fcda2017-10-23 17:59:01 -07001589 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001590 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1591 return
1592 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001593 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001594 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001595 return
1596 }
1597
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001598 // re-exporting flags
1599 if depTag == reuseObjTag {
1600 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001601 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001602 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001603 depPaths.Objs = depPaths.Objs.Append(objs)
1604 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001605 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001606 return
1607 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001608 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001609
Jiyong Parke4bb9862019-02-01 00:31:10 +09001610 if depTag == staticVariantTag {
1611 if _, ok := ccDep.compiler.(libraryInterface); ok {
1612 c.staticVariant = ccDep
1613 return
1614 }
1615 }
1616
Jiyong Park25fc6a92018-11-18 18:02:45 +09001617 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1618 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1619 // won't be matched to sharedDepTag and lateSharedDepTag.
1620 explicitlyVersioned := false
1621 if t, ok := depTag.(dependencyTag); ok {
1622 explicitlyVersioned = t.explicitlyVersioned
1623 t.explicitlyVersioned = false
1624 depTag = t
1625 }
1626
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001627 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001628 depIsStatic := false
1629 switch depTag {
1630 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1631 depIsStatic = true
1632 }
1633 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001634 depIsStubs := dependentLibrary.buildStubs()
1635 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001636 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001637 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001638
1639 var useThisDep bool
1640 if depIsStubs && explicitlyVersioned {
1641 // Always respect dependency to the versioned stubs (i.e. libX#10)
1642 useThisDep = true
1643 } else if !depHasStubs {
1644 // Use non-stub variant if that is the only choice
1645 // (i.e. depending on a lib without stubs.version property)
1646 useThisDep = true
1647 } else if c.IsForPlatform() {
1648 // If not building for APEX, use stubs only when it is from
1649 // an APEX (and not from platform)
1650 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001651 if c.inRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001652 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001653 // always link to non-stub variant
1654 useThisDep = !depIsStubs
1655 }
1656 } else {
1657 // If building for APEX, use stubs only when it is not from
1658 // the same APEX
1659 useThisDep = (depInSameApex != depIsStubs)
1660 }
1661
1662 if !useThisDep {
1663 return // stop processing this dep
1664 }
1665 }
1666
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001667 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001668 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001669 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001670 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001671 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001672
1673 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001674 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001675 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001676 // 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 -07001677 // Re-exported shared library headers must be included as well since they can help us with type information
1678 // about template instantiations (instantiated from their headers).
1679 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001680 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001681 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001682
Logan Chienf3511742017-10-31 18:04:35 +08001683 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001684 }
1685
Colin Cross26c34ed2016-09-30 17:10:16 -07001686 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001687 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001688
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001689 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001690 depFile := android.OptionalPath{}
1691
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001692 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001693 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001694 ptr = &depPaths.SharedLibs
1695 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001696 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001697 directSharedDeps = append(directSharedDeps, ccDep)
Jiyong Park64a44f22019-01-18 14:37:08 +09001698 case earlySharedDepTag:
1699 ptr = &depPaths.EarlySharedLibs
1700 depPtr = &depPaths.EarlySharedLibsDeps
1701 depFile = ccDep.linker.(libraryInterface).toc()
1702 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001703 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001704 ptr = &depPaths.LateSharedLibs
1705 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001706 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001707 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001708 ptr = nil
1709 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001710 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001711 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001712 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001713 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001714 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001715 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001716 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001717 return
1718 }
1719
1720 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001721 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001722 for i := range missingDeps {
1723 missingDeps[i] += postfix
1724 }
1725 ctx.AddMissingDependencies(missingDeps)
1726 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001727 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001728 case headerDepTag:
1729 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001730 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001731 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001732 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001733 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001734 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001735 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001736 case dynamicLinkerDepTag:
1737 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001738 }
1739
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001740 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001741 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001742 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001743 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001744 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001745 return
1746 }
1747
1748 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001749 // in static libraries act as if they were whole static libraries. The same goes for
1750 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001751 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1752 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001753 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1754 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001755
Dan Willemsen581341d2017-02-09 16:16:31 -08001756 }
1757
Colin Cross26c34ed2016-09-30 17:10:16 -07001758 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001759 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001760 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001761 return
1762 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001763 *ptr = append(*ptr, linkFile.Path())
1764 }
1765
Colin Crossc99deeb2016-04-11 15:06:20 -07001766 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001767 dep := depFile
1768 if !dep.Valid() {
1769 dep = linkFile
1770 }
1771 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001772 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001773
Logan Chien43d34c32017-12-20 01:17:32 +08001774 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001775 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001776 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001777 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001778 isLLndk := inList(libName, llndkLibraries)
Jiyong Park374510b2018-03-19 18:23:01 +09001779 isVendorPublicLib := inList(libName, vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001780 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08001781
1782 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.isVndk() && !ccDep.mustUseVendorVariant() {
1783 // The vendor module is a no-vendor-variant VNDK library. Depend on the
1784 // core module instead.
1785 return libName
1786 } else if c.useVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001787 // The vendor module in Make will have been renamed to not conflict with the core
1788 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001789 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001790 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001791 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001792 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1793 return libName + recoverySuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001794 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001795 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001796 }
Logan Chien43d34c32017-12-20 01:17:32 +08001797 }
1798
1799 // Export the shared libs to Make.
1800 switch depTag {
Jiyong Park64a44f22019-01-18 14:37:08 +09001801 case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001802 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001803 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08001804 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09001805 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001806 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001807 c.Properties.ApexesProvidingSharedLibs = append(
1808 c.Properties.ApexesProvidingSharedLibs, an)
1809 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09001810 }
1811 }
1812
Jiyong Park27b188b2017-07-18 13:23:39 +09001813 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001814 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001815 c.Properties.AndroidMkSharedLibs = append(
1816 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08001817 case ndkStubDepTag, ndkLateStubDepTag:
1818 ndkStub := ccDep.linker.(*stubDecorator)
1819 c.Properties.AndroidMkSharedLibs = append(
1820 c.Properties.AndroidMkSharedLibs,
1821 depName+"."+ndkStub.properties.ApiLevel)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001822 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1823 c.Properties.AndroidMkStaticLibs = append(
1824 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001825 case runtimeDepTag:
1826 c.Properties.AndroidMkRuntimeLibs = append(
1827 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001828 case wholeStaticDepTag:
1829 c.Properties.AndroidMkWholeStaticLibs = append(
1830 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001831 }
Colin Crossca860ac2016-01-04 14:34:37 -08001832 })
1833
Jeff Gaston294356f2017-09-27 17:05:30 -07001834 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001835 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001836
Colin Crossdd84e052017-05-17 13:44:16 -07001837 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001838 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001839 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001840 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001841 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1842
1843 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001844 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001845 }
Colin Crossdd84e052017-05-17 13:44:16 -07001846
Colin Crossca860ac2016-01-04 14:34:37 -08001847 return depPaths
1848}
1849
1850func (c *Module) InstallInData() bool {
1851 if c.installer == nil {
1852 return false
1853 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001854 return c.installer.inData()
1855}
1856
1857func (c *Module) InstallInSanitizerDir() bool {
1858 if c.installer == nil {
1859 return false
1860 }
1861 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001862 return true
1863 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001864 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001865}
1866
Jiyong Parkf9332f12018-02-01 00:54:12 +09001867func (c *Module) InstallInRecovery() bool {
1868 return c.inRecovery()
1869}
1870
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001871func (c *Module) HostToolPath() android.OptionalPath {
1872 if c.installer == nil {
1873 return android.OptionalPath{}
1874 }
1875 return c.installer.hostToolPath()
1876}
1877
Nan Zhangd4e641b2017-07-12 12:55:28 -07001878func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1879 return c.outputFile
1880}
1881
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001882func (c *Module) Srcs() android.Paths {
1883 if c.outputFile.Valid() {
1884 return android.Paths{c.outputFile.Path()}
1885 }
1886 return android.Paths{}
1887}
1888
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001889func (c *Module) static() bool {
1890 if static, ok := c.linker.(interface {
1891 static() bool
1892 }); ok {
1893 return static.static()
1894 }
1895 return false
1896}
1897
Jiyong Park379de2f2018-12-19 02:47:14 +09001898func (c *Module) staticBinary() bool {
1899 if static, ok := c.linker.(interface {
1900 staticBinary() bool
1901 }); ok {
1902 return static.staticBinary()
1903 }
1904 return false
1905}
1906
Colin Crossb60190a2018-09-04 16:28:17 -07001907func (c *Module) getMakeLinkType() string {
1908 if c.useVndk() {
1909 if inList(c.Name(), vndkCoreLibraries) || inList(c.Name(), vndkSpLibraries) || inList(c.Name(), llndkLibraries) {
1910 if inList(c.Name(), vndkPrivateLibraries) {
1911 return "native:vndk_private"
1912 } else {
1913 return "native:vndk"
1914 }
1915 } else {
1916 return "native:vendor"
1917 }
1918 } else if c.inRecovery() {
1919 return "native:recovery"
1920 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
1921 return "native:ndk:none:none"
1922 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
1923 //family, link := getNdkStlFamilyAndLinkType(c)
1924 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Vic Yangefd249e2018-11-12 20:19:56 -08001925 } else if inList(c.Name(), vndkUsingCoreVariantLibraries) {
1926 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07001927 } else {
1928 return "native:platform"
1929 }
1930}
1931
Jiyong Park9d452992018-10-03 00:38:19 +09001932// Overrides ApexModule.IsInstallabeToApex()
1933// Only shared libraries are installable to APEX.
1934func (c *Module) IsInstallableToApex() bool {
1935 if shared, ok := c.linker.(interface {
1936 shared() bool
1937 }); ok {
1938 return shared.shared()
1939 }
1940 return false
1941}
1942
Jiyong Park3b1746a2019-01-29 11:15:04 +09001943func (c *Module) imageVariation() string {
1944 variation := "core"
1945 if c.useVndk() {
1946 variation = "vendor"
1947 } else if c.inRecovery() {
1948 variation = "recovery"
1949 }
1950 return variation
1951}
1952
bralee3f49f4d2019-03-04 06:58:15 +08001953func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
1954 dpInfo.Srcs = append(dpInfo.Srcs, c.Srcs().Strings()...)
1955}
1956
Colin Cross2ba19d92015-05-07 15:44:20 -07001957//
Colin Crosscfad1192015-11-02 16:43:11 -08001958// Defaults
1959//
Colin Crossca860ac2016-01-04 14:34:37 -08001960type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001961 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001962 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09001963 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001964}
1965
Colin Cross635c3b02016-05-18 15:37:25 -07001966func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001967}
1968
Colin Cross36242852017-06-23 15:06:31 -07001969func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001970 return DefaultsFactory()
1971}
1972
Colin Cross36242852017-06-23 15:06:31 -07001973func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001974 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001975
Colin Cross36242852017-06-23 15:06:31 -07001976 module.AddProperties(props...)
1977 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001978 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001979 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001980 &BaseCompilerProperties{},
1981 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001982 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001983 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001984 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001985 &TestProperties{},
1986 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001987 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001988 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001989 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001990 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001991 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001992 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001993 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001994 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001995 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001996 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08001997 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001998 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001999 )
Colin Crosscfad1192015-11-02 16:43:11 -08002000
Colin Cross1f44a3a2017-07-07 14:33:33 -07002001 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09002002 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002003
2004 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002005}
2006
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002007const (
2008 // coreMode is the variant used for framework-private libraries, or
2009 // SDK libraries. (which framework-private libraries can use)
2010 coreMode = "core"
2011
2012 // vendorMode is the variant used for /vendor code that compiles
2013 // against the VNDK.
2014 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09002015
2016 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002017)
2018
Jiyong Park6a43f042017-10-12 23:05:00 +09002019func squashVendorSrcs(m *Module) {
2020 if lib, ok := m.compiler.(*libraryDecorator); ok {
2021 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2022 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2023
2024 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2025 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2026 }
2027}
2028
Jiyong Parkf9332f12018-02-01 00:54:12 +09002029func squashRecoverySrcs(m *Module) {
2030 if lib, ok := m.compiler.(*libraryDecorator); ok {
2031 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2032 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2033
2034 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2035 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2036 }
2037}
2038
Jiyong Parkda6eb592018-12-19 17:12:36 +09002039func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002040 if mctx.Os() != android.Android {
2041 return
2042 }
2043
Jiyong Park7ed9de32018-10-15 22:25:07 +09002044 if g, ok := mctx.Module().(*genrule.Module); ok {
2045 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09002046 var coreVariantNeeded bool = false
2047 var vendorVariantNeeded bool = false
2048 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09002049 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09002050 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002051 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09002052 coreVariantNeeded = true
2053 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09002054 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09002055 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002056 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09002057 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002058 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002059 if Bool(props.Recovery_available) {
2060 recoveryVariantNeeded = true
2061 }
2062
Jiyong Park413cc742018-06-19 01:46:06 +09002063 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002064 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09002065 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09002066 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002067 recoveryVariantNeeded = false
2068 }
2069 }
2070
Jiyong Park3f736c92018-05-24 13:36:56 +09002071 var variants []string
2072 if coreVariantNeeded {
2073 variants = append(variants, coreMode)
2074 }
2075 if vendorVariantNeeded {
2076 variants = append(variants, vendorMode)
2077 }
2078 if recoveryVariantNeeded {
2079 variants = append(variants, recoveryMode)
2080 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002081 mod := mctx.CreateVariations(variants...)
2082 for i, v := range variants {
2083 if v == recoveryMode {
2084 m := mod[i].(*genrule.Module)
2085 m.Extra.(*GenruleExtraProperties).InRecovery = true
2086 }
2087 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002088 }
2089 }
2090
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002091 m, ok := mctx.Module().(*Module)
2092 if !ok {
2093 return
2094 }
2095
2096 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002097 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002098 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002099
2100 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002101 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002102 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002103 return
2104 }
Logan Chienf3511742017-10-31 18:04:35 +08002105
2106 if vndkdep := m.vndkdep; vndkdep != nil {
2107 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002108 if productSpecific {
2109 mctx.PropertyErrorf("product_specific",
2110 "product_specific must not be true when `vndk: {enabled: true}`")
2111 return
2112 }
Logan Chienf3511742017-10-31 18:04:35 +08002113 if vendorSpecific {
2114 if !vndkdep.isVndkExt() {
2115 mctx.PropertyErrorf("vndk",
2116 "must set `extends: \"...\"` to vndk extension")
2117 return
2118 }
2119 } else {
2120 if vndkdep.isVndkExt() {
2121 mctx.PropertyErrorf("vndk",
2122 "must set `vendor: true` to set `extends: %q`",
2123 m.getVndkExtendsModuleName())
2124 return
2125 }
2126 if m.VendorProperties.Vendor_available == nil {
2127 mctx.PropertyErrorf("vndk",
2128 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2129 return
2130 }
2131 }
2132 } else {
2133 if vndkdep.isVndkSp() {
2134 mctx.PropertyErrorf("vndk",
2135 "must set `enabled: true` to set `support_system_process: true`")
2136 return
2137 }
2138 if vndkdep.isVndkExt() {
2139 mctx.PropertyErrorf("vndk",
2140 "must set `enabled: true` to set `extends: %q`",
2141 m.getVndkExtendsModuleName())
2142 return
2143 }
Justin Yun8effde42017-06-23 19:24:43 +09002144 }
2145 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002146
Jiyong Parkf9332f12018-02-01 00:54:12 +09002147 var coreVariantNeeded bool = false
2148 var vendorVariantNeeded bool = false
2149 var recoveryVariantNeeded bool = false
2150
Justin Yun71549282017-11-17 12:10:28 +09002151 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002152 // If the device isn't compiling against the VNDK, we always
2153 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002154 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002155 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2156 // LL-NDK stubs only exist in the vendor variant, since the
2157 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002158 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09002159 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2160 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09002161 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09002162 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002163 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2164 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002165 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002166 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002167 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002168 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002169 coreVariantNeeded = true
2170 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002171 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002172 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09002173 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002174 } else {
2175 // This is either in /system (or similar: /data), or is a
2176 // modules built with the NDK. Modules built with the NDK
2177 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002178 coreVariantNeeded = true
2179 }
2180
2181 if Bool(m.Properties.Recovery_available) {
2182 recoveryVariantNeeded = true
2183 }
2184
2185 if m.ModuleBase.InstallInRecovery() {
2186 recoveryVariantNeeded = true
2187 coreVariantNeeded = false
2188 }
2189
Jiyong Park413cc742018-06-19 01:46:06 +09002190 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002191 primaryArch := mctx.Config().DevicePrimaryArchType()
2192 moduleArch := m.Target().Arch.ArchType
2193 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002194 recoveryVariantNeeded = false
2195 }
2196 }
2197
Jiyong Parkf9332f12018-02-01 00:54:12 +09002198 var variants []string
2199 if coreVariantNeeded {
2200 variants = append(variants, coreMode)
2201 }
2202 if vendorVariantNeeded {
2203 variants = append(variants, vendorMode)
2204 }
2205 if recoveryVariantNeeded {
2206 variants = append(variants, recoveryMode)
2207 }
2208 mod := mctx.CreateVariations(variants...)
2209 for i, v := range variants {
2210 if v == vendorMode {
2211 m := mod[i].(*Module)
2212 m.Properties.UseVndk = true
2213 squashVendorSrcs(m)
2214 } else if v == recoveryMode {
2215 m := mod[i].(*Module)
2216 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002217 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002218 squashRecoverySrcs(m)
2219 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002220 }
2221}
2222
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002223func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002224 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002225 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2226 }
Colin Cross6510f912017-11-29 00:27:14 -08002227 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002228}
2229
Colin Cross06a931b2015-10-28 17:23:31 -07002230var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002231var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002232var BoolPtr = proptools.BoolPtr
2233var String = proptools.String
2234var StringPtr = proptools.StringPtr