blob: 18bffb510df239f7f6aae412ca1723661ad084b9 [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -07001// Copyright 2015 Google Inc. All rights reserved.
Colin Cross3f40fa42015-01-30 17:27:36 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17// This file contains the module types for compiling C/C++ for Android, and converts the properties
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
Colin Cross516c5452024-10-28 13:45:21 -070022 "errors"
Colin Cross41955e82019-05-29 14:40:35 -070023 "fmt"
Logan Chien41eabe62019-04-10 13:33:58 +080024 "io"
Colin Cross516c5452024-10-28 13:45:21 -070025 "slices"
Dan Albert9e10cd42016-08-03 14:12:14 -070026 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080027 "strings"
28
Colin Cross97ba0732015-03-23 17:50:24 -070029 "github.com/google/blueprint"
Colin Crossa14fb6a2024-10-23 16:57:06 -070030 "github.com/google/blueprint/depset"
Colin Cross06a931b2015-10-28 17:23:31 -070031 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070032
Vinh Tran367d89d2023-04-28 11:21:25 -040033 "android/soong/aidl_library"
Colin Cross635c3b02016-05-18 15:37:25 -070034 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070035 "android/soong/cc/config"
hamzehc0a671f2021-07-22 12:05:08 -070036 "android/soong/fuzz"
Colin Cross5049f022015-03-18 13:28:46 -070037 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080038)
39
Yu Liu76d94462024-10-31 23:32:36 +000040type CcMakeVarsInfo struct {
41 WarningsAllowed string
42 UsingWnoError string
43 MissingProfile string
44}
45
46var CcMakeVarsInfoProvider = blueprint.NewProvider[*CcMakeVarsInfo]()
47
Yu Liuec7043d2024-11-05 18:22:20 +000048type CcObjectInfo struct {
Yu Liu4f825132024-12-18 00:35:39 +000049 ObjFiles android.Paths
50 TidyFiles android.Paths
51 KytheFiles android.Paths
Yu Liuec7043d2024-11-05 18:22:20 +000052}
53
54var CcObjectInfoProvider = blueprint.NewProvider[CcObjectInfo]()
55
Yu Liu323d77a2024-12-16 23:13:57 +000056type AidlInterfaceInfo struct {
57 // list of aidl_interface sources
58 Sources []string
59 // root directory of AIDL sources
60 AidlRoot string
61 // AIDL backend language (e.g. "cpp", "ndk")
62 Lang string
63 // list of flags passed to AIDL generator
64 Flags []string
65}
66
67type CompilerInfo struct {
68 Srcs android.Paths
69 // list of module-specific flags that will be used for C and C++ compiles.
70 Cflags proptools.Configurable[[]string]
71 AidlInterfaceInfo AidlInterfaceInfo
72 LibraryDecoratorInfo *LibraryDecoratorInfo
73}
74
75type LinkerInfo struct {
Yu Liu4f825132024-12-18 00:35:39 +000076 WholeStaticLibs proptools.Configurable[[]string]
Yu Liu323d77a2024-12-16 23:13:57 +000077 // list of modules that should be statically linked into this module.
Yu Liu4f825132024-12-18 00:35:39 +000078 StaticLibs proptools.Configurable[[]string]
Yu Liu323d77a2024-12-16 23:13:57 +000079 // list of modules that should be dynamically linked into this module.
Yu Liu4f825132024-12-18 00:35:39 +000080 SharedLibs proptools.Configurable[[]string]
Yu Liu323d77a2024-12-16 23:13:57 +000081 // list of modules that should only provide headers for this module.
Yu Liu4f825132024-12-18 00:35:39 +000082 HeaderLibs proptools.Configurable[[]string]
83 UnstrippedOutputFile android.Path
Yu Liu323d77a2024-12-16 23:13:57 +000084
85 BinaryDecoratorInfo *BinaryDecoratorInfo
86 LibraryDecoratorInfo *LibraryDecoratorInfo
87 TestBinaryInfo *TestBinaryInfo
88 BenchmarkDecoratorInfo *BenchmarkDecoratorInfo
89 ObjectLinkerInfo *ObjectLinkerInfo
90}
91
92type BinaryDecoratorInfo struct{}
93type LibraryDecoratorInfo struct {
Yu Liu4f825132024-12-18 00:35:39 +000094 ExportIncludeDirs proptools.Configurable[[]string]
Yu Liu323d77a2024-12-16 23:13:57 +000095}
96type TestBinaryInfo struct {
97 Gtest bool
98}
99type BenchmarkDecoratorInfo struct{}
100type ObjectLinkerInfo struct{}
101
Yu Liub1bfa9d2024-12-05 18:57:51 +0000102// Common info about the cc module.
103type CcInfo struct {
Yu Liu323d77a2024-12-16 23:13:57 +0000104 HasStubsVariants bool
105 IsPrebuilt bool
106 CmakeSnapshotSupported bool
107 CompilerInfo *CompilerInfo
108 LinkerInfo *LinkerInfo
Yu Liub1bfa9d2024-12-05 18:57:51 +0000109}
110
111var CcInfoProvider = blueprint.NewProvider[CcInfo]()
112
Yu Liu986d98c2024-11-12 00:28:11 +0000113type LinkableInfo struct {
114 // StaticExecutable returns true if this is a binary module with "static_executable: true".
115 StaticExecutable bool
116}
117
118var LinkableInfoKey = blueprint.NewProvider[LinkableInfo]()
119
Colin Cross463a90e2015-06-17 14:20:06 -0700120func init() {
Paul Duffin036e7002019-12-19 19:16:28 +0000121 RegisterCCBuildComponents(android.InitRegistrationContext)
Colin Cross463a90e2015-06-17 14:20:06 -0700122
Inseob Kim3b244062023-07-11 13:31:36 +0900123 pctx.Import("android/soong/android")
Paul Duffin036e7002019-12-19 19:16:28 +0000124 pctx.Import("android/soong/cc/config")
125}
126
127func RegisterCCBuildComponents(ctx android.RegistrationContext) {
128 ctx.RegisterModuleType("cc_defaults", defaultsFactory)
129
130 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Crossac57a6c2024-06-26 13:09:53 -0700131 ctx.Transition("sdk", &sdkTransitionMutator{})
Colin Cross8a962802024-10-09 15:29:27 -0700132 ctx.BottomUp("llndk", llndkMutator)
Colin Cross767819f2024-05-22 14:22:34 -0700133 ctx.Transition("link", &linkageTransitionMutator{})
Colin Crossadd04a82024-05-22 09:57:59 -0700134 ctx.Transition("version", &versionTransitionMutator{})
Colin Cross8a962802024-10-09 15:29:27 -0700135 ctx.BottomUp("begin", BeginMutator)
Colin Cross1e676be2016-10-12 14:38:15 -0700136 })
Colin Cross16b23492016-01-06 14:41:07 -0800137
Paul Duffin036e7002019-12-19 19:16:28 +0000138 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
Liz Kammer75db9312021-07-07 16:41:50 -0400139 for _, san := range Sanitizers {
140 san.registerMutators(ctx)
141 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800142
Colin Cross8a962802024-10-09 15:29:27 -0700143 ctx.BottomUp("sanitize_runtime_deps", sanitizerRuntimeDepsMutator)
144 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator)
Ivan Lozano30c5db22018-02-21 15:49:20 -0800145
Colin Cross597bad62024-10-08 15:10:55 -0700146 ctx.Transition("fuzz", &fuzzTransitionMutator{})
Cory Barkera1da26f2022-06-07 20:12:06 +0000147
Colin Crossf5f4ad32024-01-19 15:41:48 -0800148 ctx.Transition("coverage", &coverageTransitionMutator{})
Stephen Craneba090d12017-05-09 15:44:35 -0700149
Colin Crossd38feb02024-01-23 16:38:06 -0800150 ctx.Transition("afdo", &afdoTransitionMutator{})
Yi Kongeb8efc92021-12-09 18:06:29 +0800151
Colin Cross33e0c812024-01-23 16:36:07 -0800152 ctx.Transition("orderfile", &orderfileTransitionMutator{})
Sharjeel Khanc6a93d82023-07-18 21:01:11 +0000153
Colin Cross6ac83a82024-01-23 11:23:10 -0800154 ctx.Transition("lto", &ltoTransitionMutator{})
Jooyung Hana70f0672019-01-18 15:20:43 +0900155
Colin Cross8a962802024-10-09 15:29:27 -0700156 ctx.BottomUp("check_linktype", checkLinkTypeMutator)
157 ctx.BottomUp("double_loadable", checkDoubleLoadableLibraries)
Colin Cross1e676be2016-10-12 14:38:15 -0700158 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700159
Colin Cross91ae5ec2024-10-01 14:03:40 -0700160 ctx.PostApexMutators(func(ctx android.RegisterMutatorsContext) {
Yo Chiang8aa4e3f2020-11-19 16:30:49 +0800161 // sabi mutator needs to be run after apex mutator finishes.
Colin Cross91ae5ec2024-10-01 14:03:40 -0700162 ctx.Transition("sabi", &sabiTransitionMutator{})
Yo Chiang8aa4e3f2020-11-19 16:30:49 +0800163 })
164
LaMont Jones0c10e4d2023-05-16 00:58:37 +0000165 ctx.RegisterParallelSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Cross463a90e2015-06-17 14:20:06 -0700166}
167
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500168// Deps is a struct containing module names of dependencies, separated by the kind of dependency.
169// Mutators should use `AddVariationDependencies` or its sibling methods to add actual dependency
170// edges to these modules.
171// This object is constructed in DepsMutator, by calling to various module delegates to set
172// relevant fields. For example, `module.compiler.compilerDeps()` may append type-specific
173// dependencies.
174// This is then consumed by the same DepsMutator, which will call `ctx.AddVariationDependencies()`
175// (or its sibling methods) to set real dependencies on the given modules.
Colin Crossca860ac2016-01-04 14:34:37 -0800176type Deps struct {
177 SharedLibs, LateSharedLibs []string
178 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -0800179 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +0800180 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -0700181
Colin Cross3e5e7782022-06-17 22:17:05 +0000182 // UnexportedStaticLibs are static libraries that are also passed to -Wl,--exclude-libs= to
183 // prevent automatically exporting symbols.
184 UnexportedStaticLibs []string
185
Chris Parsons79d66a52020-06-05 17:26:16 -0400186 // Used for data dependencies adjacent to tests
187 DataLibs []string
Colin Crossc8caa062021-09-24 16:50:14 -0700188 DataBins []string
Chris Parsons79d66a52020-06-05 17:26:16 -0400189
Yo Chiang219968c2020-09-22 18:45:04 +0800190 // Used by DepsMutator to pass system_shared_libs information to check_elf_file.py.
191 SystemSharedLibs []string
192
Vinh Tran367d89d2023-04-28 11:21:25 -0400193 // Used by DepMutator to pass aidl_library modules to aidl compiler
194 AidlLibs []string
195
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500196 // If true, statically link the unwinder into native libraries/binaries.
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800197 StaticUnwinderIfLegacy bool
198
Colin Cross5950f382016-12-13 12:50:57 -0800199 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700200
Colin Cross81413472016-04-11 14:37:39 -0700201 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700202
Cole Faust65cb40a2024-10-21 15:41:42 -0700203 GeneratedSources []string
204 GeneratedHeaders []string
205 DeviceFirstGeneratedHeaders []string
206 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700207
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700208 ReexportGeneratedHeaders []string
209
Colin Crossc465efd2021-06-11 18:00:04 -0700210 CrtBegin, CrtEnd []string
Dan Willemsena0790e32018-10-12 00:24:23 -0700211
212 // Used for host bionic
Colin Cross9cfe6112021-06-11 18:02:22 -0700213 DynamicLinker string
Jiyong Parke3867542020-12-03 17:28:25 +0900214
215 // List of libs that need to be excluded for APEX variant
216 ExcludeLibsForApex []string
Jooyung Han9ffbe832023-11-28 22:31:35 +0900217 // List of libs that need to be excluded for non-APEX variant
218 ExcludeLibsForNonApex []string
Hsin-Yi Chen715142a2024-03-27 16:31:16 +0800219
220 // LLNDK headers for the ABI checker to check LLNDK implementation library.
221 // An LLNDK implementation is the core variant. LLNDK header libs are reexported by the vendor variant.
Colin Cross1e954b62024-09-13 13:50:00 -0700222 // The core variant cannot depend on the vendor variant because of the order of imageTransitionMutator.Split().
Hsin-Yi Chen715142a2024-03-27 16:31:16 +0800223 // Instead, the LLNDK implementation depends on the LLNDK header libs.
224 LlndkHeaderLibs []string
Colin Crossc472d572015-03-17 15:06:21 -0700225}
226
Ivan Lozano0a468a42024-05-13 21:03:34 -0400227// A struct which to collect flags for rlib dependencies
228type RustRlibDep struct {
229 LibPath android.Path // path to the rlib
230 LinkDirs []string // flags required for dependency (e.g. -L flags)
231 CrateName string // crateNames associated with rlibDeps
232}
233
234func EqRustRlibDeps(a RustRlibDep, b RustRlibDep) bool {
235 return a.LibPath == b.LibPath
236}
237
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500238// PathDeps is a struct containing file paths to dependencies of a module.
239// It's constructed in depsToPath() by traversing the direct dependencies of the current module.
240// It's used to construct flags for various build statements (such as for compiling and linking).
241// It is then passed to module decorator functions responsible for registering build statements
242// (such as `module.compiler.compile()`).`
Colin Crossca860ac2016-01-04 14:34:37 -0800243type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700244 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900245 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700246 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900247 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700248 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700249 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Ivan Lozano0a468a42024-05-13 21:03:34 -0400250 // Paths and crateNames for RustStaticLib dependencies
251 RustRlibDeps []RustRlibDep
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700252
Colin Cross0de8a1e2020-09-18 14:15:30 -0700253 // Transitive static library dependencies of static libraries for use in ordering.
Colin Crossa14fb6a2024-10-23 16:57:06 -0700254 TranstiveStaticLibrariesForOrdering depset.DepSet[android.Path]
Colin Cross0de8a1e2020-09-18 14:15:30 -0700255
Colin Cross26c34ed2016-09-30 17:10:16 -0700256 // Paths to .o files
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100257 Objs Objects
258 // Paths to .o files in dependencies that provide them. Note that these lists
259 // aren't complete since prebuilt modules don't provide the .o files.
Dan Willemsen581341d2017-02-09 16:16:31 -0800260 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700261 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700262
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100263 // Paths to .a files in prebuilts. Complements WholeStaticLibObjs to contain
264 // the libs from all whole_static_lib dependencies.
265 WholeStaticLibsFromPrebuilts android.Paths
266
Colin Cross26c34ed2016-09-30 17:10:16 -0700267 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700268 GeneratedSources android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900269 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700270
Inseob Kimd110f872019-12-06 13:15:38 +0900271 Flags []string
Colin Cross3e5e7782022-06-17 22:17:05 +0000272 LdFlags []string
Inseob Kimd110f872019-12-06 13:15:38 +0900273 IncludeDirs android.Paths
274 SystemIncludeDirs android.Paths
275 ReexportedDirs android.Paths
276 ReexportedSystemDirs android.Paths
277 ReexportedFlags []string
278 ReexportedGeneratedHeaders android.Paths
279 ReexportedDeps android.Paths
Ivan Lozano0a468a42024-05-13 21:03:34 -0400280 ReexportedRustRlibDeps []RustRlibDep
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700281
Colin Cross26c34ed2016-09-30 17:10:16 -0700282 // Paths to crt*.o files
Colin Crossc465efd2021-06-11 18:00:04 -0700283 CrtBegin, CrtEnd android.Paths
Dan Willemsena0790e32018-10-12 00:24:23 -0700284
Dan Willemsena0790e32018-10-12 00:24:23 -0700285 // Path to the dynamic linker binary
286 DynamicLinker android.OptionalPath
Dan Willemsen47450072021-10-19 20:24:49 -0700287
288 // For Darwin builds, the path to the second architecture's output that should
289 // be combined with this architectures's output into a FAT MachO file.
290 DarwinSecondArchOutput android.OptionalPath
Vinh Tran367d89d2023-04-28 11:21:25 -0400291
292 // Paths to direct srcs and transitive include dirs from direct aidl_library deps
293 AidlLibraryInfos []aidl_library.AidlLibraryInfo
Hsin-Yi Chen715142a2024-03-27 16:31:16 +0800294
295 // LLNDK headers for the ABI checker to check LLNDK implementation library.
296 LlndkIncludeDirs android.Paths
297 LlndkSystemIncludeDirs android.Paths
Colin Crossb614cd42024-10-11 12:52:21 -0700298
299 directImplementationDeps android.Paths
300 transitiveImplementationDeps []depset.DepSet[android.Path]
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700301}
302
Colin Cross4af21ed2019-11-04 09:37:55 -0800303// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
304// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
305// command line so they can be overridden by the local module flags).
306type LocalOrGlobalFlags struct {
307 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700308 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800309 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700310 CFlags []string // Flags that apply to C and C++ source files
311 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
312 ConlyFlags []string // Flags that apply to C source files
313 CppFlags []string // Flags that apply to C++ source files
314 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700315 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800316}
317
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500318// Flags contains various types of command line flags (and settings) for use in building build
319// statements related to C++.
Colin Cross4af21ed2019-11-04 09:37:55 -0800320type Flags struct {
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500321 // Local flags (which individual modules are responsible for). These may override global flags.
322 Local LocalOrGlobalFlags
323 // Global flags (which build system or toolchain is responsible for).
Luis Useche342fa6b2024-04-01 19:33:18 -0700324 Global LocalOrGlobalFlags
325 NoOverrideFlags []string // Flags applied to the end of list of flags so they are not overridden
Colin Cross4af21ed2019-11-04 09:37:55 -0800326
327 aidlFlags []string // Flags that apply to aidl source files
328 rsFlags []string // Flags that apply to renderscript source files
329 libFlags []string // Flags to add libraries early to the link order
330 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
331 TidyFlags []string // Flags that apply to clang-tidy
332 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700333
Colin Crossc3199482017-03-30 15:03:04 -0700334 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800335 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700336 SystemIncludeFlags []string
337
Chih-Hung Hsieh7540a782022-01-08 19:56:09 -0800338 Toolchain config.Toolchain
339 Tidy bool // True if ninja .tidy rules should be generated.
340 NeedTidyFiles bool // True if module link should depend on .tidy files
341 GcovCoverage bool // True if coverage files should be generated.
342 SAbiDump bool // True if header abi dumps should be generated.
343 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
kellyhungd62ea302024-05-19 21:16:07 +0800344 ClangVerify bool // If true, append cflags "-Xclang -verify" and append "&& touch $out" to the clang command line.
Colin Crossca860ac2016-01-04 14:34:37 -0800345
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500346 // The instruction set required for clang ("arm" or "thumb").
Colin Crossca860ac2016-01-04 14:34:37 -0800347 RequiredInstructionSet string
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500348 // The target-device system path to the dynamic linker.
349 DynamicLinker string
Colin Cross16b23492016-01-06 14:41:07 -0800350
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700351 CFlagsDeps android.Paths // Files depended on by compiler flags
352 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800353
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500354 // True if .s files should be processed with the c preprocessor.
Dan Willemsen98ab3112019-08-27 21:20:40 -0700355 AssemblerWithCpp bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800356
Colin Cross19878da2019-03-28 14:45:07 -0700357 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700358 protoC bool // Whether to use C instead of C++
359 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700360
361 Yacc *YaccProperties
Matthias Maennich22fd4d12020-07-15 10:58:56 +0200362 Lex *LexProperties
Colin Crossc472d572015-03-17 15:06:21 -0700363}
364
Colin Crossca860ac2016-01-04 14:34:37 -0800365// Properties used to compile all C or C++ modules
366type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700367 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800368 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700369
Yi Kong5786f5c2024-05-28 02:22:34 +0900370 // Aggresively trade performance for smaller binary size.
371 // This should only be used for on-device binaries that are rarely executed and not
372 // performance critical.
373 Optimize_for_size *bool `android:"arch_variant"`
374
Jiyong Parkb35a8192020-08-10 15:59:36 +0900375 // The API level that this module is built against. The APIs of this API level will be
376 // visible at build time, but use of any APIs newer than min_sdk_version will render the
377 // module unloadable on older devices. In the future it will be possible to weakly-link new
378 // APIs, making the behavior match Java: such modules will load on older devices, but
379 // calling new APIs on devices that do not support them will result in a crash.
380 //
381 // This property has the same behavior as sdk_version does for Java modules. For those
382 // familiar with Android Gradle, the property behaves similarly to how compileSdkVersion
383 // does for Java code.
384 //
385 // In addition, setting this property causes two variants to be built, one for the platform
386 // and one for apps.
Nan Zhang0007d812017-11-07 10:57:05 -0800387 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700388
Jiyong Parkb35a8192020-08-10 15:59:36 +0900389 // Minimum OS API level supported by this C or C++ module. This property becomes the value
390 // of the __ANDROID_API__ macro. When the C or C++ module is included in an APEX or an APK,
391 // this property is also used to ensure that the min_sdk_version of the containing module is
392 // not older (i.e. less) than this module's min_sdk_version. When not set, this property
393 // defaults to the value of sdk_version. When this is set to "apex_inherit", this tracks
394 // min_sdk_version of the containing APEX. When the module
395 // is not built for an APEX, "apex_inherit" defaults to sdk_version.
Jooyung Han379660c2020-04-21 15:24:00 +0900396 Min_sdk_version *string
397
Colin Crossc511bc52020-04-07 16:50:32 +0000398 // If true, always create an sdk variant and don't create a platform variant.
399 Sdk_variant_only *bool
400
Colin Cross4297f402024-11-20 15:20:09 -0800401 AndroidMkSharedLibs []string `blueprint:"mutated"`
402 AndroidMkStaticLibs []string `blueprint:"mutated"`
403 AndroidMkRlibs []string `blueprint:"mutated"`
404 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
405 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
406 AndroidMkHeaderLibs []string `blueprint:"mutated"`
407 HideFromMake bool `blueprint:"mutated"`
408 PreventInstall bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700409
Yo Chiang219968c2020-09-22 18:45:04 +0800410 // Set by DepsMutator.
411 AndroidMkSystemSharedLibs []string `blueprint:"mutated"`
412
Kiyoung Kimb5fdb2e2024-01-03 14:24:34 +0900413 // The name of the image this module is built for
414 ImageVariation string `blueprint:"mutated"`
Lukacs T. Berki2f5c3402021-06-15 11:27:56 +0200415
416 // The VNDK version this module is built against. If empty, the module is not
417 // build against the VNDK.
418 VndkVersion string `blueprint:"mutated"`
419
420 // Suffix for the name of Android.mk entries generated by this module
421 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800422
423 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
424 // file
Inseob Kim37e0bb02024-04-29 15:54:44 +0900425 Logtags []string `android:"path"`
Jiyong Parkf9332f12018-02-01 00:54:12 +0900426
Yifan Hong39143a92020-10-26 12:43:12 -0700427 // Make this module available when building for ramdisk.
428 // On device without a dedicated recovery partition, the module is only
429 // available after switching root into
430 // /first_stage_ramdisk. To expose the module before switching root, install
431 // the recovery variant instead.
Yifan Hong1b3348d2020-01-21 15:53:22 -0800432 Ramdisk_available *bool
433
Yifan Hong39143a92020-10-26 12:43:12 -0700434 // Make this module available when building for vendor ramdisk.
435 // On device without a dedicated recovery partition, the module is only
436 // available after switching root into
437 // /first_stage_ramdisk. To expose the module before switching root, install
438 // the recovery variant instead.
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700439 Vendor_ramdisk_available *bool
440
Jiyong Parkf9332f12018-02-01 00:54:12 +0900441 // Make this module available when building for recovery
442 Recovery_available *bool
443
Lukacs T. Berki2f5c3402021-06-15 11:27:56 +0200444 // Used by imageMutator, set by ImageMutatorBegin()
Jihoon Kang47e91842024-06-19 00:51:16 +0000445 VendorVariantNeeded bool `blueprint:"mutated"`
446 ProductVariantNeeded bool `blueprint:"mutated"`
Lukacs T. Berki2f5c3402021-06-15 11:27:56 +0200447 CoreVariantNeeded bool `blueprint:"mutated"`
448 RamdiskVariantNeeded bool `blueprint:"mutated"`
449 VendorRamdiskVariantNeeded bool `blueprint:"mutated"`
450 RecoveryVariantNeeded bool `blueprint:"mutated"`
451
452 // A list of variations for the "image" mutator of the form
453 //<image name> '.' <version char>, for example, 'vendor.S'
454 ExtraVersionedImageVariations []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900455
456 // Allows this module to use non-APEX version of libraries. Useful
457 // for building binaries that are started before APEXes are activated.
458 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900459
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000460 // Allows this module to be included in CMake release snapshots to be built outside of Android
461 // build system and source tree.
462 Cmake_snapshot_supported *bool
463
Colin Cross1bc94122021-10-28 13:25:54 -0700464 Installable *bool `android:"arch_variant"`
Colin Crossc511bc52020-04-07 16:50:32 +0000465
466 // Set by factories of module types that can only be referenced from variants compiled against
467 // the SDK.
468 AlwaysSdk bool `blueprint:"mutated"`
469
470 // Variant is an SDK variant created by sdkMutator
471 IsSdkVariant bool `blueprint:"mutated"`
472 // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK
473 // variant to have a ".sdk" suffix.
474 SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"`
Bill Peckham945441c2020-08-31 16:07:58 -0700475
Yi-Yo Chiangc7e044f2021-06-18 19:44:24 +0800476 Target struct {
477 Platform struct {
478 // List of modules required by the core variant.
479 Required []string `android:"arch_variant"`
480
481 // List of modules not required by the core variant.
482 Exclude_required []string `android:"arch_variant"`
483 } `android:"arch_variant"`
484
485 Recovery struct {
486 // List of modules required by the recovery variant.
487 Required []string `android:"arch_variant"`
488
489 // List of modules not required by the recovery variant.
490 Exclude_required []string `android:"arch_variant"`
491 } `android:"arch_variant"`
492 } `android:"arch_variant"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700493}
494
495type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900496 // whether this module should be allowed to be directly depended by other
497 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun63e9ec72020-10-29 16:49:43 +0900498 // If set to true, two variants will be built separately, one like
499 // normal, and the other limited to the set of libraries and headers
500 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700501 //
Justin Yun63e9ec72020-10-29 16:49:43 +0900502 // The vendor variant may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700503 // so it shouldn't have any unversioned runtime dependencies, or
504 // make assumptions about the system that may not be true in the
505 // future.
506 //
Justin Yun63e9ec72020-10-29 16:49:43 +0900507 // If set to false, this module becomes inaccessible from /vendor modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900508 //
Justin Yun6977e8a2020-10-29 18:24:11 +0900509 // The modules with vndk: {enabled: true} must define 'vendor_available'
Justin Yun0b1db6d2021-01-08 15:22:34 +0900510 // to 'true'.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900511 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700512 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
513 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900514
Justin Yunebcf0c52021-01-08 18:00:19 +0900515 // This is the same as the "vendor_available" except that the install path
516 // of the vendor variant is /odm or /vendor/odm.
517 // By replacing "vendor_available: true" with "odm_available: true", the
518 // module will install its vendor variant to the /odm partition or /vendor/odm.
519 // As the modules with "odm_available: true" still create the vendor variants,
520 // they can link to the other vendor modules as the vendor_available modules do.
521 // Also, the vendor modules can link to odm_available modules.
522 //
523 // It may not be used for VNDK modules.
524 Odm_available *bool
525
Justin Yun63e9ec72020-10-29 16:49:43 +0900526 // whether this module should be allowed to be directly depended by other
527 // modules with `product_specific: true` or `product_available: true`.
528 // If set to true, an additional product variant will be built separately
529 // that is limited to the set of libraries and headers that are exposed to
530 // /product modules.
531 //
532 // The product variant may be used with a different (newer) /system,
533 // so it shouldn't have any unversioned runtime dependencies, or
534 // make assumptions about the system that may not be true in the
535 // future.
536 //
Justin Yun6977e8a2020-10-29 18:24:11 +0900537 // If set to false, this module becomes inaccessible from /product modules.
538 //
539 // Different from the 'vendor_available' property, the modules with
540 // vndk: {enabled: true} don't have to define 'product_available'. The VNDK
541 // library without 'product_available' may not be depended on by any other
542 // modules that has product variants including the product available VNDKs.
Justin Yun63e9ec72020-10-29 16:49:43 +0900543 //
544 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
545 // and PRODUCT_PRODUCT_VNDK_VERSION isn't set.
546 Product_available *bool
547
Jiyong Park5fb8c102018-04-09 12:03:06 +0900548 // whether this module is capable of being loaded with other instance
549 // (possibly an older version) of the same module in the same process.
550 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
551 // can be double loaded in a vendor process if the library is also a
552 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
553 // explicitly marked as `double_loadable: true` by the owner, or the dependency
554 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
555 Double_loadable *bool
Colin Cross127bb8b2020-12-16 16:46:01 -0800556
557 // IsLLNDK is set to true for the vendor variant of a cc_library module that has LLNDK stubs.
558 IsLLNDK bool `blueprint:"mutated"`
559
Colin Cross5271fea2021-04-27 13:06:04 -0700560 // IsVendorPublicLibrary is set for the core and product variants of a library that has
561 // vendor_public_library stubs.
562 IsVendorPublicLibrary bool `blueprint:"mutated"`
Colin Crossca860ac2016-01-04 14:34:37 -0800563}
564
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500565// ModuleContextIntf is an interface (on a module context helper) consisting of functions related
566// to understanding details about the type of the current module.
567// For example, one might call these functions to determine whether the current module is a static
568// library and/or is installed in vendor directories.
Colin Crossca860ac2016-01-04 14:34:37 -0800569type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800570 static() bool
571 staticBinary() bool
Colin Cross6a730042024-12-05 13:53:43 -0800572 staticLibrary() bool
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700573 testBinary() bool
Yi Kong56fc1b62022-09-06 16:24:00 +0800574 testLibrary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900575 header() bool
Inseob Kim7f283f42020-06-01 21:53:49 +0900576 binary() bool
Inseob Kim1042d292020-06-01 23:23:05 +0900577 object() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700578 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900579 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700580 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800581 sdkVersion() string
Jiyong Parkb35a8192020-08-10 15:59:36 +0900582 minSdkVersion() string
583 isSdkVariant() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700584 useVndk() bool
Colin Cross95f1ca02020-10-29 20:47:22 -0700585 isNdk(config android.Config) bool
Colin Cross127bb8b2020-12-16 16:46:01 -0800586 IsLlndk() bool
Colin Cross127bb8b2020-12-16 16:46:01 -0800587 isImplementationForLLNDKPublic() bool
Colin Cross5271fea2021-04-27 13:06:04 -0700588 IsVendorPublicLibrary() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900589 inProduct() bool
590 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800591 inRamdisk() bool
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700592 inVendorRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900593 inRecovery() bool
Kiyoung Kimaa394802024-01-08 12:55:45 +0900594 InVendorOrProduct() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700595 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700596 baseModuleName() string
Colin Cross3513fb12024-01-24 14:44:47 -0800597 isAfdoCompile(ctx ModuleContext) bool
Sharjeel Khanc6a93d82023-07-18 21:01:11 +0000598 isOrderfileCompile() bool
Yi Kongc702ebd2022-08-19 16:02:45 +0800599 isCfi() bool
Yi Konged79fa32023-06-04 17:15:42 +0900600 isFuzzer() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800601 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800602 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800603 isForPlatform() bool
Colin Crosse07f2312020-08-13 11:24:56 -0700604 apexVariationName() string
Dan Albertc8060532020-07-22 22:32:17 -0700605 apexSdkVersion() android.ApiLevel
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900606 bootstrap() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700607 nativeCoverage() bool
Colin Cross95b07f22020-12-16 11:06:50 -0800608 isPreventInstall() bool
Cindy Zhou5d5cfc12021-01-09 08:25:22 -0800609 isCfiAssemblySupportEnabled() bool
Chih-Hung Hsieh7540a782022-01-08 19:56:09 -0800610 getSharedFlags() *SharedFlags
Colin Cross4a9e6ec2023-12-18 15:29:41 -0800611 notInPlatform() bool
Yi Kong5786f5c2024-05-28 02:22:34 +0900612 optimizeForSize() bool
Yu Liu76d94462024-10-31 23:32:36 +0000613 getOrCreateMakeVarsInfo() *CcMakeVarsInfo
Chih-Hung Hsieh7540a782022-01-08 19:56:09 -0800614}
615
616type SharedFlags struct {
617 numSharedFlags int
618 flagsMap map[string]string
Colin Crossca860ac2016-01-04 14:34:37 -0800619}
620
621type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700622 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800623 ModuleContextIntf
624}
625
626type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700627 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800628 ModuleContextIntf
629}
630
Colin Cross37047f12016-12-13 17:06:13 -0800631type DepsContext interface {
632 android.BottomUpMutatorContext
633 ModuleContextIntf
634}
635
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500636// feature represents additional (optional) steps to building cc-related modules, such as invocation
637// of clang-tidy.
Colin Crossca860ac2016-01-04 14:34:37 -0800638type feature interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800639 flags(ctx ModuleContext, flags Flags) Flags
640 props() []interface{}
641}
642
Joe Onorato37f900c2023-07-18 16:58:16 -0700643// Information returned from Generator about the source code it's generating
644type GeneratedSource struct {
645 IncludeDirs android.Paths
646 Sources android.Paths
647 Headers android.Paths
648 ReexportedDirs android.Paths
649}
650
651// generator allows injection of generated code
652type Generator interface {
653 GeneratorProps() []interface{}
654 GeneratorInit(ctx BaseModuleContext)
655 GeneratorDeps(ctx DepsContext, deps Deps) Deps
656 GeneratorFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
657 GeneratorSources(ctx ModuleContext) GeneratedSource
658 GeneratorBuildActions(ctx ModuleContext, flags Flags, deps PathDeps)
659}
660
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500661// compiler is the interface for a compiler helper object. Different module decorators may implement
Liz Kammer718eb272022-01-07 10:53:37 -0500662// this helper differently.
Colin Crossca860ac2016-01-04 14:34:37 -0800663type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700664 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800665 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800666 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700667 compilerProps() []interface{}
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000668 baseCompilerProps() BaseCompilerProperties
Colin Cross42742b82016-08-01 13:20:05 -0700669
Colin Cross76fada02016-07-27 10:31:13 -0700670 appendCflags([]string)
671 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700672 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800673}
674
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500675// linker is the interface for a linker decorator object. Individual module types can provide
676// their own implementation for this decorator, and thus specify custom logic regarding build
677// statements pertaining to linking.
Colin Crossca860ac2016-01-04 14:34:37 -0800678type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700679 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800680 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700681 linkerFlags(ctx ModuleContext, flags Flags) Flags
682 linkerProps() []interface{}
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000683 baseLinkerProps() BaseLinkerProperties
Ivan Lozanobd721262018-11-27 14:33:03 -0800684 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700685
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700686 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700687 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900688 unstrippedOutputFilePath() android.Path
Wei Li5f5d2712023-12-11 15:40:29 -0800689 strippedAllOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700690
691 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900692 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000693
694 // Get the deps that have been explicitly specified in the properties.
Cole Fauste8a87832024-09-11 11:35:46 -0700695 linkerSpecifiedDeps(ctx android.ConfigurableEvaluatorContext, module *Module, specifiedDeps specifiedDeps) specifiedDeps
Colin Cross4a9e6ec2023-12-18 15:29:41 -0800696
697 moduleInfoJSON(ctx ModuleContext, moduleInfoJSON *android.ModuleInfoJSON)
Paul Duffin13f02712020-03-06 12:30:43 +0000698}
699
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500700// specifiedDeps is a tuple struct representing dependencies of a linked binary owned by the linker.
Paul Duffin13f02712020-03-06 12:30:43 +0000701type specifiedDeps struct {
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500702 sharedLibs []string
703 // Note nil and [] are semantically distinct. [] prevents linking against the defaults (usually
704 // libc, libm, etc.)
Colin Cross6b8f4252021-07-22 11:39:44 -0700705 systemSharedLibs []string
Colin Crossca860ac2016-01-04 14:34:37 -0800706}
707
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500708// installer is the interface for an installer helper object. This helper is responsible for
709// copying build outputs to the appropriate locations so that they may be installed on device.
Colin Crossca860ac2016-01-04 14:34:37 -0800710type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700711 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700712 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000713 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800714 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700715 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700716 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900717 relativeInstallPath() string
Jingwen Chen8ac7d7d2023-03-20 11:05:16 +0000718 makeUninstallable(mod *Module)
Inseob Kim800d1142021-06-14 12:03:51 +0900719 installInRoot() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800720}
721
Inseob Kima1888ce2022-10-04 14:42:02 +0900722type overridable interface {
723 overriddenModules() []string
724}
725
Colin Cross6e511a92020-07-27 21:26:48 -0700726type libraryDependencyKind int
727
728const (
729 headerLibraryDependency = iota
730 sharedLibraryDependency
731 staticLibraryDependency
Ivan Lozano0a468a42024-05-13 21:03:34 -0400732 rlibLibraryDependency
Colin Cross6e511a92020-07-27 21:26:48 -0700733)
734
735func (k libraryDependencyKind) String() string {
736 switch k {
737 case headerLibraryDependency:
738 return "headerLibraryDependency"
739 case sharedLibraryDependency:
740 return "sharedLibraryDependency"
741 case staticLibraryDependency:
742 return "staticLibraryDependency"
Ivan Lozano0a468a42024-05-13 21:03:34 -0400743 case rlibLibraryDependency:
744 return "rlibLibraryDependency"
Colin Cross6e511a92020-07-27 21:26:48 -0700745 default:
746 panic(fmt.Errorf("unknown libraryDependencyKind %d", k))
747 }
748}
749
750type libraryDependencyOrder int
751
752const (
753 earlyLibraryDependency = -1
754 normalLibraryDependency = 0
755 lateLibraryDependency = 1
756)
757
758func (o libraryDependencyOrder) String() string {
759 switch o {
760 case earlyLibraryDependency:
761 return "earlyLibraryDependency"
762 case normalLibraryDependency:
763 return "normalLibraryDependency"
764 case lateLibraryDependency:
765 return "lateLibraryDependency"
766 default:
767 panic(fmt.Errorf("unknown libraryDependencyOrder %d", o))
768 }
769}
770
771// libraryDependencyTag is used to tag dependencies on libraries. Unlike many dependency
772// tags that have a set of predefined tag objects that are reused for each dependency, a
773// libraryDependencyTag is designed to contain extra metadata and is constructed as needed.
774// That means that comparing a libraryDependencyTag for equality will only be equal if all
775// of the metadata is equal. Most usages will want to type assert to libraryDependencyTag and
776// then check individual metadata fields instead.
777type libraryDependencyTag struct {
778 blueprint.BaseDependencyTag
779
780 // These are exported so that fmt.Printf("%#v") can call their String methods.
781 Kind libraryDependencyKind
782 Order libraryDependencyOrder
783
784 wholeStatic bool
785
786 reexportFlags bool
787 explicitlyVersioned bool
788 dataLib bool
789 ndk bool
790
791 staticUnwinder bool
792
793 makeSuffix string
Jiyong Parke3867542020-12-03 17:28:25 +0900794
Cindy Zhou18417cb2020-12-10 07:12:38 -0800795 // Whether or not this dependency should skip the apex dependency check
796 skipApexAllowedDependenciesCheck bool
797
Jiyong Parke3867542020-12-03 17:28:25 +0900798 // Whether or not this dependency has to be followed for the apex variants
799 excludeInApex bool
Jooyung Han9ffbe832023-11-28 22:31:35 +0900800 // Whether or not this dependency has to be followed for the non-apex variants
801 excludeInNonApex bool
Colin Cross3e5e7782022-06-17 22:17:05 +0000802
803 // If true, don't automatically export symbols from the static library into a shared library.
804 unexportedSymbols bool
Colin Cross6e511a92020-07-27 21:26:48 -0700805}
806
807// header returns true if the libraryDependencyTag is tagging a header lib dependency.
808func (d libraryDependencyTag) header() bool {
809 return d.Kind == headerLibraryDependency
810}
811
812// shared returns true if the libraryDependencyTag is tagging a shared lib dependency.
813func (d libraryDependencyTag) shared() bool {
814 return d.Kind == sharedLibraryDependency
815}
816
817// shared returns true if the libraryDependencyTag is tagging a static lib dependency.
818func (d libraryDependencyTag) static() bool {
819 return d.Kind == staticLibraryDependency
820}
821
Colin Cross65cb3142021-12-10 23:05:02 +0000822func (d libraryDependencyTag) LicenseAnnotations() []android.LicenseAnnotation {
823 if d.shared() {
824 return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency}
825 }
826 return nil
827}
828
829var _ android.LicenseAnnotationsDependencyTag = libraryDependencyTag{}
830
Colin Crosse9fe2942020-11-10 18:12:15 -0800831// InstallDepNeeded returns true for shared libraries so that shared library dependencies of
832// binaries or other shared libraries are installed as dependencies.
833func (d libraryDependencyTag) InstallDepNeeded() bool {
834 return d.shared()
835}
836
837var _ android.InstallNeededDependencyTag = libraryDependencyTag{}
838
Yu Liu67a28422024-03-05 00:36:31 +0000839func (d libraryDependencyTag) PropagateAconfigValidation() bool {
840 return d.static()
841}
842
843var _ android.PropagateAconfigValidationDependencyTag = libraryDependencyTag{}
844
Colin Crosse9fe2942020-11-10 18:12:15 -0800845// dependencyTag is used for tagging miscellaneous dependency types that don't fit into
Colin Cross6e511a92020-07-27 21:26:48 -0700846// libraryDependencyTag. Each tag object is created globally and reused for multiple
847// dependencies (although since the object contains no references, assigning a tag to a
848// variable and modifying it will not modify the original). Users can compare the tag
849// returned by ctx.OtherModuleDependencyTag against the global original
850type dependencyTag struct {
851 blueprint.BaseDependencyTag
852 name string
853}
854
Colin Crosse9fe2942020-11-10 18:12:15 -0800855// installDependencyTag is used for tagging miscellaneous dependency types that don't fit into
856// libraryDependencyTag, but where the dependency needs to be installed when the parent is
857// installed.
858type installDependencyTag struct {
859 blueprint.BaseDependencyTag
860 android.InstallAlwaysNeededDependencyTag
861 name string
862}
863
Colin Crossc99deeb2016-04-11 15:06:20 -0700864var (
Colin Cross6e511a92020-07-27 21:26:48 -0700865 genSourceDepTag = dependencyTag{name: "gen source"}
866 genHeaderDepTag = dependencyTag{name: "gen header"}
867 genHeaderExportDepTag = dependencyTag{name: "gen header export"}
868 objDepTag = dependencyTag{name: "obj"}
Jiyong Parkd630bdd2020-11-25 11:47:24 +0900869 dynamicLinkerDepTag = installDependencyTag{name: "dynamic linker"}
Colin Cross6e511a92020-07-27 21:26:48 -0700870 reuseObjTag = dependencyTag{name: "reuse objects"}
871 staticVariantTag = dependencyTag{name: "static variant"}
872 vndkExtDepTag = dependencyTag{name: "vndk extends"}
873 dataLibDepTag = dependencyTag{name: "data lib"}
Colin Crossc8caa062021-09-24 16:50:14 -0700874 dataBinDepTag = dependencyTag{name: "data bin"}
Colin Crosse9fe2942020-11-10 18:12:15 -0800875 runtimeDepTag = installDependencyTag{name: "runtime lib"}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700876 stubImplDepTag = dependencyTag{name: "stub_impl"}
Muhammad Haseeb Ahmad7e744052022-03-25 22:50:53 +0000877 JniFuzzLibTag = dependencyTag{name: "jni_fuzz_lib_tag"}
Vinh Tran44cb78c2023-03-09 22:07:19 -0500878 FdoProfileTag = dependencyTag{name: "fdo_profile"}
Vinh Tran367d89d2023-04-28 11:21:25 -0400879 aidlLibraryTag = dependencyTag{name: "aidl_library"}
Hsin-Yi Chen715142a2024-03-27 16:31:16 +0800880 llndkHeaderLibTag = dependencyTag{name: "llndk_header_lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700881)
882
Roland Levillainf89cd092019-07-29 16:22:59 +0100883func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700884 ccLibDepTag, ok := depTag.(libraryDependencyTag)
885 return ok && ccLibDepTag.shared()
886}
887
888func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
889 ccLibDepTag, ok := depTag.(libraryDependencyTag)
890 return ok && ccLibDepTag.static()
Roland Levillainf89cd092019-07-29 16:22:59 +0100891}
892
Zach Johnson3df4e632020-11-06 11:56:27 -0800893func IsHeaderDepTag(depTag blueprint.DependencyTag) bool {
894 ccLibDepTag, ok := depTag.(libraryDependencyTag)
895 return ok && ccLibDepTag.header()
896}
897
Roland Levillainf89cd092019-07-29 16:22:59 +0100898func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Colin Crosse9fe2942020-11-10 18:12:15 -0800899 return depTag == runtimeDepTag
Roland Levillainf89cd092019-07-29 16:22:59 +0100900}
901
Colin Crossca860ac2016-01-04 14:34:37 -0800902// Module contains the properties and members used by all C/C++ module types, and implements
903// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500904// to construct the output file. Behavior can be customized with a Customizer, or "decorator",
905// interface.
906//
907// To define a C/C++ related module, construct a new Module object and point its delegates to
908// type-specific structs. These delegates will be invoked to register module-specific build
909// statements which may be unique to the module type. For example, module.compiler.compile() should
910// be defined so as to register build statements which are responsible for compiling the module.
911//
912// Another example: to construct a cc_binary module, one can create a `cc.binaryDecorator` struct
913// which implements the `linker` and `installer` interfaces, and points the `linker` and `installer`
914// members of the cc.Module to this decorator. Thus, a cc_binary module has custom linker and
915// installer logic.
Colin Crossca860ac2016-01-04 14:34:37 -0800916type Module struct {
hamzehc0a671f2021-07-22 12:05:08 -0700917 fuzz.FuzzModule
hamzeh41ad8812021-07-07 14:00:07 -0700918
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700919 VendorProperties VendorProperties
hamzeh41ad8812021-07-07 14:00:07 -0700920 Properties BaseProperties
Ronald Braunsteina115e262024-04-09 18:07:38 -0700921 sourceProperties android.SourceProperties
Colin Crossfa138792015-04-24 17:31:52 -0700922
Colin Crossca860ac2016-01-04 14:34:37 -0800923 // initialize before calling Init
Yu Liu76d94462024-10-31 23:32:36 +0000924 hod android.HostOrDeviceSupported
925 multilib android.Multilib
926 testModule bool
927 incremental bool
Colin Crossc472d572015-03-17 15:06:21 -0700928
Paul Duffina0843f62019-12-13 19:50:38 +0000929 // Allowable SdkMemberTypes of this module type.
930 sdkMemberTypes []android.SdkMemberType
931
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500932 // decorator delegates, initialize before calling Init
933 // these may contain module-specific implementations, and effectively allow for custom
934 // type-specific logic. These members may reference different objects or the same object.
935 // Functions of these decorators will be invoked to initialize and register type-specific
936 // build statements.
Colin Cross8ff10582023-12-07 13:10:56 -0800937 generators []Generator
938 compiler compiler
939 linker linker
940 installer installer
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500941
Spandan Dase12d2522023-09-12 21:42:31 +0000942 features []feature
943 stl *stl
944 sanitize *sanitize
945 coverage *coverage
946 fuzzer *fuzzer
947 sabi *sabi
Spandan Dase12d2522023-09-12 21:42:31 +0000948 lto *lto
949 afdo *afdo
Sharjeel Khanc6a93d82023-07-18 21:01:11 +0000950 orderfile *orderfile
Colin Cross16b23492016-01-06 14:41:07 -0800951
Colin Cross31076b32020-10-23 17:22:06 -0700952 library libraryInterface
953
Colin Cross635c3b02016-05-18 15:37:25 -0700954 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800955
Colin Crossb98c8b02016-07-29 13:44:28 -0700956 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700957
Yu Liue70976d2024-10-15 20:45:35 +0000958 subAndroidMkOnce map[subAndroidMkProviderInfoProducer]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800959
960 // Flags used to compile this module
961 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700962
Chih-Hung Hsieh7540a782022-01-08 19:56:09 -0800963 // Shared flags among build rules of this module
964 sharedFlags SharedFlags
965
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800966 // only non-nil when this is a shared library that reuses the objects of a static library
Colin Cross0de8a1e2020-09-18 14:15:30 -0700967 staticAnalogue *StaticLibraryInfo
Inseob Kim9516ee92019-05-09 10:56:13 +0900968
969 makeLinkType string
Jooyung Han75568392020-03-20 04:29:24 +0900970
971 // For apex variants, this is set as apex.min_sdk_version
Dan Albertc8060532020-07-22 22:32:17 -0700972 apexSdkVersion android.ApiLevel
Colin Cross56a83212020-09-15 18:30:11 -0700973
974 hideApexVariantFromMake bool
Yu Liueae7b362023-11-16 17:05:47 -0800975
Inseob Kim37e0bb02024-04-29 15:54:44 +0900976 logtagsPaths android.Paths
Ivan Lozanofd47b1a2024-05-17 14:13:41 -0400977
978 WholeRustStaticlib bool
Cole Faust96a692b2024-08-08 14:47:51 -0700979
980 hasAidl bool
981 hasLex bool
982 hasProto bool
983 hasRenderscript bool
984 hasSysprop bool
985 hasWinMsg bool
986 hasYacc bool
Yu Liu76d94462024-10-31 23:32:36 +0000987
988 makeVarsInfo *CcMakeVarsInfo
Colin Crossc472d572015-03-17 15:06:21 -0700989}
990
Yu Liu76d94462024-10-31 23:32:36 +0000991func (c *Module) IncrementalSupported() bool {
992 return c.incremental
993}
994
995var _ blueprint.Incremental = (*Module)(nil)
996
Lukacs T. Berkid18d8ca2021-06-25 09:11:22 +0200997func (c *Module) AddJSONData(d *map[string]interface{}) {
998 c.AndroidModuleBase().AddJSONData(d)
999 (*d)["Cc"] = map[string]interface{}{
1000 "SdkVersion": c.SdkVersion(),
1001 "MinSdkVersion": c.MinSdkVersion(),
1002 "VndkVersion": c.VndkVersion(),
1003 "ProductSpecific": c.ProductSpecific(),
1004 "SocSpecific": c.SocSpecific(),
1005 "DeviceSpecific": c.DeviceSpecific(),
1006 "InProduct": c.InProduct(),
1007 "InVendor": c.InVendor(),
1008 "InRamdisk": c.InRamdisk(),
1009 "InVendorRamdisk": c.InVendorRamdisk(),
1010 "InRecovery": c.InRecovery(),
1011 "VendorAvailable": c.VendorAvailable(),
1012 "ProductAvailable": c.ProductAvailable(),
1013 "RamdiskAvailable": c.RamdiskAvailable(),
1014 "VendorRamdiskAvailable": c.VendorRamdiskAvailable(),
1015 "RecoveryAvailable": c.RecoveryAvailable(),
1016 "OdmAvailable": c.OdmAvailable(),
1017 "InstallInData": c.InstallInData(),
1018 "InstallInRamdisk": c.InstallInRamdisk(),
1019 "InstallInSanitizerDir": c.InstallInSanitizerDir(),
1020 "InstallInVendorRamdisk": c.InstallInVendorRamdisk(),
1021 "InstallInRecovery": c.InstallInRecovery(),
1022 "InstallInRoot": c.InstallInRoot(),
Lukacs T. Berkid18d8ca2021-06-25 09:11:22 +02001023 "IsLlndk": c.IsLlndk(),
Lukacs T. Berkid18d8ca2021-06-25 09:11:22 +02001024 "IsVendorPublicLibrary": c.IsVendorPublicLibrary(),
1025 "ApexSdkVersion": c.apexSdkVersion,
Cole Faust96a692b2024-08-08 14:47:51 -07001026 "AidlSrcs": c.hasAidl,
1027 "LexSrcs": c.hasLex,
1028 "ProtoSrcs": c.hasProto,
1029 "RenderscriptSrcs": c.hasRenderscript,
1030 "SyspropSrcs": c.hasSysprop,
1031 "WinMsgSrcs": c.hasWinMsg,
1032 "YaccSrsc": c.hasYacc,
1033 "OnlyCSrcs": !(c.hasAidl || c.hasLex || c.hasProto || c.hasRenderscript || c.hasSysprop || c.hasWinMsg || c.hasYacc),
Yi Kong5786f5c2024-05-28 02:22:34 +09001034 "OptimizeForSize": c.OptimizeForSize(),
Lukacs T. Berkid18d8ca2021-06-25 09:11:22 +02001035 }
1036}
1037
Ivan Lozano3968d8f2020-12-14 11:27:52 -05001038func (c *Module) SetPreventInstall() {
1039 c.Properties.PreventInstall = true
1040}
1041
1042func (c *Module) SetHideFromMake() {
1043 c.Properties.HideFromMake = true
1044}
1045
Ivan Lozanod7586b62021-04-01 09:49:36 -04001046func (c *Module) HiddenFromMake() bool {
1047 return c.Properties.HideFromMake
1048}
1049
Cole Fauste8a87832024-09-11 11:35:46 -07001050func (c *Module) RequiredModuleNames(ctx android.ConfigurableEvaluatorContext) []string {
Cole Faust43ddd082024-06-17 12:32:40 -07001051 required := android.CopyOf(c.ModuleBase.RequiredModuleNames(ctx))
Yi-Yo Chiangc7e044f2021-06-18 19:44:24 +08001052 if c.ImageVariation().Variation == android.CoreVariation {
1053 required = append(required, c.Properties.Target.Platform.Required...)
1054 required = removeListFromList(required, c.Properties.Target.Platform.Exclude_required)
1055 } else if c.InRecovery() {
1056 required = append(required, c.Properties.Target.Recovery.Required...)
1057 required = removeListFromList(required, c.Properties.Target.Recovery.Exclude_required)
1058 }
1059 return android.FirstUniqueStrings(required)
1060}
1061
Ivan Lozano52767be2019-10-18 14:49:46 -07001062func (c *Module) Toc() android.OptionalPath {
1063 if c.linker != nil {
1064 if library, ok := c.linker.(libraryInterface); ok {
1065 return library.toc()
1066 }
1067 }
1068 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
1069}
1070
1071func (c *Module) ApiLevel() string {
1072 if c.linker != nil {
1073 if stub, ok := c.linker.(*stubDecorator); ok {
Dan Albert1a246272020-07-06 14:49:35 -07001074 return stub.apiLevel.String()
Ivan Lozano52767be2019-10-18 14:49:46 -07001075 }
1076 }
1077 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
1078}
1079
1080func (c *Module) Static() bool {
1081 if c.linker != nil {
1082 if library, ok := c.linker.(libraryInterface); ok {
1083 return library.static()
1084 }
1085 }
1086 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
1087}
1088
1089func (c *Module) Shared() bool {
1090 if c.linker != nil {
1091 if library, ok := c.linker.(libraryInterface); ok {
1092 return library.shared()
1093 }
1094 }
Lukacs T. Berki6c716762022-06-13 20:50:39 +02001095
Ivan Lozano52767be2019-10-18 14:49:46 -07001096 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
1097}
1098
1099func (c *Module) SelectedStl() string {
Colin Crossc511bc52020-04-07 16:50:32 +00001100 if c.stl != nil {
1101 return c.stl.Properties.SelectedStl
1102 }
1103 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -07001104}
1105
Ivan Lozano52767be2019-10-18 14:49:46 -07001106func (c *Module) StubDecorator() bool {
1107 if _, ok := c.linker.(*stubDecorator); ok {
1108 return true
1109 }
1110 return false
1111}
1112
Yi Kong5786f5c2024-05-28 02:22:34 +09001113func (c *Module) OptimizeForSize() bool {
1114 return Bool(c.Properties.Optimize_for_size)
1115}
1116
Ivan Lozano52767be2019-10-18 14:49:46 -07001117func (c *Module) SdkVersion() string {
1118 return String(c.Properties.Sdk_version)
1119}
1120
Artur Satayev480e25b2020-04-27 18:53:18 +01001121func (c *Module) MinSdkVersion() string {
1122 return String(c.Properties.Min_sdk_version)
1123}
1124
Jiyong Park5df7bd32021-08-25 16:18:46 +09001125func (c *Module) isCrt() bool {
Dan Albert92fe7402020-07-15 13:33:30 -07001126 if linker, ok := c.linker.(*objectLinker); ok {
1127 return linker.isCrt()
1128 }
1129 return false
1130}
1131
Jiyong Park5df7bd32021-08-25 16:18:46 +09001132func (c *Module) SplitPerApiLevel() bool {
1133 return c.canUseSdk() && c.isCrt()
1134}
1135
Colin Crossc511bc52020-04-07 16:50:32 +00001136func (c *Module) AlwaysSdk() bool {
1137 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
1138}
1139
Ivan Lozano183a3212019-10-18 14:18:45 -07001140func (c *Module) CcLibrary() bool {
1141 if c.linker != nil {
1142 if _, ok := c.linker.(*libraryDecorator); ok {
1143 return true
1144 }
Colin Crossd48fe732020-09-23 20:37:24 -07001145 if _, ok := c.linker.(*prebuiltLibraryLinker); ok {
1146 return true
1147 }
Ivan Lozano183a3212019-10-18 14:18:45 -07001148 }
1149 return false
1150}
1151
1152func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001153 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -07001154 return true
1155 }
1156 return false
1157}
1158
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001159func (c *Module) RlibStd() bool {
1160 panic(fmt.Errorf("RlibStd called on non-Rust module: %q", c.BaseModuleName()))
1161}
1162
Ivan Lozano61c02cc2023-06-09 14:06:44 -04001163func (c *Module) RustLibraryInterface() bool {
1164 return false
1165}
1166
Ivan Lozano0a468a42024-05-13 21:03:34 -04001167func (c *Module) CrateName() string {
1168 panic(fmt.Errorf("CrateName called on non-Rust module: %q", c.BaseModuleName()))
1169}
1170
1171func (c *Module) ExportedCrateLinkDirs() []string {
1172 panic(fmt.Errorf("ExportedCrateLinkDirs called on non-Rust module: %q", c.BaseModuleName()))
1173}
1174
Ivan Lozano0f9963e2023-02-06 13:31:02 -05001175func (c *Module) IsFuzzModule() bool {
1176 if _, ok := c.compiler.(*fuzzBinary); ok {
1177 return true
1178 }
1179 return false
1180}
1181
1182func (c *Module) FuzzModuleStruct() fuzz.FuzzModule {
1183 return c.FuzzModule
1184}
1185
1186func (c *Module) FuzzPackagedModule() fuzz.FuzzPackagedModule {
1187 if fuzzer, ok := c.compiler.(*fuzzBinary); ok {
1188 return fuzzer.fuzzPackagedModule
1189 }
1190 panic(fmt.Errorf("FuzzPackagedModule called on non-fuzz module: %q", c.BaseModuleName()))
1191}
1192
Hamzeh Zawawy38917492023-04-05 22:08:46 +00001193func (c *Module) FuzzSharedLibraries() android.RuleBuilderInstalls {
Ivan Lozano0f9963e2023-02-06 13:31:02 -05001194 if fuzzer, ok := c.compiler.(*fuzzBinary); ok {
1195 return fuzzer.sharedLibraries
1196 }
1197 panic(fmt.Errorf("FuzzSharedLibraries called on non-fuzz module: %q", c.BaseModuleName()))
1198}
1199
Ivan Lozano2b262972019-11-21 12:30:50 -08001200func (c *Module) NonCcVariants() bool {
1201 return false
1202}
1203
Ivan Lozano183a3212019-10-18 14:18:45 -07001204func (c *Module) SetStatic() {
1205 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -07001206 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -07001207 library.setStatic()
1208 return
1209 }
1210 }
1211 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
1212}
1213
1214func (c *Module) SetShared() {
1215 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -07001216 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -07001217 library.setShared()
1218 return
1219 }
1220 }
1221 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
1222}
1223
1224func (c *Module) BuildStaticVariant() bool {
1225 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -07001226 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -07001227 return library.buildStatic()
1228 }
1229 }
1230 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
1231}
1232
1233func (c *Module) BuildSharedVariant() bool {
1234 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -07001235 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -07001236 return library.buildShared()
1237 }
1238 }
1239 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
1240}
1241
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04001242func (c *Module) BuildRlibVariant() bool {
1243 // cc modules can never build rlib variants
1244 return false
1245}
1246
Ivan Lozano183a3212019-10-18 14:18:45 -07001247func (c *Module) Module() android.Module {
1248 return c
1249}
1250
Jiyong Parkc20eee32018-09-05 22:36:17 +09001251func (c *Module) OutputFile() android.OptionalPath {
1252 return c.outputFile
1253}
1254
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001255func (c *Module) CoverageFiles() android.Paths {
1256 if c.linker != nil {
1257 if library, ok := c.linker.(libraryInterface); ok {
1258 return library.objs().coverageFiles
1259 }
1260 }
1261 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
1262}
1263
Ivan Lozano183a3212019-10-18 14:18:45 -07001264var _ LinkableInterface = (*Module)(nil)
1265
Jiyong Park719b4462019-01-13 00:39:51 +09001266func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +09001267 if c.linker != nil {
1268 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +09001269 }
1270 return nil
1271}
1272
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001273func (c *Module) CoverageOutputFile() android.OptionalPath {
1274 if c.linker != nil {
1275 return c.linker.coverageOutputFilePath()
1276 }
1277 return android.OptionalPath{}
1278}
1279
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001280func (c *Module) RelativeInstallPath() string {
1281 if c.installer != nil {
1282 return c.installer.relativeInstallPath()
1283 }
1284 return ""
1285}
1286
Jooyung Han344d5432019-08-23 11:17:39 +09001287func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001288 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +09001289}
1290
Colin Cross36242852017-06-23 15:06:31 -07001291func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -07001292 c.AddProperties(&c.Properties, &c.VendorProperties)
Joe Onorato37f900c2023-07-18 16:58:16 -07001293 for _, generator := range c.generators {
1294 c.AddProperties(generator.GeneratorProps()...)
1295 }
Colin Crossca860ac2016-01-04 14:34:37 -08001296 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -07001297 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -08001298 }
1299 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -07001300 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -08001301 }
1302 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -07001303 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -08001304 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001305 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -07001306 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -07001307 }
Colin Cross16b23492016-01-06 14:41:07 -08001308 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -07001309 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -08001310 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001311 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -07001312 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -08001313 }
Cory Barkera1da26f2022-06-07 20:12:06 +00001314 if c.fuzzer != nil {
1315 c.AddProperties(c.fuzzer.props()...)
1316 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001317 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -07001318 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001319 }
Stephen Craneba090d12017-05-09 15:44:35 -07001320 if c.lto != nil {
1321 c.AddProperties(c.lto.props()...)
1322 }
Yi Kongeb8efc92021-12-09 18:06:29 +08001323 if c.afdo != nil {
1324 c.AddProperties(c.afdo.props()...)
1325 }
Sharjeel Khanc6a93d82023-07-18 21:01:11 +00001326 if c.orderfile != nil {
1327 c.AddProperties(c.orderfile.props()...)
1328 }
Colin Crossca860ac2016-01-04 14:34:37 -08001329 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -07001330 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -08001331 }
Ronald Braunsteina115e262024-04-09 18:07:38 -07001332 // Allow test-only on libraries that are not cc_test_library
1333 if c.library != nil && !c.testLibrary() {
1334 c.AddProperties(&c.sourceProperties)
1335 }
Colin Crossc472d572015-03-17 15:06:21 -07001336
Colin Cross36242852017-06-23 15:06:31 -07001337 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +09001338 android.InitApexModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +09001339 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +09001340
Colin Cross36242852017-06-23 15:06:31 -07001341 return c
Colin Crossc472d572015-03-17 15:06:21 -07001342}
1343
Yi-Yo Chiang1080f0c2022-11-22 18:24:14 +08001344// UseVndk() returns true if this module is built against VNDK.
1345// This means the vendor and product variants of a module.
Ivan Lozano52767be2019-10-18 14:49:46 -07001346func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +09001347 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001348}
1349
Colin Crossc511bc52020-04-07 16:50:32 +00001350func (c *Module) canUseSdk() bool {
Colin Cross94e347e2021-01-19 14:56:07 -08001351 return c.Os() == android.Android && c.Target().NativeBridge == android.NativeBridgeDisabled &&
Kiyoung Kimaa394802024-01-08 12:55:45 +09001352 !c.InVendorOrProduct() && !c.InRamdisk() && !c.InRecovery() && !c.InVendorRamdisk()
Colin Crossc511bc52020-04-07 16:50:32 +00001353}
1354
1355func (c *Module) UseSdk() bool {
1356 if c.canUseSdk() {
Colin Cross1348ce32020-10-01 13:37:16 -07001357 return String(c.Properties.Sdk_version) != ""
Colin Crossc511bc52020-04-07 16:50:32 +00001358 }
1359 return false
1360}
1361
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001362func (c *Module) isCoverageVariant() bool {
1363 return c.coverage.Properties.IsCoverageVariant
1364}
1365
Colin Cross95f1ca02020-10-29 20:47:22 -07001366func (c *Module) IsNdk(config android.Config) bool {
1367 return inList(c.BaseModuleName(), *getNDKKnownLibs(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001368}
1369
Colin Cross127bb8b2020-12-16 16:46:01 -08001370func (c *Module) IsLlndk() bool {
1371 return c.VendorProperties.IsLLNDK
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001372}
1373
Colin Cross1f3f1302021-04-26 18:37:44 -07001374func (m *Module) NeedsLlndkVariants() bool {
Ivan Lozano3a7d0002021-03-30 12:19:36 -04001375 lib := moduleLibraryInterface(m)
Colin Cross1f3f1302021-04-26 18:37:44 -07001376 return lib != nil && (lib.hasLLNDKStubs() || lib.hasLLNDKHeaders())
Ivan Lozano3a7d0002021-03-30 12:19:36 -04001377}
1378
Colin Cross5271fea2021-04-27 13:06:04 -07001379func (m *Module) NeedsVendorPublicLibraryVariants() bool {
1380 lib := moduleLibraryInterface(m)
1381 return lib != nil && (lib.hasVendorPublicLibrary())
1382}
1383
1384// IsVendorPublicLibrary returns true for vendor public libraries.
1385func (c *Module) IsVendorPublicLibrary() bool {
1386 return c.VendorProperties.IsVendorPublicLibrary
1387}
1388
Ivan Lozanof1868af2022-04-12 13:08:36 -04001389func (c *Module) IsVndkPrebuiltLibrary() bool {
1390 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
1391 return true
1392 }
1393 return false
1394}
1395
1396func (c *Module) SdkAndPlatformVariantVisibleToMake() bool {
1397 return c.Properties.SdkAndPlatformVariantVisibleToMake
1398}
1399
Ivan Lozanod7586b62021-04-01 09:49:36 -04001400func (c *Module) HasLlndkStubs() bool {
1401 lib := moduleLibraryInterface(c)
1402 return lib != nil && lib.hasLLNDKStubs()
1403}
1404
1405func (c *Module) StubsVersion() string {
1406 if lib, ok := c.linker.(versionedInterface); ok {
1407 return lib.stubsVersion()
1408 }
1409 panic(fmt.Errorf("StubsVersion called on non-versioned module: %q", c.BaseModuleName()))
1410}
1411
Colin Cross127bb8b2020-12-16 16:46:01 -08001412// isImplementationForLLNDKPublic returns true for any variant of a cc_library that has LLNDK stubs
1413// and does not set llndk.vendor_available: false.
1414func (c *Module) isImplementationForLLNDKPublic() bool {
1415 library, _ := c.library.(*libraryDecorator)
1416 return library != nil && library.hasLLNDKStubs() &&
Colin Cross0fb7fcd2021-03-02 11:00:07 -08001417 !Bool(library.Properties.Llndk.Private)
Colin Cross127bb8b2020-12-16 16:46:01 -08001418}
1419
Colin Cross3513fb12024-01-24 14:44:47 -08001420func (c *Module) isAfdoCompile(ctx ModuleContext) bool {
Yi Kong4ef54592022-02-14 20:00:10 +08001421 if afdo := c.afdo; afdo != nil {
Colin Cross3513fb12024-01-24 14:44:47 -08001422 return afdo.isAfdoCompile(ctx)
Yi Kong4ef54592022-02-14 20:00:10 +08001423 }
1424 return false
1425}
1426
Sharjeel Khanc6a93d82023-07-18 21:01:11 +00001427func (c *Module) isOrderfileCompile() bool {
1428 if orderfile := c.orderfile; orderfile != nil {
1429 return orderfile.Properties.OrderfileLoad
1430 }
1431 return false
1432}
1433
Yi Kongc702ebd2022-08-19 16:02:45 +08001434func (c *Module) isCfi() bool {
Colin Cross694fced2024-06-25 14:56:42 -07001435 return c.sanitize.isSanitizerEnabled(cfi)
Yi Kongc702ebd2022-08-19 16:02:45 +08001436}
1437
Yi Konged79fa32023-06-04 17:15:42 +09001438func (c *Module) isFuzzer() bool {
Colin Cross694fced2024-06-25 14:56:42 -07001439 return c.sanitize.isSanitizerEnabled(Fuzzer)
Yi Konged79fa32023-06-04 17:15:42 +09001440}
1441
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001442func (c *Module) isNDKStubLibrary() bool {
1443 if _, ok := c.compiler.(*stubDecorator); ok {
1444 return true
1445 }
1446 return false
1447}
1448
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001449func (c *Module) SubName() string {
1450 return c.Properties.SubName
1451}
1452
Jiyong Park25fc6a92018-11-18 18:02:45 +09001453func (c *Module) IsStubs() bool {
Colin Cross31076b32020-10-23 17:22:06 -07001454 if lib := c.library; lib != nil {
1455 return lib.buildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001456 }
1457 return false
1458}
1459
1460func (c *Module) HasStubsVariants() bool {
Colin Cross31076b32020-10-23 17:22:06 -07001461 if lib := c.library; lib != nil {
1462 return lib.hasStubsVariants()
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001463 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001464 return false
1465}
1466
Alan Stokes73feba32022-11-14 12:21:24 +00001467func (c *Module) IsStubsImplementationRequired() bool {
1468 if lib := c.library; lib != nil {
1469 return lib.isStubsImplementationRequired()
1470 }
1471 return false
1472}
1473
Colin Cross0477b422020-10-13 18:43:54 -07001474// If this is a stubs library, ImplementationModuleName returns the name of the module that contains
1475// the implementation. If it is an implementation library it returns its own name.
1476func (c *Module) ImplementationModuleName(ctx android.BaseModuleContext) string {
1477 name := ctx.OtherModuleName(c)
1478 if versioned, ok := c.linker.(versionedInterface); ok {
1479 name = versioned.implementationModuleName(name)
1480 }
1481 return name
1482}
1483
Martin Stjernholm2856c662020-12-02 15:03:42 +00001484// Similar to ImplementationModuleName, but uses the Make variant of the module
1485// name as base name, for use in AndroidMk output. E.g. for a prebuilt module
1486// where the Soong name is prebuilt_foo, this returns foo (which works in Make
1487// under the premise that the prebuilt module overrides its source counterpart
1488// if it is exposed to Make).
1489func (c *Module) ImplementationModuleNameForMake(ctx android.BaseModuleContext) string {
1490 name := c.BaseModuleName()
1491 if versioned, ok := c.linker.(versionedInterface); ok {
1492 name = versioned.implementationModuleName(name)
1493 }
1494 return name
1495}
1496
Jiyong Park7d55b612021-06-11 17:22:09 +09001497func (c *Module) Bootstrap() bool {
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001498 return Bool(c.Properties.Bootstrap)
1499}
1500
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001501func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001502 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1503 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1504 return false
1505 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001506 return c.linker != nil && c.linker.nativeCoverage()
1507}
1508
Ivan Lozano3a7d0002021-03-30 12:19:36 -04001509func (c *Module) IsSnapshotPrebuilt() bool {
Ivan Lozanod1dec542021-05-26 15:33:11 -04001510 if p, ok := c.linker.(SnapshotInterface); ok {
1511 return p.IsSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001512 }
1513 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001514}
1515
Jiyong Parkf1194352019-02-25 11:05:47 +09001516func isBionic(name string) bool {
1517 switch name {
Jooyung Hanbff73352022-12-13 18:29:44 +09001518 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001519 return true
1520 }
1521 return false
1522}
1523
Martin Stjernholm279de572019-09-10 23:18:20 +01001524func InstallToBootstrap(name string, config android.Config) bool {
Florian Mayer95cd6db2023-03-23 17:48:07 -07001525 if name == "libclang_rt.hwasan" || name == "libc_hwasan" {
Jooyung Han8ce8db92020-05-15 19:05:05 +09001526 return true
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001527 }
1528 return isBionic(name)
1529}
1530
Cindy Zhou5d5cfc12021-01-09 08:25:22 -08001531func (c *Module) isCfiAssemblySupportEnabled() bool {
1532 return c.sanitize != nil &&
1533 Bool(c.sanitize.Properties.Sanitize.Config.Cfi_assembly_support)
1534}
1535
Inseob Kim800d1142021-06-14 12:03:51 +09001536func (c *Module) InstallInRoot() bool {
1537 return c.installer != nil && c.installer.installInRoot()
1538}
1539
Colin Crossca860ac2016-01-04 14:34:37 -08001540type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001541 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001542 moduleContextImpl
1543}
1544
Colin Cross37047f12016-12-13 17:06:13 -08001545type depsContext struct {
1546 android.BottomUpMutatorContext
1547 moduleContextImpl
1548}
1549
Colin Crossca860ac2016-01-04 14:34:37 -08001550type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001551 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001552 moduleContextImpl
1553}
1554
1555type moduleContextImpl struct {
1556 mod *Module
1557 ctx BaseModuleContext
1558}
1559
Colin Crossb98c8b02016-07-29 13:44:28 -07001560func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001561 return ctx.mod.toolchain(ctx.ctx)
1562}
1563
1564func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001565 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001566}
1567
1568func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001569 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001570}
1571
Colin Cross6a730042024-12-05 13:53:43 -08001572func (ctx *moduleContextImpl) staticLibrary() bool {
1573 return ctx.mod.staticLibrary()
1574}
1575
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07001576func (ctx *moduleContextImpl) testBinary() bool {
1577 return ctx.mod.testBinary()
1578}
1579
Yi Kong56fc1b62022-09-06 16:24:00 +08001580func (ctx *moduleContextImpl) testLibrary() bool {
1581 return ctx.mod.testLibrary()
1582}
1583
Jiyong Park1d1119f2019-07-29 21:27:18 +09001584func (ctx *moduleContextImpl) header() bool {
Ivan Lozano3968d8f2020-12-14 11:27:52 -05001585 return ctx.mod.Header()
Jiyong Park1d1119f2019-07-29 21:27:18 +09001586}
1587
Inseob Kim7f283f42020-06-01 21:53:49 +09001588func (ctx *moduleContextImpl) binary() bool {
Ivan Lozanod7586b62021-04-01 09:49:36 -04001589 return ctx.mod.Binary()
Inseob Kim7f283f42020-06-01 21:53:49 +09001590}
1591
Inseob Kim1042d292020-06-01 23:23:05 +09001592func (ctx *moduleContextImpl) object() bool {
Ivan Lozanod7586b62021-04-01 09:49:36 -04001593 return ctx.mod.Object()
Inseob Kim1042d292020-06-01 23:23:05 +09001594}
1595
Yi Kong5786f5c2024-05-28 02:22:34 +09001596func (ctx *moduleContextImpl) optimizeForSize() bool {
1597 return ctx.mod.OptimizeForSize()
1598}
1599
Jooyung Hanccce2f22020-03-07 03:45:53 +09001600func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001601 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001602}
1603
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001604func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001605 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001606}
1607
1608func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001609 if ctx.ctx.Device() {
Justin Yun732aa6a2018-03-23 17:43:47 +09001610 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001611 }
1612 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001613}
1614
Jiyong Parkb35a8192020-08-10 15:59:36 +09001615func (ctx *moduleContextImpl) minSdkVersion() string {
1616 ver := ctx.mod.MinSdkVersion()
1617 if ver == "apex_inherit" && !ctx.isForPlatform() {
1618 ver = ctx.apexSdkVersion().String()
1619 }
1620 if ver == "apex_inherit" || ver == "" {
1621 ver = ctx.sdkVersion()
1622 }
Yi-Yo Chiang88960aa2024-01-19 15:02:29 +08001623
1624 if ctx.ctx.Device() {
Jooyung Hanaa2d3f52024-11-09 02:41:06 +00001625 // When building for vendor/product, use the latest _stable_ API as "current".
1626 // This is passed to clang/aidl compilers so that compiled/generated code works
1627 // with the system.
1628 if (ctx.inVendor() || ctx.inProduct()) && (ver == "" || ver == "current") {
1629 ver = ctx.ctx.Config().PlatformSdkVersion().String()
Yi-Yo Chiang88960aa2024-01-19 15:02:29 +08001630 }
1631 }
1632
Jiyong Parkfdaa5f72021-03-19 22:18:04 +09001633 // For crt objects, the meaning of min_sdk_version is very different from other types of
1634 // module. For them, min_sdk_version defines the oldest version that the build system will
1635 // create versioned variants for. For example, if min_sdk_version is 16, then sdk variant of
1636 // the crt object has local variants of 16, 17, ..., up to the latest version. sdk_version
1637 // and min_sdk_version properties of the variants are set to the corresponding version
Jiyong Park5df7bd32021-08-25 16:18:46 +09001638 // numbers. However, the non-sdk variant (for apex or platform) of the crt object is left
1639 // untouched. min_sdk_version: 16 doesn't actually mean that the non-sdk variant has to
1640 // support such an old version. The version is set to the later version in case when the
1641 // non-sdk variant is for the platform, or the min_sdk_version of the containing APEX if
1642 // it's for an APEX.
1643 if ctx.mod.isCrt() && !ctx.isSdkVariant() {
1644 if ctx.isForPlatform() {
1645 ver = strconv.Itoa(android.FutureApiLevelInt)
1646 } else { // for apex
1647 ver = ctx.apexSdkVersion().String()
1648 if ver == "" { // in case when min_sdk_version was not set by the APEX
1649 ver = ctx.sdkVersion()
1650 }
1651 }
Jiyong Parkfdaa5f72021-03-19 22:18:04 +09001652 }
1653
Jiyong Parkb35a8192020-08-10 15:59:36 +09001654 // Also make sure that minSdkVersion is not greater than sdkVersion, if they are both numbers
1655 sdkVersionInt, err := strconv.Atoi(ctx.sdkVersion())
1656 minSdkVersionInt, err2 := strconv.Atoi(ver)
1657 if err == nil && err2 == nil {
1658 if sdkVersionInt < minSdkVersionInt {
1659 return strconv.Itoa(sdkVersionInt)
1660 }
1661 }
1662 return ver
1663}
1664
1665func (ctx *moduleContextImpl) isSdkVariant() bool {
1666 return ctx.mod.IsSdkVariant()
1667}
1668
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001669func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001670 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001671}
Justin Yun8effde42017-06-23 19:24:43 +09001672
Kiyoung Kimaa394802024-01-08 12:55:45 +09001673func (ctx *moduleContextImpl) InVendorOrProduct() bool {
1674 return ctx.mod.InVendorOrProduct()
1675}
1676
Colin Cross95f1ca02020-10-29 20:47:22 -07001677func (ctx *moduleContextImpl) isNdk(config android.Config) bool {
1678 return ctx.mod.IsNdk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001679}
1680
Colin Cross127bb8b2020-12-16 16:46:01 -08001681func (ctx *moduleContextImpl) IsLlndk() bool {
1682 return ctx.mod.IsLlndk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001683}
1684
Colin Cross127bb8b2020-12-16 16:46:01 -08001685func (ctx *moduleContextImpl) isImplementationForLLNDKPublic() bool {
1686 return ctx.mod.isImplementationForLLNDKPublic()
1687}
1688
Colin Cross3513fb12024-01-24 14:44:47 -08001689func (ctx *moduleContextImpl) isAfdoCompile(mctx ModuleContext) bool {
1690 return ctx.mod.isAfdoCompile(mctx)
Yi Kong4ef54592022-02-14 20:00:10 +08001691}
1692
Sharjeel Khanc6a93d82023-07-18 21:01:11 +00001693func (ctx *moduleContextImpl) isOrderfileCompile() bool {
1694 return ctx.mod.isOrderfileCompile()
1695}
1696
Yi Kongc702ebd2022-08-19 16:02:45 +08001697func (ctx *moduleContextImpl) isCfi() bool {
1698 return ctx.mod.isCfi()
1699}
1700
Yi Konged79fa32023-06-04 17:15:42 +09001701func (ctx *moduleContextImpl) isFuzzer() bool {
1702 return ctx.mod.isFuzzer()
1703}
1704
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001705func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1706 return ctx.mod.isNDKStubLibrary()
1707}
1708
Colin Cross5271fea2021-04-27 13:06:04 -07001709func (ctx *moduleContextImpl) IsVendorPublicLibrary() bool {
1710 return ctx.mod.IsVendorPublicLibrary()
1711}
1712
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001713func (ctx *moduleContextImpl) selectedStl() string {
1714 if stl := ctx.mod.stl; stl != nil {
1715 return stl.Properties.SelectedStl
1716 }
1717 return ""
1718}
1719
Ivan Lozanobd721262018-11-27 14:33:03 -08001720func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1721 return ctx.mod.linker.useClangLld(actx)
1722}
1723
Colin Crossce75d2c2016-10-06 16:12:58 -07001724func (ctx *moduleContextImpl) baseModuleName() string {
Spandan Das2b6dfb52024-01-19 00:22:22 +00001725 return ctx.mod.BaseModuleName()
Colin Crossce75d2c2016-10-06 16:12:58 -07001726}
1727
Logan Chiene274fc92019-12-03 11:18:32 -08001728func (ctx *moduleContextImpl) isForPlatform() bool {
Colin Crossff694a82023-12-13 15:54:49 -08001729 apexInfo, _ := android.ModuleProvider(ctx.ctx, android.ApexInfoProvider)
1730 return apexInfo.IsForPlatform()
Logan Chiene274fc92019-12-03 11:18:32 -08001731}
1732
Colin Crosse07f2312020-08-13 11:24:56 -07001733func (ctx *moduleContextImpl) apexVariationName() string {
Colin Crossff694a82023-12-13 15:54:49 -08001734 apexInfo, _ := android.ModuleProvider(ctx.ctx, android.ApexInfoProvider)
1735 return apexInfo.ApexVariationName
Jiyong Park25fc6a92018-11-18 18:02:45 +09001736}
1737
Dan Albertc8060532020-07-22 22:32:17 -07001738func (ctx *moduleContextImpl) apexSdkVersion() android.ApiLevel {
Jooyung Han75568392020-03-20 04:29:24 +09001739 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001740}
1741
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001742func (ctx *moduleContextImpl) bootstrap() bool {
Jiyong Park7d55b612021-06-11 17:22:09 +09001743 return ctx.mod.Bootstrap()
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001744}
1745
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001746func (ctx *moduleContextImpl) nativeCoverage() bool {
1747 return ctx.mod.nativeCoverage()
1748}
1749
Colin Cross95b07f22020-12-16 11:06:50 -08001750func (ctx *moduleContextImpl) isPreventInstall() bool {
1751 return ctx.mod.Properties.PreventInstall
1752}
1753
Chih-Hung Hsieh7540a782022-01-08 19:56:09 -08001754func (ctx *moduleContextImpl) getSharedFlags() *SharedFlags {
1755 shared := &ctx.mod.sharedFlags
1756 if shared.flagsMap == nil {
1757 shared.numSharedFlags = 0
1758 shared.flagsMap = make(map[string]string)
1759 }
1760 return shared
1761}
1762
Cindy Zhou5d5cfc12021-01-09 08:25:22 -08001763func (ctx *moduleContextImpl) isCfiAssemblySupportEnabled() bool {
1764 return ctx.mod.isCfiAssemblySupportEnabled()
1765}
1766
Colin Cross4a9e6ec2023-12-18 15:29:41 -08001767func (ctx *moduleContextImpl) notInPlatform() bool {
1768 return ctx.mod.NotInPlatform()
1769}
1770
Yu Liu76d94462024-10-31 23:32:36 +00001771func (ctx *moduleContextImpl) getOrCreateMakeVarsInfo() *CcMakeVarsInfo {
1772 if ctx.mod.makeVarsInfo == nil {
1773 ctx.mod.makeVarsInfo = &CcMakeVarsInfo{}
1774 }
1775 return ctx.mod.makeVarsInfo
1776}
1777
Colin Cross635c3b02016-05-18 15:37:25 -07001778func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001779 return &Module{
1780 hod: hod,
1781 multilib: multilib,
1782 }
1783}
1784
Colin Cross635c3b02016-05-18 15:37:25 -07001785func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001786 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001787 module.features = []feature{
1788 &tidyFeature{},
1789 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001790 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001791 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001792 module.coverage = &coverage{}
Cory Barkera1da26f2022-06-07 20:12:06 +00001793 module.fuzzer = &fuzzer{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001794 module.sabi = &sabi{}
Stephen Craneba090d12017-05-09 15:44:35 -07001795 module.lto = &lto{}
Yi Kongeb8efc92021-12-09 18:06:29 +08001796 module.afdo = &afdo{}
Sharjeel Khanc6a93d82023-07-18 21:01:11 +00001797 module.orderfile = &orderfile{}
Colin Crossca860ac2016-01-04 14:34:37 -08001798 return module
1799}
1800
Colin Crossce75d2c2016-10-06 16:12:58 -07001801func (c *Module) Prebuilt() *android.Prebuilt {
1802 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1803 return p.prebuilt()
1804 }
1805 return nil
1806}
1807
Ivan Lozano3968d8f2020-12-14 11:27:52 -05001808func (c *Module) IsPrebuilt() bool {
1809 return c.Prebuilt() != nil
1810}
1811
Colin Crossce75d2c2016-10-06 16:12:58 -07001812func (c *Module) Name() string {
1813 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001814 if p, ok := c.linker.(interface {
1815 Name(string) string
1816 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001817 name = p.Name(name)
1818 }
1819 return name
1820}
1821
Alex Light3d673592019-01-18 14:37:31 -08001822func (c *Module) Symlinks() []string {
1823 if p, ok := c.installer.(interface {
1824 symlinkList() []string
1825 }); ok {
1826 return p.symlinkList()
1827 }
1828 return nil
1829}
1830
Chris Parsons216e10a2020-07-09 17:12:52 -04001831func (c *Module) DataPaths() []android.DataPath {
Liz Kammer1c14a212020-05-12 15:26:55 -07001832 if p, ok := c.installer.(interface {
Chris Parsons216e10a2020-07-09 17:12:52 -04001833 dataPaths() []android.DataPath
Liz Kammer1c14a212020-05-12 15:26:55 -07001834 }); ok {
1835 return p.dataPaths()
1836 }
1837 return nil
1838}
1839
Ivan Lozanof1868af2022-04-12 13:08:36 -04001840func getNameSuffixWithVndkVersion(ctx android.ModuleContext, c LinkableInterface) string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001841 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1842 // "current", it will append the VNDK version to the name suffix.
Justin Yun5f7f7e82019-11-18 19:52:14 +09001843 var nameSuffix string
Ivan Lozanof9e21722020-12-02 09:00:51 -05001844 if c.InProduct() {
Justin Yund00f5ca2021-02-03 19:43:02 +09001845 if c.ProductSpecific() {
1846 // If the module is product specific with 'product_specific: true',
1847 // do not add a name suffix because it is a base module.
1848 return ""
1849 }
Justin Yunaf1fde42023-09-27 16:22:10 +09001850 return ProductSuffix
Justin Yun5f7f7e82019-11-18 19:52:14 +09001851 } else {
Ivan Lozanoe6d30982021-02-05 10:57:43 -05001852 nameSuffix = VendorSuffix
Justin Yun5f7f7e82019-11-18 19:52:14 +09001853 }
Kiyoung Kim4e765b12024-04-04 17:33:42 +09001854 if c.VndkVersion() != "" {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001855 // add version suffix only if the module is using different vndk version than the
1856 // version in product or vendor partition.
Ivan Lozanof1868af2022-04-12 13:08:36 -04001857 nameSuffix += "." + c.VndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09001858 }
1859 return nameSuffix
1860}
1861
Ivan Lozanof1868af2022-04-12 13:08:36 -04001862func GetSubnameProperty(actx android.ModuleContext, c LinkableInterface) string {
1863 var subName = ""
Inseob Kim64c43952019-08-26 16:52:35 +09001864
1865 if c.Target().NativeBridge == android.NativeBridgeEnabled {
Ivan Lozanof1868af2022-04-12 13:08:36 -04001866 subName += NativeBridgeSuffix
Inseob Kim64c43952019-08-26 16:52:35 +09001867 }
1868
Colin Cross127bb8b2020-12-16 16:46:01 -08001869 llndk := c.IsLlndk()
Kiyoung Kimaa394802024-01-08 12:55:45 +09001870 if llndk || (c.InVendorOrProduct() && c.HasNonSystemVariants()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001871 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1872 // added for product variant only when we have vendor and product variants with core
1873 // variant. The suffix is not added for vendor-only or product-only module.
Ivan Lozanof1868af2022-04-12 13:08:36 -04001874 subName += getNameSuffixWithVndkVersion(actx, c)
Colin Cross5271fea2021-04-27 13:06:04 -07001875 } else if c.IsVendorPublicLibrary() {
Ivan Lozanof1868af2022-04-12 13:08:36 -04001876 subName += vendorPublicLibrarySuffix
1877 } else if c.IsVndkPrebuiltLibrary() {
Inseob Kim64c43952019-08-26 16:52:35 +09001878 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1879 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
Ivan Lozanof1868af2022-04-12 13:08:36 -04001880 subName += VendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001881 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
Ivan Lozanof1868af2022-04-12 13:08:36 -04001882 subName += RamdiskSuffix
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001883 } else if c.InVendorRamdisk() && !c.OnlyInVendorRamdisk() {
Ivan Lozanof1868af2022-04-12 13:08:36 -04001884 subName += VendorRamdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001885 } else if c.InRecovery() && !c.OnlyInRecovery() {
Ivan Lozanof1868af2022-04-12 13:08:36 -04001886 subName += RecoverySuffix
1887 } else if c.IsSdkVariant() && (c.SdkAndPlatformVariantVisibleToMake() || c.SplitPerApiLevel()) {
1888 subName += sdkSuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001889 if c.SplitPerApiLevel() {
Ivan Lozanof1868af2022-04-12 13:08:36 -04001890 subName += "." + c.SdkVersion()
Dan Albert92fe7402020-07-15 13:33:30 -07001891 }
Spandan Dasb2b41d52023-04-13 18:15:05 +00001892 } else if c.IsStubs() && c.IsSdkVariant() {
1893 // Public API surface (NDK)
1894 // Add a suffix to this stub variant to distinguish it from the module-lib stub variant.
1895 subName = sdkSuffix
Inseob Kim64c43952019-08-26 16:52:35 +09001896 }
Ivan Lozanof1868af2022-04-12 13:08:36 -04001897
1898 return subName
Chris Parsons8d6e4332021-02-22 16:13:50 -05001899}
1900
Sam Delmerico75dbca22023-04-20 13:13:25 +00001901func moduleContextFromAndroidModuleContext(actx android.ModuleContext, c *Module) ModuleContext {
1902 ctx := &moduleContext{
1903 ModuleContext: actx,
1904 moduleContextImpl: moduleContextImpl{
1905 mod: c,
1906 },
1907 }
1908 ctx.ctx = ctx
1909 return ctx
1910}
1911
Spandan Das20fce2d2023-04-12 17:21:39 +00001912// TODO (b/277651159): Remove this allowlist
1913var (
1914 skipStubLibraryMultipleApexViolation = map[string]bool{
1915 "libclang_rt.asan": true,
1916 "libclang_rt.hwasan": true,
1917 // runtime apex
1918 "libc": true,
1919 "libc_hwasan": true,
1920 "libdl_android": true,
1921 "libm": true,
1922 "libdl": true,
Spandan Das1a0c6e12024-01-04 01:44:17 +00001923 "libz": true,
Spandan Das20fce2d2023-04-12 17:21:39 +00001924 // art apex
Martin Stjernholm75598032024-07-12 18:47:26 +01001925 // TODO(b/234351700): Remove this when com.android.art.debug is gone.
Spandan Das20fce2d2023-04-12 17:21:39 +00001926 "libandroidio": true,
1927 "libdexfile": true,
Martin Stjernholm75598032024-07-12 18:47:26 +01001928 "libdexfiled": true, // com.android.art.debug only
Spandan Das20fce2d2023-04-12 17:21:39 +00001929 "libnativebridge": true,
1930 "libnativehelper": true,
1931 "libnativeloader": true,
1932 "libsigchain": true,
1933 }
1934)
1935
1936// Returns true if a stub library could be installed in multiple apexes
1937func (c *Module) stubLibraryMultipleApexViolation(ctx android.ModuleContext) bool {
1938 // If this is not an apex variant, no check necessary
Colin Cross2dcbca62024-11-20 14:55:14 -08001939 if info, ok := android.ModuleProvider(ctx, android.ApexInfoProvider); !ok || info.IsForPlatform() {
Spandan Das20fce2d2023-04-12 17:21:39 +00001940 return false
1941 }
1942 // If this is not a stub library, no check necessary
1943 if !c.HasStubsVariants() {
1944 return false
1945 }
1946 // Skip the allowlist
1947 // Use BaseModuleName so that this matches prebuilts.
1948 if _, exists := skipStubLibraryMultipleApexViolation[c.BaseModuleName()]; exists {
1949 return false
1950 }
1951
1952 _, aaWithoutTestApexes, _ := android.ListSetDifference(c.ApexAvailable(), c.TestApexes())
1953 // Stub libraries should not have more than one apex_available
1954 if len(aaWithoutTestApexes) > 1 {
1955 return true
1956 }
1957 // Stub libraries should not use the wildcard
1958 if aaWithoutTestApexes[0] == android.AvailableToAnyApex {
1959 return true
1960 }
1961 // Default: no violation
1962 return false
1963}
1964
Chris Parsons8d6e4332021-02-22 16:13:50 -05001965func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Ronald Braunstein6a08d492024-04-15 12:55:30 -07001966 ctx := moduleContextFromAndroidModuleContext(actx, c)
1967
Inseob Kim37e0bb02024-04-29 15:54:44 +09001968 c.logtagsPaths = android.PathsForModuleSrc(actx, c.Properties.Logtags)
1969 android.SetProvider(ctx, android.LogtagsProviderKey, &android.LogtagsInfo{
1970 Logtags: c.logtagsPaths,
1971 })
1972
Ronald Braunstein6a08d492024-04-15 12:55:30 -07001973 // If Test_only is set on a module in bp file, respect the setting, otherwise
1974 // see if is a known test module type.
1975 testOnly := c.testModule || c.testLibrary()
1976 if c.sourceProperties.Test_only != nil {
1977 testOnly = Bool(c.sourceProperties.Test_only)
1978 }
1979 // Keep before any early returns.
1980 android.SetProvider(ctx, android.TestOnlyProviderKey, android.TestModuleInformation{
1981 TestOnly: testOnly,
1982 TopLevelTarget: c.testModule,
1983 })
1984
Ivan Lozanof1868af2022-04-12 13:08:36 -04001985 c.Properties.SubName = GetSubnameProperty(actx, c)
Colin Crossff694a82023-12-13 15:54:49 -08001986 apexInfo, _ := android.ModuleProvider(actx, android.ApexInfoProvider)
Chris Parsons8d6e4332021-02-22 16:13:50 -05001987 if !apexInfo.IsForPlatform() {
1988 c.hideApexVariantFromMake = true
1989 }
1990
Chris Parsonseefc9e62021-04-02 17:36:47 -04001991 c.makeLinkType = GetMakeLinkType(actx, c)
1992
Colin Crossf18e1102017-11-16 14:33:08 -08001993 deps := c.depsToPaths(ctx)
1994 if ctx.Failed() {
1995 return
1996 }
1997
Joe Onorato37f900c2023-07-18 16:58:16 -07001998 for _, generator := range c.generators {
1999 gen := generator.GeneratorSources(ctx)
2000 deps.IncludeDirs = append(deps.IncludeDirs, gen.IncludeDirs...)
2001 deps.ReexportedDirs = append(deps.ReexportedDirs, gen.ReexportedDirs...)
2002 deps.GeneratedDeps = append(deps.GeneratedDeps, gen.Headers...)
2003 deps.ReexportedGeneratedHeaders = append(deps.ReexportedGeneratedHeaders, gen.Headers...)
2004 deps.ReexportedDeps = append(deps.ReexportedDeps, gen.Headers...)
2005 if len(deps.Objs.objFiles) == 0 {
2006 // If we are reusuing object files (which happens when we're a shared library and we're
2007 // reusing our static variant's object files), then skip adding the actual source files,
2008 // because we already have the object for it.
2009 deps.GeneratedSources = append(deps.GeneratedSources, gen.Sources...)
2010 }
2011 }
2012
2013 if ctx.Failed() {
2014 return
2015 }
2016
Spandan Das20fce2d2023-04-12 17:21:39 +00002017 if c.stubLibraryMultipleApexViolation(actx) {
2018 actx.PropertyErrorf("apex_available",
2019 "Stub libraries should have a single apex_available (test apexes excluded). Got %v", c.ApexAvailable())
2020 }
Dan Willemsen8536d6b2018-10-07 20:54:34 -07002021 if c.Properties.Clang != nil && *c.Properties.Clang == false {
2022 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
Alixb5f6d9e2022-04-20 23:00:58 +00002023 } else if c.Properties.Clang != nil && !ctx.DeviceConfig().BuildBrokenClangProperty() {
2024 ctx.PropertyErrorf("clang", "property is deprecated, see Changes.md file")
Dan Willemsen8536d6b2018-10-07 20:54:34 -07002025 }
2026
Colin Crossca860ac2016-01-04 14:34:37 -08002027 flags := Flags{
2028 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002029 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08002030 }
Joe Onorato37f900c2023-07-18 16:58:16 -07002031 for _, generator := range c.generators {
2032 flags = generator.GeneratorFlags(ctx, flags, deps)
2033 }
Colin Crossca860ac2016-01-04 14:34:37 -08002034 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08002035 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08002036 }
2037 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07002038 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08002039 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07002040 if c.stl != nil {
2041 flags = c.stl.flags(ctx, flags)
2042 }
Colin Cross16b23492016-01-06 14:41:07 -08002043 if c.sanitize != nil {
2044 flags = c.sanitize.flags(ctx, flags)
2045 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002046 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07002047 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08002048 }
Cory Barkera1da26f2022-06-07 20:12:06 +00002049 if c.fuzzer != nil {
2050 flags = c.fuzzer.flags(ctx, flags)
2051 }
Stephen Craneba090d12017-05-09 15:44:35 -07002052 if c.lto != nil {
2053 flags = c.lto.flags(ctx, flags)
2054 }
Yi Kongeb8efc92021-12-09 18:06:29 +08002055 if c.afdo != nil {
2056 flags = c.afdo.flags(ctx, flags)
2057 }
Sharjeel Khanc6a93d82023-07-18 21:01:11 +00002058 if c.orderfile != nil {
2059 flags = c.orderfile.flags(ctx, flags)
2060 }
Colin Crossca860ac2016-01-04 14:34:37 -08002061 for _, feature := range c.features {
2062 flags = feature.flags(ctx, flags)
2063 }
Colin Cross3f40fa42015-01-30 17:27:36 -08002064 if ctx.Failed() {
2065 return
2066 }
2067
Colin Cross4af21ed2019-11-04 09:37:55 -08002068 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
2069 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
2070 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08002071
Colin Cross4af21ed2019-11-04 09:37:55 -08002072 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09002073
2074 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08002075 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09002076 }
2077 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08002078 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09002079 }
2080
Colin Cross3e5e7782022-06-17 22:17:05 +00002081 flags.Local.LdFlags = append(flags.Local.LdFlags, deps.LdFlags...)
2082
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08002083 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07002084 // We need access to all the flags seen by a source file.
2085 if c.sabi != nil {
2086 flags = c.sabi.flags(ctx, flags)
2087 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07002088
Colin Cross4af21ed2019-11-04 09:37:55 -08002089 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07002090
Joe Onorato37f900c2023-07-18 16:58:16 -07002091 for _, generator := range c.generators {
2092 generator.GeneratorBuildActions(ctx, flags, deps)
2093 }
2094
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002095 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08002096 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002097 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08002098 if ctx.Failed() {
2099 return
2100 }
Colin Cross3f40fa42015-01-30 17:27:36 -08002101 }
2102
Colin Crossca860ac2016-01-04 14:34:37 -08002103 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002104 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08002105 if ctx.Failed() {
2106 return
2107 }
Colin Cross635c3b02016-05-18 15:37:25 -07002108 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09002109
Chris Parsons94a0bba2021-06-04 15:03:47 -04002110 c.maybeUnhideFromMake()
Colin Crossb614cd42024-10-11 12:52:21 -07002111
2112 android.SetProvider(ctx, ImplementationDepInfoProvider, &ImplementationDepInfo{
2113 ImplementationDeps: depset.New(depset.PREORDER, deps.directImplementationDeps, deps.transitiveImplementationDeps),
2114 })
Colin Crossce75d2c2016-10-06 16:12:58 -07002115 }
Ronald Braunsteina115e262024-04-09 18:07:38 -07002116
Colin Cross40213022023-12-13 15:19:49 -08002117 android.SetProvider(ctx, blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: deps.GeneratedSources.Strings()})
Colin Cross5049f022015-03-18 13:28:46 -07002118
Hao Chen1c8ea5b2023-10-20 23:03:45 +00002119 if Bool(c.Properties.Cmake_snapshot_supported) {
2120 android.SetProvider(ctx, cmakeSnapshotSourcesProvider, android.GlobFiles(ctx, ctx.ModuleDir()+"/**/*", nil))
2121 }
2122
Chris Parsons94a0bba2021-06-04 15:03:47 -04002123 c.maybeInstall(ctx, apexInfo)
Colin Cross4a9e6ec2023-12-18 15:29:41 -08002124
2125 if c.linker != nil {
2126 moduleInfoJSON := ctx.ModuleInfoJSON()
2127 c.linker.moduleInfoJSON(ctx, moduleInfoJSON)
2128 moduleInfoJSON.SharedLibs = c.Properties.AndroidMkSharedLibs
2129 moduleInfoJSON.StaticLibs = c.Properties.AndroidMkStaticLibs
2130 moduleInfoJSON.SystemSharedLibs = c.Properties.AndroidMkSystemSharedLibs
2131 moduleInfoJSON.RuntimeDependencies = c.Properties.AndroidMkRuntimeLibs
2132
2133 moduleInfoJSON.Dependencies = append(moduleInfoJSON.Dependencies, c.Properties.AndroidMkSharedLibs...)
2134 moduleInfoJSON.Dependencies = append(moduleInfoJSON.Dependencies, c.Properties.AndroidMkStaticLibs...)
2135 moduleInfoJSON.Dependencies = append(moduleInfoJSON.Dependencies, c.Properties.AndroidMkHeaderLibs...)
2136 moduleInfoJSON.Dependencies = append(moduleInfoJSON.Dependencies, c.Properties.AndroidMkWholeStaticLibs...)
2137
2138 if c.sanitize != nil && len(moduleInfoJSON.Class) > 0 &&
2139 (moduleInfoJSON.Class[0] == "STATIC_LIBRARIES" || moduleInfoJSON.Class[0] == "HEADER_LIBRARIES") {
2140 if Bool(c.sanitize.Properties.SanitizeMutated.Cfi) {
2141 moduleInfoJSON.SubName += ".cfi"
2142 }
2143 if Bool(c.sanitize.Properties.SanitizeMutated.Hwaddress) {
2144 moduleInfoJSON.SubName += ".hwasan"
2145 }
2146 if Bool(c.sanitize.Properties.SanitizeMutated.Scs) {
2147 moduleInfoJSON.SubName += ".scs"
2148 }
2149 }
2150 moduleInfoJSON.SubName += c.Properties.SubName
2151
2152 if c.Properties.IsSdkVariant && c.Properties.SdkAndPlatformVariantVisibleToMake {
2153 moduleInfoJSON.Uninstallable = true
2154 }
Colin Cross4a9e6ec2023-12-18 15:29:41 -08002155 }
Wei Lia1aa2972024-06-21 13:08:51 -07002156
2157 buildComplianceMetadataInfo(ctx, c, deps)
mrziwangabdb2932024-06-18 12:43:41 -07002158
Cole Faust96a692b2024-08-08 14:47:51 -07002159 if b, ok := c.compiler.(*baseCompiler); ok {
2160 c.hasAidl = b.hasSrcExt(ctx, ".aidl")
2161 c.hasLex = b.hasSrcExt(ctx, ".l") || b.hasSrcExt(ctx, ".ll")
2162 c.hasProto = b.hasSrcExt(ctx, ".proto")
2163 c.hasRenderscript = b.hasSrcExt(ctx, ".rscript") || b.hasSrcExt(ctx, ".fs")
2164 c.hasSysprop = b.hasSrcExt(ctx, ".sysprop")
2165 c.hasWinMsg = b.hasSrcExt(ctx, ".mc")
2166 c.hasYacc = b.hasSrcExt(ctx, ".y") || b.hasSrcExt(ctx, ".yy")
2167 }
2168
Yu Liuec7043d2024-11-05 18:22:20 +00002169 ccObjectInfo := CcObjectInfo{
Yu Liu4f825132024-12-18 00:35:39 +00002170 KytheFiles: objs.kytheFiles,
Yu Liuec7043d2024-11-05 18:22:20 +00002171 }
2172 if !ctx.Config().KatiEnabled() || !android.ShouldSkipAndroidMkProcessing(ctx, c) {
Yu Liu4f825132024-12-18 00:35:39 +00002173 ccObjectInfo.ObjFiles = objs.objFiles
2174 ccObjectInfo.TidyFiles = objs.tidyFiles
Yu Liuec7043d2024-11-05 18:22:20 +00002175 }
Yu Liu4f825132024-12-18 00:35:39 +00002176 if len(ccObjectInfo.KytheFiles)+len(ccObjectInfo.ObjFiles)+len(ccObjectInfo.TidyFiles) > 0 {
Yu Liuec7043d2024-11-05 18:22:20 +00002177 android.SetProvider(ctx, CcObjectInfoProvider, ccObjectInfo)
2178 }
2179
Yu Liu986d98c2024-11-12 00:28:11 +00002180 android.SetProvider(ctx, LinkableInfoKey, LinkableInfo{
2181 StaticExecutable: c.StaticExecutable(),
2182 })
2183
Yu Liu323d77a2024-12-16 23:13:57 +00002184 ccInfo := CcInfo{
2185 HasStubsVariants: c.HasStubsVariants(),
2186 IsPrebuilt: c.IsPrebuilt(),
2187 CmakeSnapshotSupported: proptools.Bool(c.Properties.Cmake_snapshot_supported),
2188 }
2189 if c.compiler != nil {
2190 ccInfo.CompilerInfo = &CompilerInfo{
2191 Srcs: c.compiler.(CompiledInterface).Srcs(),
2192 Cflags: c.compiler.baseCompilerProps().Cflags,
2193 AidlInterfaceInfo: AidlInterfaceInfo{
2194 Sources: c.compiler.baseCompilerProps().AidlInterface.Sources,
2195 AidlRoot: c.compiler.baseCompilerProps().AidlInterface.AidlRoot,
2196 Lang: c.compiler.baseCompilerProps().AidlInterface.Lang,
2197 Flags: c.compiler.baseCompilerProps().AidlInterface.Flags,
2198 },
2199 }
2200 switch decorator := c.compiler.(type) {
2201 case *libraryDecorator:
2202 ccInfo.CompilerInfo.LibraryDecoratorInfo = &LibraryDecoratorInfo{
Yu Liu4f825132024-12-18 00:35:39 +00002203 ExportIncludeDirs: decorator.flagExporter.Properties.Export_include_dirs,
Yu Liu323d77a2024-12-16 23:13:57 +00002204 }
2205 }
2206 }
2207 if c.linker != nil {
2208 ccInfo.LinkerInfo = &LinkerInfo{
Yu Liu4f825132024-12-18 00:35:39 +00002209 WholeStaticLibs: c.linker.baseLinkerProps().Whole_static_libs,
2210 StaticLibs: c.linker.baseLinkerProps().Static_libs,
2211 SharedLibs: c.linker.baseLinkerProps().Shared_libs,
2212 HeaderLibs: c.linker.baseLinkerProps().Header_libs,
2213 UnstrippedOutputFile: c.UnstrippedOutputFile(),
Yu Liu323d77a2024-12-16 23:13:57 +00002214 }
2215 switch decorator := c.linker.(type) {
2216 case *binaryDecorator:
2217 ccInfo.LinkerInfo.BinaryDecoratorInfo = &BinaryDecoratorInfo{}
2218 case *libraryDecorator:
2219 ccInfo.LinkerInfo.LibraryDecoratorInfo = &LibraryDecoratorInfo{}
2220 case *testBinary:
2221 ccInfo.LinkerInfo.TestBinaryInfo = &TestBinaryInfo{
2222 Gtest: decorator.testDecorator.gtest(),
2223 }
2224 case *benchmarkDecorator:
2225 ccInfo.LinkerInfo.BenchmarkDecoratorInfo = &BenchmarkDecoratorInfo{}
2226 case *objectLinker:
2227 ccInfo.LinkerInfo.ObjectLinkerInfo = &ObjectLinkerInfo{}
2228 }
2229 }
2230 android.SetProvider(ctx, CcInfoProvider, ccInfo)
Yu Liub1bfa9d2024-12-05 18:57:51 +00002231
mrziwangabdb2932024-06-18 12:43:41 -07002232 c.setOutputFiles(ctx)
Yu Liu76d94462024-10-31 23:32:36 +00002233
2234 if c.makeVarsInfo != nil {
2235 android.SetProvider(ctx, CcMakeVarsInfoProvider, c.makeVarsInfo)
2236 }
mrziwangabdb2932024-06-18 12:43:41 -07002237}
2238
Yu Liuec7043d2024-11-05 18:22:20 +00002239func setOutputFilesIfNotEmpty(ctx ModuleContext, files android.Paths, tag string) {
2240 if len(files) > 0 {
2241 ctx.SetOutputFiles(files, tag)
2242 }
2243}
2244
mrziwangabdb2932024-06-18 12:43:41 -07002245func (c *Module) setOutputFiles(ctx ModuleContext) {
2246 if c.outputFile.Valid() {
2247 ctx.SetOutputFiles(android.Paths{c.outputFile.Path()}, "")
2248 } else {
2249 ctx.SetOutputFiles(android.Paths{}, "")
2250 }
2251 if c.linker != nil {
2252 ctx.SetOutputFiles(android.PathsIfNonNil(c.linker.unstrippedOutputFilePath()), "unstripped")
2253 ctx.SetOutputFiles(android.PathsIfNonNil(c.linker.strippedAllOutputFilePath()), "stripped_all")
2254 }
Wei Lia1aa2972024-06-21 13:08:51 -07002255}
2256
2257func buildComplianceMetadataInfo(ctx ModuleContext, c *Module, deps PathDeps) {
2258 // Dump metadata that can not be done in android/compliance-metadata.go
2259 complianceMetadataInfo := ctx.ComplianceMetadataInfo()
2260 complianceMetadataInfo.SetStringValue(android.ComplianceMetadataProp.IS_STATIC_LIB, strconv.FormatBool(ctx.static()))
2261 complianceMetadataInfo.SetStringValue(android.ComplianceMetadataProp.BUILT_FILES, c.outputFile.String())
2262
2263 // Static deps
Yu Liuf432c2e2024-12-17 00:09:15 +00002264 staticDeps := ctx.GetDirectDepsProxyWithTag(StaticDepTag(false))
Wei Lia1aa2972024-06-21 13:08:51 -07002265 staticDepNames := make([]string, 0, len(staticDeps))
2266 for _, dep := range staticDeps {
2267 staticDepNames = append(staticDepNames, dep.Name())
2268 }
2269
2270 staticDepPaths := make([]string, 0, len(deps.StaticLibs))
2271 for _, dep := range deps.StaticLibs {
2272 staticDepPaths = append(staticDepPaths, dep.String())
2273 }
2274 complianceMetadataInfo.SetListValue(android.ComplianceMetadataProp.STATIC_DEPS, android.FirstUniqueStrings(staticDepNames))
2275 complianceMetadataInfo.SetListValue(android.ComplianceMetadataProp.STATIC_DEP_FILES, android.FirstUniqueStrings(staticDepPaths))
2276
2277 // Whole static deps
Yu Liuf432c2e2024-12-17 00:09:15 +00002278 wholeStaticDeps := ctx.GetDirectDepsProxyWithTag(StaticDepTag(true))
Wei Lia1aa2972024-06-21 13:08:51 -07002279 wholeStaticDepNames := make([]string, 0, len(wholeStaticDeps))
2280 for _, dep := range wholeStaticDeps {
2281 wholeStaticDepNames = append(wholeStaticDepNames, dep.Name())
2282 }
2283
2284 wholeStaticDepPaths := make([]string, 0, len(deps.WholeStaticLibs))
2285 for _, dep := range deps.WholeStaticLibs {
2286 wholeStaticDepPaths = append(wholeStaticDepPaths, dep.String())
2287 }
2288 complianceMetadataInfo.SetListValue(android.ComplianceMetadataProp.WHOLE_STATIC_DEPS, android.FirstUniqueStrings(wholeStaticDepNames))
2289 complianceMetadataInfo.SetListValue(android.ComplianceMetadataProp.WHOLE_STATIC_DEP_FILES, android.FirstUniqueStrings(wholeStaticDepPaths))
Chris Parsons94a0bba2021-06-04 15:03:47 -04002290}
2291
2292func (c *Module) maybeUnhideFromMake() {
2293 // If a lib is directly included in any of the APEXes or is not available to the
2294 // platform (which is often the case when the stub is provided as a prebuilt),
2295 // unhide the stubs variant having the latest version gets visible to make. In
2296 // addition, the non-stubs variant is renamed to <libname>.bootstrap. This is to
2297 // force anything in the make world to link against the stubs library. (unless it
2298 // is explicitly referenced via .bootstrap suffix or the module is marked with
2299 // 'bootstrap: true').
2300 if c.HasStubsVariants() && c.NotInPlatform() && !c.InRamdisk() &&
Kiyoung Kimaa394802024-01-08 12:55:45 +09002301 !c.InRecovery() && !c.InVendorOrProduct() && !c.static() && !c.isCoverageVariant() &&
Chris Parsons94a0bba2021-06-04 15:03:47 -04002302 c.IsStubs() && !c.InVendorRamdisk() {
2303 c.Properties.HideFromMake = false // unhide
2304 // Note: this is still non-installable
2305 }
2306}
2307
Colin Cross8ff10582023-12-07 13:10:56 -08002308// maybeInstall is called at the end of both GenerateAndroidBuildActions to run the
2309// install hooks for installable modules, like binaries and tests.
Chris Parsons94a0bba2021-06-04 15:03:47 -04002310func (c *Module) maybeInstall(ctx ModuleContext, apexInfo android.ApexInfo) {
Colin Cross1bc94122021-10-28 13:25:54 -07002311 if !proptools.BoolDefault(c.Installable(), true) {
Colin Crossa9c8c9f2020-12-16 10:20:23 -08002312 // If the module has been specifically configure to not be installed then
2313 // hide from make as otherwise it will break when running inside make
2314 // as the output path to install will not be specified. Not all uninstallable
2315 // modules can be hidden from make as some are needed for resolving make side
2316 // dependencies.
2317 c.HideFromMake()
Spandan Das034af2c2024-10-30 21:45:09 +00002318 c.SkipInstall()
Ivan Lozanod7586b62021-04-01 09:49:36 -04002319 } else if !installable(c, apexInfo) {
Colin Crossa9c8c9f2020-12-16 10:20:23 -08002320 c.SkipInstall()
2321 }
2322
2323 // Still call c.installer.install though, the installs will be stored as PackageSpecs
2324 // to allow using the outputs in a genrule.
2325 if c.installer != nil && c.outputFile.Valid() {
Colin Crossce75d2c2016-10-06 16:12:58 -07002326 c.installer.install(ctx, c.outputFile.Path())
2327 if ctx.Failed() {
2328 return
Colin Crossca860ac2016-01-04 14:34:37 -08002329 }
Dan Albertc403f7c2015-03-18 14:01:18 -07002330 }
Colin Cross3f40fa42015-01-30 17:27:36 -08002331}
2332
Colin Cross0ea8ba82019-06-06 14:33:29 -07002333func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08002334 if c.cachedToolchain == nil {
Liz Kammer356f7d42021-01-26 09:18:53 -05002335 c.cachedToolchain = config.FindToolchainWithContext(ctx)
Colin Cross3f40fa42015-01-30 17:27:36 -08002336 }
Colin Crossca860ac2016-01-04 14:34:37 -08002337 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08002338}
2339
Colin Crossca860ac2016-01-04 14:34:37 -08002340func (c *Module) begin(ctx BaseModuleContext) {
Joe Onorato37f900c2023-07-18 16:58:16 -07002341 for _, generator := range c.generators {
2342 generator.GeneratorInit(ctx)
2343 }
Colin Crossca860ac2016-01-04 14:34:37 -08002344 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07002345 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07002346 }
Colin Crossca860ac2016-01-04 14:34:37 -08002347 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07002348 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08002349 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07002350 if c.stl != nil {
2351 c.stl.begin(ctx)
2352 }
Colin Cross16b23492016-01-06 14:41:07 -08002353 if c.sanitize != nil {
2354 c.sanitize.begin(ctx)
2355 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002356 if c.coverage != nil {
2357 c.coverage.begin(ctx)
2358 }
Yi Kong9723e332023-12-04 14:52:53 +09002359 if c.afdo != nil {
2360 c.afdo.begin(ctx)
2361 }
Stephen Craneba090d12017-05-09 15:44:35 -07002362 if c.lto != nil {
2363 c.lto.begin(ctx)
2364 }
Sharjeel Khanc6a93d82023-07-18 21:01:11 +00002365 if c.orderfile != nil {
2366 c.orderfile.begin(ctx)
2367 }
Dan Albert92fe7402020-07-15 13:33:30 -07002368 if ctx.useSdk() && c.IsSdkVariant() {
Dan Albert1a246272020-07-06 14:49:35 -07002369 version, err := nativeApiLevelFromUser(ctx, ctx.sdkVersion())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07002370 if err != nil {
2371 ctx.PropertyErrorf("sdk_version", err.Error())
Dan Albert1a246272020-07-06 14:49:35 -07002372 c.Properties.Sdk_version = nil
2373 } else {
2374 c.Properties.Sdk_version = StringPtr(version.String())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07002375 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -07002376 }
Colin Crossca860ac2016-01-04 14:34:37 -08002377}
2378
Colin Cross37047f12016-12-13 17:06:13 -08002379func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07002380 deps := Deps{}
2381
Joe Onorato37f900c2023-07-18 16:58:16 -07002382 for _, generator := range c.generators {
2383 deps = generator.GeneratorDeps(ctx, deps)
2384 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002385 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07002386 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002387 }
2388 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07002389 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002390 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07002391 if c.stl != nil {
2392 deps = c.stl.deps(ctx, deps)
2393 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00002394 if c.coverage != nil {
2395 deps = c.coverage.deps(ctx, deps)
2396 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002397
Colin Crossb6715442017-10-24 11:13:31 -07002398 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
2399 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
2400 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
2401 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
2402 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
2403 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08002404 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Hsin-Yi Chen715142a2024-03-27 16:31:16 +08002405 deps.LlndkHeaderLibs = android.LastUniqueStrings(deps.LlndkHeaderLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07002406
Colin Cross516c5452024-10-28 13:45:21 -07002407 if err := checkConflictingExplicitVersions(deps.SharedLibs); err != nil {
2408 ctx.PropertyErrorf("shared_libs", "%s", err.Error())
2409 }
2410
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002411 for _, lib := range deps.ReexportSharedLibHeaders {
2412 if !inList(lib, deps.SharedLibs) {
2413 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
2414 }
2415 }
2416
2417 for _, lib := range deps.ReexportStaticLibHeaders {
Steven Morelandba407c82021-04-01 22:17:50 +00002418 if !inList(lib, deps.StaticLibs) && !inList(lib, deps.WholeStaticLibs) {
2419 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs or whole_static_libs: '%s'", lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002420 }
2421 }
2422
Colin Cross5950f382016-12-13 12:50:57 -08002423 for _, lib := range deps.ReexportHeaderLibHeaders {
2424 if !inList(lib, deps.HeaderLibs) {
2425 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
2426 }
2427 }
2428
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002429 for _, gen := range deps.ReexportGeneratedHeaders {
2430 if !inList(gen, deps.GeneratedHeaders) {
2431 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
2432 }
2433 }
2434
Colin Crossc99deeb2016-04-11 15:06:20 -07002435 return deps
2436}
2437
Colin Cross516c5452024-10-28 13:45:21 -07002438func checkConflictingExplicitVersions(libs []string) error {
2439 withoutVersion := func(s string) string {
2440 name, _ := StubsLibNameAndVersion(s)
2441 return name
2442 }
2443 var errs []error
2444 for i, lib := range libs {
2445 libName := withoutVersion(lib)
2446 libsToCompare := libs[i+1:]
2447 j := slices.IndexFunc(libsToCompare, func(s string) bool {
2448 return withoutVersion(s) == libName
2449 })
2450 if j >= 0 {
2451 errs = append(errs, fmt.Errorf("duplicate shared libraries with different explicit versions: %q and %q",
2452 lib, libsToCompare[j]))
2453 }
2454 }
2455 return errors.Join(errs...)
2456}
2457
Dan Albert7e9d2952016-08-04 13:02:36 -07002458func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08002459 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07002460 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08002461 moduleContextImpl: moduleContextImpl{
2462 mod: c,
2463 },
2464 }
2465 ctx.ctx = ctx
2466
Colin Crossca860ac2016-01-04 14:34:37 -08002467 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07002468}
2469
Jiyong Park7ed9de32018-10-15 22:25:07 +09002470// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09002471func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09002472 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
2473 version := name[sharp+1:]
2474 libname := name[:sharp]
2475 return libname, version
2476 }
2477 return name, ""
2478}
2479
Dan Albert92fe7402020-07-15 13:33:30 -07002480func GetCrtVariations(ctx android.BottomUpMutatorContext,
2481 m LinkableInterface) []blueprint.Variation {
2482 if ctx.Os() != android.Android {
2483 return nil
2484 }
2485 if m.UseSdk() {
Jiyong Parkfdaa5f72021-03-19 22:18:04 +09002486 // Choose the CRT that best satisfies the min_sdk_version requirement of this module
2487 minSdkVersion := m.MinSdkVersion()
2488 if minSdkVersion == "" || minSdkVersion == "apex_inherit" {
2489 minSdkVersion = m.SdkVersion()
2490 }
Jooyung Han94a76ee2021-06-08 09:49:48 +09002491 apiLevel, err := android.ApiLevelFromUser(ctx, minSdkVersion)
2492 if err != nil {
2493 ctx.PropertyErrorf("min_sdk_version", err.Error())
2494 }
Colin Cross363ec762023-01-13 13:45:14 -08002495
2496 // Raise the minSdkVersion to the minimum supported for the architecture.
Colin Crossbb137a32023-01-26 09:54:42 -08002497 minApiForArch := MinApiForArch(ctx, m.Target().Arch.ArchType)
Colin Cross363ec762023-01-13 13:45:14 -08002498 if apiLevel.LessThan(minApiForArch) {
2499 apiLevel = minApiForArch
2500 }
2501
Dan Albert92fe7402020-07-15 13:33:30 -07002502 return []blueprint.Variation{
2503 {Mutator: "sdk", Variation: "sdk"},
Jooyung Han94a76ee2021-06-08 09:49:48 +09002504 {Mutator: "version", Variation: apiLevel.String()},
Dan Albert92fe7402020-07-15 13:33:30 -07002505 }
2506 }
2507 return []blueprint.Variation{
2508 {Mutator: "sdk", Variation: ""},
2509 }
2510}
2511
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002512func AddSharedLibDependenciesWithVersions(ctx android.BottomUpMutatorContext, mod LinkableInterface,
2513 variations []blueprint.Variation, depTag blueprint.DependencyTag, name, version string, far bool) {
Colin Crosse7257d22020-09-24 09:56:18 -07002514
2515 variations = append([]blueprint.Variation(nil), variations...)
2516
Liz Kammer23942242022-04-08 15:41:00 -04002517 if version != "" && canBeOrLinkAgainstVersionVariants(mod) {
Colin Crosse7257d22020-09-24 09:56:18 -07002518 // Version is explicitly specified. i.e. libFoo#30
Colin Crossb614cd42024-10-11 12:52:21 -07002519 if version == "impl" {
2520 version = ""
2521 }
Colin Crosse7257d22020-09-24 09:56:18 -07002522 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002523 if tag, ok := depTag.(libraryDependencyTag); ok {
2524 tag.explicitlyVersioned = true
Colin Crossafcdce82024-10-22 13:59:33 -07002525 // depTag is an interface that contains a concrete non-pointer struct. That makes the local
2526 // tag variable a copy of the contents of depTag, and updating it doesn't change depTag. Reassign
2527 // the modified copy to depTag.
2528 depTag = tag
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002529 } else {
2530 panic(fmt.Errorf("Unexpected dependency tag: %T", depTag))
2531 }
Colin Crosse7257d22020-09-24 09:56:18 -07002532 }
Colin Crosse7257d22020-09-24 09:56:18 -07002533
Colin Cross0de8a1e2020-09-18 14:15:30 -07002534 if far {
2535 ctx.AddFarVariationDependencies(variations, depTag, name)
2536 } else {
2537 ctx.AddVariationDependencies(variations, depTag, name)
Colin Crosse7257d22020-09-24 09:56:18 -07002538 }
2539}
2540
Kiyoung Kim487689e2022-07-26 09:48:22 +09002541func GetReplaceModuleName(lib string, replaceMap map[string]string) string {
2542 if snapshot, ok := replaceMap[lib]; ok {
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002543 return snapshot
2544 }
2545
2546 return lib
2547}
2548
Kiyoung Kim37693d02024-04-04 09:56:15 +09002549// FilterNdkLibs takes a list of names of shared libraries and scans it for two types
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002550// of names:
2551//
Kiyoung Kim37693d02024-04-04 09:56:15 +09002552// 1. Name of an NDK library that refers to an ndk_library module.
Kiyoung Kim487689e2022-07-26 09:48:22 +09002553//
2554// For each of these, it adds the name of the ndk_library module to the list of
2555// variant libs.
2556//
Kiyoung Kim37693d02024-04-04 09:56:15 +09002557// 2. Anything else (so anything that isn't an NDK library).
Kiyoung Kim487689e2022-07-26 09:48:22 +09002558//
2559// It adds these to the nonvariantLibs list.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002560//
2561// The caller can then know to add the variantLibs dependencies differently from the
2562// nonvariantLibs
Kiyoung Kim37693d02024-04-04 09:56:15 +09002563func FilterNdkLibs(c LinkableInterface, config android.Config, list []string) (nonvariantLibs []string, variantLibs []string) {
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002564 variantLibs = []string{}
2565
2566 nonvariantLibs = []string{}
2567 for _, entry := range list {
2568 // strip #version suffix out
2569 name, _ := StubsLibNameAndVersion(entry)
Kiyoung Kim37693d02024-04-04 09:56:15 +09002570 if c.UseSdk() && inList(name, *getNDKKnownLibs(config)) {
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002571 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002572 } else {
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002573 nonvariantLibs = append(nonvariantLibs, entry)
2574 }
2575 }
2576 return nonvariantLibs, variantLibs
Kiyoung Kim37693d02024-04-04 09:56:15 +09002577
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002578}
2579
Kiyoung Kimd5d1ab12022-11-28 16:47:10 +09002580func rewriteLibsForApiImports(c LinkableInterface, libs []string, replaceList map[string]string, config android.Config) ([]string, []string) {
2581 nonVariantLibs := []string{}
2582 variantLibs := []string{}
2583
2584 for _, lib := range libs {
2585 replaceLibName := GetReplaceModuleName(lib, replaceList)
2586 if replaceLibName == lib {
2587 // Do not handle any libs which are not in API imports
2588 nonVariantLibs = append(nonVariantLibs, replaceLibName)
2589 } else if c.UseSdk() && inList(replaceLibName, *getNDKKnownLibs(config)) {
2590 variantLibs = append(variantLibs, replaceLibName)
2591 } else {
2592 nonVariantLibs = append(nonVariantLibs, replaceLibName)
2593 }
Kiyoung Kim487689e2022-07-26 09:48:22 +09002594 }
2595
Kiyoung Kimd5d1ab12022-11-28 16:47:10 +09002596 return nonVariantLibs, variantLibs
Kiyoung Kim487689e2022-07-26 09:48:22 +09002597}
2598
Kiyoung Kim76b06f32023-02-06 22:08:13 +09002599func (c *Module) shouldUseApiSurface() bool {
2600 if c.Os() == android.Android && c.Target().NativeBridge != android.NativeBridgeEnabled {
2601 if GetImageVariantType(c) == vendorImageVariant || GetImageVariantType(c) == productImageVariant {
2602 // LLNDK Variant
2603 return true
2604 }
2605
2606 if c.Properties.IsSdkVariant {
2607 // NDK Variant
2608 return true
2609 }
Kiyoung Kim76b06f32023-02-06 22:08:13 +09002610 }
2611
2612 return false
2613}
2614
Colin Cross1e676be2016-10-12 14:38:15 -07002615func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Cole Fausta963b942024-04-11 17:43:00 -07002616 if !c.Enabled(actx) {
Inseob Kimeec88e12020-01-22 11:11:29 +09002617 return
2618 }
2619
Colin Cross37047f12016-12-13 17:06:13 -08002620 ctx := &depsContext{
2621 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07002622 moduleContextImpl: moduleContextImpl{
2623 mod: c,
2624 },
2625 }
2626 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08002627
Colin Crossc99deeb2016-04-11 15:06:20 -07002628 deps := c.deps(ctx)
Kiyoung Kim11d91082022-10-19 19:20:57 +09002629
Kiyoung Kimd5d1ab12022-11-28 16:47:10 +09002630 apiNdkLibs := []string{}
2631 apiLateNdkLibs := []string{}
2632
Yo Chiang219968c2020-09-22 18:45:04 +08002633 c.Properties.AndroidMkSystemSharedLibs = deps.SystemSharedLibs
2634
Dan Albert914449f2016-06-17 16:45:24 -07002635 variantNdkLibs := []string{}
2636 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07002637 if ctx.Os() == android.Android {
Kiyoung Kim37693d02024-04-04 09:56:15 +09002638 deps.SharedLibs, variantNdkLibs = FilterNdkLibs(c, ctx.Config(), deps.SharedLibs)
2639 deps.LateSharedLibs, variantLateNdkLibs = FilterNdkLibs(c, ctx.Config(), deps.LateSharedLibs)
2640 deps.ReexportSharedLibHeaders, _ = FilterNdkLibs(c, ctx.Config(), deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07002641 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002642
Colin Cross32ec36c2016-12-15 07:39:51 -08002643 for _, lib := range deps.HeaderLibs {
Colin Cross8acea3e2024-12-12 14:53:30 -08002644 depTag := libraryDependencyTag{Kind: headerLibraryDependency}
Colin Cross32ec36c2016-12-15 07:39:51 -08002645 if inList(lib, deps.ReexportHeaderLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002646 depTag.reexportFlags = true
Colin Cross32ec36c2016-12-15 07:39:51 -08002647 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002648
Spandan Das73bcafc2022-08-18 23:26:00 +00002649 if c.isNDKStubLibrary() {
Jiyong Parkf8fab9b2024-09-02 15:24:15 +09002650 variationExists := actx.OtherModuleDependencyVariantExists(nil, lib)
2651 if variationExists {
2652 actx.AddVariationDependencies(nil, depTag, lib)
2653 } else {
2654 // dependencies to ndk_headers fall here as ndk_headers do not have
2655 // any variants.
2656 actx.AddFarVariationDependencies([]blueprint.Variation{}, depTag, lib)
2657 }
Spandan Dasff665182024-09-11 18:48:44 +00002658 } else if c.IsStubs() {
Colin Cross7228ecd2019-11-18 16:00:16 -08002659 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07002660 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09002661 } else {
2662 actx.AddVariationDependencies(nil, depTag, lib)
2663 }
2664 }
2665
Dan Albertf1d14c72020-07-30 14:32:55 -07002666 if c.isNDKStubLibrary() {
2667 // NDK stubs depend on their implementation because the ABI dumps are
2668 // generated from the implementation library.
Kiyoung Kim487689e2022-07-26 09:48:22 +09002669
Spandan Das8b08aea2023-03-14 19:29:34 +00002670 actx.AddFarVariationDependencies(append(ctx.Target().Variations(),
2671 c.ImageVariation(),
2672 blueprint.Variation{Mutator: "link", Variation: "shared"},
2673 ), stubImplementation, c.BaseModuleName())
Dan Albertf1d14c72020-07-30 14:32:55 -07002674 }
2675
Hsin-Yi Chen715142a2024-03-27 16:31:16 +08002676 // If this module is an LLNDK implementation library, let it depend on LlndkHeaderLibs.
2677 if c.ImageVariation().Variation == android.CoreVariation && c.Device() &&
2678 c.Target().NativeBridge == android.NativeBridgeDisabled {
2679 actx.AddVariationDependencies(
Jihoon Kang47e91842024-06-19 00:51:16 +00002680 []blueprint.Variation{{Mutator: "image", Variation: android.VendorVariation}},
Hsin-Yi Chen715142a2024-03-27 16:31:16 +08002681 llndkHeaderLibTag,
2682 deps.LlndkHeaderLibs...)
2683 }
2684
Jiyong Park5d1598f2019-02-25 22:14:17 +09002685 for _, lib := range deps.WholeStaticLibs {
Colin Cross8acea3e2024-12-12 14:53:30 -08002686 depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
Inseob Kimeec88e12020-01-22 11:11:29 +09002687
Jiyong Park5d1598f2019-02-25 22:14:17 +09002688 actx.AddVariationDependencies([]blueprint.Variation{
2689 {Mutator: "link", Variation: "static"},
2690 }, depTag, lib)
2691 }
2692
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002693 for _, lib := range deps.StaticLibs {
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04002694 // Some dependencies listed in static_libs might actually be rust_ffi rlib variants.
Colin Cross8acea3e2024-12-12 14:53:30 -08002695 depTag := libraryDependencyTag{Kind: staticLibraryDependency}
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04002696
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002697 if inList(lib, deps.ReexportStaticLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002698 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002699 }
Jiyong Parke3867542020-12-03 17:28:25 +09002700 if inList(lib, deps.ExcludeLibsForApex) {
2701 depTag.excludeInApex = true
2702 }
Dan Willemsen59339a22018-07-22 21:18:45 -07002703 actx.AddVariationDependencies([]blueprint.Variation{
2704 {Mutator: "link", Variation: "static"},
2705 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002706 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002707
Jooyung Han75568392020-03-20 04:29:24 +09002708 // staticUnwinderDep is treated as staticDep for Q apexes
2709 // so that native libraries/binaries are linked with static unwinder
2710 // because Q libc doesn't have unwinder APIs
2711 if deps.StaticUnwinderIfLegacy {
Colin Cross8acea3e2024-12-12 14:53:30 -08002712 depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002713 actx.AddVariationDependencies([]blueprint.Variation{
2714 {Mutator: "link", Variation: "static"},
Kiyoung Kim37693d02024-04-04 09:56:15 +09002715 }, depTag, staticUnwinder(actx))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002716 }
2717
Jiyong Park7ed9de32018-10-15 22:25:07 +09002718 // shared lib names without the #version suffix
2719 var sharedLibNames []string
2720
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002721 for _, lib := range deps.SharedLibs {
Colin Cross8acea3e2024-12-12 14:53:30 -08002722 depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002723 if inList(lib, deps.ReexportSharedLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002724 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002725 }
Jiyong Parke3867542020-12-03 17:28:25 +09002726 if inList(lib, deps.ExcludeLibsForApex) {
2727 depTag.excludeInApex = true
2728 }
Jooyung Han9ffbe832023-11-28 22:31:35 +09002729 if inList(lib, deps.ExcludeLibsForNonApex) {
2730 depTag.excludeInNonApex = true
2731 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002732
Jiyong Park73c54ee2019-10-22 20:31:18 +09002733 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09002734 sharedLibNames = append(sharedLibNames, name)
2735
Colin Crosse7257d22020-09-24 09:56:18 -07002736 variations := []blueprint.Variation{
2737 {Mutator: "link", Variation: "shared"},
2738 }
Spandan Dasff665182024-09-11 18:48:44 +00002739 AddSharedLibDependenciesWithVersions(ctx, c, variations, depTag, name, version, false)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002740 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002741
Colin Crossfe9acfe2021-06-14 16:13:03 -07002742 for _, lib := range deps.LateStaticLibs {
Colin Cross8acea3e2024-12-12 14:53:30 -08002743 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
Colin Crossfe9acfe2021-06-14 16:13:03 -07002744 actx.AddVariationDependencies([]blueprint.Variation{
2745 {Mutator: "link", Variation: "static"},
Kiyoung Kim37693d02024-04-04 09:56:15 +09002746 }, depTag, lib)
Colin Crossfe9acfe2021-06-14 16:13:03 -07002747 }
2748
Colin Cross3e5e7782022-06-17 22:17:05 +00002749 for _, lib := range deps.UnexportedStaticLibs {
Colin Cross8acea3e2024-12-12 14:53:30 -08002750 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency, unexportedSymbols: true}
Colin Cross3e5e7782022-06-17 22:17:05 +00002751 actx.AddVariationDependencies([]blueprint.Variation{
2752 {Mutator: "link", Variation: "static"},
Kiyoung Kim37693d02024-04-04 09:56:15 +09002753 }, depTag, lib)
Colin Cross3e5e7782022-06-17 22:17:05 +00002754 }
2755
Jiyong Park7ed9de32018-10-15 22:25:07 +09002756 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002757 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09002758 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
2759 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
2760 // linking against both the stubs lib and the non-stubs lib at the same time.
2761 continue
2762 }
Colin Cross8acea3e2024-12-12 14:53:30 -08002763 depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
Colin Crosse7257d22020-09-24 09:56:18 -07002764 variations := []blueprint.Variation{
2765 {Mutator: "link", Variation: "shared"},
2766 }
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002767 AddSharedLibDependenciesWithVersions(ctx, c, variations, depTag, lib, "", false)
Jiyong Park7ed9de32018-10-15 22:25:07 +09002768 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002769
Dan Willemsen59339a22018-07-22 21:18:45 -07002770 actx.AddVariationDependencies([]blueprint.Variation{
2771 {Mutator: "link", Variation: "shared"},
Chris Parsons79d66a52020-06-05 17:26:16 -04002772 }, dataLibDepTag, deps.DataLibs...)
2773
Colin Crossc8caa062021-09-24 16:50:14 -07002774 actx.AddVariationDependencies(nil, dataBinDepTag, deps.DataBins...)
2775
Chris Parsons79d66a52020-06-05 17:26:16 -04002776 actx.AddVariationDependencies([]blueprint.Variation{
2777 {Mutator: "link", Variation: "shared"},
Dan Willemsen59339a22018-07-22 21:18:45 -07002778 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08002779
Colin Cross68861832016-07-08 10:41:41 -07002780 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002781
2782 for _, gen := range deps.GeneratedHeaders {
2783 depTag := genHeaderDepTag
2784 if inList(gen, deps.ReexportGeneratedHeaders) {
2785 depTag = genHeaderExportDepTag
2786 }
2787 actx.AddDependency(c, depTag, gen)
2788 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002789
Cole Faust65cb40a2024-10-21 15:41:42 -07002790 for _, gen := range deps.DeviceFirstGeneratedHeaders {
2791 depTag := genHeaderDepTag
2792 actx.AddVariationDependencies(ctx.Config().AndroidFirstDeviceTarget.Variations(), depTag, gen)
2793 }
2794
Dan Albert92fe7402020-07-15 13:33:30 -07002795 crtVariations := GetCrtVariations(ctx, c)
Colin Crossbbc941b2020-09-30 12:27:01 -07002796 actx.AddVariationDependencies(crtVariations, objDepTag, deps.ObjFiles...)
Colin Crossc465efd2021-06-11 18:00:04 -07002797 for _, crt := range deps.CrtBegin {
Dan Albert92fe7402020-07-15 13:33:30 -07002798 actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
Kiyoung Kim37693d02024-04-04 09:56:15 +09002799 crt)
Colin Crossca860ac2016-01-04 14:34:37 -08002800 }
Colin Crossc465efd2021-06-11 18:00:04 -07002801 for _, crt := range deps.CrtEnd {
Dan Albert92fe7402020-07-15 13:33:30 -07002802 actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
Kiyoung Kim37693d02024-04-04 09:56:15 +09002803 crt)
Colin Cross21b9a242015-03-24 14:15:58 -07002804 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002805 if deps.DynamicLinker != "" {
2806 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002807 }
Dan Albert914449f2016-06-17 16:45:24 -07002808
2809 version := ctx.sdkVersion()
Colin Cross6e511a92020-07-27 21:26:48 -07002810
Colin Cross8acea3e2024-12-12 14:53:30 -08002811 ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002812 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross5ec407b2020-09-30 11:41:33 -07002813 {Mutator: "version", Variation: version},
Dan Willemsen59339a22018-07-22 21:18:45 -07002814 {Mutator: "link", Variation: "shared"},
2815 }, ndkStubDepTag, variantNdkLibs...)
Kiyoung Kimd5d1ab12022-11-28 16:47:10 +09002816 actx.AddVariationDependencies([]blueprint.Variation{
2817 {Mutator: "version", Variation: version},
2818 {Mutator: "link", Variation: "shared"},
2819 }, ndkStubDepTag, apiNdkLibs...)
Colin Cross6e511a92020-07-27 21:26:48 -07002820
Colin Cross8acea3e2024-12-12 14:53:30 -08002821 ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002822 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross5ec407b2020-09-30 11:41:33 -07002823 {Mutator: "version", Variation: version},
Dan Willemsen59339a22018-07-22 21:18:45 -07002824 {Mutator: "link", Variation: "shared"},
2825 }, ndkLateStubDepTag, variantLateNdkLibs...)
Kiyoung Kimd5d1ab12022-11-28 16:47:10 +09002826 actx.AddVariationDependencies([]blueprint.Variation{
2827 {Mutator: "version", Variation: version},
2828 {Mutator: "link", Variation: "shared"},
2829 }, ndkLateStubDepTag, apiLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002830
Vinh Tran367d89d2023-04-28 11:21:25 -04002831 if len(deps.AidlLibs) > 0 {
2832 actx.AddDependency(
2833 c,
2834 aidlLibraryTag,
2835 deps.AidlLibs...,
2836 )
2837 }
2838
Colin Cross6362e272015-10-29 15:25:03 -07002839}
Colin Cross21b9a242015-03-24 14:15:58 -07002840
Colin Crosse40b4ea2018-10-02 22:25:58 -07002841func BeginMutator(ctx android.BottomUpMutatorContext) {
Cole Fausta963b942024-04-11 17:43:00 -07002842 if c, ok := ctx.Module().(*Module); ok && c.Enabled(ctx) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002843 c.beginMutator(ctx)
2844 }
2845}
2846
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002847// Whether a module can link to another module, taking into
2848// account NDK linking.
Jooyung Han479ca172020-10-19 18:51:07 +09002849func checkLinkType(ctx android.BaseModuleContext, from LinkableInterface, to LinkableInterface,
Colin Cross6e511a92020-07-27 21:26:48 -07002850 tag blueprint.DependencyTag) {
2851
2852 switch t := tag.(type) {
2853 case dependencyTag:
2854 if t != vndkExtDepTag {
2855 return
2856 }
2857 case libraryDependencyTag:
2858 default:
2859 return
2860 }
2861
Ivan Lozanof9e21722020-12-02 09:00:51 -05002862 if from.Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002863 // Host code is not restricted
2864 return
2865 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002866
Ivan Lozano52767be2019-10-18 14:49:46 -07002867 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002868 // Platform code can link to anything
2869 return
2870 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002871 if from.InRamdisk() {
2872 // Ramdisk code is not NDK
2873 return
2874 }
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002875 if from.InVendorRamdisk() {
2876 // Vendor ramdisk code is not NDK
2877 return
2878 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002879 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002880 // Recovery code is not NDK
2881 return
2882 }
Colin Cross31076b32020-10-23 17:22:06 -07002883 if c, ok := to.(*Module); ok {
Colin Cross31076b32020-10-23 17:22:06 -07002884 if c.StubDecorator() {
2885 // These aren't real libraries, but are the stub shared libraries that are included in
2886 // the NDK.
2887 return
2888 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002889 }
Logan Chien834b9a62019-01-14 15:39:03 +08002890
Ivan Lozano52767be2019-10-18 14:49:46 -07002891 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002892 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2893 // to link to libc++ (non-NDK and without sdk_version).
2894 return
2895 }
2896
Ivan Lozano52767be2019-10-18 14:49:46 -07002897 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002898 // NDK code linking to platform code is never okay.
2899 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002900 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002901 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002902 }
2903
2904 // At this point we know we have two NDK libraries, but we need to
2905 // check that we're not linking against anything built against a higher
2906 // API level, as it is only valid to link against older or equivalent
2907 // APIs.
2908
Inseob Kim01a28722018-04-11 09:48:45 +09002909 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002910 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002911 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002912 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002913 // Current can't be linked against by anything else.
2914 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002915 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002916 } else {
Prashanth Swaminathan6dcbd9c2023-07-18 17:55:01 -07002917 fromApi, err := android.ApiLevelFromUserWithConfig(ctx.Config(), from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002918 if err != nil {
2919 ctx.PropertyErrorf("sdk_version",
Prashanth Swaminathan6dcbd9c2023-07-18 17:55:01 -07002920 "Invalid sdk_version value (must be int, preview or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002921 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002922 }
Prashanth Swaminathan6dcbd9c2023-07-18 17:55:01 -07002923 toApi, err := android.ApiLevelFromUserWithConfig(ctx.Config(), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002924 if err != nil {
2925 ctx.PropertyErrorf("sdk_version",
Prashanth Swaminathan6dcbd9c2023-07-18 17:55:01 -07002926 "Invalid sdk_version value (must be int, preview or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002927 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002928 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002929
Prashanth Swaminathan6dcbd9c2023-07-18 17:55:01 -07002930 if toApi.GreaterThan(fromApi) {
Inseob Kim01a28722018-04-11 09:48:45 +09002931 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002932 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002933 }
2934 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002935 }
Dan Albert202fe492017-12-15 13:56:59 -08002936
2937 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002938 fromStl := from.SelectedStl()
2939 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002940 if fromStl == "" || toStl == "" {
2941 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002942 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002943 // We can be permissive with the system "STL" since it is only the C++
2944 // ABI layer, but in the future we should make sure that everyone is
2945 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002946 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002947 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002948 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2949 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002950 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002951}
2952
Jooyung Han479ca172020-10-19 18:51:07 +09002953func checkLinkTypeMutator(ctx android.BottomUpMutatorContext) {
2954 if c, ok := ctx.Module().(*Module); ok {
2955 ctx.VisitDirectDeps(func(dep android.Module) {
2956 depTag := ctx.OtherModuleDependencyTag(dep)
2957 ccDep, ok := dep.(LinkableInterface)
2958 if ok {
2959 checkLinkType(ctx, c, ccDep, depTag)
2960 }
2961 })
2962 }
2963}
2964
Jiyong Park5fb8c102018-04-09 12:03:06 +09002965// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002966// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2967// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002968// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Colin Crossda279cf2024-09-17 14:25:45 -07002969func checkDoubleLoadableLibraries(ctx android.BottomUpMutatorContext) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002970 check := func(child, parent android.Module) bool {
2971 to, ok := child.(*Module)
2972 if !ok {
Jooyung Han479ca172020-10-19 18:51:07 +09002973 return false
Jooyung Hana70f0672019-01-18 15:20:43 +09002974 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002975
Jooyung Hana70f0672019-01-18 15:20:43 +09002976 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2977 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002978 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002979
Jiyong Park0474e1f2021-01-14 14:26:06 +09002980 // These dependencies are not excercised at runtime. Tracking these will give us
2981 // false negative, so skip.
Jiyong Park1ad8e162020-12-01 23:40:09 +09002982 depTag := ctx.OtherModuleDependencyTag(child)
2983 if IsHeaderDepTag(depTag) {
2984 return false
2985 }
Jiyong Park0474e1f2021-01-14 14:26:06 +09002986 if depTag == staticVariantTag {
2987 return false
2988 }
2989 if depTag == stubImplDepTag {
2990 return false
2991 }
Jiyong Park8bcf3c62024-03-18 18:37:10 +09002992 if depTag == android.RequiredDepTag {
2993 return false
2994 }
Jiyong Park1ad8e162020-12-01 23:40:09 +09002995
Justin Yun63e9ec72020-10-29 16:49:43 +09002996 // Even if target lib has no vendor variant, keep checking dependency
2997 // graph in case it depends on vendor_available or product_available
2998 // but not double_loadable transtively.
2999 if !to.HasNonSystemVariants() {
Jooyung Hana70f0672019-01-18 15:20:43 +09003000 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09003001 }
Jooyung Hana70f0672019-01-18 15:20:43 +09003002
Jiyong Park0474e1f2021-01-14 14:26:06 +09003003 // The happy path. Keep tracking dependencies until we hit a non double-loadable
3004 // one.
3005 if Bool(to.VendorProperties.Double_loadable) {
3006 return true
3007 }
3008
Kiyoung Kim9f26fcf2024-05-27 17:25:52 +09003009 if to.IsLlndk() {
Jooyung Hana70f0672019-01-18 15:20:43 +09003010 return false
3011 }
3012
Jooyung Hana70f0672019-01-18 15:20:43 +09003013 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
3014 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
Jiyong Park0474e1f2021-01-14 14:26:06 +09003015 "Dependency list: %s", ctx.OtherModuleName(to), ctx.GetPathString(false))
Jooyung Hana70f0672019-01-18 15:20:43 +09003016 return false
3017 }
3018 if module, ok := ctx.Module().(*Module); ok {
3019 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jiyong Park0474e1f2021-01-14 14:26:06 +09003020 if lib.hasLLNDKStubs() {
Jooyung Hana70f0672019-01-18 15:20:43 +09003021 ctx.WalkDeps(check)
3022 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09003023 }
3024 }
3025}
3026
Yu Liue4312402023-01-18 09:15:31 -08003027func findApexSdkVersion(ctx android.BaseModuleContext, apexInfo android.ApexInfo) android.ApiLevel {
3028 // For the dependency from platform to apex, use the latest stubs
3029 apexSdkVersion := android.FutureApiLevel
3030 if !apexInfo.IsForPlatform() {
3031 apexSdkVersion = apexInfo.MinSdkVersion
3032 }
3033
3034 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
3035 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
3036 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
3037 // (b/144430859)
3038 apexSdkVersion = android.FutureApiLevel
3039 }
3040
3041 return apexSdkVersion
3042}
3043
Colin Crossc99deeb2016-04-11 15:06:20 -07003044// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07003045func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08003046 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08003047
Colin Cross0de8a1e2020-09-18 14:15:30 -07003048 var directStaticDeps []StaticLibraryInfo
3049 var directSharedDeps []SharedLibraryInfo
Jeff Gaston294356f2017-09-27 17:05:30 -07003050
Colin Cross0de8a1e2020-09-18 14:15:30 -07003051 reexportExporter := func(exporter FlagExporterInfo) {
3052 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.IncludeDirs...)
3053 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.SystemIncludeDirs...)
3054 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.Flags...)
3055 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.Deps...)
3056 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.GeneratedHeaders...)
Inseob Kim69378442019-06-03 19:10:47 +09003057 }
3058
Colin Crossff694a82023-12-13 15:54:49 -08003059 apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
Yu Liue4312402023-01-18 09:15:31 -08003060 c.apexSdkVersion = findApexSdkVersion(ctx, apexInfo)
Jooyung Hande34d232020-07-23 13:04:15 +09003061
Kiyoung Kim76b06f32023-02-06 22:08:13 +09003062 skipModuleList := map[string]bool{}
3063
Colin Crossd11fcda2017-10-23 17:59:01 -07003064 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07003065 depName := ctx.OtherModuleName(dep)
3066 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07003067
Kiyoung Kim76b06f32023-02-06 22:08:13 +09003068 if _, ok := skipModuleList[depName]; ok {
3069 // skip this module because original module or API imported module matching with this should be used instead.
3070 return
3071 }
3072
Dan Willemsen47450072021-10-19 20:24:49 -07003073 if depTag == android.DarwinUniversalVariantTag {
3074 depPaths.DarwinSecondArchOutput = dep.(*Module).OutputFile()
3075 return
3076 }
3077
Vinh Tran367d89d2023-04-28 11:21:25 -04003078 if depTag == aidlLibraryTag {
Colin Cross313aa542023-12-13 13:47:44 -08003079 if aidlLibraryInfo, ok := android.OtherModuleProvider(ctx, dep, aidl_library.AidlLibraryProvider); ok {
Vinh Tran367d89d2023-04-28 11:21:25 -04003080 depPaths.AidlLibraryInfos = append(
3081 depPaths.AidlLibraryInfos,
Colin Cross313aa542023-12-13 13:47:44 -08003082 aidlLibraryInfo,
Vinh Tran367d89d2023-04-28 11:21:25 -04003083 )
3084 }
3085 }
3086
Ivan Lozano52767be2019-10-18 14:49:46 -07003087 ccDep, ok := dep.(LinkableInterface)
3088 if !ok {
3089
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07003090 // handling for a few module types that aren't cc Module but that are also supported
3091 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07003092 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07003093 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07003094 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
3095 genRule.GeneratedSourceFiles()...)
3096 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07003097 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07003098 }
Colin Crosse90bfd12017-04-26 16:59:26 -07003099 // Support exported headers from a generated_sources dependency
3100 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07003101 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07003102 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09003103 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08003104 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09003105 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09003106 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07003107 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09003108 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09003109 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
3110 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09003111 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07003112 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
Jiyong Park74955042019-10-22 20:19:51 +09003113 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07003114
Dan Willemsenb3454ab2016-09-28 17:34:58 -07003115 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07003116 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07003117 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07003118 }
Colin Crosscef792e2021-06-11 18:01:26 -07003119 case CrtBeginDepTag:
3120 depPaths.CrtBegin = append(depPaths.CrtBegin, android.OutputFileForModule(ctx, dep, ""))
3121 case CrtEndDepTag:
3122 depPaths.CrtEnd = append(depPaths.CrtEnd, android.OutputFileForModule(ctx, dep, ""))
Colin Crossca860ac2016-01-04 14:34:37 -08003123 }
Colin Crossc99deeb2016-04-11 15:06:20 -07003124 return
3125 }
3126
Colin Crossfe17f6f2019-03-28 19:30:56 -07003127 if depTag == android.ProtoPluginDepTag {
3128 return
3129 }
3130
Jiyong Park8bcf3c62024-03-18 18:37:10 +09003131 if depTag == android.RequiredDepTag {
3132 return
3133 }
3134
Colin Crossd11fcda2017-10-23 17:59:01 -07003135 if dep.Target().Os != ctx.Os() {
Steven Morelandaaae81f2024-08-27 22:55:48 +00003136 ctx.ModuleErrorf("OS mismatch between %q (%s) and %q (%s)", ctx.ModuleName(), ctx.Os().Name, depName, dep.Target().Os.Name)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07003137 return
3138 }
Colin Crossd11fcda2017-10-23 17:59:01 -07003139 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00003140 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
3141 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07003142 return
3143 }
3144
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07003145 if depTag == reuseObjTag {
Colin Crossa717db72020-10-23 14:53:06 -07003146 // Skip reused objects for stub libraries, they use their own stub object file instead.
3147 // The reuseObjTag dependency still exists because the LinkageMutator runs before the
3148 // version mutator, so the stubs variant is created from the shared variant that
3149 // already has the reuseObjTag dependency on the static variant.
Colin Cross31076b32020-10-23 17:22:06 -07003150 if !c.library.buildStubs() {
Colin Cross313aa542023-12-13 13:47:44 -08003151 staticAnalogue, _ := android.OtherModuleProvider(ctx, dep, StaticLibraryInfoProvider)
Colin Crossa717db72020-10-23 14:53:06 -07003152 objs := staticAnalogue.ReuseObjects
3153 depPaths.Objs = depPaths.Objs.Append(objs)
Colin Cross313aa542023-12-13 13:47:44 -08003154 depExporterInfo, _ := android.OtherModuleProvider(ctx, dep, FlagExporterInfoProvider)
Colin Crossa717db72020-10-23 14:53:06 -07003155 reexportExporter(depExporterInfo)
3156 }
Colin Cross0de8a1e2020-09-18 14:15:30 -07003157 return
Jiyong Parke4bb9862019-02-01 00:31:10 +09003158 }
3159
Hsin-Yi Chen715142a2024-03-27 16:31:16 +08003160 if depTag == llndkHeaderLibTag {
3161 depExporterInfo, _ := android.OtherModuleProvider(ctx, dep, FlagExporterInfoProvider)
3162 depPaths.LlndkIncludeDirs = append(depPaths.LlndkIncludeDirs, depExporterInfo.IncludeDirs...)
3163 depPaths.LlndkSystemIncludeDirs = append(depPaths.LlndkSystemIncludeDirs, depExporterInfo.SystemIncludeDirs...)
3164 }
3165
Colin Cross6e511a92020-07-27 21:26:48 -07003166 linkFile := ccDep.OutputFile()
3167
3168 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
3169 // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
Dan Albertc8060532020-07-22 22:32:17 -07003170 if libDepTag.staticUnwinder && c.apexSdkVersion.GreaterThan(android.SdkVersion_Android10) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003171 return
3172 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003173
Jiyong Parke3867542020-12-03 17:28:25 +09003174 if !apexInfo.IsForPlatform() && libDepTag.excludeInApex {
3175 return
3176 }
Jooyung Han9ffbe832023-11-28 22:31:35 +09003177 if apexInfo.IsForPlatform() && libDepTag.excludeInNonApex {
3178 return
3179 }
Jiyong Parke3867542020-12-03 17:28:25 +09003180
Colin Cross313aa542023-12-13 13:47:44 -08003181 depExporterInfo, _ := android.OtherModuleProvider(ctx, dep, FlagExporterInfoProvider)
Colin Crossc99deeb2016-04-11 15:06:20 -07003182
Colin Cross6e511a92020-07-27 21:26:48 -07003183 var ptr *android.Paths
3184 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07003185
Colin Cross6e511a92020-07-27 21:26:48 -07003186 depFile := android.OptionalPath{}
Colin Cross26c34ed2016-09-30 17:10:16 -07003187
Colin Cross6e511a92020-07-27 21:26:48 -07003188 switch {
3189 case libDepTag.header():
Colin Cross313aa542023-12-13 13:47:44 -08003190 if _, isHeaderLib := android.OtherModuleProvider(ctx, dep, HeaderLibraryInfoProvider); !isHeaderLib {
Colin Cross649d8172020-12-10 12:30:21 -08003191 if !ctx.Config().AllowMissingDependencies() {
3192 ctx.ModuleErrorf("module %q is not a header library", depName)
3193 } else {
3194 ctx.AddMissingDependencies([]string{depName})
3195 }
3196 return
3197 }
Colin Cross6e511a92020-07-27 21:26:48 -07003198 case libDepTag.shared():
Colin Cross313aa542023-12-13 13:47:44 -08003199 if _, isSharedLib := android.OtherModuleProvider(ctx, dep, SharedLibraryInfoProvider); !isSharedLib {
Colin Cross0de8a1e2020-09-18 14:15:30 -07003200 if !ctx.Config().AllowMissingDependencies() {
3201 ctx.ModuleErrorf("module %q is not a shared library", depName)
3202 } else {
3203 ctx.AddMissingDependencies([]string{depName})
3204 }
3205 return
3206 }
Jiyong Parke3867542020-12-03 17:28:25 +09003207
Jiyong Park7d55b612021-06-11 17:22:09 +09003208 sharedLibraryInfo, returnedDepExporterInfo := ChooseStubOrImpl(ctx, dep)
3209 depExporterInfo = returnedDepExporterInfo
Colin Cross0de8a1e2020-09-18 14:15:30 -07003210
Jiyong Park1ad8e162020-12-01 23:40:09 +09003211 // Stubs lib doesn't link to the shared lib dependencies. Don't set
3212 // linkFile, depFile, and ptr.
3213 if c.IsStubs() {
3214 break
3215 }
3216
Colin Cross0de8a1e2020-09-18 14:15:30 -07003217 linkFile = android.OptionalPathForPath(sharedLibraryInfo.SharedLibrary)
3218 depFile = sharedLibraryInfo.TableOfContents
3219
Colin Crossb614cd42024-10-11 12:52:21 -07003220 if !sharedLibraryInfo.IsStubs {
3221 depPaths.directImplementationDeps = append(depPaths.directImplementationDeps, android.OutputFileForModule(ctx, dep, ""))
3222 if info, ok := android.OtherModuleProvider(ctx, dep, ImplementationDepInfoProvider); ok {
3223 depPaths.transitiveImplementationDeps = append(depPaths.transitiveImplementationDeps, info.ImplementationDeps)
3224 }
3225 }
3226
Colin Cross6e511a92020-07-27 21:26:48 -07003227 ptr = &depPaths.SharedLibs
3228 switch libDepTag.Order {
3229 case earlyLibraryDependency:
3230 ptr = &depPaths.EarlySharedLibs
3231 depPtr = &depPaths.EarlySharedLibsDeps
3232 case normalLibraryDependency:
3233 ptr = &depPaths.SharedLibs
3234 depPtr = &depPaths.SharedLibsDeps
Colin Cross0de8a1e2020-09-18 14:15:30 -07003235 directSharedDeps = append(directSharedDeps, sharedLibraryInfo)
Colin Cross6e511a92020-07-27 21:26:48 -07003236 case lateLibraryDependency:
3237 ptr = &depPaths.LateSharedLibs
3238 depPtr = &depPaths.LateSharedLibsDeps
3239 default:
3240 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Colin Crossc99deeb2016-04-11 15:06:20 -07003241 }
Ivan Lozano0a468a42024-05-13 21:03:34 -04003242
Colin Cross6e511a92020-07-27 21:26:48 -07003243 case libDepTag.static():
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04003244 if ccDep.RustLibraryInterface() {
3245 rlibDep := RustRlibDep{LibPath: linkFile.Path(), CrateName: ccDep.CrateName(), LinkDirs: ccDep.ExportedCrateLinkDirs()}
3246 depPaths.RustRlibDeps = append(depPaths.RustRlibDeps, rlibDep)
3247 depPaths.IncludeDirs = append(depPaths.IncludeDirs, depExporterInfo.IncludeDirs...)
3248 if libDepTag.wholeStatic {
3249 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, depExporterInfo.IncludeDirs...)
3250 depPaths.ReexportedRustRlibDeps = append(depPaths.ReexportedRustRlibDeps, rlibDep)
Jiyong Park1ad8e162020-12-01 23:40:09 +09003251
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04003252 // If whole_static, track this as we want to make sure that in a final linkage for a shared library,
3253 // exported functions from the rust generated staticlib still exported.
3254 if c.CcLibrary() && c.Shared() {
3255 c.WholeRustStaticlib = true
3256 }
Colin Cross6e511a92020-07-27 21:26:48 -07003257 }
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04003258
Colin Cross6e511a92020-07-27 21:26:48 -07003259 } else {
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04003260 staticLibraryInfo, isStaticLib := android.OtherModuleProvider(ctx, dep, StaticLibraryInfoProvider)
3261 if !isStaticLib {
3262 if !ctx.Config().AllowMissingDependencies() {
3263 ctx.ModuleErrorf("module %q is not a static library", depName)
3264 } else {
3265 ctx.AddMissingDependencies([]string{depName})
3266 }
3267 return
Inseob Kimeec88e12020-01-22 11:11:29 +09003268 }
Ivan Lozano0a468a42024-05-13 21:03:34 -04003269
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04003270 // Stubs lib doesn't link to the static lib dependencies. Don't set
3271 // linkFile, depFile, and ptr.
3272 if c.IsStubs() {
3273 break
3274 }
Ivan Lozano0a468a42024-05-13 21:03:34 -04003275
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04003276 linkFile = android.OptionalPathForPath(staticLibraryInfo.StaticLibrary)
3277 if libDepTag.wholeStatic {
3278 ptr = &depPaths.WholeStaticLibs
3279 if len(staticLibraryInfo.Objects.objFiles) > 0 {
3280 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLibraryInfo.Objects)
3281 } else {
3282 // This case normally catches prebuilt static
3283 // libraries, but it can also occur when
3284 // AllowMissingDependencies is on and the
3285 // dependencies has no sources of its own
3286 // but has a whole_static_libs dependency
3287 // on a missing library. We want to depend
3288 // on the .a file so that there is something
3289 // in the dependency tree that contains the
3290 // error rule for the missing transitive
3291 // dependency.
3292 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
3293 }
3294 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts,
3295 staticLibraryInfo.WholeStaticLibsFromPrebuilts...)
3296 } else {
3297 switch libDepTag.Order {
3298 case earlyLibraryDependency:
3299 panic(fmt.Errorf("early static libs not supported"))
3300 case normalLibraryDependency:
3301 // static dependencies will be handled separately so they can be ordered
3302 // using transitive dependencies.
3303 ptr = nil
3304 directStaticDeps = append(directStaticDeps, staticLibraryInfo)
3305 case lateLibraryDependency:
3306 ptr = &depPaths.LateStaticLibs
3307 default:
3308 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
3309 }
3310 }
3311
3312 // Collect any exported Rust rlib deps from static libraries which have been included as whole_static_libs
3313 depPaths.RustRlibDeps = append(depPaths.RustRlibDeps, depExporterInfo.RustRlibDeps...)
3314
3315 if libDepTag.unexportedSymbols {
3316 depPaths.LdFlags = append(depPaths.LdFlags,
3317 "-Wl,--exclude-libs="+staticLibraryInfo.StaticLibrary.Base())
3318 }
Colin Cross3e5e7782022-06-17 22:17:05 +00003319 }
Inseob Kimeec88e12020-01-22 11:11:29 +09003320 }
3321
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04003322 if libDepTag.static() && !libDepTag.wholeStatic && !ccDep.RustLibraryInterface() {
Colin Cross6e511a92020-07-27 21:26:48 -07003323 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
3324 ctx.ModuleErrorf("module %q not a static library", depName)
3325 return
3326 }
Logan Chien43d34c32017-12-20 01:17:32 +08003327
Colin Cross6e511a92020-07-27 21:26:48 -07003328 // When combining coverage files for shared libraries and executables, coverage files
3329 // in static libraries act as if they were whole static libraries. The same goes for
3330 // source based Abi dump files.
3331 if c, ok := ccDep.(*Module); ok {
3332 staticLib := c.linker.(libraryInterface)
3333 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
3334 staticLib.objs().coverageFiles...)
3335 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
3336 staticLib.objs().sAbiDumpFiles...)
Colin Cross0de8a1e2020-09-18 14:15:30 -07003337 } else {
Colin Cross6e511a92020-07-27 21:26:48 -07003338 // Handle non-CC modules here
3339 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
Colin Cross0de8a1e2020-09-18 14:15:30 -07003340 ccDep.CoverageFiles()...)
Jiyong Parkde866cb2018-12-07 23:08:36 +09003341 }
3342 }
3343
Colin Cross6e511a92020-07-27 21:26:48 -07003344 if ptr != nil {
3345 if !linkFile.Valid() {
3346 if !ctx.Config().AllowMissingDependencies() {
3347 ctx.ModuleErrorf("module %q missing output file", depName)
3348 } else {
3349 ctx.AddMissingDependencies([]string{depName})
3350 }
3351 return
3352 }
3353 *ptr = append(*ptr, linkFile.Path())
3354 }
3355
3356 if depPtr != nil {
3357 dep := depFile
3358 if !dep.Valid() {
3359 dep = linkFile
3360 }
3361 *depPtr = append(*depPtr, dep.Path())
3362 }
3363
Colin Cross0de8a1e2020-09-18 14:15:30 -07003364 depPaths.IncludeDirs = append(depPaths.IncludeDirs, depExporterInfo.IncludeDirs...)
3365 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, depExporterInfo.SystemIncludeDirs...)
3366 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, depExporterInfo.Deps...)
3367 depPaths.Flags = append(depPaths.Flags, depExporterInfo.Flags...)
Ivan Lozano0a468a42024-05-13 21:03:34 -04003368 depPaths.RustRlibDeps = append(depPaths.RustRlibDeps, depExporterInfo.RustRlibDeps...)
3369
3370 // Only re-export RustRlibDeps for cc static libs
3371 if c.static() {
3372 depPaths.ReexportedRustRlibDeps = append(depPaths.ReexportedRustRlibDeps, depExporterInfo.RustRlibDeps...)
3373 }
Colin Cross0de8a1e2020-09-18 14:15:30 -07003374
3375 if libDepTag.reexportFlags {
3376 reexportExporter(depExporterInfo)
3377 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
3378 // Re-exported shared library headers must be included as well since they can help us with type information
3379 // about template instantiations (instantiated from their headers).
Colin Cross0de8a1e2020-09-18 14:15:30 -07003380 c.sabi.Properties.ReexportedIncludes = append(
3381 c.sabi.Properties.ReexportedIncludes, depExporterInfo.IncludeDirs.Strings()...)
Hsin-Yi Chen5f228b02024-04-02 12:38:47 +08003382 c.sabi.Properties.ReexportedSystemIncludes = append(
3383 c.sabi.Properties.ReexportedSystemIncludes, depExporterInfo.SystemIncludeDirs.Strings()...)
Colin Cross0de8a1e2020-09-18 14:15:30 -07003384 }
3385
Spandan Das3faa7922024-02-26 19:42:32 +00003386 makeLibName := MakeLibName(ctx, c, ccDep, ccDep.BaseModuleName()) + libDepTag.makeSuffix
Colin Cross6e511a92020-07-27 21:26:48 -07003387 switch {
3388 case libDepTag.header():
Colin Cross370173e2020-07-29 12:48:33 -07003389 c.Properties.AndroidMkHeaderLibs = append(
3390 c.Properties.AndroidMkHeaderLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07003391 case libDepTag.shared():
Colin Cross6e511a92020-07-27 21:26:48 -07003392 // Note: the order of libs in this list is not important because
3393 // they merely serve as Make dependencies and do not affect this lib itself.
Colin Cross370173e2020-07-29 12:48:33 -07003394 c.Properties.AndroidMkSharedLibs = append(
3395 c.Properties.AndroidMkSharedLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07003396 case libDepTag.static():
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04003397 if !ccDep.RustLibraryInterface() {
3398 if libDepTag.wholeStatic {
3399 c.Properties.AndroidMkWholeStaticLibs = append(
3400 c.Properties.AndroidMkWholeStaticLibs, makeLibName)
3401 } else {
3402 c.Properties.AndroidMkStaticLibs = append(
3403 c.Properties.AndroidMkStaticLibs, makeLibName)
3404 }
Colin Cross6e511a92020-07-27 21:26:48 -07003405 }
3406 }
Jiyong Park1ad8e162020-12-01 23:40:09 +09003407 } else if !c.IsStubs() {
3408 // Stubs lib doesn't link to the runtime lib, object, crt, etc. dependencies.
3409
Colin Cross6e511a92020-07-27 21:26:48 -07003410 switch depTag {
3411 case runtimeDepTag:
3412 c.Properties.AndroidMkRuntimeLibs = append(
Spandan Das3faa7922024-02-26 19:42:32 +00003413 c.Properties.AndroidMkRuntimeLibs, MakeLibName(ctx, c, ccDep, ccDep.BaseModuleName())+libDepTag.makeSuffix)
Colin Cross6e511a92020-07-27 21:26:48 -07003414 case objDepTag:
3415 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
3416 case CrtBeginDepTag:
Colin Crossc465efd2021-06-11 18:00:04 -07003417 depPaths.CrtBegin = append(depPaths.CrtBegin, linkFile.Path())
Colin Cross6e511a92020-07-27 21:26:48 -07003418 case CrtEndDepTag:
Colin Crossc465efd2021-06-11 18:00:04 -07003419 depPaths.CrtEnd = append(depPaths.CrtEnd, linkFile.Path())
Colin Cross6e511a92020-07-27 21:26:48 -07003420 case dynamicLinkerDepTag:
3421 depPaths.DynamicLinker = linkFile
3422 }
Jiyong Park27b188b2017-07-18 13:23:39 +09003423 }
Colin Crossca860ac2016-01-04 14:34:37 -08003424 })
3425
Jeff Gaston294356f2017-09-27 17:05:30 -07003426 // use the ordered dependencies as this module's dependencies
Colin Cross0de8a1e2020-09-18 14:15:30 -07003427 orderedStaticPaths, transitiveStaticLibs := orderStaticModuleDeps(directStaticDeps, directSharedDeps)
3428 depPaths.TranstiveStaticLibrariesForOrdering = transitiveStaticLibs
3429 depPaths.StaticLibs = append(depPaths.StaticLibs, orderedStaticPaths...)
Jeff Gaston294356f2017-09-27 17:05:30 -07003430
Colin Crossdd84e052017-05-17 13:44:16 -07003431 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07003432 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09003433 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
3434 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09003435 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Ivan Lozano0a468a42024-05-13 21:03:34 -04003436 depPaths.RustRlibDeps = android.FirstUniqueFunc(depPaths.RustRlibDeps, EqRustRlibDeps)
3437
Jiyong Park74955042019-10-22 20:19:51 +09003438 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
3439 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07003440 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09003441 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09003442 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Ivan Lozano0a468a42024-05-13 21:03:34 -04003443 depPaths.ReexportedRustRlibDeps = android.FirstUniqueFunc(depPaths.ReexportedRustRlibDeps, EqRustRlibDeps)
Dan Willemsenfe92c962017-08-29 12:28:37 -07003444
3445 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09003446 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Hsin-Yi Chen5f228b02024-04-02 12:38:47 +08003447 c.sabi.Properties.ReexportedSystemIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedSystemIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07003448 }
Colin Crossdd84e052017-05-17 13:44:16 -07003449
Colin Crossca860ac2016-01-04 14:34:37 -08003450 return depPaths
3451}
3452
Spandan Das10c41362024-12-03 01:33:09 +00003453func ShouldUseStubForApex(ctx android.ModuleContext, parent, dep android.Module) bool {
Kiyoung Kimaa394802024-01-08 12:55:45 +09003454 inVendorOrProduct := false
Jiyong Park7d55b612021-06-11 17:22:09 +09003455 bootstrap := false
Spandan Das10c41362024-12-03 01:33:09 +00003456 if linkable, ok := parent.(LinkableInterface); !ok {
3457 ctx.ModuleErrorf("Not a Linkable module: %q", ctx.ModuleName())
Jiyong Park7d55b612021-06-11 17:22:09 +09003458 } else {
Kiyoung Kimaa394802024-01-08 12:55:45 +09003459 inVendorOrProduct = linkable.InVendorOrProduct()
Jiyong Park7d55b612021-06-11 17:22:09 +09003460 bootstrap = linkable.Bootstrap()
3461 }
3462
Spandan Das10c41362024-12-03 01:33:09 +00003463 apexInfo, _ := android.OtherModuleProvider(ctx, parent, android.ApexInfoProvider)
Kiyoung Kim76b06f32023-02-06 22:08:13 +09003464
3465 useStubs := false
3466
Kiyoung Kimaa394802024-01-08 12:55:45 +09003467 if lib := moduleLibraryInterface(dep); lib.buildStubs() && inVendorOrProduct { // LLNDK
Kiyoung Kim76b06f32023-02-06 22:08:13 +09003468 if !apexInfo.IsForPlatform() {
3469 // For platform libraries, use current version of LLNDK
3470 // If this is for use_vendor apex we will apply the same rules
3471 // of apex sdk enforcement below to choose right version.
3472 useStubs = true
3473 }
3474 } else if apexInfo.IsForPlatform() || apexInfo.UsePlatformApis {
3475 // If not building for APEX or the containing APEX allows the use of
3476 // platform APIs, use stubs only when it is from an APEX (and not from
3477 // platform) However, for host, ramdisk, vendor_ramdisk, recovery or
3478 // bootstrap modules, always link to non-stub variant
3479 isNotInPlatform := dep.(android.ApexModule).NotInPlatform()
3480
Spandan Dasff665182024-09-11 18:48:44 +00003481 useStubs = isNotInPlatform && !bootstrap
Kiyoung Kim76b06f32023-02-06 22:08:13 +09003482 } else {
Colin Crossea91a172024-11-05 16:14:05 -08003483 // If building for APEX, always use stubs (can be bypassed by depending on <dep>#impl)
3484 useStubs = true
Kiyoung Kim76b06f32023-02-06 22:08:13 +09003485 }
3486
3487 return useStubs
3488}
3489
3490// ChooseStubOrImpl determines whether a given dependency should be redirected to the stub variant
3491// of the dependency or not, and returns the SharedLibraryInfo and FlagExporterInfo for the right
3492// dependency. The stub variant is selected when the dependency crosses a boundary where each side
3493// has different level of updatability. For example, if a library foo in an APEX depends on a
3494// library bar which provides stable interface and exists in the platform, foo uses the stub variant
3495// of bar. If bar doesn't provide a stable interface (i.e. buildStubs() == false) or is in the
3496// same APEX as foo, the non-stub variant of bar is used.
3497func ChooseStubOrImpl(ctx android.ModuleContext, dep android.Module) (SharedLibraryInfo, FlagExporterInfo) {
3498 depTag := ctx.OtherModuleDependencyTag(dep)
3499 libDepTag, ok := depTag.(libraryDependencyTag)
3500 if !ok || !libDepTag.shared() {
3501 panic(fmt.Errorf("Unexpected dependency tag: %T", depTag))
3502 }
3503
Colin Cross313aa542023-12-13 13:47:44 -08003504 sharedLibraryInfo, _ := android.OtherModuleProvider(ctx, dep, SharedLibraryInfoProvider)
3505 depExporterInfo, _ := android.OtherModuleProvider(ctx, dep, FlagExporterInfoProvider)
3506 sharedLibraryStubsInfo, _ := android.OtherModuleProvider(ctx, dep, SharedLibraryStubsProvider)
Jiyong Park7d55b612021-06-11 17:22:09 +09003507
3508 if !libDepTag.explicitlyVersioned && len(sharedLibraryStubsInfo.SharedStubLibraries) > 0 {
Jiyong Park7d55b612021-06-11 17:22:09 +09003509 // when to use (unspecified) stubs, use the latest one.
Spandan Das10c41362024-12-03 01:33:09 +00003510 if ShouldUseStubForApex(ctx, ctx.Module(), dep) {
Jiyong Park7d55b612021-06-11 17:22:09 +09003511 stubs := sharedLibraryStubsInfo.SharedStubLibraries
3512 toUse := stubs[len(stubs)-1]
3513 sharedLibraryInfo = toUse.SharedLibraryInfo
3514 depExporterInfo = toUse.FlagExporterInfo
3515 }
3516 }
3517 return sharedLibraryInfo, depExporterInfo
3518}
3519
Colin Cross0de8a1e2020-09-18 14:15:30 -07003520// orderStaticModuleDeps rearranges the order of the static library dependencies of the module
3521// to match the topological order of the dependency tree, including any static analogues of
Colin Crossa14fb6a2024-10-23 16:57:06 -07003522// direct shared libraries. It returns the ordered static dependencies, and a depset.DepSet
Colin Cross0de8a1e2020-09-18 14:15:30 -07003523// of the transitive dependencies.
Colin Crossa14fb6a2024-10-23 16:57:06 -07003524func orderStaticModuleDeps(staticDeps []StaticLibraryInfo, sharedDeps []SharedLibraryInfo) (ordered android.Paths, transitive depset.DepSet[android.Path]) {
3525 transitiveStaticLibsBuilder := depset.NewBuilder[android.Path](depset.TOPOLOGICAL)
Colin Cross0de8a1e2020-09-18 14:15:30 -07003526 var staticPaths android.Paths
3527 for _, staticDep := range staticDeps {
3528 staticPaths = append(staticPaths, staticDep.StaticLibrary)
3529 transitiveStaticLibsBuilder.Transitive(staticDep.TransitiveStaticLibrariesForOrdering)
3530 }
3531 for _, sharedDep := range sharedDeps {
Colin Crossa14fb6a2024-10-23 16:57:06 -07003532 transitiveStaticLibsBuilder.Transitive(sharedDep.TransitiveStaticLibrariesForOrdering)
Colin Cross0de8a1e2020-09-18 14:15:30 -07003533 }
3534 transitiveStaticLibs := transitiveStaticLibsBuilder.Build()
3535
3536 orderedTransitiveStaticLibs := transitiveStaticLibs.ToList()
3537
3538 // reorder the dependencies based on transitive dependencies
3539 staticPaths = android.FirstUniquePaths(staticPaths)
3540 _, orderedStaticPaths := android.FilterPathList(orderedTransitiveStaticLibs, staticPaths)
3541
3542 if len(orderedStaticPaths) != len(staticPaths) {
3543 missing, _ := android.FilterPathList(staticPaths, orderedStaticPaths)
3544 panic(fmt.Errorf("expected %d ordered static paths , got %d, missing %q %q %q", len(staticPaths), len(orderedStaticPaths), missing, orderedStaticPaths, staticPaths))
3545 }
3546
3547 return orderedStaticPaths, transitiveStaticLibs
3548}
3549
Ivan Lozanod67a6b02021-05-20 13:01:32 -04003550// BaseLibName trims known prefixes and suffixes
3551func BaseLibName(depName string) string {
Colin Cross6e511a92020-07-27 21:26:48 -07003552 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
3553 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Paul Duffind23c7262020-12-11 18:13:08 +00003554 libName = android.RemoveOptionalPrebuiltPrefix(libName)
Colin Cross6e511a92020-07-27 21:26:48 -07003555 return libName
3556}
3557
Ivan Lozanoc08897c2021-04-02 12:41:32 -04003558func MakeLibName(ctx android.ModuleContext, c LinkableInterface, ccDep LinkableInterface, depName string) string {
Ivan Lozanod67a6b02021-05-20 13:01:32 -04003559 libName := BaseLibName(depName)
Colin Cross127bb8b2020-12-16 16:46:01 -08003560 ccDepModule, _ := ccDep.(*Module)
3561 isLLndk := ccDepModule != nil && ccDepModule.IsLlndk()
Justin Yuncbca3732021-02-03 19:24:13 +09003562 nonSystemVariantsExist := ccDep.HasNonSystemVariants() || isLLndk
Colin Cross6e511a92020-07-27 21:26:48 -07003563
Justin Yuncbca3732021-02-03 19:24:13 +09003564 if ccDepModule != nil {
Colin Cross6e511a92020-07-27 21:26:48 -07003565 // Use base module name for snapshots when exporting to Makefile.
Ivan Lozanod1dec542021-05-26 15:33:11 -04003566 if snapshotPrebuilt, ok := ccDepModule.linker.(SnapshotInterface); ok {
Justin Yuncbca3732021-02-03 19:24:13 +09003567 baseName := ccDepModule.BaseModuleName()
Colin Cross6e511a92020-07-27 21:26:48 -07003568
Ivan Lozanod1dec542021-05-26 15:33:11 -04003569 return baseName + snapshotPrebuilt.SnapshotAndroidMkSuffix()
Colin Cross6e511a92020-07-27 21:26:48 -07003570 }
3571 }
3572
Kiyoung Kim22152f62024-05-24 10:45:28 +09003573 if ccDep.InVendorOrProduct() && nonSystemVariantsExist {
Justin Yuncbca3732021-02-03 19:24:13 +09003574 // The vendor and product modules in Make will have been renamed to not conflict with the
3575 // core module, so update the dependency name here accordingly.
Ivan Lozanoc08897c2021-04-02 12:41:32 -04003576 return libName + ccDep.SubName()
Colin Cross6e511a92020-07-27 21:26:48 -07003577 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
Matthew Maurerc6868382021-07-13 14:12:37 -07003578 return libName + RamdiskSuffix
Yifan Hong60e0cfb2020-10-21 15:17:56 -07003579 } else if ccDep.InVendorRamdisk() && !ccDep.OnlyInVendorRamdisk() {
Ivan Lozanoe6d30982021-02-05 10:57:43 -05003580 return libName + VendorRamdiskSuffix
Colin Cross6e511a92020-07-27 21:26:48 -07003581 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Matthew Maurer460ee942021-02-11 12:31:46 -08003582 return libName + RecoverySuffix
Ivan Lozanof9e21722020-12-02 09:00:51 -05003583 } else if ccDep.Target().NativeBridge == android.NativeBridgeEnabled {
Matthew Maurera61e31f2021-05-27 11:09:11 -07003584 return libName + NativeBridgeSuffix
Colin Cross6e511a92020-07-27 21:26:48 -07003585 } else {
3586 return libName
3587 }
3588}
3589
Colin Crossca860ac2016-01-04 14:34:37 -08003590func (c *Module) InstallInData() bool {
3591 if c.installer == nil {
3592 return false
3593 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07003594 return c.installer.inData()
3595}
3596
3597func (c *Module) InstallInSanitizerDir() bool {
3598 if c.installer == nil {
3599 return false
3600 }
3601 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07003602 return true
3603 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07003604 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08003605}
3606
Yifan Hong1b3348d2020-01-21 15:53:22 -08003607func (c *Module) InstallInRamdisk() bool {
3608 return c.InRamdisk()
3609}
3610
Yifan Hong60e0cfb2020-10-21 15:17:56 -07003611func (c *Module) InstallInVendorRamdisk() bool {
3612 return c.InVendorRamdisk()
3613}
3614
Jiyong Parkf9332f12018-02-01 00:54:12 +09003615func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07003616 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09003617}
3618
Jingwen Chen8ac7d7d2023-03-20 11:05:16 +00003619func (c *Module) MakeUninstallable() {
3620 if c.installer == nil {
3621 c.ModuleBase.MakeUninstallable()
3622 return
3623 }
3624 c.installer.makeUninstallable(c)
3625}
3626
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07003627func (c *Module) HostToolPath() android.OptionalPath {
3628 if c.installer == nil {
3629 return android.OptionalPath{}
3630 }
3631 return c.installer.hostToolPath()
3632}
3633
Nan Zhangd4e641b2017-07-12 12:55:28 -07003634func (c *Module) IntermPathForModuleOut() android.OptionalPath {
3635 return c.outputFile
3636}
3637
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00003638func (c *Module) static() bool {
3639 if static, ok := c.linker.(interface {
3640 static() bool
3641 }); ok {
3642 return static.static()
3643 }
3644 return false
3645}
3646
Colin Cross6a730042024-12-05 13:53:43 -08003647func (c *Module) staticLibrary() bool {
3648 if static, ok := c.linker.(interface {
3649 staticLibrary() bool
3650 }); ok {
3651 return static.staticLibrary()
3652 }
3653 return false
3654}
3655
Jiyong Park379de2f2018-12-19 02:47:14 +09003656func (c *Module) staticBinary() bool {
3657 if static, ok := c.linker.(interface {
3658 staticBinary() bool
3659 }); ok {
3660 return static.staticBinary()
3661 }
3662 return false
3663}
3664
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003665func (c *Module) testBinary() bool {
3666 if test, ok := c.linker.(interface {
3667 testBinary() bool
3668 }); ok {
3669 return test.testBinary()
3670 }
3671 return false
3672}
3673
Jingwen Chen537242c2022-08-24 11:53:27 +00003674func (c *Module) testLibrary() bool {
3675 if test, ok := c.linker.(interface {
3676 testLibrary() bool
3677 }); ok {
3678 return test.testLibrary()
3679 }
3680 return false
3681}
3682
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003683func (c *Module) benchmarkBinary() bool {
3684 if b, ok := c.linker.(interface {
3685 benchmarkBinary() bool
3686 }); ok {
3687 return b.benchmarkBinary()
3688 }
3689 return false
3690}
3691
3692func (c *Module) fuzzBinary() bool {
3693 if f, ok := c.linker.(interface {
3694 fuzzBinary() bool
3695 }); ok {
3696 return f.fuzzBinary()
3697 }
3698 return false
3699}
3700
Ivan Lozano3968d8f2020-12-14 11:27:52 -05003701// Header returns true if the module is a header-only variant. (See cc/library.go header()).
3702func (c *Module) Header() bool {
Jiyong Park1d1119f2019-07-29 21:27:18 +09003703 if h, ok := c.linker.(interface {
3704 header() bool
3705 }); ok {
3706 return h.header()
3707 }
3708 return false
3709}
3710
Ivan Lozanod7586b62021-04-01 09:49:36 -04003711func (c *Module) Binary() bool {
Inseob Kim7f283f42020-06-01 21:53:49 +09003712 if b, ok := c.linker.(interface {
3713 binary() bool
3714 }); ok {
3715 return b.binary()
3716 }
3717 return false
3718}
3719
Justin Yun5e035862021-06-29 20:50:37 +09003720func (c *Module) StaticExecutable() bool {
3721 if b, ok := c.linker.(*binaryDecorator); ok {
3722 return b.static()
3723 }
3724 return false
3725}
3726
Ivan Lozanod7586b62021-04-01 09:49:36 -04003727func (c *Module) Object() bool {
Inseob Kim1042d292020-06-01 23:23:05 +09003728 if o, ok := c.linker.(interface {
3729 object() bool
3730 }); ok {
3731 return o.object()
3732 }
3733 return false
3734}
3735
Kiyoung Kim37693d02024-04-04 09:56:15 +09003736func (m *Module) Dylib() bool {
3737 return false
3738}
3739
3740func (m *Module) Rlib() bool {
3741 return false
3742}
3743
Ivan Lozanof9e21722020-12-02 09:00:51 -05003744func GetMakeLinkType(actx android.ModuleContext, c LinkableInterface) string {
Kiyoung Kim8487c0b2024-01-11 16:03:13 +09003745 if c.InVendorOrProduct() {
Colin Cross127bb8b2020-12-16 16:46:01 -08003746 if c.IsLlndk() {
Ivan Lozanof9e21722020-12-02 09:00:51 -05003747 return "native:vndk"
Jooyung Han38002912019-05-16 04:01:54 +09003748 }
Ivan Lozanof9e21722020-12-02 09:00:51 -05003749 if c.InProduct() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003750 return "native:product"
3751 }
Jooyung Han38002912019-05-16 04:01:54 +09003752 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08003753 } else if c.InRamdisk() {
3754 return "native:ramdisk"
Yifan Hong60e0cfb2020-10-21 15:17:56 -07003755 } else if c.InVendorRamdisk() {
3756 return "native:vendor_ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07003757 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07003758 return "native:recovery"
Ivan Lozanof9e21722020-12-02 09:00:51 -05003759 } else if c.Target().Os == android.Android && c.SdkVersion() != "" {
Colin Crossb60190a2018-09-04 16:28:17 -07003760 return "native:ndk:none:none"
3761 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
3762 //family, link := getNdkStlFamilyAndLinkType(c)
3763 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
3764 } else {
3765 return "native:platform"
3766 }
3767}
3768
Jiyong Park9d452992018-10-03 00:38:19 +09003769// Overrides ApexModule.IsInstallabeToApex()
Colin Cross3a02c7b2024-05-21 13:46:22 -07003770// Only shared/runtime libraries .
Jiyong Park9d452992018-10-03 00:38:19 +09003771func (c *Module) IsInstallableToApex() bool {
Colin Cross31076b32020-10-23 17:22:06 -07003772 if lib := c.library; lib != nil {
Jiyong Park73c54ee2019-10-22 20:31:18 +09003773 // Stub libs and prebuilt libs in a versioned SDK are not
3774 // installable to APEX even though they are shared libs.
Paul Duffin458a15b2022-11-25 12:18:24 +00003775 return lib.shared() && !lib.buildStubs()
Jiyong Park9d452992018-10-03 00:38:19 +09003776 }
3777 return false
3778}
3779
Jiyong Parka90ca002019-10-07 15:47:24 +09003780func (c *Module) AvailableFor(what string) bool {
Yu Liub73c3a62024-12-10 00:58:06 +00003781 return android.CheckAvailableForApex(what, c.ApexAvailableFor())
3782}
3783
3784func (c *Module) ApexAvailableFor() []string {
3785 list := c.ApexModuleBase.ApexAvailable()
Jiyong Parka90ca002019-10-07 15:47:24 +09003786 if linker, ok := c.linker.(interface {
Yu Liub73c3a62024-12-10 00:58:06 +00003787 apexAvailable() []string
Jiyong Parka90ca002019-10-07 15:47:24 +09003788 }); ok {
Yu Liub73c3a62024-12-10 00:58:06 +00003789 list = append(list, linker.apexAvailable()...)
Jiyong Parka90ca002019-10-07 15:47:24 +09003790 }
Yu Liub73c3a62024-12-10 00:58:06 +00003791
3792 return android.FirstUniqueStrings(list)
Jiyong Parka90ca002019-10-07 15:47:24 +09003793}
3794
Paul Duffin0cb37b92020-03-04 14:52:46 +00003795func (c *Module) EverInstallable() bool {
3796 return c.installer != nil &&
3797 // Check to see whether the module is actually ever installable.
3798 c.installer.everInstallable()
3799}
3800
Ivan Lozanod7586b62021-04-01 09:49:36 -04003801func (c *Module) PreventInstall() bool {
3802 return c.Properties.PreventInstall
3803}
3804
3805func (c *Module) Installable() *bool {
Colin Cross1bc94122021-10-28 13:25:54 -07003806 if c.library != nil {
3807 if i := c.library.installable(); i != nil {
3808 return i
3809 }
3810 }
Ivan Lozanod7586b62021-04-01 09:49:36 -04003811 return c.Properties.Installable
3812}
3813
3814func installable(c LinkableInterface, apexInfo android.ApexInfo) bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00003815 ret := c.EverInstallable() &&
3816 // Check to see whether the module has been configured to not be installed.
Ivan Lozanod7586b62021-04-01 09:49:36 -04003817 proptools.BoolDefault(c.Installable(), true) &&
3818 !c.PreventInstall() && c.OutputFile().Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09003819
3820 // The platform variant doesn't need further condition. Apex variants however might not
3821 // be installable because it will likely to be included in the APEX and won't appear
3822 // in the system partition.
Colin Cross56a83212020-09-15 18:30:11 -07003823 if apexInfo.IsForPlatform() {
Jiyong Parkfe9a4302020-01-07 16:59:44 +09003824 return ret
3825 }
3826
3827 // Special case for modules that are configured to be installed to /data, which includes
3828 // test modules. For these modules, both APEX and non-APEX variants are considered as
3829 // installable. This is because even the APEX variants won't be included in the APEX, but
3830 // will anyway be installed to /data/*.
3831 // See b/146995717
3832 if c.InstallInData() {
3833 return ret
3834 }
3835
3836 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09003837}
3838
Logan Chien41eabe62019-04-10 13:33:58 +08003839func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
3840 if c.linker != nil {
3841 if library, ok := c.linker.(*libraryDecorator); ok {
3842 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
3843 }
3844 }
3845}
3846
Jiyong Park45bf82e2020-12-15 22:29:02 +09003847var _ android.ApexModule = (*Module)(nil)
3848
3849// Implements android.ApexModule
Colin Crossf7bbd2f2024-12-05 13:57:10 -08003850func (c *Module) OutgoingDepIsInSameApex(depTag blueprint.DependencyTag) bool {
Colin Crossc1b36442021-05-06 13:42:48 -07003851 if depTag == stubImplDepTag {
3852 // We don't track from an implementation library to its stubs.
Jiyong Park7d95a512020-05-10 15:16:24 +09003853 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003854 }
Jiyong Park12177fc2021-01-05 14:37:15 +09003855 if depTag == staticVariantTag {
3856 // This dependency is for optimization (reuse *.o from the static lib). It doesn't
3857 // actually mean that the static lib (and its dependencies) are copied into the
3858 // APEX.
3859 return false
3860 }
Colin Cross8acea3e2024-12-12 14:53:30 -08003861
3862 libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
3863 if isLibDepTag && c.static() && libDepTag.shared() {
3864 // shared_lib dependency from a static lib is considered as crossing
3865 // the APEX boundary because the dependency doesn't actually is
3866 // linked; the dependency is used only during the compilation phase.
3867 return false
3868 }
3869
3870 if isLibDepTag && libDepTag.excludeInApex {
3871 return false
3872 }
3873
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003874 return true
3875}
3876
Colin Crossf7bbd2f2024-12-05 13:57:10 -08003877func (c *Module) IncomingDepIsInSameApex(depTag blueprint.DependencyTag) bool {
Colin Crossf7bbd2f2024-12-05 13:57:10 -08003878 if c.HasStubsVariants() {
3879 if IsSharedDepTag(depTag) {
3880 // dynamic dep to a stubs lib crosses APEX boundary
3881 return false
3882 }
3883 if IsRuntimeDepTag(depTag) {
3884 // runtime dep to a stubs lib also crosses APEX boundary
3885 return false
3886 }
3887 if IsHeaderDepTag(depTag) {
3888 return false
3889 }
3890 }
3891 if c.IsLlndk() {
3892 return false
3893 }
Colin Crossf7bbd2f2024-12-05 13:57:10 -08003894
3895 return true
3896}
3897
Jiyong Park45bf82e2020-12-15 22:29:02 +09003898// Implements android.ApexModule
Dan Albertc8060532020-07-22 22:32:17 -07003899func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
3900 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +09003901 // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
3902 if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
3903 return nil
3904 }
Jooyung Han749dc692020-04-15 11:03:39 +09003905 // We don't check for prebuilt modules
3906 if _, ok := c.linker.(prebuiltLinkerInterface); ok {
3907 return nil
3908 }
Kiyoung Kim487689e2022-07-26 09:48:22 +09003909
Jooyung Han749dc692020-04-15 11:03:39 +09003910 minSdkVersion := c.MinSdkVersion()
3911 if minSdkVersion == "apex_inherit" {
3912 return nil
3913 }
3914 if minSdkVersion == "" {
3915 // JNI libs within APK-in-APEX fall into here
3916 // Those are okay to set sdk_version instead
3917 // We don't have to check if this is a SDK variant because
3918 // non-SDK variant resets sdk_version, which works too.
3919 minSdkVersion = c.SdkVersion()
3920 }
Dan Albertc8060532020-07-22 22:32:17 -07003921 if minSdkVersion == "" {
3922 return fmt.Errorf("neither min_sdk_version nor sdk_version specificed")
3923 }
3924 // Not using nativeApiLevelFromUser because the context here is not
3925 // necessarily a native context.
3926 ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
Jooyung Han749dc692020-04-15 11:03:39 +09003927 if err != nil {
3928 return err
3929 }
Dan Albertc8060532020-07-22 22:32:17 -07003930
Colin Cross8ca61c12022-10-06 21:00:14 -07003931 // A dependency only needs to support a min_sdk_version at least
3932 // as high as the api level that the architecture was introduced in.
3933 // This allows introducing new architectures in the platform that
3934 // need to be included in apexes that normally require an older
3935 // min_sdk_version.
Colin Crossbb137a32023-01-26 09:54:42 -08003936 minApiForArch := MinApiForArch(ctx, c.Target().Arch.ArchType)
Colin Cross8ca61c12022-10-06 21:00:14 -07003937 if sdkVersion.LessThan(minApiForArch) {
3938 sdkVersion = minApiForArch
3939 }
3940
Dan Albertc8060532020-07-22 22:32:17 -07003941 if ver.GreaterThan(sdkVersion) {
Jooyung Han749dc692020-04-15 11:03:39 +09003942 return fmt.Errorf("newer SDK(%v)", ver)
3943 }
3944 return nil
3945}
3946
Paul Duffinb5769c12021-05-12 16:16:51 +01003947// Implements android.ApexModule
3948func (c *Module) AlwaysRequiresPlatformApexVariant() bool {
3949 // stub libraries and native bridge libraries are always available to platform
3950 return c.IsStubs() || c.Target().NativeBridge == android.NativeBridgeEnabled
3951}
3952
Inseob Kima1888ce2022-10-04 14:42:02 +09003953func (c *Module) overriddenModules() []string {
3954 if o, ok := c.linker.(overridable); ok {
3955 return o.overriddenModules()
3956 }
3957 return nil
3958}
3959
Liz Kammer35ca77e2021-12-22 15:31:40 -05003960type moduleType int
3961
3962const (
3963 unknownType moduleType = iota
3964 binary
3965 object
3966 fullLibrary
3967 staticLibrary
3968 sharedLibrary
3969 headerLibrary
Jingwen Chen537242c2022-08-24 11:53:27 +00003970 testBin // testBinary already declared
Spandan Das1278c2c2022-08-19 18:17:28 +00003971 ndkLibrary
Liz Kammer35ca77e2021-12-22 15:31:40 -05003972)
3973
3974func (c *Module) typ() moduleType {
Jingwen Chen537242c2022-08-24 11:53:27 +00003975 if c.testBinary() {
3976 // testBinary is also a binary, so this comes before the c.Binary()
3977 // conditional. A testBinary has additional implicit dependencies and
3978 // other test-only semantics.
3979 return testBin
3980 } else if c.Binary() {
Liz Kammer35ca77e2021-12-22 15:31:40 -05003981 return binary
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003982 } else if c.Object() {
Liz Kammer35ca77e2021-12-22 15:31:40 -05003983 return object
Jingwen Chen537242c2022-08-24 11:53:27 +00003984 } else if c.testLibrary() {
3985 // TODO(b/244431896) properly convert cc_test_library to its own macro. This
3986 // will let them add implicit compile deps on gtest, for example.
3987 //
Liz Kammerefc51d92023-04-21 15:11:25 -04003988 // For now, treat them as regular libraries.
3989 return fullLibrary
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003990 } else if c.CcLibrary() {
Chris Parsons58852a02021-12-09 18:10:18 -05003991 static := false
3992 shared := false
3993 if library, ok := c.linker.(*libraryDecorator); ok {
3994 static = library.MutatedProperties.BuildStatic
3995 shared = library.MutatedProperties.BuildShared
3996 } else if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
3997 static = library.MutatedProperties.BuildStatic
3998 shared = library.MutatedProperties.BuildShared
3999 }
Liz Kammerbe46fcc2021-11-01 15:32:43 -04004000 if static && shared {
Liz Kammer35ca77e2021-12-22 15:31:40 -05004001 return fullLibrary
Liz Kammerbe46fcc2021-11-01 15:32:43 -04004002 } else if !static && !shared {
Liz Kammer35ca77e2021-12-22 15:31:40 -05004003 return headerLibrary
Liz Kammerbe46fcc2021-11-01 15:32:43 -04004004 } else if static {
Liz Kammer35ca77e2021-12-22 15:31:40 -05004005 return staticLibrary
4006 }
4007 return sharedLibrary
Spandan Das1278c2c2022-08-19 18:17:28 +00004008 } else if c.isNDKStubLibrary() {
4009 return ndkLibrary
Liz Kammer35ca77e2021-12-22 15:31:40 -05004010 }
4011 return unknownType
4012}
4013
Colin Crosscfad1192015-11-02 16:43:11 -08004014// Defaults
Colin Crossca860ac2016-01-04 14:34:37 -08004015type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07004016 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07004017 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09004018 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08004019}
4020
Patrice Arrudac249c712019-03-19 17:00:29 -07004021// cc_defaults provides a set of properties that can be inherited by other cc
4022// modules. A module can use the properties from a cc_defaults using
4023// `defaults: ["<:default_module_name>"]`. Properties of both modules are
4024// merged (when possible) by prepending the default module's values to the
4025// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07004026func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07004027 return DefaultsFactory()
4028}
4029
Colin Cross36242852017-06-23 15:06:31 -07004030func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08004031 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08004032
Colin Cross36242852017-06-23 15:06:31 -07004033 module.AddProperties(props...)
4034 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08004035 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07004036 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08004037 &BaseCompilerProperties{},
4038 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01004039 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07004040 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07004041 &StaticProperties{},
4042 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07004043 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08004044 &BinaryLinkerProperties{},
Trevor Radcliffef389cb42022-03-24 21:06:14 +00004045 &TestLinkerProperties{},
4046 &TestInstallerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07004047 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07004048 &BenchmarkProperties{},
hamzehc0a671f2021-07-22 12:05:08 -07004049 &fuzz.FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08004050 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08004051 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07004052 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07004053 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07004054 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08004055 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08004056 &SAbiProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07004057 &LTOProperties{},
Yi Kongeb8efc92021-12-09 18:06:29 +08004058 &AfdoProperties{},
Sharjeel Khanc6a93d82023-07-18 21:01:11 +00004059 &OrderfileProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08004060 &android.ProtoProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -04004061 // RustBindgenProperties is included here so that cc_defaults can be used for rust_bindgen modules.
4062 &RustBindgenClangProperties{},
Yu-Chi Cheng24b2b0f2021-06-23 15:56:39 -07004063 &prebuiltLinkerProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07004064 )
Colin Crosscfad1192015-11-02 16:43:11 -08004065
Jooyung Hancc372c52019-09-25 15:18:44 +09004066 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07004067
4068 return module
Colin Crosscfad1192015-11-02 16:43:11 -08004069}
4070
Jiyong Park2286afd2020-06-16 21:58:53 +09004071func (c *Module) IsSdkVariant() bool {
Lukacs T. Berki2063a0d2021-06-17 09:32:36 +02004072 return c.Properties.IsSdkVariant
Jiyong Park2286afd2020-06-16 21:58:53 +09004073}
4074
Sasha Smundak2a4549e2018-11-05 16:49:08 -08004075func kytheExtractAllFactory() android.Singleton {
4076 return &kytheExtractAllSingleton{}
4077}
4078
4079type kytheExtractAllSingleton struct {
4080}
4081
4082func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
4083 var xrefTargets android.Paths
Yu Liuec7043d2024-11-05 18:22:20 +00004084 ctx.VisitAllModuleProxies(func(module android.ModuleProxy) {
Yu Liu4f825132024-12-18 00:35:39 +00004085 files := android.OtherModuleProviderOrDefault(ctx, module, CcObjectInfoProvider).KytheFiles
Yu Liuec7043d2024-11-05 18:22:20 +00004086 if len(files) > 0 {
4087 xrefTargets = append(xrefTargets, files...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08004088 }
4089 })
4090 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
4091 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07004092 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08004093 }
4094}
4095
Jihoon Kangf78a8902022-09-01 22:47:07 +00004096func (c *Module) Partition() string {
4097 if p, ok := c.installer.(interface {
4098 getPartition() string
4099 }); ok {
4100 return p.getPartition()
4101 }
4102 return ""
4103}
4104
Spandan Das2b6dfb52024-01-19 00:22:22 +00004105type sourceModuleName interface {
4106 sourceModuleName() string
4107}
4108
4109func (c *Module) BaseModuleName() string {
4110 if smn, ok := c.linker.(sourceModuleName); ok && smn.sourceModuleName() != "" {
4111 // if the prebuilt module sets a source_module_name in Android.bp, use that
4112 return smn.sourceModuleName()
4113 }
4114 return c.ModuleBase.BaseModuleName()
4115}
4116
Spandan Dase20c56c2024-07-23 21:34:24 +00004117func (c *Module) stubsSymbolFilePath() android.Path {
4118 if library, ok := c.linker.(*libraryDecorator); ok {
4119 return library.stubsSymbolFilePath
4120 }
4121 return android.OptionalPath{}.Path()
4122}
4123
Colin Cross06a931b2015-10-28 17:23:31 -07004124var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07004125var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08004126var BoolPtr = proptools.BoolPtr
4127var String = proptools.String
4128var StringPtr = proptools.StringPtr